JamesBops

Untitled

Dec 3rd, 2023
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. import requests
  2. import typing as T
  3. import re
  4. import multiprocessing as mp
  5. import threading
  6. import queue
  7. import os
  8.  
  9. if not os.path.isdir('results'):
  10. os.mkdir('results')
  11.  
  12. class Config(T.TypedDict):
  13. name: str
  14. file: str
  15. match: T.Pattern
  16.  
  17. class Check:
  18.  
  19. __regex_configs: T.List[Config] = [
  20. {
  21. 'file': 'aws.txt',
  22. 'name': 'AWS Key',
  23. 'match': r'AKIA[0-9A-Z]{16}'
  24. },
  25. {
  26. 'file': 'twilio.txt',
  27. 'name': 'Twilio',
  28. 'match': r'AC[a-z0-9]{32}'
  29. },
  30. {
  31. 'file': 'sendgrid.txt',
  32. 'name': 'Sendgrid SMTP',
  33. 'match': r'smtp\.sendgrid\.net'
  34. },
  35. {
  36. 'file': 'nexmo.txt',
  37. 'name': 'Nexmo',
  38. 'match': r'NEXMO_|nexmo_|VONAGE_|vonage_'
  39. },
  40. {
  41. 'file': 'office365.txt',
  42. 'name': 'Office365 SMTP',
  43. 'match': r'smtp\.office365\.com'
  44. },
  45. {
  46. 'file': 'aws_smtp.txt',
  47. 'name': 'AWS SMTP',
  48. 'match': r'email-smtp\.'
  49. }
  50. ]
  51.  
  52. def __init__(self) -> None:
  53. pass
  54.  
  55. def validate(self, url: str, body: str) -> T.List[str]:
  56. found: T.List[str] = []
  57. for config in self.__regex_configs:
  58. if re.search(config.get('match'), body):
  59. found.append(
  60. config.get('name')
  61. )
  62. with open('results/' + config.get('file'), mode='a') as file:
  63. file.write(url + '\n')
  64. return found
  65.  
  66.  
  67. class Scanner:
  68.  
  69. def __init__(self) -> None:
  70. self.__urls: T.List[str] = []
  71. self.__check = Check()
  72. self.__paths: T.List[str] = None
  73. self.__queue = queue.Queue()
  74. self.__thread: int = mp.cpu_count()
  75. self.__threads: T.List[threading.Thread] = []
  76.  
  77. def set_urls(self, urls: T.List[str]):
  78. not_valid_urls = 0
  79. for url in urls:
  80. if '://' not in url:
  81. url = 'http://' + url
  82. if url.endswith('/'):
  83. url = url[:-1]
  84. if not '.' in url:
  85. not_valid_urls += 1
  86. else:
  87. self.__urls.append(
  88. url
  89. )
  90. if not_valid_urls:
  91. print(f'Removed {not_valid_urls} not valid url')
  92. print(f'Found {len(self.__urls)} valid url')
  93.  
  94. def set_paths(self, paths: T.List[str]):
  95. self.__paths = paths
  96.  
  97. def create_tasks(self):
  98. for url in self.__urls:
  99. for path in self.__paths:
  100. self.__queue.put(
  101. f'{url}{path}'
  102. )
  103. print(f'Created {self.__queue.qsize()} tasks')
  104.  
  105. def start(self):
  106. print('Starting scan')
  107. for i in range(self.__thread):
  108. th = threading.Thread(target=self.scan)
  109. self.__threads.append(
  110. th
  111. )
  112. for i in self.__threads:
  113. i.start()
  114. for i in self.__threads:
  115. i.join()
  116. print('Done scanning :)')
  117.  
  118. def check(self, target: str):
  119. try:
  120. resp = requests.get(
  121. url=target,
  122. headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36'},
  123. allow_redirects=False,
  124. verify=False,
  125. timeout=10
  126. )
  127. check = self.__check.validate(target, resp.text)
  128. if check:
  129. for found in check:
  130. print(f'{target} > Found {found}')
  131. else:
  132. print(f'{target} > Can\'t found anything')
  133. except Exception as err:
  134. print(f'{target} > {err}')
  135.  
  136. def scan(self):
  137. while not self.__queue.empty():
  138. url = self.__queue.get()
  139. self.check(url)
  140. self.__queue.task_done()
  141.  
  142.  
  143. class GeneratePaths:
  144.  
  145. __paths: T.List[str] = [
  146. '/', '/config/'
  147. ]
  148.  
  149. __files: T.List[str] = [
  150. 'config', 'dev', 'test',
  151. 'development', 'staging', 'aws',
  152. 's3', 'env', 'default',
  153. 'prod', 'credentials', 'settings',
  154. 'configuration'
  155. ]
  156.  
  157. __extensions: T.List[str] = [
  158. '.ts', '.js', '.json',
  159. '.yaml', '.yml'
  160. ]
  161.  
  162. __additionals: T.List[str] = [
  163. '/.env', '/.aws/credentials'
  164. ]
  165.  
  166. def __init__(self) -> None:
  167. self.__generated: T.List[str] = []
  168.  
  169. def merge_paths(self):
  170. for path in self.__paths:
  171. for file in self.__files:
  172. for extension in self.__extensions:
  173. self.__generated.append(
  174. f'{path}{file}{extension}'
  175. )
  176. for additional in self.__additionals:
  177. self.__generated.append(
  178. additional
  179. )
  180.  
  181. def get_paths(self) -> T.List[str]:
  182. return self.__generated
  183.  
  184.  
  185. def main():
  186. try:
  187. paths = GeneratePaths()
  188. paths.merge_paths()
  189. scan = Scanner()
  190. scan.set_paths(paths=paths.get_paths())
  191. urls = open(input('List Urls ? '), mode='r').read().splitlines()
  192. scan.set_urls(urls=urls)
  193. scan.create_tasks()
  194. scan.start()
  195. except FileNotFoundError as err:
  196. print(err)
  197.  
  198.  
  199. if __name__ == '__main__':
  200. main()
  201.  
Advertisement
Add Comment
Please, Sign In to add comment