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
Post a Comment