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!
- Contrary to the other sheets, you will not hand in solutions to the tasks on this sheet. Instead, you are advised to solve them on your own or in a group, and we will talk about the tasks in the first exercise session on 2020-11-13.
- All tasks should be solved under Linux (Fedora, Arch Linux, Ubuntu, Kali, <your_favorite_distro_here>). Use a virtual machine if you do not have access to a native linux machine.
Task 1 - Python Programming With pwntools
Write a Python 3 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 (i.e. use your brain) 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
buffer
reside? - Where in memory (memory segment) do
user_input
and*user_input
reside? - What values does
buffer
contain after the initialization? - What’s the difference between
strcpy
andstrncpy
? Isstrncpy
secure 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.c
and 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.c
and also runfile main.o
for 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 doesU
mean?
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.so
and 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 -lhello
and 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
gcc
command… what happens if you leave the-L$(pwd)
flag and why? (maybeld -lhello --verbose
will 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…