Showing posts with label GDB. Show all posts
Showing posts with label GDB. Show all posts
13 September 2012
"Congratulations! You've defused the bomb!"
Guess what? The famous Bomb Lab of Computer Systems: A Programmer's Perspective! I have done this before in the university, three years ago. After three years, I do it again. However, the lab has changed so much that I can not believe I have ever seen this . . . or maybe just because I am forgetful.
Fortunately time did not rust my skills. There is no substantial difficulty for me to do reverse engineering on this binary bomb. Identifying the transfer of control, determining the control flow, identifying the function calls, finding out the function prototypes, identifying the names of global variables, analyzing the data structures, and so on, everything can be done in a certain routine. Nevertheless, seeing the success message appearing on the screen still excited me a lot.
What is worth mentioning is the secret phase, which I did not ever find three years ago. Its entry is in the phase_defused function. The function decides whether to enter the secret phase by checking the string buffer of a certain phase. The read_line function read the user input into the string buffers. Actually it can take more than needed into the buffers, which we can exploit. To solve the secret phase, you just need to be aware that it operates recursively on a binary tree.
From the lab you can learn many things about GDB. Like me, I found that GDB can print the variable names associated with the memory addresses when I use x to check them, which helped me a lot. Another discovery is that Python is a really good command line calculator. Now I shall continue to the other lab of this chapter—the Buffer Lab.
17 April 2012
Input Redirection in GDB (MinGW)
When using GDB to debug my program, I ran into a problem that GDB cannot accept my input redirection, because the GDB provided with MinGW passes on verbatim all arguments including redirects to the debugee.
I have found several solutions to solve this problem on the Internet, which I decide to write down here in case that I forget them.
- Parsing a -i ifile argument using argc and argv to get input from ifile instead of stdin and parsing a -o ofile to write output to ofile instead of stdout.
- Setting symbols for the debugee while compiling (gcc -g), and proceeding in the following manner:
(gdb) b main
(gdb) r non-redirect-arguments-if-any
(gdb) p dup2(open("input.txt", 0), 0)
(gdb) c
Subscribe to:
Posts (Atom)