Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. import argparse
  2. from pwn import *
  3. context.terminal = ['tmux', 'splitw', '-h']
  4.  
  5. # cmdline argument - how to connect to binary
  6. parser = argparse.ArgumentParser()
  7. parser.add_argument("--local", help="Run exploit locally", action="store_true")
  8. parser.add_argument("--attach", help="Run exploit locally and attach debugger", action="store_true")
  9. parser.add_argument("--remote", help="Run exploit on remote service", action="store_true")
  10. parser.add_argument("--ssh", help="Run exploit on SSH server", action="store_true")
  11. args = parser.parse_args()
  12.  
  13. # GDB commands
  14. debugging = False
  15. gdb_cmd = [
  16. "c"
  17. ]
  18.  
  19. # Binary names
  20. bin_fname = ''
  21. libc_fname = ''
  22.  
  23. # Remote
  24. IP = ''
  25. PORT = 0
  26.  
  27. # SSH
  28. URL = ''
  29. username = ''
  30. password = ''
  31. bin_abs_path = ''
  32.  
  33. # Create ELF objects
  34. e = ELF(bin_fname)
  35. libc = ELF(libc_fname) if libc_fname else None
  36. x64 = e.bits != 32
  37.  
  38. # Command line args
  39. # e.g. arg1 = cyclic_find('ahaa') * 'a' + '\xbd\x86\x04\x08' + 'a' * 4 + p32(next(e.search('/bin/sh')))
  40. arg1 = ''
  41. proc_args = [bin_fname, arg1]
  42.  
  43. if args.remote:
  44. p = remote(IP, PORT)
  45. elif args.local or args.attach:
  46. p = process(proc_args)
  47. if args.attach:
  48. gdb.attach(p, gdbscript="\n".join(gdb_cmd))
  49. elif args.ssh:
  50. s = ssh(host=URL, user=username, password=password)
  51. s.set_working_directory(bin_abs_path)
  52. p = s.process(proc_args)
  53. else:
  54. p = gdb.debug(proc_args, gdbscript="\n".join(gdb_cmd))
  55. debugging = True
  56.  
  57. """
  58. Exploit
  59.  
  60. Examples:
  61. func_offset = libc.symbols['puts'] # Offset in libc
  62. puts_addr = p32(e.got['puts'])
  63. main = e.symbols['main']
  64. addr_string = next(e.search('/bin/cat flag.txt'))
  65. """
  66.  
  67. p.sendline(cyclic(100, n=8 if x64 else 4))
  68. # buf = cyclic_find('', n=8 if x64 else 4) * 'a'
  69. p.interactive()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement