<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Evan Custodio on Medium]]></title>
        <description><![CDATA[Stories by Evan Custodio on Medium]]></description>
        <link>https://medium.com/@defparam?source=rss-444ff95c7157------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wLAUoXD4aMAXJb8BhDObHw.jpeg</url>
            <title>Stories by Evan Custodio on Medium</title>
            <link>https://medium.com/@defparam?source=rss-444ff95c7157------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 21:06:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@defparam/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[iOS App Testing Through Burp on Corellium]]></title>
            <link>https://defparam.medium.com/ios-app-testing-through-burp-on-corellium-fe59ed849516?source=rss-444ff95c7157------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe59ed849516</guid>
            <dc:creator><![CDATA[Evan Custodio]]></dc:creator>
            <pubDate>Thu, 17 Jun 2021 21:43:54 GMT</pubDate>
            <atom:updated>2021-06-17T22:19:59.326Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*z2WrI4_KBCH9gVnD" /><figcaption>Photo by <a href="https://unsplash.com/@californong?utm_source=medium&amp;utm_medium=referral">Nong Vang</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>In recent weeks I had an itch to take another look at mobile testing. The last time I looked at mobile testing most of my environment revolved around applications developed for Android. I think this is a choice that most testers choose due to the fact of how complicated it is to get bootstrapped into an environment for iOS testing. Apple does not make things easy for the security researcher. First, getting root access to an iOS device requires obtaining/finding a jailbreak for your device. Second, emulation for iOS did not exist for a long time until Corellium showed up, and even then Apple tried to buy them and then sue them out of existence (luckily they still exist!). Third, applications from the official App Store are encrypted/signed with Apple being the only authority. Forth, official iOS development has been pretty much locked to OS X only. Fifth, because of the cat and mouse game between Apple and jailbreakers, googling for information on how to do any of this security research is hit or miss and ever-changing year by year making this whole process super confusing.</p><p>I decided to write this blog post as a set of steps for myself to take whenever I need to create an environment for iOS testing in the modern day. In this blog post I will describe the following steps for testing on 2 types of environments:</p><p><strong>Environment: Physical Device</strong></p><ol><li>Enabling ssh on your physical iOS device</li><li>Create an iOS tweak development environment on Ubuntu (AWS EC2)</li><li>Deploy certificate pinning bypass from Ubuntu to physical iOS device</li><li>Set up Burp MITM for testing Apps on your physical iOS device</li></ol><p><strong>Environment: Emulated Device (Corellium)</strong></p><ol><li>Set up an emulated jailbroken iOS device on Corellium</li><li>Configure emulated iOS device to side load apps via ssh</li><li>Be able to decrypt apps from your physical iOS device, re-package them and side load them onto your emulated iOS device</li><li>Test Apps on your emulated iOS device through Burp</li></ol><p>Best of all is that all these steps do not require OS X. This guide sets up Burp for a physical iOS device and an emulated iOS device. You are probably wondering why we can’t just use an emulated iOS device. The answer is that you can if you have an unencrypted IPA file of the App you wish to test on Corellium. However, I am assuming if you are a bug bounty hunter then you are trying to obtain the most up-to-date apps that the App Store has to offer from your target. Unfortunately due to certain limitations Corellium emulated iOS devices cannot give you access to the App Store. Therefore, this guide shows how you can pull Apps off of a physical device with App Store access and decrypt/re-sign the App and deploy it on 1 or more Corellium emulated devices. So let’s get started!</p><h3>Jailbreak</h3><p>OK so I lied a tiny bit. I did have to use a MacBook (OS X) briefly to pull off my jailbreak (but technically you shouldn’t need to). For my target physical device I decided to purchase an iPad Mini 4. The reason why I chose this hardware is because the Mini 4 still gets the latest iOS updates (at the time of this writing) and has hardware that is vulnerable to the bootrom exploit triggered by checkra1n. You can find checkra1n here: <a href="https://checkra.in/">https://checkra.in/</a> and in theory checkra1n should work on devices running linux, but in practice I could never get it to work. Using a MacBook on the other hand always yielded a successful jailbreak. I’m not going to document the steps here on how to jailbreak your specific device, there are tons of resources on the internet on how to do such a thing. The best place to start is: <a href="https://canijailbreak.com/">https://canijailbreak.com/</a></p><figure><img alt="The output screen of a successful checkra1n jailbreak" src="https://cdn-images-1.medium.com/max/1024/0*oujiQBQn09APWfXa.jpg" /><figcaption>Checkra1n Jailbreak</figcaption></figure><h3>Setting up iOS device for SSH/Tweaks</h3><p>After you’ve jailbroken your device and you are on your device with Cydia installed, the next thing to do is to ensure that OpenSSH is installed and running and that mobilesubstrate is up to date. To do that follow these steps:</p><pre>1) Once you’ve successfully jailbroken your device and have Cydia installed go ahead an open “Cydia”<br>2) Cydia may ask you to upgrade, go ahead an select “Complete Upgrade”, &quot;Confirm&quot; and “Return to Cydia” when complete<br>3) Tap on the search tool and search for “openssh”, tap on it and then tap on “install” and “confirm”<br>4) Tap on “Return to Cydia”<br>5) Next thing to install/update is mobilesubstrate for supporting tweaks, go to the search tool again<br>6) Search for “cydia substrate”, tap on it<br>7) Tap on install (or modify then tap on update)<br>8) Tap on “Restart Springboard”<br>9) If for whatever reason your respring fails in an infinite loop, re-jailbrake your device in safe mode and reinstall “cydia substrate”</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/0*Fp7gho28MEzMylFd.png" /><figcaption>Cydia App</figcaption></figure><h3>Setting up a Linux Development Environment</h3><p>Next, we’ll create a development environment on Ubuntu. Specifically for me I am using Ubuntu 20 on a T2 EC2 AWS instance. There is no hard requirement to using EC2, feel free to use other cloud service provider or your own hardware. Next, we’ll be installing all the requirements for Theos <a href="https://github.com/theos/theos">https://github.com/theos/theos</a> . Theos is an iOS development toolchain that is cross platform and will allow us to build iOS software on our linux instance and deploy it to either our physical iOS device or emulated iOS device. The following are the terminal commands I used to get everything configured.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*tNy05yI8xUz-OcGE.png" /><figcaption>Setting up our iOS development environment on EC2</figcaption></figure><p>Starting from a WSL2/Linux terminal we first set up an ssh tunnel to our linux instance with a remote port forward to our physical iOS device (You can do the same in Putty, but for this tutorial I’ll stick to linux). For this example lets assume our iOS device IP is 192.168.1.100 (change this to what your device IP really is) and we use the -R flag to create a service on the linux instance at port 2222 to forward into our device’s ssh port at 192.168.1.100:22</p><pre>1) ssh &lt;Instance IP&gt; -R 2222:192.168.1.100:22 </pre><p>Next while on the instance we start to provision the dependencies we need for the software we intend to use.</p><pre>2) sudo apt update<br>3) sudo apt-get install git zstd perl clang-6.0 build-essential libz3-dev zip unzip openvpn -y</pre><p>We then configure our bash profile to be aware of Theos specific configuration.</p><pre>4) nano ~/.profile<br>    a) append the following lines in nano and save:<br>    b) export THEOS=~/theos<br>    c) export PATH=$THEOS/bin:$PATH<br>    d) export THEOS_DEVICE_IP=127.0.0.1<br>    e) export THEOS_DEVICE_PORT=2222<br>    f) alias theos=&quot;nic.pl&quot;<br>Exit the instance and ssh back to sync the settings<br>5) exit -&gt; ssh &lt;Instance IP&gt; -R 2222:192.168.1.100:22</pre><p>Now lets install Theos</p><pre>6) git clone --recursive <a href="https://github.com/theos/theos.git">https://github.com/theos/theos.git</a> $THEOS</pre><p>Next we need to deploy the iOS SDKs into Theos</p><pre>7) curl -LO <a href="https://github.com/theos/sdks/archive/master.zip">https://github.com/theos/sdks/archive/master.zip</a><br>8) TMP=$(mktemp -d)<br>9) unzip master.zip -d $TMP<br>10) mv $TMP/sdks-master/*.sdk $THEOS/sdks<br>11) rm -r master.zip $TMP</pre><p>Next we need to deploy the clang toolchain for compiling ObjC and Swift apps</p><pre>12) wget <a href="https://github.com/CRKatri/llvm-project/releases/download/swift-5.3.2-RELEASE/swift-5.3.2-RELEASE-ubuntu20.04.tar.zst">https://github.com/CRKatri/llvm-project/releases/download/swift-5.3.2-RELEASE/swift-5.3.2-RELEASE-ubuntu20.04.tar.zst</a><br>13) tar -I zstd -xvf swift-5.3.2-RELEASE-ubuntu20.04.tar.zst<br>14) mkdir -p $THEOS/toolchain/linux/iphone<br>15) mv ./swift-5.3.2-RELEASE-ubuntu20.04/* $THEOS/toolchain/linux/iphone/<br>16) rm -rf swift-5.3.2-RELEASE-ubuntu20.04*</pre><p>(Optional) Next lets try and create our very first iOS tweak</p><pre>17) run command &quot;theos&quot;<br>18) &lt;select iphone/tweak&gt;<br>19) &lt;name project &quot;test&quot;&gt;<br>20) &lt;press enter for the remaining questions&gt;<br>21) cd test<br>22) make</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H1adG6TAMDi-Ft78QiwIvQ.png" /><figcaption>compilation of example tweak</figcaption></figure><p>At this point your tweak should have successfully compiled, neat.</p><p>(Optional) Other tips:</p><pre>a) make package # this creates a deb package to deploy<br>b) make install # this connects via SSH to install deb package<br>c) make GO_EASY_ON_ME=1 # to turn off warnings as errors</pre><p>That’s it! you now have a workable iOS development environment in Linux.</p><h3>Setting up your physical iOS Device through Burp</h3><p>For those familiar with web app testing using Burp Suite on Android this section of steps should seem straight forward. These steps assume a fairly open network configuration, if your network is set up differently then your steps on how to proxy traffic from iOS through Burp may vary, however this is a good example in any case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*ntHkcUpeZxkf2EN1PL_rJw.png" /><figcaption>Burp Suite Community Edition</figcaption></figure><pre>1)      Download and install Burp Suite Community Edition from <a href="https://portswigger.net/">https://portswigger.net/</a><br>2)      Start Burp Suite<br>3)      Click on the “Proxy” tab<br>4)      Click on “Intercept is on” button<br>5)      Click on “Options” tab<br>6)      Under Proxy Listeners click on “127.0.0.1:8080” and click edit<br>7)      Click on the “All Interfaces” radio button and click “OK”<br>8)      Click on “Yes” to the listen on all interfaces warning dialog<br>9)      Click on the “HTTP History” tab<br>10)   On your physical iOS device open the “Settings” app<br>11)   tap on “Wi-Fi”<br>12)   tap on the “i” button on your connected Wi-Fi network<br>13)   tap on “Configure Proxy”<br>14)   tap on “Manual”<br>15)   tap on “Server” and enter the internal IP address of the machine running Burp Suite (assuming its on the same network)<br>16)   tap on “Port” and enter “8080” and tap on “Save”<br>17)   tap on home button to go back to main screen</pre><p>At this point you should have all HTTP/HTTPS traffic proxying through Burp, however all TLS session should fail due to either a lack of a trusted certificate or failure of certification pin validation. Let’s test that real quick:</p><pre>1)      Go to into Safari<br>2)      Navigate to <a href="https://www.google.com/">https://www.google.com</a><br>3)      At this point you should have a “This Connection is Not Private” warning</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*xly7BVGvzJG4WLrUlN2FNg.png" /><figcaption>(Just a stock image)</figcaption></figure><h3>Using SSLBypass to Bypass All Certificate Checks</h3><p>So at this point many people are familiar with installing a Burp Suite signed certificate into the OS to get TLS running. Furthermore, if you are familiar with certificate pinning bypass on Android using Frida you are probably also concerned with cert pin failures on iOS. We can kill 2 birds with 1 stone by using a tweak from <a href="https://twitter.com/EvilPenguin_">EvilPeguin</a> called<em> </em><a href="https://github.com/evilpenguin/SSLBypass">SSLBypass</a>. Let’s go back to our EC2 dev instance and compile this tweak.</p><pre>1)      Go back to your EC2 instance at your home directory: cd ~<br>2)      git clone <a href="https://github.com/evilpenguin/SSLBypass">https://github.com/evilpenguin/SSLBypass</a><br>3)      cd SSLBypass<br>4)      make package<br>5)      make install # use &#39;alpine&#39; when asked for a password</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yd_9fyAgEtqiT9gk04vICg.png" /><figcaption>Compile and Install of SSLBypass</figcaption></figure><p>After a quick restart of the SpringBoard the iOS device should now be fully capable of establishing TLS connections through burp via Safari or native app and you can now test apps on your device to your heart’s content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*2RI7_DEb2ogoPf6MjMiVdg.png" /><figcaption>Mobile Safari Burp Traffic</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*1q7Rw0c4XTp3N31C8Hg0hg.png" /><figcaption>We’ve intercepted Google (Just a stock image)</figcaption></figure><h3>Decrypt Apps for Reversing and Sideloading</h3><p>So now that we have our physical device set up correctly there is an important reason why we need it for Corellium. The emulated iOS instances do not allow you to download apps off the AppStore. What we need to do is download any/all Apps we require from the AppStore on an authentic device, transfer the app off the device and side load it onto the emulated iOS instance. However, in order to package the app correctly for it to run on Corellium we need to decrypt the binary. All apps on the AppStore are encrypted so that they are only allowed to run from the intended device. Luckily we can use another piece of software to decrypt binaries. The other benefit of decrypting iOS app binaries is that you can load them into IDA and other binary research tools for further reverse engineering analysis. For this example we will be using Twitter’s iOS app as an arbitrary example. They do allow researchers to test their app per their bounty program guidelines found <a href="https://hackerone.com/twitter">here</a>.</p><pre>Prep the device<br>1) On your physical device go back to settings and turn off the proxy settings in order to remove Burp out of the loop.<br>2) On your physical device download/install Twitter from the AppStore (account and login required)<br>3) SSH into your physical device: ssh root@127.0.0.1 -p 2222</pre><pre>Install flexdecrypt by John Coates on your device<br>4) wget <a href="https://github.com/JohnCoates/flexdecrypt/releases/download/1.1/flexdecrypt.deb">https://github.com/JohnCoates/flexdecrypt/releases/download/1.1/flexdecrypt.deb</a><br>5) dpkg -i flexdecrypt.deb<br>6) rm flexdecrypt.deb</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*R0QxfD-ZyDDlliH6rKbFeA.png" /></figure><p>Now that we have flexdecrypt installed we can decrypt any Mach-O binary on your iOS device. This tool can be used for dumping and re-packaging iOS apps off your physical device and onto a Corellium device. In order to assist in this process I created a wrapper tool for flexdecrypt called flexdump found <a href="https://gist.github.com/defparam/71d67ee738341559c35c684d659d40ac">here</a>. Using this tool you can dump the Twitter app into an IPA file to load onto Corellium. Flexdump was a hack script that was created for this tutorial and was only tested on an iPad mini 4 running iOS 14.6. This script may not work in older versions of iOS.</p><pre>First lets install some dependencies:<br>1) apt update # make sure manual proxy is not configured<br>2) apt install zip unzip</pre><pre>Next we install flexdump by running this exact command:<br>3) wget <a href="https://gist.githubusercontent.com/defparam/71d67ee738341559c35c684d659d40ac/raw/30c7612262f1faf7871ba8e32fbe29c0f3ef9e27/flexdump">https://gist.githubusercontent.com/defparam/71d67ee738341559c35c684d659d40ac/raw/30c7612262f1faf7871ba8e32fbe29c0f3ef9e27/flexdump</a> -P /usr/local/bin; chmod +x /usr/local/bin/flexdump</pre><p>You can review all the apps you have installed by running: flexdump list</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*nQYs2vBi1OaK1Wyqyrhskw.png" /></figure><p>Now that we know the app name Twitter.app we can dump, decrypt and create an IPA package by running: flexdump dump Twitter.app which should look roughly like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gd9qTj6ywGQMwOG2eGmToQ.png" /></figure><p>Sweet! we now have an IPA file that we can transfer off the physical device and transfer onto out Corellium device. Next lets exit the iOS device back to our EC2 instance, and transfer the IPA file onto your instance by running the command:</p><pre>scp -P 2222 root@127.0.0.1:/var/mobile/Documents/Flexdump/Twitter_8.69.2_fd.ipa ~</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1YGOJEq5P-Z4tffvW9TkRg.png" /></figure><p>And that’s it! We no longer need the physical device anymore and we can now distribute the IPA file to all your Corellium instances or fellow collaborators running Corellium that don’t have iOS hardware.</p><p>(edit) Note: Just a quick warning on IPA dumps. They will not always work for every app. Because decryption/signing will modify the various binaries in the IPA this may break application specific integrity checks. For example if the app you are targeting has logic that checks if the device or the app itself has been tampered than you may not be successful running the App on a different device.</p><h3>Setup a Corellium Instance and Install IPA</h3><p>Now that we have a decrypted IPA file of the target app off your authentic iOS device lets now create an emulated iOS device and install the app onto it.</p><p>Go to <a href="https://app.corellium.com/login">https://app.corellium.com/</a> and login into your account</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*_uHAboHeK6-JJ_9ORzTa8w.png" /></figure><p>Once logged in go and create a new device</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*I_zPwxry96Nc2Q4kh3SJCg.png" /></figure><p>Select the device that is close if not identical to your physical device. In my case I tested this flow on an iPad mini 4 (Wi-Fi only).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*fQo783L_DgXEQ5Z6K0p1xg.png" /></figure><p>Select your iOS version and make sure the device is jailbroken. In my case this flow was tested on iOS 14.6.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*apY7icNubIOC4mMg1Xe3rQ.png" /></figure><p>Feel free to name your device and set advanced boot options. In my case I just clicked “Create Device”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*tOFa4h8NSjjWH66YvT1xhQ.png" /></figure><p>Now wait a moment as your emulated device is being created in the background (Note: this may take a while)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xopggAZrpbEl1kKuxHM6-A.png" /></figure><p>Done and running!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3j8dcUTcG2IShJYLZLEuog.png" /></figure><p>So at this point the emulated device is ready for the IPA file to be installed onto it. Corellium has an interface to install IPA files in the web interface however, this interface is not reliable for IPA files built using Flexdump. In order to install this IPA file we need to install AppSync/appinst onto our emulated device. We can do that through our EC2 instance using a VPN tunnel to the device. Let’s start by setting up that tunnel.</p><p>First click on the OPVN FILE button under the connect tab, save the file because we will be using it later on the windows side and open the opvn file in a text editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*EZSRrCDoVAs41dfWSnzFqw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*bycf7n4kOtZmdRDihI26lA.png" /></figure><p>Copy the entire contents of this file into your clipboard and go into your EC2 instance and run the command: nano ~/device.ovpn</p><p>This will open up nano, paste the entire contents of the ovpn data and save the file to disk. This way we can connect to the VPN both from Windows and from your EC2 instance.</p><p>On your EC2 instance lets go ahead and connect to the VPN by running the following command:</p><pre>sudo openvpn --config ~/device.ovpn &amp;</pre><p>This should connect to the VPN successfully like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*URk-sLv1ZkIMKpPknTNDRw.png" /><figcaption>We have VPN access into Corellium, yay!</figcaption></figure><p>We have successfully connected to the Corellium VPN service and we can now access our emulated device via the SSH service on 10.11.1.1:22</p><p>Now lets go ahead and compile/install AppSync/Appinst on our instance place it onto our emulated device.</p><pre>First lets clone the repo for AppSync/Appinst:<br>1) git clone <a href="https://github.com/akemin-dayo/AppSync">https://github.com/akemin-dayo/AppSync</a><br>2) cd AppSync</pre><pre>Next we need to patch the Makefile real quick for THEOS to work<br>3) sed -i &#39;s/clang::5.0/clang::6.0/g&#39; ./Makefile<br>4) sed -i &#39;s/clang::5.0/clang::6.0/g&#39; ./appinst/Makefile</pre><pre>Next set up the THEOS variable for installing onto Corellium. Corellium in the WebUI should specify the device IP address<br>5) export THEOS_DEVICE_IP=10.11.1.1 # The IP shown in webui<br>6) export THEOS_DEVICE_PORT=22</pre><pre>Next lets build/install AppSync onto Corellium<br>7) make package GO_EASY_ON_ME=1<br>8) make install # enter password &#39;alpine&#39; each time it asks</pre><pre>Next lets build/install Appinst onto Corellium<br>9) cd ./appinst<br>10) make package GO_EASY_ON_ME=1<br>11) make install # enter password &#39;alpine&#39; each time it asks</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RMGIBRSF2qsYgiPaiAVqdg.png" /><figcaption>Installing AppSync</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*UsdlXvDZBB6dyipWFKKHUg.png" /><figcaption>Installing Appinst</figcaption></figure><p>Now that we have appinst installed we can finally install our Twitter IPA onto the Corellium device. If you remember, the IPA is currently at ~/Twitter_8.69.2_fd.ipa on our instance. Lets go head and load it onto our Corellium device via SCP:</p><pre>1) scp ~/Twitter_8.69.2_fd.ipa root@10.11.1.1:~</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*cT0zllKgVVYVNa0v9tsh3w.png" /></figure><p>Excellent next lets go ahead an SSH into our Corellium device and use appinst to finally install the dumped Twitter IPA:</p><pre>1) ssh root@10.11.1.1 # password &#39;alpine&#39;</pre><pre>Once your are in the device<br>2) appinst ~/Twitter_8.69.2_fd.ipa</pre><p>And that’s it! Once the IPA is installed the output should look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*cZRPdLLyfKywtny2xYx3Aw.png" /></figure><p>And most importantly your device output screen should show the app and be able to open it successfully!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QpzLJDVHE9ZL17lxlCmVgQ.png" /></figure><p>Now before we loop Burp Suite in this flow I just want to identify that Corellium has a nice traffic viewer. If you go into the “Network” tab and click on “Start Monitoring” you can get a pretty nice view of some of the HTTPS traffic that the app sends at launch:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s5kS_NmgHk35J_gg5r99EQ.png" /></figure><h3>Setup Burp Suite for Analysis with Corellium</h3><p>So now that we have the app installed on Burp Suite we are going to follow similar steps from the steps listed in the above section “Setting up your physical iOS Device through Burp”. The first thing you’ll want to do is install OpenVPN for Windows. Go to <a href="https://openvpn.net/">https://openvpn.net</a> and download/install the client for Windows. Once you have OpenVPN running go to the taskbar and right click on the OpenVPN icon and click “Import File…”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*nRxQVrk6Pa9b1MoQlILIvg.png" /></figure><p>Remember the OVPN file we downloaded earlier? Go ahead and navigate/import the file into OpenVPN. Then go back to the OpenVPN icon and click on “Connect”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/247/1*7bmQ89AaKGIVRLhzUb4GfQ.png" /></figure><p>Once a connection is made OpenVPN should have an IP address assign to you and you can have your emulated device interact with your Burp Suite session. In my case, the IP address assigned to me is 10.11.3.3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*v1gMb9o3kQfNT_qvUSa-ag.png" /></figure><p>At this point the steps on setting up Burp Suite are similar to the ones above, namely:</p><pre>1)      Start Burp Suite<br>2)      Click on the “Proxy” tab<br>3)      Click on “Intercept is on” button<br>4)      Click on “Options” tab<br>5)      Under Proxy Listeners click on “127.0.0.1:8080” and click edit<br>6)      Click on the “All Interfaces” radio button and click “OK”<br>7)      Click on “Yes” to the listen on all interfaces warning dialog<br>8)      Click on the “HTTP History” tab<br>9)   On your Corellium iOS device open the “Settings” app<br>10)   tap on “Wi-Fi”<br>11)   tap on the “i” button on the &quot;Corellium&quot; Wi-Fi network<br>12)   tap on “Configure Proxy”<br>13)   tap on “Manual”<br>14)   tap on “Server” and enter the IP address given to you from OpenVPN, in my case this is &quot;10.11.3.3&quot;<br>15)   tap on “Port” and enter “8080” and tap on “Save”<br>16)   tap on home button to go back to main screen</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z-YUmZES48rBvze6sG7M0g.png" /><figcaption>Proxy Setup</figcaption></figure><p>Now when you open the Twitter app and attempt to login you will see all the traffic being routed through Burp Suite on your Windows machine via the VPN. Also it appears we don’t need to install the SSLBypass tweak to bypass cert pinning or to install the Burp certificate. I believe by virtue of starting the Network Monitor, Corellium does some magic in the background to take care of the certificate validation in order to enhance our visibility and make it easier for researchers. If for whatever reason this proves not to be true in all cases, feel free to follow the SSLBypass tweak install steps in the above section and target the Corellium device IP instead of your physical device. SSLBypass should be able to be installed on Corellium devices too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ni7AH_tkeEFOuuwFQkhgfQ.png" /><figcaption>Sweet, Sweet Traffic</figcaption></figure><h3>Conclusion</h3><p>I wrote this document after several weeks of bashing my head trying to figure out how to do all this. This document serves as reference material for me in the future because I WILL forget all these nitty-gritty steps. I’m happy to publish this material for everyone else to use in order to bootstrap yourself into an iOS testing enviroment for pentesters and bounty hunters. The wonderful thing about Corellium is that once one pentester or bounty hunter has dumped a target IPA on a physical device they can now enable all their collaborators to test the target iOS app on emulated Corellium devices without having to purchase expensive Apple hardware and deal with jailbraking!</p><p>A big thanks to my colleague James Emrich (<a href="https://twitter.com/EvilPenguin_">EvilPenguin</a>) for developing SSLBypass and for helping me reason through A LOT of issues I encountered along the way. And thanks to you for reading this, happy testing!</p><p>-Evan</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe59ed849516" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Finding Issues In Regular Expression Logic Using Differential Fuzzing]]></title>
            <link>https://defparam.medium.com/finding-issues-in-regular-expression-logic-using-differential-fuzzing-30d78d4cb1d5?source=rss-444ff95c7157------2</link>
            <guid isPermaLink="false">https://medium.com/p/30d78d4cb1d5</guid>
            <category><![CDATA[regular-expressions]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[libfuzzer]]></category>
            <category><![CDATA[fuzzing]]></category>
            <category><![CDATA[web-security-testing]]></category>
            <dc:creator><![CDATA[Evan Custodio]]></dc:creator>
            <pubDate>Sun, 14 Mar 2021 01:58:48 GMT</pubDate>
            <atom:updated>2021-03-14T02:19:58.007Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*POrMbqke-AYgxVwn" /><figcaption>Photo by <a href="https://unsplash.com/@miracleday?utm_source=medium&amp;utm_medium=referral">Elena Mozhvilo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Regular expressions (or commonly known as regex) have been used for years to provide developers a quick way to pattern match or parse various data in applications. In web security, regexes can be found fairly often as a way to parse untrusted input in order to allow or disallow the input from affecting downstream functions. For example, lets say we have a web application in which a post request has a URL parameter to guide the application logic on a resource location. Typically in this case it is security concern if that URL is pointing to a resource outside an acceptable allowlist of locations. Regexes can be used in this case to lock down the acceptable resource locations while still allowing flexibility in the URL parameter itself. Any breakout of this regex onto the disallowed space can result in an open redirect issue or even worse an SSRF issue (Server Side Request Forgery). Whats worse is that regexes can be very complex structures, difficult to audit and very easy to get wrong. In this post I will outline how developers and testers can validate their assumptions of regexes using a technique called differential fuzzing.</p><h3>Binary Fuzzing? (In Websec?)</h3><p>For decades fuzzing software has been a viable strategy in finding bugs. The idea being we take the software under test, wrap it in a harness and fire endless streams of random input into an untrusted surface hoping for a crash. Recently software like AFL, LibFuzzer and AFL++ have gained a lot of traction in both industry and academia to perform what is called coverage-guided fuzzing (Fuzzing with feedback to guide future test mutations). While fuzzing for memory safety issues in itself is a interesting security concern, it is typically not a bug class thought of too much in web security. Specifically, in our case we would like to find issues with regex logic in well formed expressions and not memory safety issues in the regex engine itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/152/1*PuqoIWrovJ7bcvf1GrUwPg.gif" /></figure><h3>Differential Fuzzing to the Rescue!</h3><p>Luckily for us we can leverage these popular fuzzers to perform a technique called differential fuzzing. In differential fuzzing instead of having a test harness in which the fuzzer sends random data to a single piece of software, we instead have a harness where the fuzzer sends test cases to two (or more) independent pieces of software inside the same harness. These two software stacks consume the same test case and logically produce the same output. These two outputs are analyzed at the end of the test and if there is any discrepancy in output, the fuzzer will flag this as a fatal issue for analysis. While theoretically the fuzzer could find a memory issue with either of the two pieces of software, the more likely exception would be a difference of output and parsing logic.</p><h3>A Regex With A Typo (but it mostly works…)</h3><p>For the purpose of this exercise we will be trying to validate if a custom regex actually does the job the author intended. In our scenario we have a web application that uses a regex to validate that an untrusted URL parameter is pointing to a location that is deemed acceptable per an allow list of domains.</p><p>Our Regex under test:</p><pre>^(((([A-Za-z0-9.-]*\.)?example1\.com)|(([A-Za-z0-9.-]*\.)\?example2\.com)|(([A-Za-z0-9.-]*\.)?example3\.com)))</pre><p>The developer’s intention here is to validate that the input URL must be pointing to a *.example1.com, *.example2.com or *.example3.com domain. However, for you regex auditing experts can you spot the bug? When prompted you probably can see the abnormality but could you deduce by looking at it that this small typo just completely broke the regex’s security function? While it’s good to study regex syntax, URL format standards and stare at this expression all day, lets instead try to use differential fuzzing to spot the bug instead.</p><h3>Google Atheris</h3><p>I would like to introduce a fairly new fuzzer project released by Google in December 2020 called Atheris. Atheris is a coverage-guided Python fuzzing engine. It supports fuzzing of Python code, but also native extensions written for CPython. Atheris is based off of libFuzzer and you can find the repo here: <a href="https://github.com/google/atheris">https://github.com/google/atheris</a>. The wonderful thing about Atheris is that is it dirt simple to install and use without touching a single line of C code or playing with exotic C compilers. Typically on a Ubuntu 20 machine you can apt install clang then pip install atheris and you are done. Here is an example of a very simple harness where the bug is an input of b“bad”</p><pre>import atheris<br>import sys<br><br>def TestOneInput(data):<br>  if data == b&quot;bad&quot;:<br>    raise RuntimeError(&quot;Badness!&quot;)<br><br>atheris.Setup(sys.argv, TestOneInput)<br>atheris.Fuzz()</pre><p>In this case the software under test is the function TestOneInput. Atheris will send a steam of random test cases until it locates a crash.</p><h3>Our Atheris-based Differential Fuzzer</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*Kqgjmu22UMtQU074RLraKQ.png" /></figure><p>So with this new tool we can construct a very simple differential fuzzing architecture shown above. Our strategy here is to take random test case from Atheris and process it with our sketchy regex. We then take the same input and process it through a trusted source. The trusted source in this case is python’s Urllib. We will assume that in this experiment Urllib is 100% bug free and follows the same URI parsing logic as most common web browsers and HTTP libraries. Once we have the output results from both Urllib and our regex, we check to see if their outputs contain any issues with respect to each other. More specifically, we first check to ensure that the regex validated the input as trusted, if it did we then validate that the parsed domain string from Urllib contains one of the three allow list domains. If the regex flagged an input as matching/trusted and we find none of the allow list domains inside the authority string from Urllib, we can then conclude that we have bypassed the regex allow list logic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*FCe6tEoNhpJi8-dnO_HBOw.png" /></figure><h3>Execution and Implementation</h3><p>Let’s first create a directory called RegexFuzz. In this directory we will have the fuzzer implementation called fuzz.py and we will have a directory called corpus</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*EfAnDn_FzLf1lWlAIwE3bg.png" /></figure><p>The corpus directory contains initial data for the fuzzer to start with, this can be very helpful for assisting the fuzzer to gain more code coverage and keeping it in the “ballpark” of where potential issues exist. Also as the fuzzer finds more interesting inputs, it will store those inputs into the corpus directory for later use. Lets create two initial corpus with somewhat legit looking subdomains.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*amIZ-6430WSrApE8Yu9BNQ.png" /></figure><p>At this point we can just run the fuzzer as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hx-KFylQj12jpKMS27eFmQ.png" /></figure><p>Before I show you the crash, lets go through the important pieces of fuzz.py. I have uploaded fuzz.py for all to check out and run for themselves:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35e9707f5213021a21e2e2a537c9b28e/href">https://medium.com/media/35e9707f5213021a21e2e2a537c9b28e/href</a></iframe><p>At the beginning we pull in all necessary libraries required, we compile our regex once in the global space so that we don’t keep recompiling it in the fuzz loop and lose performance. We also keep a global list (called Allowlist) of what we believe are the acceptable domains per the regex.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hSo2CFHS8p4Lf8kCJJPNWQ.png" /></figure><p>We define the harness as TestOneInput that accepts a python bytes argument from Atheris called data. We then place a lower bound limit to make sure any test case we accept contains at least 5 bytes. In reality to find this bug we need at least 3 bytes (the first byte as a domain selector and 2 bytes to trigger the bug). Line 21 is showing how we reformat the test case. We use the first byte of entropy to select a domain from the Allowlist we then use the remaining test bytes and prepend it to the selected domain. This allows us to ensure that we always use the fuzzer’s entropy in selecting the allowed domain. We could have instead placed random bytes directly into the regex and seeded our corpus with example1.com,example2.com,example3.com. However, we know roughly based on the regex that we need to keep the parent domain static and unfuzzed. Having the parent domain part of the fuzzing path would still locate the bug, but would take much longer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pubm7VrdJp07BimHFtuasQ.png" /></figure><p>On line 24 we pass our test data into the regex, if the regex match results in “None” then there is no need to continue the fuzz loop, we return right away at line 29. If the match returns an object then we know that the regex successfully validated the fuzz input as trusted and we can continue onto passing that data into Urllib. Urllib has a couple requirements, it will throw exception on malformed UTF-8 which the fuzzer is bound to create. So in order for that to not register as a crash we enclose it into a try block and return on exception. Secondly our regex doesn’t use a scheme in its matching pattern but Urllib requires one so we give it a hardcoded “https://”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xsJBY46Zz5xfErbpXhbwVQ.png" /></figure><p>At this point we have output results back from both our regex and Urllib, we also know that our regex has validated the input as trusted. To detemine if there is a logic error and a bypass, we iterate through every domain that is in our Allowlist and perform a check to see if that domain is contained within what Urllib believes to be the parsed authority string of the testcase. If the loop finds a domain in the authority string it will return since the authority is indeed trusted. However, if the loop finds no sign of an Allowlist domain in Urllib’s interpretation of the authority string, we then can conclude that we found a payload that successfully passes the regex as trusted but is not contained in the Allowlist and could potentially be used as a bypass.</p><p>The last two lines are global calls to invoke atheris to run against our harness, sys.argv are arguments passed to the LibFuzzer backend of atheris.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1L1tzloykm_ub6mN8Ixiaw.png" /></figure><h3>CRASH!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0UlD658i5S9KG1THcx5lvw.png" /></figure><p>We run the fuzzer and within seconds it found a fuzzing differential exception! Let’s zero in on the payload:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2woey6t2yQeeKMMAbMY7qw.png" /></figure><p>So if you zero in on the payload it turns out that 888888.?example2.com passes the regex successfully and Urllib parsed out the example2.com from the authority leaving only the substring. As it turns out having a ? prior to the domain does indeed parse it out of the authority in proper URI parsing. We have found a bypass to the regex, but where did it go wrong? When I run the crash several more times the domain is always example2.com and there is always a .? preceding it. Let’s now revisit our regex:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*50Z--3nBthpuH9Bo7qWxtw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*gpO5S4EnI58koIyQ0YIiNw.png" /></figure><p>And there is it! The question mark (Quantifier operator) used to specify 0 or 1 of the preceding group was accidentally escaped during development, and most likely the developer did not have a test case to validate this specific sub expression. We can now use a payload like evil.com.?example2.com to bypass this filter.</p><p>By the way, how difficult was it to code this differential fuzzer? 29 lines of operational code! This is a testament to how much heavy lifting Atheris provides when fuzzing in python.</p><h3>Takeaways</h3><p>This was just a toy example of an easy to miss logic bug which differential fuzzing was able to find in short order. This technique is not exclusive to just parsing URLs. If you have any regex performing some type of data parsing and you have an independent library that can perform the same parsing as a trusted entity, then you can use this technique to find logic errors in any custom rolled regex.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30d78d4cb1d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>