Skip to main content

TamuCTF 2019 pwn challenge 1 write up (ง'̀-'́)ง (day 26)


Image result for pwning meme

It's been a couple of days since I started learning about pwning, I guess it's time to test it by doing some CTF challenges.

the following CTF resources come from https://github.com/tamuctf/TAMUctf-2019

kudos to the author of the GitHub page

We are going to start at the first challenge and the next blog will be second and so on...

Let's run the binary to know what we are dealing with. As you can see it need some input


we are going to dissect the binary using radare2 and when I try to understand the flow of the program I found out that it has three string comparisons using strcmp.

 

the first two checks are completely straight forward. Our first string (s1) in the first check will be compared against ebx-0x159f and our second string (s1) in the second check will be compared against ebx-0x154d


But the third check is comparing us with hex decimal value (0xdea110c8). So what is var_10h, if we try to compare it with the actual source code you can see that it was a variable "secret" that holds the value of 0.




Now the big question is how do we change the secret variable into 0xdea110c8. This can be done by using buffer overflow, you may notice that the third input is using "gets" c function and according to the man page in Linux, it is not recommended to use it since it will stored character past the buffer causing a buffer overflow.


Now what we know our entry point to buffer overflow let's try to figure out what is the string in first and second check that is going to be compared.

Open again the binary but in debugging mode, put a breakpoint on each of the strcmp call functions and try to analyze the register using ps command.




yea we got the first and second string

let's switch to peda to craft our payload (i prefer to use radare2 when doing reverse engineering)

we need to put the breakpoint at the third check and fill it with some random pattern string so we know where we can put the hex value.


I use https://github.com/ickerwx/pattern tools to generate a random pattern



Once we hit the breakpoint, as you can see the stack of the program is filled with a random pattern. We need to find out what value overflows the var_10h (located at ebp-0x10)


so here is the 4 hex value that overflow var_10h, let's try to convert it into a string. But before you do it, you need to convert to the right order because it's in little-endian.

I use https://github.com/JohnTroony/Scriptology



 



It looks like we can overflow our var_10h after 43 bytes and we can place the hex decimal after that. 


we need to convert out compared string into little-endian hexadecimal

To make this more realistic we can map the binary to port so other machines can interact with it. So I put the binary to my virtual machine and run it along with socat.

I create bash script that looks like this and just runs it:

#!/bin/bash

echo "port 4321 is open"
su -c "exec socat TCP-LISTEN:4321,reuseaddr,fork EXEC:/home/tux/tamuctf/pwn1,stderr" - root;




Now, all we have to do is to create a python script that will overflow the var_10h with the desired value automatically. To do this I use pwntools library to make exploitation easy.




we did it because I don't have the flag.txt It only prints "Right. Off you go" when you successfully finish the challenge

Comments

Popular posts from this blog

Having fun analyzing nginx log to find malicious attacker in the net (ง'̀-'́)ง (day 37)

  What makes you sleepless at night? is it because of a ghost or scary stories? is it because you have an important meeting tomorrow? or is it because you have an exam? For me, what keeps me up all night is that I keep thinking about what happens to a website that I just created, is it safe from an attacker (certainly not) or did I missing some security adjustments that lead to vulnerability? well I'm not the best secure programmer in the world, I'm still learning and there is a big possibility that I can make a mistake but for me, a mistake can be a valuable investment to myself or yourself to be better so from this idea, I want to know more about what attackers casually do when attacking a website. Here in this post, I'm going to show you how I analyzed attack to the website that I have permission to design and also some interesting findings that I could get from the analysis Background: All of this analysis comes from the traffic that is targeted to th...

Utilize Pwntools for crafting ROP chain :') (day 69)

who doesn't like pwntools? it is a very versatile tool and can be customized according to our need using the python script but did you need to know that pwntools itself can help us to automatically craft a rop chain for us? so in this post, I will show you how to make rop chain less painful and make pwntools do all the heavy lifting. To demonstrate this I will use the binary challenge callme 64 bit from ropemporium link: https://ropemporium.com/challenge/callme.html Crashing the app: Like any other exploitation process, we need to crash the program by generating a long string pattern to determine the offset. based on the information from the above figure we can see that we required to provide 40 bytes of offset Fun stuff: now this where the fun stuff began write the following python script: as in the guideline of the challenged said we need to chain the function call by first to call the callme_one function, callme_two function and then callme_three funct...

Why you should always cautious on your VPN: Study Case on Broken Cryptography of Android VPN (day 91) ಠ_ಠ

source: https://me.me/i/when-you-make-a-meme-in-europe-but-you-use-22778509 Disclaimer: This blog post is heavily based on https://www.youtube.com/watch?v=ofTts7jlC2Y&t=177s created by Lukas Stefanko. I strongly suggest you guys check his youtube videos it contain many great android security study cases that you can learn free Background: Who doesn't know VPN, right?! It is a wonderful program that lets us maintain the confidentiality of our identity and information while surfing the internet. It is fast and more importantly is "FREE!" there are tons of free VPN applications that you can download in play store and use it in a click of a button. The workflow is also not really that difficult to understand: Source: https://blog.sucuri.net/2020/03/vpn-secure-online-work-environment.html Pay attention to the above figure, this diagram explains the difference in our connection when using a VPN and not using VPN. When using a VPN before we connect to ...