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.

274 lines
8.8 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. __author__ = 'DarkWeb'
  2. '''
  3. Quest 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.Quest.parser import quest_links_parser
  23. from MarketPlaces.Utilities.utilities import cleanHTML
  24. counter = 1
  25. baseURL = 'http://questxwvkwvsw2qgeeljz4fbv6cq2kbmapo7tw5heu4nng2ufgykapid.onion'
  26. def startCrawling():
  27. mktName = getMKTName()
  28. driver = getAccess()
  29. if driver != 'down':
  30. try:
  31. login(driver)
  32. crawlForum(driver)
  33. except Exception as e:
  34. print(driver.current_url, e)
  35. closeDriver(driver)
  36. new_parse(mktName, baseURL, True)
  37. # Returns the name of the website
  38. def getMKTName():
  39. name = 'Quest'
  40. return name
  41. # Return the base link of the website
  42. def getFixedURL():
  43. url = 'http://questxwvkwvsw2qgeeljz4fbv6cq2kbmapo7tw5heu4nng2ufgykapid.onion'
  44. return url
  45. # Closes Tor Browser
  46. def closeDriver(driver):
  47. # global pid
  48. # os.system("taskkill /pid " + str(pro.pid))
  49. # os.system("taskkill /t /f /im tor.exe")
  50. print('Closing Tor...')
  51. driver.close()
  52. time.sleep(3)
  53. return
  54. # Creates FireFox 'driver' and configure its 'Profile'
  55. # to use Tor proxy and socket
  56. def createFFDriver():
  57. from MarketPlaces.Initialization.markets_mining import config
  58. ff_binary = FirefoxBinary(config.get('TOR', 'firefox_binary_path'))
  59. ff_prof = FirefoxProfile(config.get('TOR', 'firefox_profile_path'))
  60. ff_prof.set_preference("places.history.enabled", False)
  61. ff_prof.set_preference("privacy.clearOnShutdown.offlineApps", True)
  62. ff_prof.set_preference("privacy.clearOnShutdown.passwords", True)
  63. ff_prof.set_preference("privacy.clearOnShutdown.siteSettings", True)
  64. ff_prof.set_preference("privacy.sanitize.sanitizeOnShutdown", True)
  65. ff_prof.set_preference("signon.rememberSignons", False)
  66. ff_prof.set_preference("network.cookie.lifetimePolicy", 2)
  67. # ff_prof.set_preference("network.dns.disablePrefetch", True)
  68. # ff_prof.set_preference("network.http.sendRefererHeader", 0)
  69. ff_prof.set_preference("permissions.default.image", 3)
  70. ff_prof.set_preference("browser.download.folderList", 2)
  71. ff_prof.set_preference("browser.download.manager.showWhenStarting", False)
  72. ff_prof.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain")
  73. ff_prof.set_preference('network.proxy.type', 1)
  74. ff_prof.set_preference("network.proxy.socks_version", 5)
  75. ff_prof.set_preference('network.proxy.socks', '127.0.0.1')
  76. ff_prof.set_preference('network.proxy.socks_port', 9150)
  77. ff_prof.set_preference('network.proxy.socks_remote_dns', True)
  78. ff_prof.set_preference("javascript.enabled", False)
  79. ff_prof.update_preferences()
  80. service = Service(config.get('TOR', 'geckodriver_path'))
  81. driver = webdriver.Firefox(firefox_binary=ff_binary, firefox_profile=ff_prof, service=service)
  82. driver.maximize_window()
  83. return driver
  84. #the driver 'gets' the url, attempting to get on the site, if it can't access return 'down'
  85. def getAccess():
  86. url = getFixedURL()
  87. driver = createFFDriver()
  88. try:
  89. driver.get(url)
  90. return driver
  91. except:
  92. driver.close()
  93. return 'down'
  94. def login(driver):
  95. WebDriverWait(driver, 100).until(EC.visibility_of_element_located(
  96. (By.XPATH, '//*[@id="username"]')))
  97. # entering username and password into input boxes
  98. usernameBox = driver.find_element(by=By.XPATH, value='//*[@id="username"]')
  99. # Username here
  100. usernameBox.send_keys('CashCarti')
  101. passwordBox = driver.find_element(by=By.XPATH, value='//*[@id="password"]')
  102. # Password here
  103. passwordBox.send_keys('Mahogany')
  104. # Clicking the login button
  105. # login_button = driver.find_element(By.XPATH, value='/html/body/div[2]/div/div[3]/div/div/div/div[1]/form/div[4]/div/div/button')
  106. # login_button.click()
  107. input("Press ENTER when CAPTCHA is completed\n")
  108. # wait for listing page show up (This Xpath may need to change based on different seed url)
  109. WebDriverWait(driver, 100).until(EC.visibility_of_element_located(
  110. (By.XPATH, '/html/body/div[1]/nav/div/a/img')))
  111. def savePage(driver, page, url):
  112. cleanPage = cleanHTML(driver, page)
  113. filePath = getFullPathName(url)
  114. os.makedirs(os.path.dirname(filePath), exist_ok=True)
  115. open(filePath, 'wb').write(cleanPage.encode('utf-8'))
  116. return
  117. def getFullPathName(url):
  118. from MarketPlaces.Initialization.markets_mining import config, CURRENT_DATE
  119. mainDir = os.path.join(config.get('Project', 'shared_folder'), "MarketPlaces/" + getMKTName() + "/HTML_Pages")
  120. fileName = getNameFromURL(url)
  121. if isDescriptionLink(url):
  122. fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Description\\' + fileName + '.html')
  123. else:
  124. fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Listing\\' + fileName + '.html')
  125. return fullPath
  126. def getMKTName() -> str:
  127. name = 'Quest'
  128. return name
  129. def getNameFromURL(url):
  130. global counter
  131. name = ''.join(e for e in url if e.isalnum())
  132. if name == '':
  133. name = str(counter)
  134. counter = counter + 1
  135. return name
  136. def getInterestedLinks():
  137. links = []
  138. ## Services
  139. links.append('http://questxwvkwvsw2qgeeljz4fbv6cq2kbmapo7tw5heu4nng2ufgykapid.onion/category/8ae67900-22ed-11ec-a710-31f963ce8d35')
  140. ## Software
  141. links.append('http://questxwvkwvsw2qgeeljz4fbv6cq2kbmapo7tw5heu4nng2ufgykapid.onion/category/92809300-22ed-11ec-b143-af312e1dab77')
  142. ## Tutorial
  143. links.append('http://questxwvkwvsw2qgeeljz4fbv6cq2kbmapo7tw5heu4nng2ufgykapid.onion/category/9d1592b0-22ed-11ec-b82d-c3d2878a8716')
  144. ## Malware
  145. links.append('http://questxwvkwvsw2qgeeljz4fbv6cq2kbmapo7tw5heu4nng2ufgykapid.onion/category/a35bae90-22ed-11ec-ad2e-410f5a5339b5')
  146. ## Hacking
  147. links.append('http://questxwvkwvsw2qgeeljz4fbv6cq2kbmapo7tw5heu4nng2ufgykapid.onion/category/b4252cf0-22ed-11ec-8032-751549438ed5')
  148. ## Exploits
  149. links.append('http://questxwvkwvsw2qgeeljz4fbv6cq2kbmapo7tw5heu4nng2ufgykapid.onion/category/c0c3ac60-22ed-11ec-9e97-41cd1912fdee')
  150. ## Carding
  151. links.append('http://questxwvkwvsw2qgeeljz4fbv6cq2kbmapo7tw5heu4nng2ufgykapid.onion/category/cbe06b00-22ec-11ec-ab3a-816857220dec')
  152. return links
  153. def crawlForum(driver):
  154. print("Crawling the Quest market")
  155. linksToCrawl = getInterestedLinks()
  156. i = 0
  157. while i < len(linksToCrawl):
  158. link = linksToCrawl[i]
  159. print('Crawling :', link)
  160. try:
  161. has_next_page = True
  162. count = 0
  163. while has_next_page:
  164. try:
  165. driver.get(link)
  166. except:
  167. driver.refresh()
  168. html = driver.page_source
  169. savePage(driver, html, link)
  170. list = productPages(html)
  171. for item in list:
  172. itemURL = urlparse.urljoin(baseURL, str(item))
  173. try:
  174. driver.get(itemURL)
  175. except:
  176. driver.refresh()
  177. savePage(driver, driver.page_source, item)
  178. driver.back()
  179. # # comment out
  180. # break
  181. #
  182. # # comment out
  183. # if count == 1:
  184. # break
  185. try:
  186. link_elem = driver.find_element(by=By.CSS_SELECTOR, value='a.page-link[rel="next"]')
  187. link = link_elem.get_attribute('href')
  188. if link == "":
  189. raise NoSuchElementException
  190. count += 1
  191. except NoSuchElementException:
  192. has_next_page = False
  193. except Exception as e:
  194. print(link, e)
  195. i += 1
  196. print("Crawling the Quest market done.")
  197. # Returns 'True' if the link is Topic link, may need to change for every website
  198. def isDescriptionLink(url):
  199. if 'product' in url:
  200. return True
  201. return False
  202. # Returns True if the link is a listingPage link, may need to change for every website
  203. def isListingLink(url):
  204. if 'category' in url:
  205. return True
  206. return False
  207. def productPages(html):
  208. soup = BeautifulSoup(html, "html.parser")
  209. return quest_links_parser(soup)
  210. def crawler():
  211. startCrawling()