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.

307 lines
11 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. __author__ = 'DarkWeb'
  2. '''
  3. Ares Market 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.common.by import By
  11. from selenium.webdriver.support import expected_conditions as EC
  12. from selenium.webdriver.support.ui import WebDriverWait
  13. from PIL import Image
  14. import urllib.parse as urlparse
  15. import os, time
  16. from datetime import date
  17. import subprocess
  18. from bs4 import BeautifulSoup
  19. from MarketPlaces.Initialization.prepare_parser import new_parse
  20. from MarketPlaces.Ares.parser import ares_links_parser
  21. from MarketPlaces.Utilities.utilities import cleanHTML
  22. counter = 1
  23. baseURL = 'http://sn2sfdqay6cxztroslaxa36covrhoowe6a5xug6wlm6ek7nmeiujgvad.onion'
  24. # Opens Tor Browser, crawls the website
  25. def startCrawling():
  26. marketName = getMarketName()
  27. driver = getAccess()
  28. if driver != 'down':
  29. try:
  30. login(driver)
  31. crawlForum(driver)
  32. except Exception as e:
  33. print(driver.current_url, e)
  34. closeDriver(driver)
  35. new_parse(marketName, False)
  36. # Login using premade account credentials and do login captcha manually
  37. def login(driver):
  38. #wait for login page
  39. WebDriverWait(driver, 100).until(EC.visibility_of_element_located(
  40. (By.XPATH, "/html/body/div[3]/div[3]/div[2]/div/div[2]/div/center")))
  41. #entering username and password into input boxes
  42. usernameBox = driver.find_element(by=By.XPATH, value='//*[@id="username"]')
  43. #Username here
  44. usernameBox.send_keys('blabri')
  45. passwordBox = driver.find_element(by=By.XPATH, value='//*[@id="password"]')
  46. #Password here
  47. passwordBox.send_keys('fishowal')
  48. '''
  49. # wait for captcha page show up
  50. WebDriverWait(driver, 100).until(EC.visibility_of_element_located(
  51. (By.XPATH, "/html/body/div[3]/div[3]/div[2]/div/div[2]/div/form/div/div[3]/div/div/img")))
  52. # save captcha to local
  53. driver.find_element(by=By.XPATH, value='/html/body/div[3]/div[3]/div[2]/div/div[2]/div/form/div/div[3]/div/div/img').screenshot(
  54. r'..\Ares\captcha.png')
  55. # This method will show image in any image viewer
  56. im = Image.open(r'..\Ares\captcha.png')
  57. im.show()
  58. # wait until input space show up
  59. inputBox = driver.find_element(by=By.XPATH, value='/html/body/div[3]/div[3]/div[2]/div/div[2]/div/form/div/div[3]/input')
  60. # ask user input captcha solution in terminal
  61. userIn = input("Enter solution: ")
  62. # send user solution into the input space
  63. inputBox.send_keys(userIn)
  64. # click the verify(submit) button
  65. driver.find_element(by=By.XPATH, value="/html/body/div[3]/div[3]/div[2]/div/div[2]/div/form/div/div[4]/div/div/button").click()
  66. '''
  67. input("Press ENTER when CAPTCHA is completed\n")
  68. # wait for listing page show up (This Xpath may need to change based on different seed url)
  69. WebDriverWait(driver, 50).until(EC.visibility_of_element_located(
  70. (By.XPATH, '/html/body/div[7]/div[3]/div[2]/div[1]/div[1]')))
  71. # Returns the name of the website
  72. def getMarketName():
  73. name = 'Ares'
  74. return name
  75. # Return the link of the website
  76. def getFixedURL():
  77. url = 'http://sn2sfdqay6cxztroslaxa36covrhoowe6a5xug6wlm6ek7nmeiujgvad.onion'
  78. return url
  79. # Closes Tor Browser
  80. def closeDriver(driver):
  81. # global pid
  82. # os.system("taskkill /pid " + str(pro.pid))
  83. # os.system("taskkill /t /f /im tor.exe")
  84. print('Closing Tor...')
  85. driver.quit()
  86. time.sleep(3)
  87. return
  88. # Creates FireFox 'driver' and configure its 'Profile'
  89. # to use Tor proxy and socket
  90. def createFFDriver():
  91. from MarketPlaces.Initialization.markets_mining import config
  92. ff_binary = FirefoxBinary(config.get('TOR', 'firefox_binary_path'))
  93. ff_prof = FirefoxProfile(config.get('TOR', 'firefox_profile_path'))
  94. ff_prof.set_preference("places.history.enabled", False)
  95. ff_prof.set_preference("privacy.clearOnShutdown.offlineApps", True)
  96. ff_prof.set_preference("privacy.clearOnShutdown.passwords", True)
  97. ff_prof.set_preference("privacy.clearOnShutdown.siteSettings", True)
  98. ff_prof.set_preference("privacy.sanitize.sanitizeOnShutdown", True)
  99. ff_prof.set_preference("signon.rememberSignons", False)
  100. ff_prof.set_preference("network.cookie.lifetimePolicy", 2)
  101. ff_prof.set_preference("network.dns.disablePrefetch", True)
  102. ff_prof.set_preference("network.http.sendRefererHeader", 0)
  103. ff_prof.set_preference("permissions.default.image", 3)
  104. ff_prof.set_preference("browser.download.folderList", 2)
  105. ff_prof.set_preference("browser.download.manager.showWhenStarting", False)
  106. ff_prof.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain")
  107. ff_prof.set_preference('network.proxy.type', 1)
  108. ff_prof.set_preference("network.proxy.socks_version", 5)
  109. ff_prof.set_preference('network.proxy.socks', '127.0.0.1')
  110. ff_prof.set_preference('network.proxy.socks_port', 9150)
  111. ff_prof.set_preference('network.proxy.socks_remote_dns', True)
  112. ff_prof.set_preference("javascript.enabled", False)
  113. ff_prof.update_preferences()
  114. service = Service(config.get('TOR', 'geckodriver_path'))
  115. driver = webdriver.Firefox(firefox_binary=ff_binary, firefox_profile=ff_prof, service=service)
  116. driver.maximize_window()
  117. return driver
  118. def getAccess():
  119. url = getFixedURL()
  120. driver = createFFDriver()
  121. try:
  122. driver.get(url)
  123. return driver
  124. except:
  125. driver.close()
  126. return 'down'
  127. # Saves the crawled html page
  128. def savePage(driver, page, url):
  129. cleanPage = cleanHTML(driver, page)
  130. filePath = getFullPathName(url)
  131. os.makedirs(os.path.dirname(filePath), exist_ok=True)
  132. open(filePath, 'wb').write(cleanPage.encode('utf-8'))
  133. return
  134. # Gets the full path of the page to be saved along with its appropriate file name
  135. def getFullPathName(url):
  136. from MarketPlaces.Initialization.markets_mining import config, CURRENT_DATE
  137. mainDir = os.path.join(config.get('Project', 'shared_folder'), "MarketPlaces/" + getMKTName() + "/HTML_Pages")
  138. fileName = getNameFromURL(url)
  139. if isDescriptionLink(url):
  140. fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Description\\' + fileName + '.html')
  141. else:
  142. fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Listing\\' + fileName + '.html')
  143. return fullPath
  144. # Creates the file name from passed URL
  145. def getNameFromURL(url):
  146. global counter
  147. name = ''.join(e for e in url if e.isalnum())
  148. if name == '':
  149. name = str(counter)
  150. counter = counter + 1
  151. return name
  152. def getInterestedLinks():
  153. links = []
  154. # # Digital - Other
  155. # links.append('http://sn2sfdqay6cxztroslaxa36covrhoowe6a5xug6wlm6ek7nmeiujgvad.onion/category/91ecd5d0-002c-11ec-9b46-ede2378c5d3c')
  156. # # Digital - VPN
  157. # links.append('http://sn2sfdqay6cxztroslaxa36covrhoowe6a5xug6wlm6ek7nmeiujgvad.onion/category/9431b830-002b-11ec-86d6-cdaf65cd97f1')
  158. # # Digital - Coding
  159. # links.append('http://sn2sfdqay6cxztroslaxa36covrhoowe6a5xug6wlm6ek7nmeiujgvad.onion/category/948b7400-a939-11ec-adc5-2f775203130c')
  160. # Digital - Malware
  161. links.append('http://sn2sfdqay6cxztroslaxa36covrhoowe6a5xug6wlm6ek7nmeiujgvad.onion/category/95c37970-002c-11ec-a5dc-1f4432087ed2')
  162. # # Digital - Guides
  163. # links.append('http://sn2sfdqay6cxztroslaxa36covrhoowe6a5xug6wlm6ek7nmeiujgvad.onion/category/9a8bea70-002b-11ec-a3db-c90dd329f662')
  164. # # Digital - Hacking
  165. # links.append('http://sn2sfdqay6cxztroslaxa36covrhoowe6a5xug6wlm6ek7nmeiujgvad.onion/category/a81693f0-002b-11ec-9c39-110550ce4921')
  166. # # Digital - Malware
  167. # links.append('http://sn2sfdqay6cxztroslaxa36covrhoowe6a5xug6wlm6ek7nmeiujgvad.onion/category/b3258c50-002b-11ec-b658-876d3d651145')
  168. # # Digital - Services
  169. # links.append('http://sn2sfdqay6cxztroslaxa36covrhoowe6a5xug6wlm6ek7nmeiujgvad.onion/category/bae64840-002b-11ec-bbcc-a93431540099')
  170. # # Digital - Software
  171. # links.append('http://sn2sfdqay6cxztroslaxa36covrhoowe6a5xug6wlm6ek7nmeiujgvad.onion/category/cff75df0-002b-11ec-8d0a-81fddeb36bf1')
  172. # # Digital - Exploits
  173. # links.append('http://sn2sfdqay6cxztroslaxa36covrhoowe6a5xug6wlm6ek7nmeiujgvad.onion/category/ef029550-002f-11ec-8711-675a8b116ba6')
  174. # # Digital - Tutorials
  175. # links.append('http://sn2sfdqay6cxztroslaxa36covrhoowe6a5xug6wlm6ek7nmeiujgvad.onion/category/f6e9c3b0-002b-11ec-85aa-c79a6ac8cfe8')
  176. return links
  177. def crawlForum(driver):
  178. print("Crawling the Ares market")
  179. linksToCrawl = getInterestedLinks()
  180. i = 0
  181. while i < len(linksToCrawl):
  182. link = linksToCrawl[i]
  183. print('Crawling :', link)
  184. try:
  185. has_next_page = True
  186. count = 0
  187. while has_next_page:
  188. try:
  189. driver.get(link)
  190. except:
  191. driver.refresh()
  192. html = driver.page_source
  193. savePage(driver, html, link)
  194. list = productPages(html)
  195. for item in list:
  196. itemURL = urlparse.urljoin(baseURL, str(item))
  197. try:
  198. driver.get(itemURL)
  199. except:
  200. driver.refresh()
  201. savePage(driver, driver.page_source, item)
  202. driver.back()
  203. # comment out
  204. break
  205. # comment out
  206. if count == 1:
  207. break
  208. try:
  209. nav = driver.find_element(by=By.XPATH, value=
  210. '/html/body/div[7]/div[3]/div/div[2]/nav')
  211. a = nav.find_element(by=By.LINK_TEXT, value="Next")
  212. link = a.get_attribute('href')
  213. if link == "":
  214. raise NoSuchElementException
  215. count += 1
  216. except NoSuchElementException:
  217. has_next_page = False
  218. except Exception as e:
  219. print(link, e)
  220. i += 1
  221. input("Crawling Ares market done sucessfully. Press ENTER to continue\n")
  222. # Returns 'True' if the link is Topic link
  223. def isDescriptionLink(url):
  224. if 'product' in url:
  225. return True
  226. return False
  227. # Returns True if the link is a listingPage link
  228. def isListingLink(url):
  229. if 'category' in url:
  230. return True
  231. return False
  232. # calling the parser to define the links
  233. def productPages(html):
  234. soup = BeautifulSoup(html, "html.parser")
  235. return ares_links_parser(soup)
  236. def crawler():
  237. startCrawling()
  238. # print("Crawling and Parsing BestCardingWorld .... DONE!")