{"id":354,"date":"2016-11-20T15:59:49","date_gmt":"2016-11-20T20:59:49","guid":{"rendered":"http:\/\/jebware.com\/blog\/?p=354"},"modified":"2016-11-22T08:55:37","modified_gmt":"2016-11-22T13:55:37","slug":"how-and-why-to-run-a-man-in-the-middle-attack-on-your-own-app","status":"publish","type":"post","link":"https:\/\/jebware.com\/blog\/?p=354","title":{"rendered":"How, and Why, to run a Man-In-The-Middle Attack on Your Own App"},"content":{"rendered":"<h6>Wait, what? Why would I want to do that?<\/h6>\n<p>Lots of good reasons:<\/p>\n<ul>\n<li>If you want to see the actual traffic you\u2019re sending over the network, for debugging purposes.<\/li>\n<li>See what third-party libraries might be sending, and how they\u2019re sending it.<\/li>\n<li>Demonstrating how trivial it is to do so, as a pre-condition for mitigating it.<\/li>\n<\/ul>\n<h6>But I\u2019m using HTTPS, so I can\u2019t MITM my traffic.<\/h6>\n<p><a href=\"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/id45.gif\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-355\" src=\"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/id45.gif\" alt=\"id45\" width=\"620\" height=\"360\" \/><\/a><small>(side note: any day I can use an Independence Day GIF is a good day)<\/small><\/p>\n<p>Yes, by using HTTPS, a random third-party can\u2019t decrypt your payloads.<\/p>\n<p><a href=\"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/https-side-by-side-marked.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-357\" src=\"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/https-side-by-side-marked.png\" alt=\"https-side-by-side-marked\" width=\"1259\" height=\"371\" srcset=\"https:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/https-side-by-side-marked.png 1259w, https:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/https-side-by-side-marked-300x88.png 300w, https:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/https-side-by-side-marked-768x226.png 768w, https:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/https-side-by-side-marked-1024x302.png 1024w, https:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/https-side-by-side-marked-1200x354.png 1200w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><\/p>\n<p>But while HTTPS protects you from a third-party listening in to your traffic, the endpoints are still vulnerable.<\/p>\n<p><a href=\"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/alice-bob-carol-marked.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-358\" src=\"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/alice-bob-carol-marked.png\" alt=\"alice-bob-carol-marked\" width=\"756\" height=\"351\" srcset=\"https:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/alice-bob-carol-marked.png 756w, https:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/alice-bob-carol-marked-300x139.png 300w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/a><\/p>\n<p>I don\u2019t want to get sidetracked with a detailed explanation of <a href=\"http:\/\/robertheaton.com\/2014\/03\/27\/how-does-https-actually-work\/\">how HTTPS protects you<\/a>, so here\u2019s the short version: First, you verify the server\u2019s identity using the Public Key Infrastructure. The server presents a certificate saying \u201cI am example.com\u201d. That certificate has been <strong>signed<\/strong> by a trusted third-party, called a Root Certificate Authority (CA). That signature says \u201cI am Trusted CA, Inc. and that really is example.com\u201d. Your OS has a couple hundred root CA certificates installed, so it can be sure that it\u2019s really Trusted CA, Inc. that signed the certificate. (In reality, the server\u2019s certificate has actually been signed by an intermediary CA, which was in turn signed by the root CA. We call this the <strong>chain of trust<\/strong>).<\/p>\n<p>After you\u2019ve established the server\u2019s identity, you exchange public keys, and can encrypt messages to each other that can only be decrypted by the known party &#8211; no third party can listen in to your encrypted messages and see what you\u2019re saying.<\/p>\n<p>Since we can\u2019t decrypt your HTTPS payloads, we\u2019re going to attack by making a fake root CA and installing it as one of the device\u2019s trusted roots.<\/p>\n<h6>Isn\u2019t that hard?<\/h6>\n<p>Nope. We\u2019re going to install a tool that handles it all for you.<\/p>\n<p>Step 1. <a href=\"http:\/\/docs.mitmproxy.org\/en\/latest\/install.html\">Install mitmproxy<\/a> on your dev machine.<\/p>\n<p>Step 2. Run mitmproxy on your dev machine. Down in the bottom-right corner, it\u2019ll tell you what port it\u2019s running on. Also, make note of your dev machine\u2019s IP address.<\/p>\n<p>Step 3. Connect your Android (or iOS or whatever else) device to the same network as your dev machine, and in your network settings, set your proxy to your dev machine\u2019s IP address and the port that mitmproxy is running on. The exact details of how to do this vary by OS version, so&#8217;ll have to google that for yourself.<\/p>\n<p>Step 4. On your target device, open a browser and go to (mitm.it) This magic domain will help you install mitmproxy\u2019s certificate as a trusted root CA on your device.<\/p>\n<p>Step 5. Run your app, and watch mitmproxy dump all of your traffic.<\/p>\n<p><a href=\"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/mitm-https-cleartext-marked.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-359\" src=\"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/mitm-https-cleartext-marked.png\" alt=\"mitm-https-cleartext-marked\" width=\"657\" height=\"429\" srcset=\"https:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/mitm-https-cleartext-marked.png 657w, https:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/mitm-https-cleartext-marked-300x196.png 300w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/a><\/p>\n<h6>So what do I do now?<\/h6>\n<p>You <a href=\"http:\/\/jebware.com\/blog\/?p=364\">pin your certificates<\/a>. <del>I\u2019ll follow up with another blog post soon to help you do that<\/del> (edit: follow-up <a href=\"http:\/\/jebware.com\/blog\/?p=364\">post on certificate pinning<\/a> is up). (Good news: it\u2019s pretty easy)<\/p>\n<p>Also, you learn a little more about HTTPS. Knowledge is power.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wait, what? Why would I want to do that? Lots of good reasons: If you want to see the actual traffic you\u2019re sending over the network, for debugging purposes. See what third-party libraries might be sending, and how they\u2019re sending it. Demonstrating how trivial it is to do so, as a pre-condition for mitigating it. &hellip; <a href=\"https:\/\/jebware.com\/blog\/?p=354\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How, and Why, to run a Man-In-The-Middle Attack on Your Own App&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"twitterCardType":"summary_large_image","cardImageID":0,"cardImage":"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2016\/11\/id45.gif","cardTitle":"","cardDesc":"","cardImageAlt":"","cardPlayer":"","cardPlayerWidth":0,"cardPlayerHeight":0,"cardPlayerStream":"","cardPlayerCodec":""},"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/354"}],"collection":[{"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=354"}],"version-history":[{"count":6,"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/354\/revisions"}],"predecessor-version":[{"id":374,"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/354\/revisions\/374"}],"wp:attachment":[{"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}