Hacking.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # ReK2
  2. # gemini://rek2.hispagatos.org
  3. # gemini://hispagatos.org
  4. # https://hispagatos.org
  5. # gemini://2600.madrid
  6. # Hispagatos - 2023
  7. import mitmproxy.http
  8. from typing import Sequence
  9. from mitmproxy import types, flow, command, ctx
  10. from subprocess import run
  11. import shlex
  12. from bs4 import BeautifulSoup, Comment
  13. import os
  14. class Hacking:
  15. def __init__(self):
  16. self.file_path = input("Enter the path to save results: ")
  17. self.extensions = ".txt,.php,.html,.sh,.md,.db,.sql"
  18. self.cookie = None
  19. def response(self, flow: mitmproxy.http.HTTPFlow):
  20. self.extract_comments(flow)
  21. self.extract_links(flow)
  22. def extract_comments(self, flow: mitmproxy.http.HTTPFlow):
  23. html = flow.response.text
  24. soup = BeautifulSoup(html, "html.parser")
  25. comments = soup.find_all(string=lambda text: isinstance(text, Comment))
  26. with open(f"{self.file_path}/mitmproxy_comments.txt", "a") as file:
  27. for comment in comments:
  28. file.write(f"{comment}\n")
  29. def extract_links(self, flow: mitmproxy.http.HTTPFlow):
  30. html = flow.response.text
  31. soup = BeautifulSoup(html, "html.parser")
  32. links = set([a["href"] for a in soup.find_all("a", href=True)])
  33. with open(f"{self.file_path}/mitmproxy_links.txt", "a") as file:
  34. for link in links:
  35. file.write(f"{link}\n")
  36. @command.command("hacking.dirbust")
  37. def dirbust(
  38. self,
  39. flows: types.Sequence[flow.Flow],
  40. wordlist: str = "/usr/share/seclists/Discovery/Web-Content/common.txt",
  41. ):
  42. for flow in flows:
  43. if isinstance(flow, mitmproxy.http.HTTPFlow):
  44. url = flow.request.url
  45. gobuster_command = f"gobuster dir -u {url} -w {wordlist} -x {self.extensions} -o {self.file_path}/mitmproxy_gobuster_results.txt"
  46. run(shlex.split(gobuster_command))
  47. @command.command("hacking.nikto")
  48. def nikto(
  49. self,
  50. flows: types.Sequence[flow.Flow],
  51. ):
  52. for flow in flows:
  53. if isinstance(flow, mitmproxy.http.HTTPFlow):
  54. url = flow.request.url
  55. host = flow.request.host
  56. nikto_command = f"nikto -host {host} -output {self.file_path}/mitmproxy_nikto_results.txt"
  57. run(shlex.split(nikto_command))
  58. @command.command("hacking.stickcookie")
  59. def stickcookie(self, toggle: str) -> str:
  60. if toggle.lower() == "on":
  61. cookie_file_path = os.path.join(self.file_path, "cookie.txt")
  62. if not os.path.exists(cookie_file_path):
  63. return "Cookie file not found in the specified directory."
  64. with open(cookie_file_path, "r") as f:
  65. self.cookie = f.read().strip()
  66. ctx.log.info("Sticky cookie set.")
  67. elif toggle.lower() == "off":
  68. self.cookie = None
  69. ctx.log.info("Sticky cookie removed.")
  70. else:
  71. return "Invalid command usage. Use 'on' to activate sticky cookies or 'off' to deactivate."
  72. return "Sticky cookie command executed."
  73. def request(self, flow: mitmproxy.http.HTTPFlow) -> None:
  74. if self.cookie and "cookie" not in flow.request.headers:
  75. flow.request.headers["cookie"] = self.cookie
  76. # addons = [Hacking()]