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.

270 lines
8.9 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. Ares 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.Ares.parser import ares_links_parser
  23. from MarketPlaces.Utilities.utilities import cleanHTML
  24. counter = 1
  25. baseURL = 'http://aresonewgdyfb7oyyanlvp6e75arfivpkuy7rwo5uegayrv7rkztfwad.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 = 'Ares'
  40. return name
  41. # Return the base link of the website
  42. def getFixedURL():
  43. url = 'http://aresonewgdyfb7oyyanlvp6e75arfivpkuy7rwo5uegayrv7rkztfwad.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. # input("Press ENTER when CAPTCHA is complete and login page has loaded\n")
  96. WebDriverWait(driver, 100).until(EC.visibility_of_element_located(
  97. (By.XPATH, '//*[@id="username"]')))
  98. # entering username and password into input boxes
  99. usernameBox = driver.find_element(by=By.XPATH, value='//*[@id="username"]')
  100. # Username here
  101. usernameBox.send_keys('blabri')
  102. passwordBox = driver.find_element(by=By.XPATH, value='//*[@id="password"]')
  103. # Password here
  104. passwordBox.send_keys('fishowal')
  105. input("Press ENTER when BROKEN CIRCLE is pressed\n")
  106. # wait for listing page show up (This Xpath may need to change based on different seed url)
  107. WebDriverWait(driver, 100).until(EC.visibility_of_element_located(
  108. (By.XPATH, '/html/body/div[6]/div[3]/div[2]/div[1]/div[1]')))
  109. def savePage(driver, page, url):
  110. cleanPage = cleanHTML(driver, page)
  111. filePath = getFullPathName(url)
  112. os.makedirs(os.path.dirname(filePath), exist_ok=True)
  113. open(filePath, 'wb').write(cleanPage.encode('utf-8'))
  114. return
  115. def getFullPathName(url):
  116. from MarketPlaces.Initialization.markets_mining import config, CURRENT_DATE
  117. mainDir = os.path.join(config.get('Project', 'shared_folder'), "MarketPlaces/" + getMKTName() + "/HTML_Pages")
  118. fileName = getNameFromURL(url)
  119. if isDescriptionLink(url):
  120. fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Description\\' + fileName + '.html')
  121. else:
  122. fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Listing\\' + fileName + '.html')
  123. return fullPath
  124. def getMKTName() -> str:
  125. name = 'Ares'
  126. return name
  127. def getNameFromURL(url):
  128. global counter
  129. name = ''.join(e for e in url if e.isalnum())
  130. if name == '':
  131. name = str(counter)
  132. counter = counter + 1
  133. return name
  134. def getInterestedLinks():
  135. links = []
  136. # Digital - Malware
  137. links.append('http://aresonewgdyfb7oyyanlvp6e75arfivpkuy7rwo5uegayrv7rkztfwad.onion/category/95c37970-002c-11ec-a5dc-1f4432087ed2')
  138. # Digital - Guides (Mostly carding, some useful hacking guides. probably dont use)
  139. links.append('http://aresonewgdyfb7oyyanlvp6e75arfivpkuy7rwo5uegayrv7rkztfwad.onion/category/9a8bea70-002b-11ec-a3db-c90dd329f662')
  140. # Digital - Hacking
  141. links.append('http://aresonewgdyfb7oyyanlvp6e75arfivpkuy7rwo5uegayrv7rkztfwad.onion/category/a81693f0-002b-11ec-9c39-110550ce4921')
  142. # Digital - Malware2
  143. links.append('http://aresonewgdyfb7oyyanlvp6e75arfivpkuy7rwo5uegayrv7rkztfwad.onion/category/b3258c50-002b-11ec-b658-876d3d651145')
  144. # Digital - Sofware (50/50 hacking stuff and cracked software)
  145. links.append('http://aresonewgdyfb7oyyanlvp6e75arfivpkuy7rwo5uegayrv7rkztfwad.onion/category/cff75df0-002b-11ec-8d0a-81fddeb36bf1')
  146. # Digital - Exploits
  147. links.append('http://aresonewgdyfb7oyyanlvp6e75arfivpkuy7rwo5uegayrv7rkztfwad.onion/category/ef029550-002f-11ec-8711-675a8b116ba6')
  148. # Digital - Tutorials (Mostly random stuff, some useful tutorials, probably dont use)
  149. links.append('http://aresonewgdyfb7oyyanlvp6e75arfivpkuy7rwo5uegayrv7rkztfwad.onion/category/f6e9c3b0-002b-11ec-85aa-c79a6ac8cfe8')
  150. return links
  151. def crawlForum(driver):
  152. print("Crawling the Ares market")
  153. linksToCrawl = getInterestedLinks()
  154. i = 0
  155. while i < len(linksToCrawl):
  156. link = linksToCrawl[i]
  157. print('Crawling :', link)
  158. try:
  159. has_next_page = True
  160. count = 0
  161. while has_next_page:
  162. try:
  163. driver.get(link)
  164. except:
  165. driver.refresh()
  166. html = driver.page_source
  167. savePage(driver, html, link)
  168. list = productPages(html)
  169. for item in list:
  170. itemURL = urlparse.urljoin(baseURL, str(item))
  171. try:
  172. driver.get(itemURL)
  173. except:
  174. driver.refresh()
  175. savePage(driver, driver.page_source, item)
  176. driver.back()
  177. # # comment out
  178. # break
  179. #
  180. # # comment out
  181. # if count == 1:
  182. # break
  183. try:
  184. link = driver.find_element(by=By.XPATH, value='//a[contains(text(), "Next")]').get_attribute('href')
  185. if link == "":
  186. raise NoSuchElementException
  187. count += 1
  188. except NoSuchElementException:
  189. has_next_page = False
  190. except Exception as e:
  191. print(link, e)
  192. i += 1
  193. print("Crawling the Ares market done.")
  194. # Returns 'True' if the link is Topic link, may need to change for every website
  195. def isDescriptionLink(url):
  196. if 'product' in url:
  197. return True
  198. return False
  199. # Returns True if the link is a listingPage link, may need to change for every website
  200. def isListingLink(url):
  201. if 'category' in url:
  202. return True
  203. return False
  204. def productPages(html):
  205. soup = BeautifulSoup(html, "html.parser")
  206. return ares_links_parser(soup)
  207. def crawler():
  208. startCrawling()