{"id":7755,"date":"2023-03-03T14:47:31","date_gmt":"2023-03-03T13:47:31","guid":{"rendered":"https:\/\/www.iprog.it\/blog\/?p=7755"},"modified":"2023-03-03T14:47:34","modified_gmt":"2023-03-03T13:47:34","slug":"patch-an-ios-application-with-frida","status":"publish","type":"post","link":"https:\/\/www.iprog.it\/blog\/sicurezza-informatica\/patch-an-ios-application-with-frida\/","title":{"rendered":"Patch an iOS application with frida"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2019\/07\/frida-twitter-profile.png\" rel=\"lightbox[7755]\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2019\/07\/frida-twitter-profile.png\" alt=\"\" class=\"wp-image-7378\" width=\"219\" height=\"219\" srcset=\"https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2019\/07\/frida-twitter-profile.png 400w, https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2019\/07\/frida-twitter-profile-300x300.png 300w, https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2019\/07\/frida-twitter-profile-176x176.png 176w, https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2019\/07\/frida-twitter-profile-60x60.png 60w, https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2019\/07\/frida-twitter-profile-150x150.png 150w\" sizes=\"auto, (max-width: 219px) 100vw, 219px\" \/><\/a><figcaption>The purpose of this blog is to show you how to patch an iOS application using Frida, but first, it is necessary to explain what an application patcher is.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Patching an iOS application with Frida involves injecting custom code into the application&#8217;s runtime to modify its behavior. Tools like Hopper, Ghidra, and others can typically be used to modify an application&#8217;s opcode and patch it but this is another topic.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Demo<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In the upcoming demonstration, we will be patching an iOS application that verifies if the device is jailbroken. This will involve utilizing NOP code on the bl instruction, which stands for Branch with Link.<br>As first thing we need to download the iOS application from <a href=\"https:\/\/drive.google.com\/file\/d\/1BrMHu4Zvs0ZxAlb123hXTTIMLYdjazFn\/view?usp=share_link\">here<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2023\/03\/Untitled_2.png\" rel=\"lightbox[7755]\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"330\" src=\"https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2023\/03\/Untitled_2-940x330.png\" alt=\"\" class=\"wp-image-7756\" srcset=\"https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2023\/03\/Untitled_2-940x330.png 940w, https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2023\/03\/Untitled_2-620x218.png 620w, https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2023\/03\/Untitled_2-300x105.png 300w, https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2023\/03\/Untitled_2-768x270.png 768w, https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2023\/03\/Untitled_2-1536x539.png 1536w, https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2023\/03\/Untitled_2-624x219.png 624w, https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2023\/03\/Untitled_2.png 1758w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/a><figcaption>Upon analyzing the binary using Hopper, we can observe that the check function invokes the isJailbroken function. To avoid the detection of a jailbroken device, we will replace the bl instruction with a nop instruction, which will skip the invocation of isJailbroken function and prevent detection.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">To achieve that we will use the following Frida script:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var targetModule=Process.enumerateModulesSync()&#91;0].name\nvar addr=ptr(0x5bac);\nvar moduleBase=Module.getBaseAddress(targetModule);\nvar targetAddress=moduleBase.add(addr);\n\n\nMemory.patchCode(targetAddress, 4, code => {\n    let cs = new Arm64Writer(code, { pc: code });\n    cs.putNop()\n    cs.flush();\n});\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Instead to use <strong>cs.putNop<\/strong> we could use the following instruction <strong>cs.putInstruction(0x1F2003D5)<\/strong> where <strong>0x1F2003D5 <\/strong>is the equivalent of the Nop op code in Hex.<br>To convert arm instruction to hex and viceversa I usally use the following website: https:\/\/armconverter.com\/?disasm&amp;code=1F2003D5%0A<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Other usefull links are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>https:\/\/developer.arm.com\/<\/li><li>https:\/\/frida.re\/docs\/javascript-api\/#armwriter<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Patching an iOS application with Frida involves injecting custom code into the application&#8217;s runtime to modify its behavior. Tools like Hopper, Ghidra, and others can typically be used to modify an application&#8217;s opcode and patch it but this is another topic. Demo In the upcoming demonstration, we will be patching&#8230; <a href=\"https:\/\/www.iprog.it\/blog\/sicurezza-informatica\/patch-an-ios-application-with-frida\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":7378,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2259],"tags":[2371,2546],"class_list":["post-7755","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sicurezza-informatica","tag-ethical-hacking","tag-mobilesecurity"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Patch an iOS application with frida - iProg<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.iprog.it\/blog\/sicurezza-informatica\/patch-an-ios-application-with-frida\/\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Patch an iOS application with frida - iProg\" \/>\n<meta name=\"twitter:description\" content=\"Patching an iOS application with Frida involves injecting custom code into the application&#8217;s runtime to modify its behavior. Tools like Hopper, Ghidra, and others can typically be used to modify an application&#8217;s opcode and patch it but this is another topic. Demo In the upcoming demonstration, we will be patching... Read more &raquo;\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2019\/07\/frida-twitter-profile.png\" \/>\n<meta name=\"twitter:creator\" content=\"@flexkid1\" \/>\n<meta name=\"twitter:site\" content=\"@iprogblog\" \/>\n<meta name=\"twitter:label1\" content=\"Scritto da\" \/>\n\t<meta name=\"twitter:data1\" content=\"Diego\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo di lettura stimato\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/sicurezza-informatica\\\/patch-an-ios-application-with-frida\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/sicurezza-informatica\\\/patch-an-ios-application-with-frida\\\/\"},\"author\":{\"name\":\"Diego\",\"@id\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/#\\\/schema\\\/person\\\/048c8acb70f8a33f1498675ab9db41a3\"},\"headline\":\"Patch an iOS application with frida\",\"datePublished\":\"2023-03-03T13:47:31+00:00\",\"dateModified\":\"2023-03-03T13:47:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/sicurezza-informatica\\\/patch-an-ios-application-with-frida\\\/\"},\"wordCount\":248,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/sicurezza-informatica\\\/patch-an-ios-application-with-frida\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/frida-twitter-profile.png\",\"keywords\":[\"Ethical hacking\",\"MobileSecurity\"],\"articleSection\":[\"Sicurezza Informatica\"],\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.iprog.it\\\/blog\\\/sicurezza-informatica\\\/patch-an-ios-application-with-frida\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/sicurezza-informatica\\\/patch-an-ios-application-with-frida\\\/\",\"url\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/sicurezza-informatica\\\/patch-an-ios-application-with-frida\\\/\",\"name\":\"Patch an iOS application with frida - iProg\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/sicurezza-informatica\\\/patch-an-ios-application-with-frida\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/sicurezza-informatica\\\/patch-an-ios-application-with-frida\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/frida-twitter-profile.png\",\"datePublished\":\"2023-03-03T13:47:31+00:00\",\"dateModified\":\"2023-03-03T13:47:34+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/#\\\/schema\\\/person\\\/048c8acb70f8a33f1498675ab9db41a3\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.iprog.it\\\/blog\\\/sicurezza-informatica\\\/patch-an-ios-application-with-frida\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/sicurezza-informatica\\\/patch-an-ios-application-with-frida\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/frida-twitter-profile.png\",\"contentUrl\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/frida-twitter-profile.png\",\"width\":400,\"height\":400},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/\",\"name\":\"iProg\",\"description\":\"perch\u00e9 reinventare la ruota?\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/#\\\/schema\\\/person\\\/048c8acb70f8a33f1498675ab9db41a3\",\"name\":\"Diego\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bf8084effa4627f8e50af0d50d06b0677e4a9de5e895e347c0590ad5696fdfc9?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bf8084effa4627f8e50af0d50d06b0677e4a9de5e895e347c0590ad5696fdfc9?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bf8084effa4627f8e50af0d50d06b0677e4a9de5e895e347c0590ad5696fdfc9?s=96&r=g\",\"caption\":\"Diego\"},\"description\":\"Google+\",\"sameAs\":[\"http:\\\/\\\/it.linkedin.com\\\/in\\\/diegocaridei\\\/\",\"https:\\\/\\\/x.com\\\/flexkid1\",\"http:\\\/\\\/www.youtube.com\\\/channel\\\/UCjQ2z1ygV9tv55QAc2q3JHA\"],\"url\":\"https:\\\/\\\/www.iprog.it\\\/blog\\\/author\\\/flexkid\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Patch an iOS application with frida - iProg","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.iprog.it\/blog\/sicurezza-informatica\/patch-an-ios-application-with-frida\/","twitter_card":"summary_large_image","twitter_title":"Patch an iOS application with frida - iProg","twitter_description":"Patching an iOS application with Frida involves injecting custom code into the application&#8217;s runtime to modify its behavior. Tools like Hopper, Ghidra, and others can typically be used to modify an application&#8217;s opcode and patch it but this is another topic. Demo In the upcoming demonstration, we will be patching... Read more &raquo;","twitter_image":"https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2019\/07\/frida-twitter-profile.png","twitter_creator":"@flexkid1","twitter_site":"@iprogblog","twitter_misc":{"Scritto da":"Diego","Tempo di lettura stimato":"2 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.iprog.it\/blog\/sicurezza-informatica\/patch-an-ios-application-with-frida\/#article","isPartOf":{"@id":"https:\/\/www.iprog.it\/blog\/sicurezza-informatica\/patch-an-ios-application-with-frida\/"},"author":{"name":"Diego","@id":"https:\/\/www.iprog.it\/blog\/#\/schema\/person\/048c8acb70f8a33f1498675ab9db41a3"},"headline":"Patch an iOS application with frida","datePublished":"2023-03-03T13:47:31+00:00","dateModified":"2023-03-03T13:47:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.iprog.it\/blog\/sicurezza-informatica\/patch-an-ios-application-with-frida\/"},"wordCount":248,"commentCount":0,"image":{"@id":"https:\/\/www.iprog.it\/blog\/sicurezza-informatica\/patch-an-ios-application-with-frida\/#primaryimage"},"thumbnailUrl":"https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2019\/07\/frida-twitter-profile.png","keywords":["Ethical hacking","MobileSecurity"],"articleSection":["Sicurezza Informatica"],"inLanguage":"it-IT","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.iprog.it\/blog\/sicurezza-informatica\/patch-an-ios-application-with-frida\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.iprog.it\/blog\/sicurezza-informatica\/patch-an-ios-application-with-frida\/","url":"https:\/\/www.iprog.it\/blog\/sicurezza-informatica\/patch-an-ios-application-with-frida\/","name":"Patch an iOS application with frida - iProg","isPartOf":{"@id":"https:\/\/www.iprog.it\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.iprog.it\/blog\/sicurezza-informatica\/patch-an-ios-application-with-frida\/#primaryimage"},"image":{"@id":"https:\/\/www.iprog.it\/blog\/sicurezza-informatica\/patch-an-ios-application-with-frida\/#primaryimage"},"thumbnailUrl":"https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2019\/07\/frida-twitter-profile.png","datePublished":"2023-03-03T13:47:31+00:00","dateModified":"2023-03-03T13:47:34+00:00","author":{"@id":"https:\/\/www.iprog.it\/blog\/#\/schema\/person\/048c8acb70f8a33f1498675ab9db41a3"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.iprog.it\/blog\/sicurezza-informatica\/patch-an-ios-application-with-frida\/"]}]},{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/www.iprog.it\/blog\/sicurezza-informatica\/patch-an-ios-application-with-frida\/#primaryimage","url":"https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2019\/07\/frida-twitter-profile.png","contentUrl":"https:\/\/www.iprog.it\/blog\/wp-content\/uploads\/2019\/07\/frida-twitter-profile.png","width":400,"height":400},{"@type":"WebSite","@id":"https:\/\/www.iprog.it\/blog\/#website","url":"https:\/\/www.iprog.it\/blog\/","name":"iProg","description":"perch\u00e9 reinventare la ruota?","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.iprog.it\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/www.iprog.it\/blog\/#\/schema\/person\/048c8acb70f8a33f1498675ab9db41a3","name":"Diego","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/secure.gravatar.com\/avatar\/bf8084effa4627f8e50af0d50d06b0677e4a9de5e895e347c0590ad5696fdfc9?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/bf8084effa4627f8e50af0d50d06b0677e4a9de5e895e347c0590ad5696fdfc9?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/bf8084effa4627f8e50af0d50d06b0677e4a9de5e895e347c0590ad5696fdfc9?s=96&r=g","caption":"Diego"},"description":"Google+","sameAs":["http:\/\/it.linkedin.com\/in\/diegocaridei\/","https:\/\/x.com\/flexkid1","http:\/\/www.youtube.com\/channel\/UCjQ2z1ygV9tv55QAc2q3JHA"],"url":"https:\/\/www.iprog.it\/blog\/author\/flexkid\/"}]}},"views":1665,"_links":{"self":[{"href":"https:\/\/www.iprog.it\/blog\/wp-json\/wp\/v2\/posts\/7755","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.iprog.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iprog.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iprog.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iprog.it\/blog\/wp-json\/wp\/v2\/comments?post=7755"}],"version-history":[{"count":1,"href":"https:\/\/www.iprog.it\/blog\/wp-json\/wp\/v2\/posts\/7755\/revisions"}],"predecessor-version":[{"id":7757,"href":"https:\/\/www.iprog.it\/blog\/wp-json\/wp\/v2\/posts\/7755\/revisions\/7757"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.iprog.it\/blog\/wp-json\/wp\/v2\/media\/7378"}],"wp:attachment":[{"href":"https:\/\/www.iprog.it\/blog\/wp-json\/wp\/v2\/media?parent=7755"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iprog.it\/blog\/wp-json\/wp\/v2\/categories?post=7755"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iprog.it\/blog\/wp-json\/wp\/v2\/tags?post=7755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}