Skip to main content

WriteUp RE lezz go UNICTF ( ͠° ͟ʖ ͡°) (day 40)


Next, we are going to talk about how to finish the lezz go challenge which categorized as reverse engineering. lets have a little sneak peek about what we are dealing with:



So first the binary that is given to us is actually a golang binary and it ask you to input something to the program if it's not right it will print "Y U No Go!? " lol

when I first get this challenge I was really panicked since I never reverse a golang binary.

so I just do some research and I found a really good web that explain how to get started

https://rednaga.io/2016/09/21/reversing_go_binaries_like_a_pro/

I found out that when you try to disassemble golang binary the amount of code to analyses is going to be multiply by two and it is going to waste you a lot of time to read it one by one.

So to overcome this the author suggest to look for the main function, named "main_main".

I load the binary at ghidra and radare2 so I have a good view of the flow and the source code

In ghidra, I was able to find the main.main function


Hmmmm there is a function called checkFlag we will analyze the function after a quick glance of the main function.


 urrrghhh this makes my head hurt but don't worry all of this code is not significant just go down and we found some if statement that picks my interest.






before the if statement is used the function checkflag called first. Let's analyze it

oh no! i think ghidra is unable to translate the function fully so we have to rely on radare2 and try to understand the workflow of the code.


Load the binary to radare2 and go to the functions that we have just analyze:


It seems at the beginning of the function there is some check value in RAX register, lets put a breakpoint there and try to figure out what is the value that is trying to be compared.




aha! so as we can see that the comparison takes the value of the character length of our input (the dummy value "blablabla" has length of 9 characters) and try to check f the value is 0x12 (18)

re-run the program again but this time I put dummy data that has a length of 18 characters.





go down a little bit we are served with another comparison check


but here we see before the first jump the register rdx is being xored which means that the register is set to 0 and it compared with value 0x12 again but this time we already know that the rdx is zero so its not meet with the condition of jge and will jump to another address. Try to go down more


we see that there is another comparison and if it equals the register rdx is incremented and get back to the previous part so it's kinda like a loop and if it's not it will exit the function.

lets put a breakpoint at the comparison (cmp bl,sil) and see what value is being compared.

"sil" represent the lower 8 bits of the esi register.

and

"bl" represent the lower 8 bits of the rbx register.




look at the value of rbx and rsi it same with our first char of the dummy strings ("H") and if we try to continue the execution it will hit the breakpoint again and the value of rbx and rsi it same with our second char of the dummy strings ("T")

so we can conclude that the program checks the input of our string with the flag per character so all we have to do is just create a python script that will collect all of the character one by one and just circumvent the cmp until it finishes.


and if we run it we got the flag yeaayy!


ok thats all I hope you enjoy it :D







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

Bypassing stack canaries protection :') (day 51)

In my previous blogs, I show you guys how to bypass some common protection usually used in Linux binary such as NX and ASLR but this time we are going to take it to the next level we are going to talk about protection employ in the modern Linux OS which is "The Canaries" and how to bypass it. note: this post was not originally mined it was inspired by the following resources https://ctf-wiki.github.io/ctf-wiki/pwn/linux/mitigation/canary/ (Credit goes to the author) we are going to start this post about what is stack canaries and types of different implementation of it then move to the implementation about how to bypass this protection. We are going to focus on "leak canaries" technique What is stack canary: In layman terms, canaries are just another protection mechanism to prevent stack overflow implemented by appending 4/8 bytes value (depend on the architecture) into the stack when a function is entered. When the function is at the end of its exec...