-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexploitable.c
39 lines (36 loc) · 870 Bytes
/
exploitable.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#define SECRET_PHRASE "bed bananas"
#define SECRET_FILE "./secret.txt"
void win() {
FILE *fd = fopen(SECRET_FILE, "r");
if (fd == 0) {
perror(SECRET_FILE);
return;
}
fseek(fd, 0, SEEK_END);
long sz = ftell(fd);
fseek(fd, 0, SEEK_SET);
char *buf = malloc(sz+1);
fread(buf, sz, 1, fd);
buf[sz] = 0;
printf("%s\n", buf);
return;
}
int main(int argc, char **argv) {
char pass[12] = {0};
printf("What is the secret phrase?\n");
// scanf("11%[^\n]", pass);
scanf("%[^\n]", pass);
if (0 == (strncmp(SECRET_PHRASE, pass, sizeof(SECRET_PHRASE)))) {
win();
} else {
printf("The secret phrase is not: %s\n", pass);
}
return 0;
}