-
Notifications
You must be signed in to change notification settings - Fork 2
Reverse
For this lab we propose a series of simple reverse engineering exercises 1_basic
to 6_problem
.
The goal of this session is to analyse a few challenges and make you confortable with using reverse engineering tools, in particular disassemblers.
-
Download and install Cutter. Go to the folder you want to have it and run
wget https://github.com/radareorg/cutter/releases/download/v1.7.2/Cutter-v1.7.2-x86_64.Linux.AppImage chmod +x Cutter-v1.7.2-x86_64.Linux.AppImage
-
Run for the
filename
you want to analyse./Cutter-v1.7.2-x86_64.Linux.AppImage <filename>
Goal: Basic introduction to a disassembler
- Understand how a basic binary looks like in assembly using a graph view of a disassembler.
Method:
-
Run and interact with the binary
- If you're sure it's not malware of course ;)
- Can you get any information?
- How can you determine what's the key? Let's open the binary in a disassembler.
-
Open the binary in a disassembler and try to understand the assembly (
gdb
is NOT a disassembler; try Cutter).- Go to the
main
function and press<SPACE>
to open the graph view. - Can you understand what is happening? Focus on the calls, and for now try to ignore the assembly between them.
- Find out how the key is being compared with your input.
- Easy, right?
- Was there other ways to do this outside of Cutter?
- Go to the
Goal: Practice what you learned in the first challenge.
Method:
-
Interact (as before)
- Can you get any information?
- Can you do your magic again? It doesn't work?
- You might have to learn new tricks ;-)
-
Try again with a dissassembler
- Does something jump to your attention?
- Go on. Follow your path.
Goals: Keep practicing. Learn a bit more how assembly and function calls work.
- Understand that functions return on the
rax
register (specifically foratoi
in this binary). - Understand the
cmp
instruction.
Method:
-
Interact (as before) to get some information.
-
Open it in a dissassembler
- Determine what is being compared now.
- Is it still a string like in he previous challenge? or is it something else?
- Do not reverse the
gen_flag
function. It misses the point of the challenge.
Goals: Basic introduction to dynamic analysis
- Matching strings are generated at runtime.
- Using a debugger to see values after they have been computed.
Method:
-
Interact (as before) to get some information.
-
Open it in a dissassembler
- What is difference now?
- Sometimes you can use a more dynamic approach instead of a static one as before.
- Try to use
gdb
to better understand what is happening at the crutial moment. - You can reverse the
gen_flag
function but it misses again the point of the challenge.
Goal: Learn how to patch binaries and bypass anti-debugging techniques.
Method:
-
Interact (as before) to get some information.
-
Open it in a dissassembler.
- Is everything equal to the previous challenge? What happens when you try to use
gdb
to debug the binary? - Have you tried
ltrace
? - Well, Google search
ptrace anti-debugging
. - You have to remove the anti-debugging technique.
- Make a copy of the orginal binary before patching it!
- If you right click over an instruction in Cutter you can convert it to
nops
underEdit
. If you don't know what anop
is, googlex86 instruction nop
.
- Is everything equal to the previous challenge? What happens when you try to use
@NOTE
- Open the binary in write mode to ensure the patches you want are applied. If debugging is still not working afterwards, reopen the file and ensure that you indeed wrote what you intended. Cutter can be a bit buggy sometimes.
Goal: Statically reverse a more 'complex' function
Method:
-
Interact (as before) to get some information.
-
Open it in a dissassembler.
- How is the flag being checked?
- This time a dynamic approach would be harder as the check function returns as soon as a single character is wrong. If you want to try it this way look at how to script the radare2 debugger with
r2pipe
. - An easier solution is to reverse the
check_flag
function.
-
Reversing the
check_flag
function statically:- Understand the function in general. Where is the loop?
- Understand what is happening before the loop..
- Now to the fun part! The loop...
- understand the typical loop variables;
- identify the
i
and the stop condition(s); - in Cutter you can rename the variables by clicking
Shift+n
over a variable.
- When you understand what is happening you can write a C or python script that implements the inverse function of
check_flag
.
- Home
- SSof Scoreboard
- Virtual Machine Details
- Basic usage of tools
- Using Burp Suite as a Web Proxy (2019/20)
- gdb Basics
- Labs
- Still to be updated to current year
- Lab Extra - Reverse Enginneering (2018/19)