[p15jra@hostname]$ setarch -R bash # or fish, or zsh, or your favourite shell
$ ./foo # whatever you run now will have ASLR disabled
22 May 2024
More exploration of low-level software basics: debugging in hard mode and (a very little bit of) tampering.
1. Preparation
Complete the following steps before coming to the lab. For this week, you do not need to submit your pre-lab work, but you are very welcome to ask questions if anything doesn’t make sense to you.
-
Download, compile and run some of the C and C++ examples from Lecture 2. Ensure that you understand their outputs.
2. Procedure
Complete the following procedure, recording all commands that you execute and their outputs.
2.1. Compilation
Ensure that you have all output files from Lab 0.
2.2. Debugging in hard mode
-
Edit
Makefile
to remove the-g
flag fromCPPFLAGS
andLDFLAGS
. Clean the build directory (runmake clean
), then runmake
to re-build everything. How does the size of the newproduct.o
compare with the previous one? -
Download and save the executable binary game.
-
How does its
nm
output compare to that the of C++ programproduct
(from last week)? -
How does its
objdump
output compare to that the ofproduct
?
-
-
Use the
strings
program to inspect all of the string literals ingame
. What is the secret word? -
Run the
game
program and make a guess at the secret number. What do you observe? -
Using your
objdump
output, set a breakpoint at the beginning of themain
function.run
until you hit the breakpoint. When the game prompts you, enter the guess 4660 (0x1234). -
Run the
disas
command to disassemble the current function. Locate the address of thecmp
instruction just before the call to theplay_game
function (this comparison is part of the conditional check that will either allow you to play the game or not, depending on whether or not you guessed the secret number). Set a breakpoint at this address andcontinue
execution.-
When the game pauses at your breakpoint, what is the value of
rbp
? -
What is the value of
eax
? -
What is the value of
rbp
minus the offset shown in the current instruction (e.g.,-0x10(%rbp)
means "the value ofrbp
minus 0x10")?
-
-
Use the
mem read
command to read the four bytes of memory at the indicated offset fromrbp
. What are these four bytes (in hexadecimal representation)? What is the decimal representation of this integer? -
Use the
mem write
command (seehelp mem write
for information) to modify the secret value in memory to match your already-inputted guess (1). Demonstrate that you have bypassed the "secret number" check. -
Having learned the program’s "secret value" above, re-run the program and input the correct guess. Demonstrate that this works.
-
Bonus: without modifying any source code, modify the
product
program from the previous section lab to fix its bug.
2.3. Stack smashing
Graduate students (ENGI 9823) are expected to complete this section of the lab. Undergraduate students (ECE 7420) may complete it for extra credit but are not required to do so.
Use the techniques we covered in
lecture 3
to smash the stack of the sum
program that was presented in that lecture.
You may find it helpful to start a shell with ASLR disabled by running the
setarch
command: