splo.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # This exploit template was generated via:
  4. # $ pwn template ./demo2 --host 127.0.0.1 --port 1234
  5. from pwn import *
  6. # Set up pwntools for the correct architecture
  7. exe = context.binary = ELF('./task_name')
  8. if exe.bits == 32:
  9. lindbg = "/root/linux_server"
  10. else:
  11. lindbg = "/root/linux_server64"
  12. # Many built-in settings can be controlled on the command-line and show up
  13. # in "args". For example, to dump all data sent/received, and disable ASLR
  14. # for all created processes...
  15. # ./exploit.py DEBUG NOASLR
  16. # ./exploit.py GDB HOST=example.com PORT=4141
  17. host = args.HOST or '10.0.2.15'
  18. port = int(args.PORT or 1234)
  19. def local(argv=[], *a, **kw):
  20. '''Execute the target binary locally'''
  21. if args.GDB:
  22. return gdb.debug([exe.path] + argv, gdbscript=gdbscript, *a, **kw)
  23. elif args.EDB:
  24. return process(['edb', '--run', exe.path] + argv, *a, **kw)
  25. elif args.QIRA:
  26. return process(['qira', exe.path] + argv, *a, **kw)
  27. elif args.IDA:
  28. return process([lindbg], *a, **kw)
  29. else:
  30. return process([exe.path] + argv, *a, **kw)
  31. def remote(argv=[], *a, **kw):
  32. '''Connect to the process on the remote host'''
  33. io = connect(host, port)
  34. if args.GDB:
  35. gdb.attach(io, gdbscript=gdbscript)
  36. return io
  37. def start(argv=[], *a, **kw):
  38. '''Start the exploit against the target.'''
  39. if args.LOCAL:
  40. return local(argv, *a, **kw)
  41. else:
  42. return remote(argv, *a, **kw)
  43. # Specify your GDB script here for debugging
  44. # GDB will be launched if the exploit is run via e.g.
  45. # ./exploit.py GDB
  46. gdbscript = '''
  47. tbreak main
  48. continue
  49. '''.format(**locals())
  50. #===========================================================
  51. # EXPLOIT GOES HERE
  52. #===========================================================
  53. # Arch: amd64-64-little
  54. # RELRO: Partial RELRO
  55. # Stack: No canary found
  56. # NX: NX disabled
  57. # PIE: No PIE (0x400000)
  58. # RWX: Has RWX segments
  59. io = start()
  60. io.interactive()