root-me: Stack buffer overflow basic 1
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
|
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
int var;
int check = 0x04030201;
char buf[40];
fgets(buf,45,stdin);
printf("\n[buf]: %s\n", buf);
printf("[check] %p\n", check);
if ((check != 0x04030201) && (check != 0xdeadbeef))
printf ("\nYou are on the right way!\n");
if (check == 0xdeadbeef)
{
printf("Yeah dude! You win!\nOpening your shell...\n");
setreuid(geteuid(), geteuid());
system("/bin/bash");
printf("Shell closed! Bye.\n");
}
return 0;
}
| cs |
이게 소스코드다. 스택 상으로
[buf]
[check]
[var]
이렇게 되어있을것이고, buf 사이즈가 40인데 반해 fgets로 45만큼 받으니, buf를 40개만큼 채운 뒤에 deadbeef를 넣어주면 될것이다!
Comments
Post a Comment