this is based on calsyslab project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

284 lines
9.1 KiB

  1. __author__ = 'DarkWeb'
  2. '''
  3. ZeroDay Marketplace Crawler (Selenium)
  4. '''
  5. from selenium import webdriver
  6. from selenium.common.exceptions import NoSuchElementException
  7. from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
  8. from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
  9. from selenium.webdriver.firefox.service import Service
  10. from selenium.webdriver.support.ui import WebDriverWait
  11. from selenium.webdriver.support.ui import Select
  12. from selenium.webdriver.support import expected_conditions as EC
  13. from selenium.webdriver.common.by import By
  14. from PIL import Image
  15. import urllib.parse as urlparse
  16. import os, re, time
  17. from datetime import date
  18. import subprocess
  19. import configparser
  20. from bs4 import BeautifulSoup
  21. from MarketPlaces.Initialization.prepare_parser import new_parse
  22. from MarketPlaces.ZeroDay.parser import zeroday_links_parser
  23. from MarketPlaces.Utilities.utilities import cleanHTML
  24. counter = 1
  25. baseURL = 'http://sq542reyqwagfkghieehykb6hh6ohku5irarrrbeeo5iyozdbhe5n3id.onion/'
  26. def startCrawling():
  27. mktName = getMKTName()
  28. driver = getAccess()
  29. if driver != 'down':
  30. try:
  31. # login(driver)
  32. agreeToTerms(driver)
  33. crawlForum(driver)
  34. except Exception as e:
  35. print(driver.current_url, e)
  36. closeDriver(driver)
  37. new_parse(mktName, baseURL, True)
  38. # Returns the name of the website
  39. def getMKTName():
  40. name = 'ZeroDay'
  41. return name
  42. # Return the base link of the website
  43. def getFixedURL():
  44. url = 'http://sq542reyqwagfkghieehykb6hh6ohku5irarrrbeeo5iyozdbhe5n3id.onion/'
  45. return url
  46. # Closes Tor Browser
  47. def closeDriver(driver):
  48. # global pid
  49. # os.system("taskkill /pid " + str(pro.pid))
  50. # os.system("taskkill /t /f /im tor.exe")
  51. print('Closing Tor...')
  52. driver.close()
  53. time.sleep(3)
  54. return
  55. # Creates FireFox 'driver' and configure its 'Profile'
  56. # to use Tor proxy and socket
  57. def createFFDriver():
  58. from MarketPlaces.Initialization.markets_mining import config
  59. ff_binary = FirefoxBinary(config.get('TOR', 'firefox_binary_path'))
  60. ff_prof = FirefoxProfile(config.get('TOR', 'firefox_profile_path'))
  61. ff_prof.set_preference("places.history.enabled", False)
  62. ff_prof.set_preference("privacy.clearOnShutdown.offlineApps", True)
  63. ff_prof.set_preference("privacy.clearOnShutdown.passwords", True)
  64. ff_prof.set_preference("privacy.clearOnShutdown.siteSettings", True)
  65. ff_prof.set_preference("privacy.sanitize.sanitizeOnShutdown", True)
  66. ff_prof.set_preference("signon.rememberSignons", False)
  67. ff_prof.set_preference("network.cookie.lifetimePolicy", 2)
  68. ff_prof.set_preference("network.dns.disablePrefetch", True)
  69. ff_prof.set_preference("network.http.sendRefererHeader", 0)
  70. ff_prof.set_preference("permissions.default.image", 3)
  71. ff_prof.set_preference("browser.download.folderList", 2)
  72. ff_prof.set_preference("browser.download.manager.showWhenStarting", False)
  73. ff_prof.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain")
  74. ff_prof.set_preference('network.proxy.type', 1)
  75. ff_prof.set_preference("network.proxy.socks_version", 5)
  76. ff_prof.set_preference('network.proxy.socks', '127.0.0.1')
  77. ff_prof.set_preference('network.proxy.socks_port', 9150)
  78. ff_prof.set_preference('network.proxy.socks_remote_dns', True)
  79. ff_prof.set_preference("javascript.enabled", False)
  80. ff_prof.update_preferences()
  81. service = Service(config.get('TOR', 'geckodriver_path'))
  82. driver = webdriver.Firefox(firefox_binary=ff_binary, firefox_profile=ff_prof, service=service)
  83. driver.maximize_window()
  84. return driver
  85. #the driver 'gets' the url, attempting to get on the site, if it can't access return 'down'
  86. def getAccess():
  87. url = getFixedURL()
  88. driver = createFFDriver()
  89. try:
  90. driver.get(url)
  91. return driver
  92. except:
  93. driver.close()
  94. return 'down'
  95. def agreeToTerms(driver):
  96. try:
  97. agree_button = driver.find_element(by=By.XPATH, value='//input[@type="submit" and @name="agree" and @value="Yes, I agree"]')
  98. agree_button.click()
  99. except Exception as e:
  100. print('Problem with clicking agree button', e)
  101. def login(driver):
  102. # input("Press ENTER when CAPTCHA is complete and login page has loaded\n")
  103. WebDriverWait(driver, 100).until(EC.visibility_of_element_located(
  104. (By.XPATH, '//*[@id="username"]')))
  105. # entering username and password into input boxes
  106. usernameBox = driver.find_element(by=By.XPATH, value='//*[@id="username"]')
  107. # Username here
  108. usernameBox.send_keys('blabri')
  109. passwordBox = driver.find_element(by=By.XPATH, value='//*[@id="password"]')
  110. # Password here
  111. passwordBox.send_keys('fishowal')
  112. input("Press ENTER when BROKEN CIRCLE is pressed\n")
  113. # wait for listing page show up (This Xpath may need to change based on different seed url)
  114. WebDriverWait(driver, 100).until(EC.visibility_of_element_located(
  115. (By.XPATH, '/html/body/div[6]/div[3]/div[2]/div[1]/div[1]')))
  116. def savePage(driver, page, url):
  117. cleanPage = cleanHTML(driver, page)
  118. filePath = getFullPathName(url)
  119. os.makedirs(os.path.dirname(filePath), exist_ok=True)
  120. open(filePath, 'wb').write(cleanPage.encode('utf-8'))
  121. return
  122. def getFullPathName(url):
  123. from MarketPlaces.Initialization.markets_mining import config, CURRENT_DATE
  124. mainDir = os.path.join(config.get('Project', 'shared_folder'), "MarketPlaces/" + getMKTName() + "/HTML_Pages")
  125. fileName = getNameFromURL(url)
  126. if isDescriptionLink(url):
  127. fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Description\\' + fileName + '.html')
  128. else:
  129. fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Listing\\' + fileName + '.html')
  130. return fullPath
  131. def getMKTName() -> str:
  132. name = 'ZeroDay'
  133. return name
  134. def getNameFromURL(url):
  135. global counter
  136. name = ''.join(e for e in url if e.isalnum())
  137. if name == '':
  138. name = str(counter)
  139. counter = counter + 1
  140. return name
  141. def getInterestedLinks():
  142. links = []
  143. # Private category sells private exploits and vulnerabilities
  144. # Remote exploits
  145. links.append('http://sq542reyqwagfkghieehykb6hh6ohku5irarrrbeeo5iyozdbhe5n3id.onion/private/remote')
  146. # Local exploits
  147. links.append('http://sq542reyqwagfkghieehykb6hh6ohku5irarrrbeeo5iyozdbhe5n3id.onion/private/local')
  148. # Web App exploits
  149. links.append('http://sq542reyqwagfkghieehykb6hh6ohku5irarrrbeeo5iyozdbhe5n3id.onion/private/webapps')
  150. # doc/poc - denial of service / proof of concept
  151. links.append('http://sq542reyqwagfkghieehykb6hh6ohku5irarrrbeeo5iyozdbhe5n3id.onion/private/dos')
  152. # Remote
  153. links.append('http://sq542reyqwagfkghieehykb6hh6ohku5irarrrbeeo5iyozdbhe5n3id.onion/remote')
  154. # Local
  155. links.append('http://sq542reyqwagfkghieehykb6hh6ohku5irarrrbeeo5iyozdbhe5n3id.onion/local')
  156. # Web app
  157. links.append('http://sq542reyqwagfkghieehykb6hh6ohku5irarrrbeeo5iyozdbhe5n3id.onion/webapps')
  158. # dos/poc
  159. links.append('http://sq542reyqwagfkghieehykb6hh6ohku5irarrrbeeo5iyozdbhe5n3id.onion/dos')
  160. # Shellcode
  161. links.append('http://sq542reyqwagfkghieehykb6hh6ohku5irarrrbeeo5iyozdbhe5n3id.onion/shellcode')
  162. return links
  163. def crawlForum(driver):
  164. print("Crawling the ZeroDay market")
  165. linksToCrawl = getInterestedLinks()
  166. i = 0
  167. while i < len(linksToCrawl):
  168. link = linksToCrawl[i]
  169. print('Crawling :', link)
  170. try:
  171. has_next_page = True
  172. count = 0
  173. while has_next_page:
  174. try:
  175. driver.get(link)
  176. except:
  177. driver.refresh()
  178. html = driver.page_source
  179. savePage(driver, html, link)
  180. list = productPages(html)
  181. for item in list:
  182. itemURL = urlparse.urljoin(baseURL, str(item))
  183. try:
  184. driver.get(itemURL)
  185. except:
  186. driver.refresh()
  187. savePage(driver, driver.page_source, item)
  188. driver.back()
  189. # # comment out
  190. # break
  191. #
  192. # comment out
  193. # if count == 1:
  194. # break
  195. try:
  196. link = driver.find_element(by=By.XPATH, value='//a[contains(text(), "next")]').get_attribute('href')
  197. if link == "":
  198. raise NoSuchElementException
  199. count += 1
  200. except NoSuchElementException:
  201. has_next_page = False
  202. except Exception as e:
  203. print(link, e)
  204. i += 1
  205. print("Crawling the Ares market done.")
  206. # Returns 'True' if the link is Topic link, may need to change for every website
  207. def isDescriptionLink(url):
  208. if 'description' in url:
  209. return True
  210. return False
  211. # Returns True if the link is a listingPage link, may need to change for every website
  212. def isListingLink(url):
  213. if 'category' in url:
  214. return True
  215. return False
  216. def productPages(html):
  217. soup = BeautifulSoup(html, "html.parser")
  218. return zeroday_links_parser(soup)
  219. def crawler():
  220. startCrawling()