This lab is about learning to use GDB effectively on a real binary. You are not expected to brute force inputs. The goal is to use GDB to reverse engineer and understand the program’s control flow, data, and logic well enough to defuse each phase.
You must read the contents of a secret flag planted at /flag.txt. Only root has access to it; luckily a special binary is given to you to help you read the file. However, to use it properly, you must give it 3 secret passphrases or else get blown up.
Use GDB to learn how the secret passphrases and get access to the flag!
Note: you will be quizzed on the things you learn in this lab!
bomb— the executable you will run and debugbomb.c— optional / reference
Run the bomb with:
./bombFor each phase:
-
Run the bomb under GDB
-
Set a breakpoint at the phase function
-
Step through instructions
-
Identify:
- required input format
- comparisons and constraints
- success vs failure paths
-
Craft the correct input and move on
Take notes per phase.
gdb ./bombUseful startup settings:
layout asm
layout regsIf your terminal gets messed up, hit ctrl + l to reset it.
start # set a temporary breakpoint at the first instruction and begin execution
[r]un # start program
[c]ontinue # resume execution
quit[b]reak main
[b]reak phase_1
[b]reak *0x40123a # breakpoint at address
[i]nfo breakpoints
[d]elete 1 # delete breakpoint 1
disable 1 / enable 1step # step into (source-level)
next # step over (source-level)
stepi / si # step one instruction
nexti / ni # step over instruction
finish # run until function returns[disas]semble
disassemble phase_2
x/20i $rip # inspect instructions at RIP[i]nfo registers
p $rax
p/x $ripx/x 0x601050 # examine memory (hex)
x/d $rsp # decimal
x/s $rdi # string
x/16gx $rsp # stack dumpFormat: x/<count><format><size> <address>
Common formats: x hex, d decimal, s string, i instruction
You can also use print and cast memory/register values into types.
Note that we are debugging a 64-bit program. The calling convention may differ slightly from x86 32 bit programs such as xv6.
Function arguments:
rdirsirdxrcxr8r9
Return value: rax
jump *0x4012ab # jump to instruction
set $rax = 0 # modify register
set *(int*)0xADDR = 5Note: depending on where you jump, you can get stack corruption and segfault.
strcmp,strlen,sscanf- bitwise checks and masks
- loops comparing array elements
If you see a call to explode_bomb, backtrack and understand why.
- Understand function calls and their arguments
- Watch how user input is parsed/transformed
- Don’t guess — verify with GDB
Good luck!