This blog is meant to be the prerequisite of "OWASP crackme write up version 2 level 2" post since it will talk about how to solve the challenge using debugging and patching techniques. I figured out that it is better to split up these two techniques into two blog posts so it will not become boring and long.
Background:
Over the year, radare2 has become a prominent tool for reverse engineering in Linux and utilizes a sweet command-line interface as opposed to a graphical one. Personally, I like to do RE in radare2 because of it already pre-installed in my kali Linux and it can be piped into python script making the whole process go a lot easier.I found a really good Github page and it's also used as the reference for this post that teaches you the essentials of the tools to get the grasp the basic operation.
- Exercise: https://github.com/monosource/radare2-explorations-binaries (clone this repository to your local directory)
Getting your hands dirty:
- First, you need to "make" the binary in order to get the executable
- After we got the executable binary now its time to do some reverse engineering (but it is best to create a copy of the original file). Load the executable to radare2 shell using "r2 -Aw patchme". The following command means that radare2 will automatically analyze to any relevant data that make our analysis so much easier and also it will open the file in write mode so web able to patch the binary
- Once we got the shell, type "afl" to show all the functions of the program. It is shown that there is the main function, let's try to go to that function type "s main" to move to the "main" section.
- The "pdf" command will list the assembly command of the function. The result is pretty straight forward that the function only prints the string "hello there can you patch me up to call my function" and exit the program. But from the printed value we can deduce that there is another function that we must call in order to finish this challenge. But what is it?
- Try to dump the string inside the binary may be we can get some more hint about this hidden function. We can see that there are two strings, one is from the main function and one that we never saw before (i guess that this is the secret function). type "axt 0x00004052" to do some xref so we know the source of the string (tips: s `axt 0x00004052~[1] help you to move to the xref address), unfortunately, it seems that we cannot dump the function assembly code.
- type "Vp" to enter visual mode so we can see the assembly code that contains inside the memory address. If you try to navigate up with arrow key we can see some prologue and epilogue code and it seems we ended up inside an unknown function that radare2 wasn't able to map it after all it is not used by other functions.
- We need to define the function so that we can put it inside the main function. type "d" and "f" it will automatically assign radare2 to define the function and named it according to its format.
- To make this easier let's try to rename the function into something more memorable, type "d" and "r" put the new name, I'm gonna call this function "fcn.callme"
- Next, it is time to put the function callme to the main function, type "A" and it will prompt you "[VA:0]>" navigate your prompt to that many nop in the main function that we saw earlier. Type "call fcn.callme" and enter to save the newly edited program. type "q" to exit the shell and "quit" again from radare2.
- WALLAA! we succesfully patch the binary.
Comments
Post a Comment