Sheet 0
PABE Exercise Sheet 0
NOTE:
- This sheet is not part of the mandatory sheets that are required for the admission for the final exam!
- All tasks should be solved under Linux (Ubuntu, Kali, Debian, your_favorite_distro_here)
Task 1 - Python Programming With pwntools
Write a Python 2 script and use pwntools (link). In more detail, connect to pabe.seclab-bonn.de on port 11337 with remote (link) and do the following:
- read the first string that always ends with an
@character (link) - read the second string that always ends with a
%character - concatenate those two strings without the special characters
@and%and send them back to the server - the server will send a string back to tell you that everything was correct -> check that string!
Task 2 - Intel x86 Assembler
Have a look at the following snippet of assembler code:
|
|
What are the final contents of eax, ebx, ecx, and edx? You can do this mentally or use a tool like Jasmin (link) or even Unicorn Engine if you want to get really fancy ;) (link)
Task 3 - Understanding a C Program
Look at the following source code:
|
|
Answer the following questions:
- What does the program do? Go through all the lines and try to understand (really understand) what it does.
- Where in memory (memory segment) does
bufferreside? - Where in memory (memory segment) does
user_inputand*user_inputreside? - What values does
buffercontain after the initialization? - What’s the difference between
strcpyandstrncpy? Isstrncpysecure for all parameters? - What’s the difference between
user_input,&user_input, and*user_input? - Look at the following assembler code:
To which line(s) in the above source code might this snippet correspond? What is happening there?
1 2 3 4 5 6 7 8 9... sub esp, 0xc push 0x400 call 8048430 <REDACTED@plt> add esp, 0x10 mov DWORD PTR [ebp-0x410], eax cmp DWORD PTR [ebp-0x410], 0x0 jne 804862d <main+0x82> ...
Task 4 - Compilation of a C Program
Have a look at the following code in a file called main.c:
|
|
Answer the following questions:
- What is the output of
gcc -E -P main.c? What can you see? Where is themain()function and what are the other lines? - Run
gcc -S -masm=intel main.cand have a look at the newly created filemain.s? Can you make sense of those lines? Is there a semantic connection between the C source code above? Can you find matching lines? - Run
gcc -c main.cand also runfile main.ofor the newly created filemain.o. What does the output tell you? - Run
strings main.o, can you find anything related to the C source code? - Run
xxd main.o, what do you see? What do the different columns mean? Why are there sometimes.(dots) in the rightmost column? - Run
nm main.o, what do you see and more concrete what doesUmean?
Have a look at the following code of a file called lib_hello.c:
|
|
and this code called use_lib.c:
|
|
Answer the following questions:
- Compile the code with
gcc -shared -fPIC lib_hello.c -o libhello.soand runfile libhello.so. What is the output and how is it different to the output offile main.o? - Run
gcc -L$(pwd) -o use_lib use_lib.c -lhelloand describe what the command does. What is the result? (if you want to run the final binary executeLD_LIBRARY_PATH=$(pwd) ./use_lib) - In the previous
gcccommand… what happens if you leave the-L$(pwd)flag and why? (maybeld -lhello --verbosewill help you)
Task 5 - Bug Hunting
Download the following (not so well written) source code and try to win the game! The goal is to make the program print out the flag
(#define FLAG "FLAG{REDACTED}"). Connect to pabe.seclab-bonn.de on port 11338 and get the flag! Hint: Maybe your name has an impact on the fortune…