Skip to main content

TamuCTF 2019 pwn challenge 2 write up (ง'̀-'́)ง (day 27)

Image result for you just got pwned

Alright let's move to the second challenge of the pwn CTF

Try to run it first so we know what we up against


hmmm, ok I try to enter something and nothing happen I assume we need to find the correct string to trigger something in the program.

load it to peda and look at the disassembly code. As we can see there is function name "one" and "two" that will print if function one called "This is function one \n" and if function two called "This is function two \n"


the first two mentioned function is not interesting, let just quickly analyze main and move to select_func.


in main function, it clearly indicates that we can overflow the binary since it's using gets function after that our input is passed to the select_func



dump the select_func assembly code and try to type "checksec" to see what kinda protection used in the binary. One that is caught my eyes is the PIE (Position Independent Executable)

ok so take a look at the highlighted function which is "<__x86.get_pc_thunk.bx>" this function is used in PIE that supports ASLR (memory randomization) used to prevent memory corruption

whereas for NX it's explaining that the memory segment used by the application is not executable

as you can see there are two functions from libc that called in this function (strncpy and strcmp) one is to copy a value from variable to variable and the other one is to compare two string.

to get more about this assembly code I load the executable at the Ghidra

notice that if we enter string "one" it will call one function but if we don't put the expected string and the program called the local_10 variable to execute function two.

let's try to input a random string to find out what will happen if we overflow the stack.



 if you try to execute the application couple of time you notice that the memory is always ended up in 0x80000xxx and at the end of the function it will call value in EAX register which is a pointer to the function two


notice in the above pic the EAX is changed to 0x80000641 and you may notice that 41 is "A"

and we know that print_func located at


cool! so the EAX and the location of print_flag is almost the same and all we have to do is to change last two bytes into "d8"

but the problem is how we can find in what offset that we need to put the value "d8"

you have two choices to calculate how many offsets you need to have to overwrite the EAX to control the flow of the function

1st choice: using math 

take a look at this assembly code:

this equivalent to:

  code *local_10;
 
  local_10 = two;

this two line of code tells us to point the address of function two to the [ebp-0xc]

and take a look at another at this assembly code:

this equivalent to:

strncpy(ebp-0x2a,ebp+0x8,0x1f)

ebp+0x8 is our input, ebp-0x2a is the destination with the size of limit to copy is 0x1f(31)

realize that the function two destinations that were moved are (ebp-0xc) is near the destination of copy (ebp-0x2a) of our input since we can overflow the copy (ebp-0x2a) we can control the function two destination

| ebp-0xc| aaaaaaaaaaaaaaaaaaaa
................ aaaaaaaaaaaaaaaaaaaa
.................aaaaaaaaaaaaaaaaaaaa
|ebp-0x2a|aaaaaaaaaaaaaaaaaaaa

to calculate the offset all we have to do is to subtract

0x2a(42) - 0xc(12) = 30

2nd choice: using fuzzing

as you know when we try to figure out how many offsets need to control the EIP is pretty difficult when using pattern exploits. What we need now is to have pattern exploit that every char is distinguished to each other

we can do it using python:

 ~# import string
~# print string.ascii_letters + string.digits







cool so we got how many offset that we need to overwrite the EAX to control the program execution.



yess we are able to control execution in the program

have a nice day

resources:(Kudos to the one who made the write up)

https://github.com/zst123/tamuctf-2019-writeups/tree/master/Solved/Pwn2

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 ...