[p15jra@hostname]$ setarch -R bash # or fish, or zsh, or your favourite shell
$ ./foo # whatever you run now will have ASLR disabled
23 May 2025
1. Preparation
Please ensure that you have all output files from Lab 0.
2. Procedure
Complete the following procedure, recording all commands that you execute and their outputs.
2.1. Debugging in hard mode
-
Edit
Makefileto remove the-gflag fromCPPFLAGSandLDFLAGS. Clean the build directory (runmake clean), then runmaketo re-build everything. How does the size of the newproduct.ocompare with the previous one? -
Download and save the executable binary game.
-
How does its
nmoutput compare to that the of C++ programproduct(from last week)? -
How does its
objdumpoutput compare to that the ofproduct?
-
-
Use the
stringsprogram to inspect all of the string literals ingame. What is the secret word? -
Run the
gameprogram and make a guess at the secret number. What do you observe? -
Set a breakpoint at the beginning of the
mainfunction.rununtil you hit the breakpoint. When the game prompts you, enter the guess 4660 (0x1234). -
Run the
disascommand to disassemble the current function. Locate the address of thecmpinstruction just before the call to theplay_gamefunction (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 andcontinueexecution.-
When the game pauses at your breakpoint, what is the value of
rbp? -
What is the value of
eax? -
What is the value of
rbpminus the offset shown in the current instruction (e.g.,-0x10(%rbp)means "the value ofrbpminus 0x10")?
-
-
Use the
mem readcommand 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 writecommand (seehelp mem writefor 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
productprogram from the previous lab to fix its bug.
2.2. 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: