Skip to content

Commit 27562f2

Browse files
committed
binary-analysis: Add session content
Add content related to binary-analysis. Signed-off-by: Mihnea Firoiu <mihneafiroiu0@gmail.com>
1 parent 2371bd7 commit 27562f2

File tree

29 files changed

+97
-96
lines changed

29 files changed

+97
-96
lines changed

chapters/binary-introduction/binary-analysis/drills/easy-to-spot/sol/README.md

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Easy to Spot
2+
3+
It's an easy challenge.
4+
Really.
5+
6+
If you're having difficulties solving this exercise, go through [this](../../../reading/static-analysis.md) reading material.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Easy to Spot Solution
2+
3+
The easiest way to find the flag is by using the `strings` tool, as the flag is stored in plaintext in a variable.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Ghidra Killer
2+
3+
Some people just hate the people that use decompilers.
4+
One of those people left you a binary, to investigate.
5+
6+
If you're having difficulties solving this exercise, go through [this](../../../reading/dynamic-analysis.md) reading material.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Packaging is Important
2+
3+
Someone delivered you a mysterious package.
4+
5+
If you're having difficulties solving this exercise, go through [this](../../../reading/static-analysis.md) reading material.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Spaghetti
2+
3+
Someone felt like cooking today.
4+
Can you find the flag?
5+
6+
If you're having difficulties solving this exercise, go through [this](../../../reading/static-analysis.md) reading material.

chapters/binary-introduction/binary-analysis/drills/spaghetti/sol/README.md chapters/binary-introduction/binary-analysis/drills/tasks/spaghetti/solution/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ In this task, you must use `Ghidra` to follow the function-call graph, to find t
99
The function call sequence, that ends with `fn11()` is the following:
1010
`fn37()` -> `fn28()` -> `fn30()` -> `fn11()`.
1111

12-
`fn37()` is called by enetring the `38` number.
12+
`fn37()` is called by entering the `38` number.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Dynamic Analysis
2+
3+
Dynamic analysis means observing the behaviour of the binary, while it is running.
4+
This is performed by tracing or sandboxing.
5+
6+
Tracing is the process during which various checkpoints are placed in the code, that send alerts when the execution has reached them.
7+
Generally, the context (registers, stack, variables) is also displayed.
8+
9+
Sandboxing is a more complex process, in which you isolate a binary in a virtual machine (usually), run it and observe the changes made on the system: modified files, network traffic, etc.
10+
11+
Today, we are going to explore tracing.
12+
13+
## strace
14+
15+
`strace` shows system calls performed by a binary application.
16+
That means opening any kind of file, reading and writing into files, `mprotect`s and other things.
17+
It is useful to find out if the program does any changes to the system itself, or if it writes in some files.
18+
19+
## ltrace
20+
21+
`ltrace` shows calls to dynamic library functions, along with system calls.
22+
It is similar to `strace`.
23+
24+
## gdb
25+
26+
GDB is the most powerful dynamic analysis tool available to the regular user.
27+
It allows executing the code instruction by instruction, inspecting memory areas, changing memory areas, jumping to other pieces of code, that weren't executed normally.
28+
GDB is best used when the user has knowledge about assembly language, which will be presented in the last 2 sessions.
29+
For this session, GDB isn't required.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Introduction
2+
3+
Today's session aims to give you some tools to analyze a binary, in order to determine what that binary does and if it can hurt your system.
4+
5+
## Reminders
6+
7+
- code can't just be run;
8+
it needs to be compiled and linked, becoming an executable
9+
- the value of most symbols is placed in the binary file, in sections, and can be observed without actually running the executable
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,28 @@
1-
---
2-
linkTitle: 09. Binary Analysis
3-
type: docs
4-
weight: 10
5-
---
6-
7-
# Binary Analysis
8-
9-
## Reminders
10-
11-
- code can't just be run;
12-
it needs to be compiled and linked, becoming an executable
13-
- the value of most symbols is placed in the binary file, in sections, and can be observed without actually running the executable
14-
15-
## Introduction
16-
17-
Today's session aims to give you some tools to analyze a binary, in order to determine what that binary does and if it can hurt your system.
18-
19-
## Static Analysis
1+
# Static Analysis
202

213
Static analysis implies investigating the binary without running it.
224
This means looking into the effective binary file for strings, symbols, interesting addresses and so on.
235

24-
### strings
6+
## strings
257

268
`strings` is used to find strings in a binary file - very intuitive.
279
It is the most basic static analysis tool available.
2810
Before any other more complex analysis takes place, a `strings` can find many hidden secrets.
2911

30-
### file
12+
## file
3113

3214
`file` is another useful tool, not only for binary analysis.
3315
It should be used before any investigation, to make sure that the binary is a binary file, and not an archive.
3416
It also shows if the executable is statically-linked (lots of strings, functions) or dynamically-linked.
3517

36-
#### Counter-measures
18+
### Counter-measures
3719

3820
For `file` there is no counter-measure to hide the data that would be found by it.
3921
For `strings`, one way to counter it is to encrypt / obfuscate important data.
4022
But keep in mind that the codified content will be visible, and can be deciphered.
4123
That's why they are, almost always, used first when analysing a binary.
4224

43-
### nm
25+
## nm
4426

4527
`nm` is used to find **symbols** - variable names, function names, and their addresses.
4628
It also shows where these symbols are placed: text (T or t), rodata (R or r), bss (B or b), etc.
@@ -51,90 +33,31 @@ Capital-letter symbols are global, meaning they can be referenced from other obj
5133
Example: `object1.o` has a global symbol named `global_var`.
5234
`object2.o` can use `global_var`, if `object1.o` and `object2.o` are linked together.
5335

54-
#### Counter-measures: Strip
36+
### Counter-measures: Strip
5537

5638
`strip` removes all symbols from a binary file.
5739
If a binary is stripped, `nm` becomes useless.
5840

59-
### objdump
41+
## objdump
6042

6143
`objdump` is a disassembler.
6244
It takes binary files and transforms them to hexadecimal values and, where possible, assembly language.
6345
It is useful in many cases: when we want to explore the sections of a program, when we want to see what a specific function does, or when we want to make sure that the binary won't crash more complex analysis tools (!).
6446
`objdump` is a fast way to turn a binary file into more accessible format.
6547

66-
#### Counter-measures
48+
### Counter-measures
6749

6850
`objdump` is pretty good at what it must do.
6951
It becomes less helpful if the binary is large, with multiple functions that call each other and we have a hard time understanding the flow of the application.
7052
That's why it is a bad idea, generally, to break down real-life applications with `objdump`.
7153

72-
### Ghidra
54+
## Ghidra
7355

7456
`Ghidra` is a decompiler: it turns a binary file back into C code.
7557
It also does function analysis, meaning it constructs a tree of function calls.
7658
It is the best tool to understand what a binary does, without running it.
7759

78-
#### Counter-measures
60+
### Counter-measures
7961

8062
Unorthodox code, self-changing code, polymorphic code and other measures were taken by various people to counter Ghidra.
8163
[This talk](https://www.youtube.com/watch?v=HlUe0TUHOIc&ab_channel=DEFCONConference) by Christopher Domas is one of the best examples of measures taken to counter Ghidra and other decompilers.
82-
83-
## Dynamic Analysis
84-
85-
Dynamic analysis means observing the behaviour of the binary, while it is running.
86-
This is performed by tracing or sandboxing.
87-
88-
Tracing is the process during which various checkpoints are placed in the code, that send alerts when the execution has reached them.
89-
Generally, the context (registers, stack, variables) is also displayed.
90-
91-
Sandboxing is a more complex process, in which you isolate a binary in a virtual machine (usually), run it and observe the changes made on the system: modified files, network traffic, etc.
92-
93-
Today, we are going to explore tracing.
94-
95-
### strace
96-
97-
`strace` shows system calls performed by a binary application.
98-
That means opening any kind of file, reading and writing into files, `mprotect`s and other things.
99-
It is useful to find out if the program does any changes to the system itself, or if it writes in some files.
100-
101-
### ltrace
102-
103-
`ltrace` shows calls to dynamic library functions, along with system calls.
104-
It is similar to `strace`.
105-
106-
### gdb
107-
108-
GDB is the most powerful dynamic analysis tool available to the regular user.
109-
It allows executing the code instruction by instruction, inspecting memory areas, changing memory areas, jumping to other pieces of code, that weren't executed normally.
110-
GDB is best used when the user has knowledge about assembly language, which will be presented in the last 2 sessions.
111-
For this session, GDB isn't required.
112-
113-
## Summary
114-
115-
- Static analysis is the investigation of a binary file without actually running it.
116-
It means disassembling, decompiling the executable, or directly reading the actual contents of the executable.
117-
- Static analysis is performed with tools like `strings`, `file`, `nm`, `Ghidra`.
118-
- Dynamic analysis the investigation of an executable while it is running
119-
- Dynamic analysis is performed using tools like `strace`, `ltrace`, `gdb`.
120-
121-
## Activities
122-
123-
### Challenge: Easy to Spot
124-
125-
It's an easy challenge.
126-
Really.
127-
128-
### Challenge: Packaging is Important
129-
130-
Someone delivered you a mysterious package.
131-
132-
### Challenge: Ghidra Killer
133-
134-
Some people just hate the people that use decompilers.
135-
One of those people left you a binary, to investigate.
136-
137-
### Challenge: Spaghetti
138-
139-
Someone felt like cooking today.
140-
Can you find the flag?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Summary
2+
3+
- Static analysis is the investigation of a binary file without actually running it.
4+
It means disassembling, decompiling the executable, or directly reading the actual contents of the executable.
5+
- Static analysis is performed with tools like `strings`, `file`, `nm`, `Ghidra`.
6+
- Dynamic analysis the investigation of an executable while it is running
7+
- Dynamic analysis is performed using tools like `strace`, `ltrace`, `gdb`.

config.yaml

+15-5
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ docusaurus:
100100
- Tasks:
101101
path: tasks/
102102
subsections:
103-
- Empty Files/: empty-files/README.md
104-
- Find us if you can/: find-us-if-you-can/README.md
105-
- Not your doge/: not-your-doge/README.md
106-
- Surgical precision/: surgical-precision/README.md
103+
- Empty Files/: empty-files/README.md
104+
- Find us if you can/: find-us-if-you-can/README.md
105+
- Not your doge/: not-your-doge/README.md
106+
- Surgical precision/: surgical-precision/README.md
107107
- Demystifying the Web:
108108
- Explaining the Internet:
109109
path: chapters/demystifying-web/explaining-the-internet/
@@ -233,7 +233,17 @@ docusaurus:
233233
- Binary Analysis:
234234
path: chapters/binary-introduction/binary-analysis/
235235
subsections:
236-
- Reading: reading/README.md
236+
- Reading:
237+
- Introduction: reading/introduction.md
238+
- Static Analysis: reading/static-analysis.md
239+
- Dynamic Analysis: reading/dynamic-analysis.md
240+
- Summary: reading/summary.md
241+
- Drills:
242+
- Tasks:
243+
- Easy to spot/: drills/tasks/easy-to-spot/README.md
244+
- Ghidra killer/: drills/tasks/ghidra-killer/README.md
245+
- Packaging is important/: drills/tasks/packaging-is-important/README.md
246+
- Spaghetti/: drills/tasks/spaghetti/README.md
237247
- Assembly Language:
238248
path: chapters/binary-introduction/assembly-language/
239249
extra:

0 commit comments

Comments
 (0)