This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
session:04-gdb [2014/07/02 23:43] rcaragea |
session:04-gdb [2020/07/19 12:49] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
Although it is a powerful tool, gdb is pretty cumbersome to use by itself. Even simple tasks such as execution tracing are made difficult by the lack of " | Although it is a powerful tool, gdb is pretty cumbersome to use by itself. Even simple tasks such as execution tracing are made difficult by the lack of " | ||
To overcome this, we're going to use a wrapper over gdb that greatly enhances its default functionality. This tool is called " | To overcome this, we're going to use a wrapper over gdb that greatly enhances its default functionality. This tool is called " | ||
Even though there are lots of goodies included in it we're going to go only over what we need right now. | Even though there are lots of goodies included in it we're going to go only over what we need right now. | ||
- | |||
====== Installation ====== | ====== Installation ====== | ||
Line 29: | Line 28: | ||
set history size 32768 | set history size 32768 | ||
set history expansion on | set history expansion on | ||
+ | |||
+ | # By default peda clears the screen after most commands, displaying a single | ||
+ | # context frame at a time and allowing you to access the previous/ | ||
+ | # using Shift+PageUp/ | ||
+ | # terminal, leaving you unable to access any older information. If that is the | ||
+ | # case, uncomment the following line: | ||
+ | # | ||
+ | #pset opt clearscr off | ||
</ | </ | ||
====== Basic stuff ====== | ====== Basic stuff ====== | ||
The most common actions done in gdb are: setting breakpoints, | The most common actions done in gdb are: setting breakpoints, | ||
* '' | * '' | ||
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
* '' | * '' | ||
* '' | * '' | ||
- | * '' | + | * '' |
* '' | * '' | ||
* '' | * '' | ||
* '' | * '' | ||
+ | <note info> | ||
+ | |||
+ | In order to provide command line arguments to a program run under gdb we can use (assume the name of the program is '' | ||
+ | <code bash> | ||
+ | gdb test | ||
+ | ... # GDB banner is skipped | ||
+ | gdb-peda$ run arg0 arg1 arg2 | ||
+ | </ | ||
+ | |||
+ | In order to redirect both '' | ||
+ | <code bash> | ||
+ | gdb test | ||
+ | ... # GDB banner is skipped | ||
+ | gdb-peda$ run < inputfile > outputfile | ||
+ | </ | ||
+ | |||
+ | Obviously, one could combine the two examples into one, meaning that command line arguments, standard input and standard output are all controlled from inside GDB. This is great for debugging your exploits in an automated way. | ||
+ | <code bash> | ||
+ | gdb test | ||
+ | ... # GDB banner is skipped | ||
+ | gdb-peda$ run arg0 arg1 arg2 < inputfile > outputfile | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== Practice the basic stuff ===== | ||
Let's find out how to do these on a previous crackme from session 01.Remember that the point was that it implemented a custom '' | Let's find out how to do these on a previous crackme from session 01.Remember that the point was that it implemented a custom '' | ||
Line 148: | Line 180: | ||
Breakpoint 1, 0x080484fc in my_strcmp () | Breakpoint 1, 0x080484fc in my_strcmp () | ||
</ | </ | ||
- | If you remember from the last session, the parameters passed to a function are on the stack. Because we have just arrived at this function using a '' | + | If you remember from the last session, the parameters passed to a function are on the stack. Because we have just arrived at this function using a '' |
Note that peda automatically // | Note that peda automatically // | ||
Line 247: | Line 279: | ||
* Download level01 from Smash the stack and solve it using peda. Break on '' | * Download level01 from Smash the stack and solve it using peda. Break on '' | ||
< | < | ||
- | $ scp level1@io.smashthestack.org:/ | + | $ scp level1@io.netgarage.org:/ |
</ | </ | ||