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.

299 lines
9.6 KiB

1 year ago
  1. __author__ = 'DarkWeb'
  2. '''
  3. DWForums Forum 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. import urllib.parse as urlparse
  14. import os, time
  15. from datetime import date
  16. import subprocess
  17. from bs4 import BeautifulSoup
  18. from Forums.Initialization.prepare_parser import new_parse
  19. from Forums.DWForums.parser import dwForums_links_parser
  20. from Forums.Utilities.utilities import cleanHTML
  21. counter = 1
  22. baseURL = 'http://dwforumuugiyderhybcpfxmlmoawgq6z3w6hk45nrnem3p7kwszhybad.onion/'
  23. # Opens Tor Browser, crawls the website
  24. def startCrawling():
  25. # opentor()
  26. # forumName = getForumName()
  27. driver = getAccess()
  28. if driver != 'down':
  29. login(driver)
  30. crawlForum(driver)
  31. closetor(driver)
  32. # new_parse(forumName, False)
  33. # Opens Tor Browser
  34. def opentor():
  35. global pid
  36. print("Connecting Tor...")
  37. path = open('../../path.txt').readline().strip()
  38. pro = subprocess.Popen(path)
  39. pid = pro.pid
  40. time.sleep(7.5)
  41. input('Tor Connected. Press ENTER to continue\n')
  42. return
  43. # Login using premade account credentials and do login captcha manually
  44. def login(driver):
  45. #click login button
  46. WebDriverWait(driver, 100).until(EC.visibility_of_element_located(
  47. (By.CSS_SELECTOR, ".button--icon--user")))
  48. login_link = driver.find_element_by_css_selector(".button--icon--user")
  49. login_link.click()
  50. #entering username and password into input boxes
  51. WebDriverWait(driver, 100).until(EC.visibility_of_element_located(
  52. (By.XPATH, "/html/body/div[4]/div/div[2]/div/form/div[1]")))
  53. container = driver.find_element(by=By.XPATH, value="/html/body/div[4]/div/div[2]/div/form/div[1]")
  54. # print(container.get_attribute("outerHTML"))
  55. boxes = container.find_elements_by_class_name("input")
  56. # print(len(boxes))
  57. #Username here
  58. boxes[0].send_keys('nice_reamer08')
  59. #Password here
  60. boxes[1].send_keys('tjpv$]Nc}XG@`%LM')
  61. # no captcha on this site
  62. # click the verify(submit) button
  63. driver.find_element_by_css_selector(".button--icon--login").click()
  64. # wait for listing page show up (This Xpath may need to change based on different seed url)
  65. WebDriverWait(driver, 50).until(EC.visibility_of_element_located(
  66. (By.CSS_SELECTOR, '.p-staffBar-inner > div:nth-child(4) > div:nth-child(1) > a:nth-child(1)')))
  67. # Returns the name of the website
  68. def getForumName():
  69. name = 'DWForums'
  70. return name
  71. # Return the link of the website
  72. def getFixedURL():
  73. url = 'http://dwforumuugiyderhybcpfxmlmoawgq6z3w6hk45nrnem3p7kwszhybad.onion/'
  74. return url
  75. # Closes Tor Browser
  76. def closetor(driver):
  77. global pid
  78. # os.system("taskkill /pid " + str(pro.pid))
  79. os.system("taskkill /t /f /im tor.exe")
  80. print('Closing Tor...')
  81. driver.close()
  82. time.sleep(3)
  83. return
  84. # Creates FireFox 'driver' and configure its 'Profile'
  85. # to use Tor proxy and socket
  86. def createFFDriver():
  87. file = open('../../path.txt', 'r')
  88. lines = file.readlines()
  89. ff_binary = FirefoxBinary(lines[0].strip())
  90. ff_prof = FirefoxProfile(lines[1].strip())
  91. ff_prof.set_preference("places.history.enabled", False)
  92. ff_prof.set_preference("privacy.clearOnShutdown.offlineApps", True)
  93. ff_prof.set_preference("privacy.clearOnShutdown.passwords", True)
  94. ff_prof.set_preference("privacy.clearOnShutdown.siteSettings", True)
  95. ff_prof.set_preference("privacy.sanitize.sanitizeOnShutdown", True)
  96. ff_prof.set_preference("signon.rememberSignons", False)
  97. ff_prof.set_preference("network.cookie.lifetimePolicy", 2)
  98. ff_prof.set_preference("network.dns.disablePrefetch", True)
  99. ff_prof.set_preference("network.http.sendRefererHeader", 0)
  100. ff_prof.set_preference("permissions.default.image", 3)
  101. ff_prof.set_preference("browser.download.folderList", 2)
  102. ff_prof.set_preference("browser.download.manager.showWhenStarting", False)
  103. ff_prof.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain")
  104. ff_prof.set_preference('network.proxy.type', 1)
  105. ff_prof.set_preference("network.proxy.socks_version", 5)
  106. ff_prof.set_preference('network.proxy.socks', '127.0.0.1')
  107. ff_prof.set_preference('network.proxy.socks_port', 9150)
  108. ff_prof.set_preference('network.proxy.socks_remote_dns', True)
  109. ff_prof.set_preference("javascript.enabled", True)
  110. ff_prof.update_preferences()
  111. service = Service(lines[2].strip())
  112. driver = webdriver.Firefox(firefox_binary=ff_binary, firefox_profile=ff_prof, service=service)
  113. return driver
  114. def getAccess():
  115. url = getFixedURL()
  116. driver = createFFDriver()
  117. try:
  118. driver.get(url)
  119. return driver
  120. except:
  121. return 'down'
  122. # Saves the crawled html page
  123. def savePage(page, url):
  124. cleanPage = cleanHTML(page)
  125. filePath = getFullPathName(url)
  126. os.makedirs(os.path.dirname(filePath), exist_ok=True)
  127. open(filePath, 'wb').write(cleanPage.encode('utf-8'))
  128. return
  129. # Gets the full path of the page to be saved along with its appropriate file name
  130. def getFullPathName(url):
  131. fileName = getNameFromURL(url)
  132. if isDescriptionLink(url):
  133. fullPath = r'..\DWForums\HTML_Pages\\' + str(
  134. "%02d" % date.today().month) + str("%02d" % date.today().day) + str(
  135. "%04d" % date.today().year) + r'\\' + r'Description\\' + fileName + '.html'
  136. else:
  137. fullPath = r'..\DWForums\HTML_Pages\\' + str(
  138. "%02d" % date.today().month) + str("%02d" % date.today().day) + str(
  139. "%04d" % date.today().year) + r'\\' + r'Listing\\' + fileName + '.html'
  140. return fullPath
  141. # Creates the file name from passed URL
  142. def getNameFromURL(url):
  143. global counter
  144. name = ''.join(e for e in url if e.isalnum())
  145. if (name == ''):
  146. name = str(counter)
  147. counter = counter + 1
  148. return name
  149. def getInterestedLinks():
  150. links = []
  151. # Hacking
  152. links.append('http://dwforumuugiyderhybcpfxmlmoawgq6z3w6hk45nrnem3p7kwszhybad.onion/forums/hacking-forum.33/')
  153. # # Beginner Carding and Fraud
  154. links.append('http://dwforumuugiyderhybcpfxmlmoawgq6z3w6hk45nrnem3p7kwszhybad.onion/forums/remote-administration.34/')
  155. # # Cracking Tools
  156. links.append('http://dwforumuugiyderhybcpfxmlmoawgq6z3w6hk45nrnem3p7kwszhybad.onion/forums/cracking-tools.35/')
  157. # # Cracking Tutorials and Other Methods - error here about file not exisitng
  158. # links.append('http://dwforumuugiyderhybcpfxmlmoawgq6z3w6hk45nrnem3p7kwszhybad.onion/forums/cracking-tutorials-other-methods.36/')
  159. # # Combolists and Configs
  160. links.append('http://dwforumuugiyderhybcpfxmlmoawgq6z3w6hk45nrnem3p7kwszhybad.onion/forums/combolists-and-configs.58/')
  161. # # Paid Software and Antivirus
  162. links.append('http://dwforumuugiyderhybcpfxmlmoawgq6z3w6hk45nrnem3p7kwszhybad.onion/forums/paid-softwares-and-antivirus.59/')
  163. return links
  164. def crawlForum(driver):
  165. print("Crawling the DWForums forum")
  166. linksToCrawl = getInterestedLinks()
  167. visited = set(linksToCrawl)
  168. initialTime = time.time()
  169. i = 0
  170. count = 0
  171. while i < len(linksToCrawl):
  172. link = linksToCrawl[i]
  173. print('Crawling :', link)
  174. try:
  175. try:
  176. driver.get(link)
  177. except:
  178. driver.refresh()
  179. html = driver.page_source
  180. savePage(html, link)
  181. has_next_page = True
  182. while has_next_page:
  183. list = topicPages(html)
  184. for item in list:
  185. itemURL = urlparse.urljoin(baseURL, str(item))
  186. try:
  187. driver.get(itemURL)
  188. except:
  189. driver.refresh()
  190. savePage(driver.page_source, item)
  191. driver.back()
  192. # comment out
  193. break
  194. # comment out
  195. if count == 1:
  196. count = 0
  197. break
  198. try:
  199. temp = driver.find_element_by_link_text("Next")
  200. link = temp.get_attribute('href')
  201. if link == "":
  202. raise NoSuchElementException
  203. try:
  204. driver.get(link)
  205. except:
  206. driver.refresh()
  207. html = driver.page_source
  208. savePage(html, link)
  209. count += 1
  210. except NoSuchElementException:
  211. has_next_page = False
  212. except Exception as e:
  213. print(link, e.message)
  214. i += 1
  215. # finalTime = time.time()
  216. # print finalTime - initialTime
  217. input("Crawling DWForums forum done sucessfully. Press ENTER to continue\n")
  218. # Returns 'True' if the link is Topic link
  219. def isDescriptionLink(url):
  220. if '/threads/' in url:
  221. return True
  222. return False
  223. # Returns True if the link is a listingPage link
  224. def isListingLink(url):
  225. if '/forums/' in url:
  226. return True
  227. return False
  228. # calling the parser to define the links
  229. def topicPages(html):
  230. soup = BeautifulSoup(html, "html.parser")
  231. #print(soup.find('div', id="container").find('div', id="content").find('table', {"class": "tborder clear"}).find('tbody').find('tr',{"class": "inline_row"}).find('strong').text)
  232. return dwForums_links_parser(soup)
  233. def crawler():
  234. startCrawling()
  235. # print("Crawling and Parsing BestCardingWorld .... DONE!")