<?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 1byte on Medium]]></title>
        <description><![CDATA[Stories by 1byte on Medium]]></description>
        <link>https://medium.com/@ctfgudai?source=rss-9bdd8886168a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*Rgve4VE2UoIu7Uv1nNSEwQ.png</url>
            <title>Stories by 1byte on Medium</title>
            <link>https://medium.com/@ctfgudai?source=rss-9bdd8886168a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 25 Nov 2026 01:08:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ctfgudai/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[Roulette — CSCML2020(500 pts.)]]></title>
            <link>https://medium.com/@ctfgudai/roulette-cscml2020-500-pts-3b8a19069e70?source=rss-9bdd8886168a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b8a19069e70</guid>
            <category><![CDATA[script]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[obfuscation]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[1byte]]></dc:creator>
            <pubDate>Fri, 03 Jul 2020 12:08:50 GMT</pubDate>
            <atom:updated>2020-07-03T14:37:04.986Z</atom:updated>
            <content:encoded><![CDATA[<h3>Roulette — CSCML2020(500 pts.)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*HodHSIVjfIlIavC8u4-FLw.png" /></figure><p>So, we get an exe file and as usual we have to find the flag. Like every reverse engineering challenge, we need to understand what we’re looking at. So let’s do the usual thing, and initially use some tools to help us look at the data in a better way. To detect if it’s packed, I used <a href="https://github.com/horsicq/Detect-It-Easy">Detect It Easy</a>, which is probably one of the best packer detectors around.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*iX0ZH9ppiICSDDBmIJULZA.png" /><figcaption>Detect it easy doesn’t detect packing</figcaption></figure><p>The next tool we’re going to use is <a href="https://www.winitor.com/">PEStudio</a> which will display some general infomation about the executable file. We can see the sections look quite normal, and by looking at the entropy we don’t have suspicion for packed code in any of the sections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*klUDJNVB03je4jFXITLObw.png" /><figcaption>Sections of the roulette.exe file</figcaption></figure><p>Okay, nothing else seems to stick out, and the strings / imports don’t reveal much of what’s going on. <a href="http://www.angusj.com/resourcehacker/">Resource Hacker</a> doesn’t find any interesting resources except for the normal one we can see in quite new executables.</p><p>Next thing we’ll do it pop the program inside ida, and try to statically reverse engineer it. When we pop the roulette.exe file inside IDA we notice the start function looks a little odd, and if you’re dealing with this for the first time, it can be quite confusing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LoocX33U1YBsUTIZafOS3g.png" /><figcaption>The start function</figcaption></figure><p>Luckily for us IDA knows to mark this code as __SEH_prolog4, which means this isn’t code generated by the user, and usually code before the main function does some setup and later on jmp s or call s the main function at the end. So we scroll to the end when we see the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*VLoLQ2VqBiO68g-iWhiMBQ.png" /><figcaption>The end of the start function</figcaption></figure><p>Again, IDA comes in for the rescue, and labels argv and argc for us, which can probably tell us sub_4030A0 is the actual main function. So we label it main and continue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*v62TTBp5j5_yqv1nqRQHCg.png" /><figcaption>The main function</figcaption></figure><p>Okay, so we can see that the program should be used with program_name flag , we can also deduce that sub_401010 is printf. So we relabel and continue snooping around. While inspecting the main code, we can see some weird function (sub_403180) being called with constant arguments which returns a function that gets called. Let’s relabel it weird_function for easier detection.</p><p>We try to reverse engineer that function, but the code is quite complex and looks pretty obfuscated. (I did notice usage of the PEB though :) )</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/156/1*o7sfcsbDbmjq9xZA5pTdEQ.png" /><figcaption>sub_403180</figcaption></figure><p>Okay, so I think we’re done with the static analysis and we can start dynamically analysing this. We open the roulette.exe file in x32dbg, and give it a command line option of flag{AAAAAAAAAAAAAAAAAAAAAAAAAAAAA} . So press “Run to user code” -&gt; Look for the main function and break in it.</p><p>So let’s inspect the first function which gets called in the process:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*gh4l5svqVbtJy25h8wJ_gg.png" /><figcaption>sub_4032d0</figcaption></figure><p>Look at that! Our weird function is also used here, let’s step into this function and try to see what’s going on. I step over until I reach the weird_function call:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lZkYYX54wd7wrX_ONaPZ9Q.png" /></figure><p>Stepping over 1 more time reveals the function’s actual usage. We step over 1 more time and look at the registers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*Q6NWi2yYb6pFm9zfDpzwgQ.png" /></figure><p>Ah! So that weird obfuscated function actually returns pointers to winapi functions. That’s pretty cool! We can step over all the other function calls and use it to relabel the variables which get set to the result of this function. (I relabeled the function to be calledget_func , and relabeled every variable with its proper function)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pDRQ1z6PVv7lnKZhxilmjw.png" /><figcaption>sub_4032d0</figcaption></figure><p>After relabelling the functions, it’s super clear what this function does. It opens a handle to the current process’ file (Little tip, when you notice the value 260 in strings / char[] always think about the GetModuleHandle function or any file interactions, since 260 represents the MAX_PATH constant, which specifies how large paths can be), so let’s relabel this function get_current_exe_handle and continue.</p><p>Let’s dive into the sub_4033a0 function. Small note: IDA can sometimes misinterpret function declarations, and misintrepret function parameters. So in order to fix this we need to lookup the function definition in MSDN and actually fix it. After casting the function to our desired type, we need to right click whenever the function gets called, and select “Force cast”.</p><p>After labelling everything, the flow looks like this:</p><p>GetFileSize (currentExe) -&gt; Allocate space in heap -&gt; Read current exe and put inside allocated space in heap -&gt; xor data read with character from flag -&gt; Allocate more space in heap -&gt; Create temporary file and insert its name into the allocated heap space -&gt; Get handle to temporary file -&gt; Write into temporary file (what we read from the exe)</p><p>So we can label this function create_temp_modified_exe_file , 1 more function to go and we’re almost done :) Let’s inspect the sub_4035d0 function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_TkljXanx9rayEjmWVgVaA.png" /><figcaption>sub_4035d0</figcaption></figure><p>Wow, it’s pretty simple! It calls the createprocessA function with the commandline arguments: &lt;tmp_file_name&gt; &lt;our_flag&gt; . Later on in the function it actually tries to wait until the process ends, and if the process ends with a status code different than an OK status code, the function actually returns 0, which means we failed. So let’s call this function verify_flag</p><p>Now, let’s see what the temporary file contains, we run the roulette.exe file with the flag{AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA} parameter. (remember the xor uses the character in the 40th index)</p><p>So in order to inspect the temporary file, we set a breakpoint before the DeleteFileA function (and before the createprocessA function just for comfortability) and run it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*UyV6XtG4T7FUgSwuXVMcNQ.png" /><figcaption>Opening the .tmp file in IDA</figcaption></figure><p>Uhm… Looks like the temporary file is corrupted or something. Remember that most functions start with the push ebp; mov ebp, esp prolog? And we also remember our exe file gets XORed with the 40th index of our flag, we know XOR is reversible. We know the first opcode got calculated in the following way:</p><p>first_opcode = our_exe_file ^ flag[40]</p><p>We want first_opcode to be 0x55 (since 0x55 is push ebp ), so we have 2 equations and we have to solve them</p><p>first_opcode = our_exe_file ^ flag[40] and 0x55 = our_exe_file ^ ?</p><p>Since XOR is reversible, our_exe_file = 0x55 ^ ? therefore first_opcode = 0x55 ^ ? ^ flag[40] =&gt; ? = first_opcode ^ flag[40] ^ 0x55 So let’s try calculating the unknown variable and see if we get some valid code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*8lZUnji2z6bShDpJlwtz8Q.png" /><figcaption>Undefined start function</figcaption></figure><p>So we undefine the first opcode in order to see its value, it’s 0x79. so first_opcode=0x79 , next remember flag[40]=A=0x41 , so ?=0x55 ^ 0x41 ^ 0x79 = 109 = &#39;m&#39;. Now let’s try doing the same thing with flag[40]=m</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*BhnLBs5_AVBnfglAYnUhRA.png" /><figcaption>New .tmp file after using flag[40] = ‘m’</figcaption></figure><p>Wow! This looks just like our exe’s code, so we probably have to do this recursively for all .tmp files that come out of this tmp file, so I wrote a script that does exactly what we did.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*gknOTGGJBUJw-yGbunX1fA.png" /></figure><p>For some unknown reason* the script gives a ` after the p3 , but it’s an easy fix from ` =&gt; _. So it’s pretty easy to do :)</p><p>*EDIT: I discovered the last stub actually is just an exit() so it doesn’t contain the push ebp; mov ebp, esp prolog we were talking about.</p><p>The script’s code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c81a08a2462e859efc9734572dafa23d/href">https://medium.com/media/c81a08a2462e859efc9734572dafa23d/href</a></iframe><p>Thank you for reading :) And thanks to the challenge’s creator. Make sure to follow him <a href="https://medium.com/u/870076408a61">Omer Katz</a> (@omerk2511 — twitter handle)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b8a19069e70" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Snappaste (2) — BSidesTLV 2020 (600 pts.)]]></title>
            <link>https://medium.com/@ctfgudai/snappaste-2-bsidestlv-2020-600-pts-14632ee87a97?source=rss-9bdd8886168a------2</link>
            <guid isPermaLink="false">https://medium.com/p/14632ee87a97</guid>
            <category><![CDATA[2020]]></category>
            <category><![CDATA[bsides]]></category>
            <category><![CDATA[pwn]]></category>
            <category><![CDATA[snappaste]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[1byte]]></dc:creator>
            <pubDate>Tue, 30 Jun 2020 12:41:59 GMT</pubDate>
            <atom:updated>2020-06-30T12:41:59.016Z</atom:updated>
            <content:encoded><![CDATA[<h3>Snappaste (2) — BSidesTLV 2020 (600 pts.)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*82kYOyvvjpiUz7lCRSgrBA.png" /></figure><pre>Here&#39;s an improved version of our pasting service. Some weird stuff was happening in the previous version, so we added an integrity check for the pastes. Also, due to misuse, we began limiting the size of the pasted snippets (please don&#39;t paste Kali Linux ISOs, thanks).</pre><pre><strong>URL:</strong> <a href="https://snappaste2.ctf.bsidestlv.com/">https://snappaste2.ctf.bsidestlv.com/</a></pre><pre><strong>To compile, Use the following commands:</strong></pre><pre>gcc -c -std=c99 zlib/*.c  <br>g++ -c -std=c++14 snappaste.cc   <br>g++ -o snappaste *.o -pthread</pre><p>I will keep this one quite short. Since this challenge is a continuation of the previous snappaste challenge (link for my writeup is <a href="https://medium.com/@ctfgudai/snappaste-1-bsidestlv-2020-450-pts-ee5bbe0314f2">here</a>).</p><p>In this challenge, the size of the variables are actually checked, but a new feature was added: crc32 to “verify” the contents of our message.</p><p>We know the flag gets copied to our data buffer if the decompressed data’s length is greater than its length, but if our data is actually smaller than the decompressed data’s size, remaining parts of the flag remain in the data variable. As described in the graph below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*qDQ-j4GGD9_Zb3AWYgxynQ.png" /></figure><p>So to calculate the flag’s length. we can calculate the CRC32 of AAAAAAAAAAAAAAAAAAA}, and send it over to the server. If we don’t get a CRC32 error, we know we got the correct length, else we increment decompressed_data_size. We start by declaring decompressed_data_size=1 .</p><p>After finding the flag’s length, we can calculate the rest of the characters with the following fashion: We set decompressed_data_sizeto be the length of the flag minus 1. We calculate the crc of AAAAAAAAAAAAAAAAAAAAA!}, if we get a crc error, we know it’s not the character and continue on. If we don’t get a crc error, it is the character and we decrement decompressed_data_size trying on the next character AAAAAAAAAAAAAAAAAAAA!h}.</p><p>So the following script solves it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8db3e9b0833a23f023470e05d9b6a619/href">https://medium.com/media/8db3e9b0833a23f023470e05d9b6a619/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14632ee87a97" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Snappaste (1) — BSidesTLV 2020 (450 pts.)]]></title>
            <link>https://medium.com/@ctfgudai/snappaste-1-bsidestlv-2020-450-pts-ee5bbe0314f2?source=rss-9bdd8886168a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee5bbe0314f2</guid>
            <category><![CDATA[2020]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[pwn]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[bsides]]></category>
            <dc:creator><![CDATA[1byte]]></dc:creator>
            <pubDate>Tue, 30 Jun 2020 12:15:31 GMT</pubDate>
            <atom:updated>2020-06-30T12:15:31.492Z</atom:updated>
            <content:encoded><![CDATA[<h3>Snappaste (1) — BSidesTLV 2020 (450 pts.)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*XImw6Op1ejwLRjooCgyZDw.png" /></figure><pre>We felt like there were not enough pasting services, so we created Snappaste! For better privacy, each pasted text can only be accessed once. We care about performance, and therefore we developed Snappaste in C++. We hope that we didn&#39;t introduce any security bugs :)</pre><pre><strong>URL:</strong> <a href="https://snappaste.ctf.bsidestlv.com/">https://snappaste.ctf.bsidestlv.com/</a></pre><pre><strong>To compile, Use the following commands:</strong></pre><pre>gcc -c -std=c99 zlib/*.c  <br>g++ -c -std=c++14 snappaste.cc   <br>g++ -o snappaste *.o -pthread</pre><p>TL;DR at the bottom for whoever just wants to read the solution (a script is attached)</p><p>In this challenge, we are given a link to a paste website which allows its users to create a single-use paste with a randomly generated 16 byte name. Like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MC8VX8GIypoIzNwPJ4x54Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Up4R9shIjDkdgFHw1CgPzw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KOZN8OTrkm2C4LTLQXzXaw.png" /></figure><p>Okay, so after viewing the site’s features we can safely dive into the source code which was also given by the challenge. We extract the zip to our challenge folder, and compile the challenge as the challenge creator instructed to do (notice we added the g flag in order to enable debugging symbols which will allow us for an easier time debugging):</p><pre>gcc -g -c -std=c99 zlib/*.c  <br>g++ -g -c -std=c++14 snappaste.cc   <br>g++ -g -o snappaste *.o -pthread</pre><p>While inspecting the code, I came across several interesting paths to solve this challenge:</p><ul><li>The backdoor_filenamevariable is pretty suspicious, so it might have to do something with it.</li><li>Might be some sort of path traversal vulnerability (although we can disqualify this because this is a PWN challenge)</li></ul><p>Delving deeper into the source code we can see there are a few preconfigured paths we can use (I’ve only listed the interesting ones):</p><ul><li>/paste (<strong>POST</strong>) — Alows us to paste in content</li><li>/view/[a-z]{16} (<strong>GET</strong>)— Tries to read a paste with the provided name, and if it exists it’s also deleted.</li><li>/backdoor/[a-z]{16} (<strong>GET</strong>)— Was supposedly added for testing purposes, and provides us with the backdoor_filenamevariable’s address.</li></ul><p><strong>Note</strong>: [a-z]{16} is basically a regular expression which matches 16 (no more and no less) characters from a to z, so abcdefghabcdefgh will match, but abcdefghabcdefg (15 characters), Abcdefghabcdefgh (1 uppercase letter) will both not match</p><p>The view endpoint also has an extra feature, if the backdoor_filename is the same as our provided filename we get the flag, and achieve great victory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*MERDYVwYBbO7y8pJ4IdMrA.png" /></figure><p>Unfortunately for us, the line that modifies the backdoor_filename variable with our provided content has been commented out and we have to find a different way to modify the backdoor_filename variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*9J8nxx7FifJ1Ir5qb2j-Fw.png" /></figure><p>The next interesting thing we probably should investigate is the paste function since it is the main functionality of our program, and we will probably find the error in it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60d43489c02a767e44bbf8162a6576bb/href">https://medium.com/media/60d43489c02a767e44bbf8162a6576bb/href</a></iframe><p>In order to understand better what’s going on, I have drawn a small graph to demonstrate the process happening.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*axuMFe0ze-eAMVnR2EKMWg.png" /></figure><p>The sizes at the top are a part of the PASTE_NETWORK_HEADER struct which is defined as the following:</p><pre>struct PASTE_NETWORK_HEADER {</pre><pre>dword metadata_size;</pre><pre>dword data_compressed_size;</pre><pre>dword data_decompressed_size;</pre><pre>};</pre><p>Let’s go over line by line what the paste function is actually doing:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/634bace1c0ab6952a4d7c792ffe84b44/href">https://medium.com/media/634bace1c0ab6952a4d7c792ffe84b44/href</a></iframe><p>The first if verifies we have the sizes described at the top, the second if checks if we have more data than we actually claim to have. After that if, we might get a bit confused since what does metadata + header-&gt;metadata_size have to do with anything? Well if we remember metadata is a pointer, it actually makes sense. Let’s look back at the earlier graph:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*nKQmjO8abHCGyHzE_XXV3Q.png" /></figure><p>So now this makes sense, raw is a pointer to the beginning of the request, the sizes are described by the PASTE_NETWORK_HEADER struct so raw + sizeof(PASTE_NETWORK_HEADER) will be metadata, and therefore the compressed data will be at raw + sizeof(PASTE_NETWORK_HEADER) + metadata_size which makes sense.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc85a815a04e7c7c4c67d9a502e18b1f/href">https://medium.com/media/fc85a815a04e7c7c4c67d9a502e18b1f/href</a></iframe><p>Next, we allocate a block of memory the size of the metadata + the size of the decompressed data + the size of the customly defined struct. So it will look like the following in memory:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*zwK4sbukw_-LeKPSRCcexQ.png" /></figure><p>next we uncompress the given data (which was compressed with zlib’s compression) into the paste_received-&gt;data variable. (Which lies in the second part of our graph)</p><p>After the decompression, we copy the metadata into the paste_received-&gt;metadata pointer, which lies in the first part of our graph.</p><p>Since we are given the backdoor_filename ‘s address we might think of ideas to override paste_received-&gt;metadata pointer with the backdoor_filename ‘s address therefore copying our metadata to the variable. One way to do this would be to actually to declare we have less decompressed data than we actually have, and then when decompressing the data it will actually overflow into the paste_received struct. But the uncompress , unfortunately for us, checks for this, and will return with an error.</p><p>After a long time of searching, I tried to mess with the provided sizes, and noticed something very interesting</p><pre>dword num_bytes = header-&gt;metadata_size + header-&gt;data_decompressed_size + sizeof(PASTE_RECEIVED);</pre><p>The num_bytes variable is a DWORD, but it is getting assigned to a DWORD + DWORD + sizeof(PASTE_RECEIVED), this is a classical overflow, and we can actually cause the num_bytes to be smaller than the actual data we provide. Now remember that we need to copy over 16 characters from the metadata to the backdoor_filename variable, so we’ll set the metadata size to 17, and set the decompressed data size to 0xffffffff which is the maximum variable size we can have.</p><p>From here, we have a write-what-where exploit, by overriding the paste_received-&gt;metadata pointer with whatever we want, we can write the metadata variable into the backdoor_filename variable. So this is the final exploit:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c378eafa0927292ac9c3572321648ce/href">https://medium.com/media/2c378eafa0927292ac9c3572321648ce/href</a></iframe><p><strong>TL;DR: </strong>In this challenge we have a DWORD overflow, because the website allocates the decompressed data before the PASTE_RECEIVED struct, we can override the metadata pointer with our data therefore allowing a write-what-where situation and modifying the backdoor_filename variable with our own paste link.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee5bbe0314f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ångstromCTF 2020 — A Peculiar Query [180]]]></title>
            <link>https://medium.com/@ctfgudai/%C3%A5ngstromctf-2020-a-peculiar-query-180-e0ddf836d7df?source=rss-9bdd8886168a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0ddf836d7df</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[angstromctf]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[web-exploitation]]></category>
            <category><![CDATA[a-peculiar-query]]></category>
            <dc:creator><![CDATA[1byte]]></dc:creator>
            <pubDate>Thu, 19 Mar 2020 02:09:22 GMT</pubDate>
            <atom:updated>2020-03-19T02:09:22.068Z</atom:updated>
            <content:encoded><![CDATA[<h3>ångstromCTF 2020 — <strong>A Peculiar Query</strong> [180]</h3><blockquote>Clam thinks he’s really cool and compiled a database of “criminal records” with a <a href="https://peculiarquery.2020.chall.actf.co/">site</a> to top it all off. I’ve dropped the tables once before but this time he took some extra security measures and I think he even hid a flag in there. Can you get it?</blockquote><blockquote>Author: aplet123</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hj7ihzL5VyQTFdf9Lcl7KA.png" /></figure><p>In this challenge we get the sourcecode, and a site.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/caf100feb0307731f2a643821d70bdc2/href">https://medium.com/media/caf100feb0307731f2a643821d70bdc2/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c4ei9h4G9WKfVzEkZeKTeg.png" /></figure><p>From the sourcecode we can see there are characters which are unallowed, and from then on the server “censors” the string, for example if we insert hello&#39;world then the server would censor it to hello****** .</p><p>What can we do here? Well, the server doesn’t check for a data type, so in theory, we could insert an array and while looping over the array no strings would be any of the characters, another thing we notice is ${[&quot;&#39; OR &#39;1&#39;=&#39;1&quot;]}=&quot;&#39; OR &#39;1&#39;=&#39;1&quot; (basically the array gets turned into a string).</p><p>But what happens when we try entering an array?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*vdzWpi71ICg8qWd46WKJmA.png" /></figure><p>uhm, seems like an array doesn’t have a substring so the program fails. What happens when we do [] + [] = ? , well let’s try:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/80/1*1J9GvJSyffdZaygKWAcBXg.png" /></figure><p>Javascript truly is a weird language, who would’ve thought addition of 2 arrays would us a string? So we should try failing once, therefore changing our arrys into a string and bypassing the check. Let’s try again:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*vOBLVNVkSNKzneuDoJFiug.png" /></figure><p>This time the rest of our “hello world” was censored, even though we first bypassed the test. (Why is that? because q.length changes when the array turns into a string) So it censored every character after e , so I created a script in order to fail after a certain character:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ad67bbdbed9d7cc6e71e169dcabcd13/href">https://medium.com/media/1ad67bbdbed9d7cc6e71e169dcabcd13/href</a></iframe><p>We run the script and get:</p><p>[‘hello world’, ‘q’, ‘q’, ‘q’, ‘q’, ‘q’, ‘q’, ‘q’, ‘q’, ‘q’, ‘q’, “‘“]</p><p>Let’s try running this through the censoring system now:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*cuZfA5GDzO8RryjEKKemVQ.png" /></figure><p>So, we have bypassed the test, now we can use an sql injection, so we can rewrite this script to fit a get request. So this is the script I wrote:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c56244ccff44bbe313e7eb640a71049f/href">https://medium.com/media/c56244ccff44bbe313e7eb640a71049f/href</a></iframe><p>We use the payload ’ AND 1=0 UNION SELECT COLUMN_NAME FROM information_schema.COLUMNS in order to view all the columns (can’t add a where clause because of the 80 character limit).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KOAZI0nCjzmgOOlCTiZXcg.png" /></figure><p>So we know there is a “Crime Reason”, let’s try searching for crime :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DX37CjjmlyWWZTbpmhhPWg.png" /></figure><p>Now we can create a different payload in order to view all the crimes. ‘ AND 1=0 UNION SELECT crime FROM Criminals-- should show us all the crimes from the Criminals table. Let’s try it: The script gives us</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nc0PZZzGbkKqrqO9B_4Tjw.png" /></figure><p>And we solved it :) the flag is actf{qu3r7_s7r1ng5_4r3_0u7_70_g37_y0u}</p><p>I’d like to use this opportunity to thank the angstromCTF team for hosting this fun CTF and giving me such a wonderful experience learning and solving challenges.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0ddf836d7df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ångstromCTF 2020 — LeetTube [190]]]></title>
            <link>https://medium.com/@ctfgudai/%C3%A5ngstromctf-2020-leettube-190-1cae1279d083?source=rss-9bdd8886168a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cae1279d083</guid>
            <category><![CDATA[angstromctf]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[leettube]]></category>
            <category><![CDATA[web-exploitation]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[1byte]]></dc:creator>
            <pubDate>Thu, 19 Mar 2020 00:48:24 GMT</pubDate>
            <atom:updated>2020-03-19T00:49:41.210Z</atom:updated>
            <content:encoded><![CDATA[<h3>ångstromCTF 2020 — LeetTube [190]</h3><blockquote>I developed a new video streaming service just for hackers. Learn all about viruses, IP addresses, and more on <a href="https://leettube.2020.chall.actf.co/">LeetTube</a>! Here’s the <a href="https://files.actf.co/5fb7188c18fde9206e4a43f5c817b4a9db6ee784366b65033904a2538d0d1782/leettube.py">source code</a> and the <a href="https://files.actf.co/929adf47a8fe915cc89618c9f4ec38068cc08525087171832cdd3c9c3f6db897/Dockerfile">Dockerfile</a>.</blockquote><blockquote>Note: the server is also running behind NGINX.</blockquote><blockquote>Hint: I wonder what’s in that unpublished video…</blockquote><blockquote>Author: kmh11</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xk1lr1vTpyiWE5OjcwP4jA.png" /></figure><p>In this challenge we are given the sourcecode and a Dockerfile for the following site:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v8SIdVMq6jiXDjCTO3YPAQ.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/857746c9c598a49f26f1b18b244ed5c1/href">https://medium.com/media/857746c9c598a49f26f1b18b244ed5c1/href</a></iframe><p>We can see the server handles the requests manually, and tries parsing the path in order to decide what happens next. <br>Let’s inspect the following piece of code:</p><pre>18: self.path = urllib.parse.unquote(self.path)<br>19: if self.path.startswith(&#39;/videos/&#39;):<br>20:     file = os.path.abspath(&#39;.&#39;+self.path)</pre><p>We notice the server just checks the beginning of the path, while the coder intended /videos/video_file_name to pass, instead we can validate /videos/../different_file_name and by that open any arbituary file. We know the file tree looks like this:</p><pre>app<br>├── leettube.py<br>└── videos<br>    ├── Killer.mp4<br>    ├── Null Pointer.mp4<br>    └── Virus.mp4</pre><p>So we could test our theory by requesting /videos/../leettube.py</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u70I463ujU9LfQ7A3KEHIw.png" /></figure><p>And we receive back leettube.py next thing we would want to check whether we have access to the entire filesystem, so in order to do that we could do the routine check of /etc/passwd , but when we try getting /videos/../../etc/passwd we receive a 400 BAD REQUEST</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t6D7QqXBYwldkmkLiWdRtQ.png" /></figure><p>Well, the note says they are using nginx. So in order to understand why this fails, we have to understand how a reverse proxy nginx works:<br>It takes in a path provided by the user, and checks if it matches any of the paths it has. So on our case we have the path /app/ , if so it redirects us to the webpage. Else it doesn’t know what to do, and just throws a 400.</p><p>The usual request will be /app/&lt;path&gt; , so by doing /app/videos/../../ we tell nginx we try accessing / , but this path isn’t defined as far as nginx knows so we get a 400. In order to bypass that we would need to use parameters.</p><p>What could we use that would leave us at the same page, but at the same time help us get access to the entire filesystem? Well we do know the server uses os.path.abspath on our path, so by giving it /path_doesnt_exist/../ it will automatically convert it to / without checking if path_doesnt_exist actually exists, so we could try accessing /app/videos/../?path_doesnt_exist/../../ and this will be actually converted to: /app/videos/../../ = /app/../ = / so let’s try testing this by accessing <br>/videos/../?path_doesnt_exist/../../etc/passwd</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T2H2_ZQ12oh1XBU8P2H8NA.png" /></figure><pre>videos = []</pre><p>So from this we assume the videos must be in the memory, so in order to view them we could go to the special filesystem path /proc/self/maps which will give us the memory ranges of the program, so we request /proc/self/maps and get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uZsDRhjhwH5q3exdJwSXNw.png" /></figure><p>Let’s try reading the first map range from /proc/self/mem . Remember we can use the header Range: bytes &lt;byte_0&gt;-&lt;byte_1&gt; in order to read from /proc/self/mem and actually get data, so we try reading the first part with burp:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JJV4vsarDNMyPzCKw0e9hw.png" /></figure><p>I took the memory ranges from burp, and formatted them into a file that is in the following format:</p><pre>range1-range2<br>range3-range4<br>...</pre><p>And created a script in order to download the data into files:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f702e13d9c93111ff8fce0d2712958cf/href">https://medium.com/media/f702e13d9c93111ff8fce0d2712958cf/href</a></iframe><p>where ../ranges is the formatted file with the ranges. <br>So we downloaded the files, and now we have to search inside them for video files, according to <a href="https://www.garykessler.net/library/file_sigs.html">this</a>, the mp4 file signature begins with ftyp . So I created another script in order to detect any files that match the above criteria:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a95db63d1864fdd7ad32b298d95420c3/href">https://medium.com/media/a95db63d1864fdd7ad32b298d95420c3/href</a></iframe><p>Running it gave me the following output:</p><blockquote><em>[$user@user-comp]files$ python3 find_content.py <br>file24 [‘0x34’, ‘0x51e034’, ‘0x5ad034’, ‘0x622034’, ‘0x622034’]<br>file24 [‘0x63’, ‘0x4307a’, ‘0x12bbd2’, ‘0x4a5e19’, ‘0x51dd3d’, ‘0x51dd3d’]</em></blockquote><p>So we can confirm there are files that match this description, in order to view them I created a bash script that will help me extract these files:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0bd6fa3d9de136ac6c947d2b3ce2c2b0/href">https://medium.com/media/0bd6fa3d9de136ac6c947d2b3ce2c2b0/href</a></iframe><p>We run it and get:</p><blockquote>[$user@user-comp]files$ ./extract.sh <br>files/file24 52<br>files/file24 5365812<br>files/file24 5951540<br>files/file24 6430772<br>files/file24 52<br>…<br>9179089 bytes (9.2 MB, 8.8 MiB) copied, 0.534308 s, 17.2 MB/s<br>files/file24 5365812<br>…<br>3813329 bytes (3.8 MB, 3.6 MiB) copied, 0.00367175 s, 1.0 GB/s<br>files/file24 5951540<br>…<br>3227601 bytes (3.2 MB, 3.1 MiB) copied, 0.00636029 s, 507 MB/s<br>files/file24 6430772<br>…<br>2748369 bytes (2.7 MB, 2.6 MiB) copied, 0.00544803 s, 504 MB/s</blockquote><p>Let’s check the directory we have</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mlw4xhSfKS57t-t1bVjEeA.png" /></figure><p>and we notice some mp4 files, opening one of them will show us the following video:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fimgur.com%2Fa%2FbOwxwKG%2Fembed%3Fpub%3Dtrue%26ref%3Dhttps%253A%252F%252Fembed.ly%26w%3D900&amp;display_name=Imgur&amp;url=https%3A%2F%2Fimgur.com%2Fa%2FbOwxwKG&amp;image=https%3A%2F%2Fi.imgur.com%2F06up0Dn.jpg%3Ffbplay&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=imgur" width="900" height="566" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d41b4dd59888a74cfb8b379827b36ea/href">https://medium.com/media/0d41b4dd59888a74cfb8b379827b36ea/href</a></iframe><p>So we have the flag:</p><p>actf{1337tube?_more_like_l34ktube}</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cae1279d083" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BSides San Francisco — Recipes(204 points)]]></title>
            <link>https://medium.com/@ctfgudai/bsides-san-francisco-recipes-204-points-e1cd93fe9ef?source=rss-9bdd8886168a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1cd93fe9ef</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[writeup]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[bsides]]></category>
            <category><![CDATA[exploitation]]></category>
            <dc:creator><![CDATA[1byte]]></dc:creator>
            <pubDate>Tue, 25 Feb 2020 03:08:41 GMT</pubDate>
            <atom:updated>2020-02-25T03:12:22.201Z</atom:updated>
            <content:encoded><![CDATA[<h3>BSides San Francisco — Recipes(204)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*QhTcO-pDyRSni43ElFk4pQ.png" /><figcaption>Challenge information</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*akI7ypXhjEUmraDfF91fwQ.png" /><figcaption>Web page given when entering the challenge</figcaption></figure><p>From the first look, it seems like we are given a website with a normal login page, and a register page. We register an account called 1p4nm4n and login with it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DaYr9JBbTnqU_E0ZVfoHfQ.png" /></figure><p>We are greeted with a new recipes endpoint, and upon further inspection of the source code we can see a new /users endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*WlvwmG49WtqKXEYkf6oVug.png" /></figure><p>But as soon as we try to access it we receive an error that says we are not allowed to access the endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*gXn95QEIdMs-t4cKohBi5Q.png" /></figure><p>Let’s move on for now… This might be valuable later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*70SvLhL5VQ_10Be5_yPEvg.png" /></figure><p>Adding a new recipe is a basic form submittion and from past experience we can be suspicious of the picture URL property of our recipe, since many times programmers forget to make validation checks that the service is actually performing requests to valid PNG or JPG files. And instead we get SSRF which stands for Server Side Request Forgery (<a href="https://portswigger.net/web-security/ssrf">portswigger</a>, <a href="https://owasp.org/www-community/attacks/Server_Side_Request_Forgery">OWASP</a>) — Which basically means we can make the server do requests for us, which means we can access internal pages that are not exposed to the public network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*yJqi7PmEf7Moo5TBumDaWw.png" /></figure><p>So here the interesting/users endpoint comes into play, we try to submit a form with picture_url=”http://0.0.0.0:8080/users” and hope we get back a valid response. (We add ?a=.png incase the server checks for a .png extension at the end of the url — which is a pretty common check that can get bypassed pretty fast)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*euY0uJQjNZk8Tv9eycXFNQ.png" /></figure><p>Hmmm, we don’t seem to get anything except for an invalid image. Or do we? Let’s try inspecting the image closer -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zrgJL84bfjrqxUCCkI7tTw.png" /></figure><p>And we have a weird <a href="https://www.base64decode.org/">base64</a> encoded string, wonder what that could be… We try to decode the string and voilà! We get a webpage with a list of users:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;</pre><pre>&lt;head&gt;</pre><pre>&lt;meta charset=&quot;utf-8&quot;&gt;<br>  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1, shrink-to-fit=no&quot;&gt;<br>  &lt;meta name=&quot;description&quot; content=&quot;&quot;&gt;<br>  &lt;meta name=&quot;author&quot; content=&quot;&quot;&gt;</pre><pre>&lt;title&gt;RecipeServ&lt;/title&gt;</pre><pre>&lt;link href=&quot;/static/bootstrap/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;&gt;</pre><pre>&lt;/head&gt;</pre><pre>&lt;body&gt;</pre><pre>&lt;nav class=&quot;navbar navbar-expand-lg navbar-dark bg-dark static-top&quot;&gt;<br>    &lt;div class=&quot;container&quot;&gt;<br>      &lt;a class=&quot;navbar-brand&quot; href=&quot;#&quot;&gt;RecipeServ&lt;/a&gt;<br>      &lt;button class=&quot;navbar-toggler&quot; type=&quot;button&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#navbarResponsive&quot; aria-controls=&quot;navbarResponsive&quot; aria-expanded=&quot;false&quot; aria-label=&quot;Toggle navigation&quot;&gt;<br>        &lt;span class=&quot;navbar-toggler-icon&quot;&gt;&lt;/span&gt;<br>      &lt;/button&gt;<br>      &lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;navbarResponsive&quot;&gt;<br>        &lt;ul class=&quot;navbar-nav ml-auto&quot;&gt;<br>          &lt;li class=&quot;nav-item&quot;&gt;<br>            &lt;a class=&quot;nav-link&quot; href=&quot;/&quot;&gt;Home<br>            &lt;/a&gt;<br>          &lt;/li&gt;<br>          <br>          &lt;li class=&quot;nav-item&quot;&gt;<br>            &lt;a class=&quot;nav-link&quot; href=&quot;/login&quot;&gt;Login&lt;/a&gt;<br>          &lt;/li&gt;<br>          &lt;li class=&quot;nav-item&quot;&gt;<br>            &lt;a class=&quot;nav-link&quot; href=&quot;/register&quot;&gt;Register&lt;/a&gt;<br>          &lt;/li&gt;<br>          <br>        &lt;/ul&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/nav&gt;</pre><pre>&lt;div class=&quot;container pt-3&quot;&gt;<br>    &lt;div class=&quot;row&quot;&gt;<br>      &lt;div class=&quot;col-md-8 offset-md-2&quot;&gt;<br>    <br>  &lt;ul&gt;<br>  <br>    &lt;li&gt;&lt;a href=&#39;/profile/00100d2d-3e53-4c96-828f-fb64aa5294bf&#39;&gt;RPISEC&lt;/a&gt;&lt;/li&gt;<br>  /*</pre><pre>............... SHORTED FOR READABILITY ......................<br>  */<br>   &lt;li&gt;&lt;a href=&#39;/profile/6180f0c8-778b-442f-a5ab-10e18bef4c2d&#39;&gt;boudin_bakery&lt;/a&gt;&lt;/li&gt;</pre><pre>    &lt;li&gt;&lt;a href=&#39;/profile/d473c635-b959-4486-afd8-e40367498d9a&#39;&gt;1p4nm4n&lt;/a&gt;&lt;/li&gt;<br>  <br>  <br>  &lt;/ul&gt;</pre><pre>&lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;</pre><pre>&lt;script src=&quot;/static/jquery/jquery.slim.min.js&quot;&gt;&lt;/script&gt;<br>  &lt;script src=&quot;/static/bootstrap/js/bootstrap.bundle.min.js&quot;&gt;&lt;/script&gt;</pre><pre>&lt;/body&gt;</pre><pre>&lt;/html&gt;</pre><p>There is a huge list of usernames(including ours), so I removed most of them and left out some. From the challenge info we notice we have to get the recipes from Boudin Bakery (There is another user who created the name Boudin Bakery, but the real one is boudin_bakery). We see there is an endpoint for /profile/6180f0c8–778b-442f-a5ab-10e18bef4c2d but when we try accessing it internally or externally we get a 404.</p><p>So we try something else, let’s look at the cookie we got to authenticate our user:</p><p>auth_token= eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODI2MDE2ODUsImlhdCI6MTU4MjU5ODA4NSwiaXNzIjoicmVjaXBlYm90IiwibmJmIjoxNTgyNTk4MDg1LCJzdWIiOiJkNDczYzYzNS1iOTU5LTQ0ODYtYWZkOC1lNDAzNjc0OThkOWEifQ.ztW4yuHvdwvlKyoM-FTRHPi31uBymD7htHfVhXUckos</p><p>This looks oddly familiar to a JWT(Json Web Token), we try base64 decoding the first block and second block (not the third since it is the signature, and the interesting bits are in the first and second). And we get the following data pieces: {“alg”:”HS256&quot;,”typ”:”JWT”} .{“exp”:1582603228,”iat”:1582599628,”iss”:”recipebot”,”nbf”:1582599628,”sub”:”d473c635-b959–4486-afd8-e40367498d9a”} .{signature}</p><p>If we look carefully, the sub matches our ID from the /profile/ endpoint. So from here we could try to impersonate the boudin_bakery account in multiple ways: Check if alg=none <a href="https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/">attack</a> works, or try to <a href="https://medium.com/@valeriyshevchenko/brute-forcing-jwt-token-hs256-6f545d24c7c3">bruteforce</a> our jwt cookie and sign our own cookie.</p><p>I went with the first way (which is probably the intended). In order to use the alg=none attack we have to base64 encode the block {“alg”:”none&quot;,”typ”:”JWT”} which is: eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0= , then we have to craft a new second block which will be using boudin_bakery’s sub. so we want {“exp”:1582603228,”iat”:1582599628,”iss”:”recipebot”,”nbf”:1582599628,”sub”:”6180f0c8–778b-442f-a5ab-10e18bef4c2d”} and base64 encoded is: eyJleHAiOjE1ODI2MDMyMjgsImlhdCI6MTU4MjU5OTYyOCwiaXNzIjoicmVjaXBlYm90IiwibmJmIjoxNTgyNTk5NjI4LCJzdWIiOiI2MTgwZjBjOC03NzhiLTQ0MmYtYTVhYi0xMGUxOGJlZjRjMmQifQ== . The only thing left to execute the attack is to chain them together, and remove the signature.</p><p>Let’s try changing our cookie to:</p><p>eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0=.eyJleHAiOjE1ODI2MDMyMjgsImlhdCI6MTU4MjU5OTYyOCwiaXNzIjoicmVjaXBlYm90IiwibmJmIjoxNTgyNTk5NjI4LCJzdWIiOiI2MTgwZjBjOC03NzhiLTQ0MmYtYTVhYi0xMGUxOGJlZjRjMmQifQ==.</p><p>We set this as the auth_token and when we access recipes we can see 4 new recipes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HxFTtuoq6KQSf72ftaNhAA.png" /></figure><p>As expected, entering Flag Bread will give us the flag CTF{let_the_shellz_rise_b4_baking}</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*tHjBDcOpVXcfJzjo7b38lA.png" /></figure><h3>Summary</h3><p>In this writeup we exploited SSRF in order to gain a UUID, and with JWT exploitation we were able to impersonate boudin_bakery and steal all his recipes!</p><p>Thank you for reading this writeup, if you have any inqueries feel free to mail me at ctfgudai@gmail.com or send me a tweet @guysudai1</p><p>I’d like to thank the BSidesSF team members and volunteers who helped set this whole CTF up, I’ve had so much fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1cd93fe9ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[KipodAfterFreeCTF — Happy Cake 2]]></title>
            <link>https://medium.com/@ctfgudai/kipodafterfreectf-happy-cake-2-a5b789aa354f?source=rss-9bdd8886168a------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5b789aa354f</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[1byte]]></dc:creator>
            <pubDate>Fri, 27 Dec 2019 12:20:40 GMT</pubDate>
            <atom:updated>2019-12-27T12:20:40.761Z</atom:updated>
            <content:encoded><![CDATA[<h3>KipodAfterFreeCTF — Happy Cake 2</h3><blockquote>Who needs cakes these days — Mini Cakes(TM) are way more compact.</blockquote><blockquote><a href="http://ctf.kaf.sh:1170/">http://ctf.kaf.sh:1170</a></blockquote><p>We enter the challenge and we get a prompt:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2WisA7SwGRFt1fCH9a2qYA.png" /></figure><p>Let’s try entering a username: TEST12345, we get the following new cookies:</p><blockquote>choclatechips=8986be71408ace74486e35bd17c4ea6bc7fe5f020be9ab46f2f5dfd73f28a397; choclatechip=TEST12345</blockquote><p>In addition, we get a new menu screen with different kinds of cookies to Add 1 to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hxrqx3T3lrXu6xQ7GhxgiQ.png" /></figure><p>If we look at the sourcecode we might be able to find a script that’s no longer in use-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Ss7zHllD25jBr4omR3jAw.png" /></figure><p>Here we can find different functions — some of which are interesting and others not. The most interesting things from the script are</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ejl0UNVK2HTKdh60QfY5Jg.png" /></figure><p>The secret SERVER_SIGNATURE value, the “FLAG” type which is probably the flag we are trying to get. And we can see a new function we haven’t seen before- the renameBox function, and a new interesting path files/boxes/?name</p><p>So let’s try accessing files/boxes/?name=TEST12345&amp;type=Flag&amp;secret=8986be71408ace74486e35bd17c4ea6bc7fe5f020be9ab46f2f5dfd73f28a397 and we get an empty HTML page, hmmm I guess we truly do need to be an admin. Let’s test if it actually works and try accessing the biscotti cookies with files/boxes/?name=TEST12345&amp;type=Biscotti&amp;secret=8986be71408ace74486e35bd17c4ea6bc7fe5f020be9ab46f2f5dfd73f28a397 OK. We receive the following code:</p><blockquote>&lt;! —</blockquote><blockquote>?php<br>const BOX_NAME = “Default”;<br>const BOX_AMOUNT = 1;<br>const BOX_NAME_HASH = “f450ec01252f13caa8e516c174ceee9d2b314cba47e9cae33b1c3330f9e93b2a”; --&gt;</blockquote><p>Hmmmm. Seems like it’s trying to scrape the box’s name (Default) from the PHP file. What would we like to see there? The thing we would wish to acquire is:</p><blockquote>&lt;! —</blockquote><blockquote>?php<br>const BOX_NAME = SERVER_SIGNATURE;<br>const BOX_AMOUNT = 1;<br>const BOX_NAME_HASH = “f450ec01252f13caa8e516c174ceee9d2b314cba47e9cae33b1c3330f9e93b2a”; --&gt;</blockquote><p>Luckily, we remember there is a function called renameBox which allows use to modify this BOX_NAME variable. Let’s try calling rename box and testing for a PHP injection:</p><blockquote>new_name = “\”.SERVER_SIGNATURE.\””</blockquote><blockquote>secret = “f450ec01252f13caa8e516c174ceee9d2b314cba47e9cae33b1c3330f9e93b2a”</blockquote><blockquote>renameBox(“Biscotti”, new_name, secret);</blockquote><p>Hmmm, but we seem to get an error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yKZH0psvVXgCCoXq-d5W1g.png" /><figcaption>Secret doesn’t match name “.SERVER_SIGNATURE.”</figcaption></figure><p>Hmmm, seems like the secret we provide gets verified with the username, let’s try creating a user with the name “.SERVER_SIGNATURE.” (We use SERVER_SIGNATURE and not $SERVER_SIGNATURE because it’s a constant value) and creating a replay attack with the secret.(If user already exists you can use“.SERVER_SIGNATURE.&quot;&quot;.”and keep appending as many .””. as you’d like) We sign in with &quot;.SERVER_SIGNATURE.”and get the following secret: choclatechips= 529d9e01daaf7176ae424b337d84a45df5aeb70390f3343b2f749fc42eefeccb</p><p>Let’s attempt changing the box name now:</p><blockquote>new_name = “\”.SERVER_SIGNATURE.\””<br>secret=”529d9e01daaf7176ae424b337d84a45df5aeb70390f3343b2f749fc42eefeccb”<br>renameBox(“Biscotti”, new_name, secret);</blockquote><p>It worked!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H-KckxtD1l-vH7UPqIHLDA.png" /><figcaption>We acquire SERVER_SIGNATURE</figcaption></figure><p>Now we can sign our own cookie and login as admin in order to get the flag. I used <a href="https://www.freeformatter.com/hmac-generator.html#ad-output">this</a> online tool to generate a new signed cookie(Use mode sha256). We sign a cookie called admin and the secret will be 6b9fe740f2589d560d09f7bc3041e9ab7c41138aae20d8f89e83b8dd1b7d7d14</p><p>Let’s try accessing files/boxes/?name=admin&amp;type=Flag&amp;secret=6b9fe740f2589d560d09f7bc3041e9ab7c41138aae20d8f89e83b8dd1b7d7d14 It works! And we receive the flag: KAF{_w00ps_f0rg0t_t0_d0_s3cur1ty}</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tyPPgoF9Z_8AncG9B6XrVg.png" /><figcaption>Received flag</figcaption></figure><p><strong>Summary</strong></p><p>We used a replay attack in order to exploit a PHP injection in the renameBox function, from there we signed our own cookie as admin and used it in order to view the flag.</p><p>This is my first Medium CTF Writeup, thank you for taking the time to read this! I hope to write many more of these, feel free to write to me @guysudai1 on twitter, or by email ctfgudai@gmail.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5b789aa354f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>