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

WriteUp PWN tarzan ROP UNICTF ಠ_ಠ (day 61)

So in this post, I'm going to talk about how to solve the Tarzan pwn challenge from UNICTF 2019. Back in the day when the competition is still going I couldn't finish it and don't have any clue to solve this but this time I was able to finish it :) Also in this post, we will be going to be heavily focused on how to utilize pwntools to construct a ROP chain. If you kinda confused about my explanation in this post you can refer to this following youtube video, link: https://www.youtube.com/watch?v=gWU2yOu0COk I build the python script based on this video Ok, let's get started! In this challenge, you will get two binary first go with tarzan and libc-2.29.so by providing .so file it tell us what version library that the target machine is using this could help us to do ROP chain. first, we run the Tarzan binary to get the basic idea of the program work and as you can see it just show you some text, newline and when you try to input something it doesn't gi