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.

331 lines
11 KiB

  1. __author__ = 'DarkWeb'
  2. '''
  3. Cardingleaks Forum Crawler (Selenium)
  4. FIXED
  5. '''
  6. from selenium import webdriver
  7. from selenium.common.exceptions import NoSuchElementException
  8. from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
  9. from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
  10. from selenium.webdriver.firefox.service import Service
  11. from selenium.webdriver.common.by import By
  12. from selenium.webdriver.support import expected_conditions as EC
  13. from selenium.webdriver.support.ui import WebDriverWait
  14. from PIL import Image
  15. import urllib.parse as urlparse
  16. import os, re, time
  17. import subprocess
  18. from bs4 import BeautifulSoup
  19. from Forums.Initialization.prepare_parser import new_parse
  20. from Forums.Cardingleaks.parser import cardingleaks_links_parser
  21. from Forums.Utilities.utilities import cleanHTML
  22. counter = 1
  23. baseURL = 'https://cardingleaks.ws/'
  24. # Opens Tor Browser, crawls the website
  25. def startCrawling():
  26. opentor()
  27. forumName = getForumName()
  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. closetor(driver)
  36. new_parse(forumName, baseURL, False)
  37. # Opens Tor Browser
  38. def opentor():
  39. from Forums.Initialization.forums_mining import config
  40. global pid
  41. print("Connecting Tor...")
  42. pro = subprocess.Popen(config.get('TOR', 'firefox_binary_path'))
  43. pid = pro.pid
  44. time.sleep(7.5)
  45. input('Tor Connected. Press ENTER to continue\n')
  46. return
  47. # Login using premade account credentials and do login captcha manually
  48. def login(driver):
  49. #click login button
  50. login_link = driver.find_element(
  51. by=By.XPATH, value='/html/body/div[2]/div[1]/nav/div/div[3]/div[1]/a[1]').\
  52. get_attribute('href')
  53. driver.get(login_link)# open tab with url
  54. #entering username and password into input boxes
  55. usernameBox = driver.find_element(by=By.NAME, value='login')
  56. #Username here
  57. usernameBox.send_keys('somanyfrogs')#sends string to the username box
  58. passwordBox = driver.find_element(by=By.NAME, value='password')
  59. #Password here
  60. passwordBox.send_keys('therearewaytoomanyherehowwhy')# sends string to passwordBox
  61. login = driver.find_element(by=By.CLASS_NAME, value='block-container')
  62. login_link = login.find_element(by=By.TAG_NAME, value='button')
  63. login_link.click()
  64. # input('input')
  65. # wait for listing page show up (This Xpath may need to change based on different seed url)
  66. # wait for 50 sec until id = tab_content is found, then cont
  67. WebDriverWait(driver, 50).until(EC.visibility_of_element_located(
  68. (By.CLASS_NAME, 'p-body-pageContent')))
  69. # Returns the name of the website
  70. def getForumName() -> str:
  71. name = 'Cardingleaks'
  72. return name
  73. # Return the link of the website
  74. def getFixedURL():
  75. url = 'https://cardingleaks.ws/'
  76. return url
  77. # Closes Tor Browser
  78. def closetor(driver):
  79. # global pid
  80. # os.system("taskkill /pid " + str(pro.pid))
  81. # os.system("taskkill /t /f /im tor.exe")
  82. print('Closing Tor...')
  83. driver.close() #close tab
  84. time.sleep(3)
  85. return
  86. # Creates FireFox 'driver' and configure its 'Profile'
  87. # to use Tor proxy and socket
  88. def createFFDriver():
  89. from Forums.Initialization.forums_mining import config
  90. ff_binary = FirefoxBinary(config.get('TOR', 'firefox_binary_path'))
  91. ff_prof = FirefoxProfile(config.get('TOR', 'firefox_profile_path'))
  92. ff_prof.set_preference("places.history.enabled", False)
  93. ff_prof.set_preference("privacy.clearOnShutdown.offlineApps", True)
  94. ff_prof.set_preference("privacy.clearOnShutdown.passwords", True)
  95. ff_prof.set_preference("privacy.clearOnShutdown.siteSettings", True)
  96. ff_prof.set_preference("privacy.sanitize.sanitizeOnShutdown", True)
  97. ff_prof.set_preference("signon.rememberSignons", False)
  98. ff_prof.set_preference("network.cookie.lifetimePolicy", 2)
  99. ff_prof.set_preference("network.dns.disablePrefetch", True)
  100. ff_prof.set_preference("network.http.sendRefererHeader", 0)
  101. ff_prof.set_preference("permissions.default.image", 3)
  102. ff_prof.set_preference("browser.download.folderList", 2)
  103. ff_prof.set_preference("browser.download.manager.showWhenStarting", False)
  104. ff_prof.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain")
  105. ff_prof.set_preference('network.proxy.type', 1)
  106. ff_prof.set_preference("network.proxy.socks_version", 5)
  107. ff_prof.set_preference('network.proxy.socks', '127.0.0.1')
  108. ff_prof.set_preference('network.proxy.socks_port', 9150)
  109. ff_prof.set_preference('network.proxy.socks_remote_dns', True)
  110. ff_prof.set_preference("javascript.enabled", True)
  111. ff_prof.update_preferences()
  112. service = Service(config.get('TOR', 'geckodriver_path'))
  113. driver = webdriver.Firefox(firefox_binary=ff_binary, firefox_profile=ff_prof, service=service)
  114. return driver
  115. def getAccess():
  116. url = getFixedURL()
  117. driver = createFFDriver()
  118. try:
  119. driver.get(url)
  120. return driver
  121. except:
  122. driver.close()
  123. return 'down'
  124. # Saves the crawled html page
  125. def savePage(page, url):
  126. cleanPage = cleanHTML(page)
  127. filePath = getFullPathName(url)
  128. os.makedirs(os.path.dirname(filePath), exist_ok=True)
  129. open(filePath, 'wb').write(cleanPage.encode('utf-8'))
  130. return
  131. # Gets the full path of the page to be saved along with its appropriate file name
  132. def getFullPathName(url):
  133. from Forums.Initialization.forums_mining import config, CURRENT_DATE
  134. mainDir = os.path.join(config.get('Project', 'shared_folder'), "Forums/" + getForumName() + "/HTML_Pages")
  135. fileName = getNameFromURL(url)
  136. if isDescriptionLink(url):
  137. fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Description\\' + fileName + '.html')
  138. else:
  139. fullPath = os.path.join(mainDir, CURRENT_DATE + 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. # # carding methods
  152. links.append('https://cardingleaks.ws/forums/carding-methods.82/')
  153. # # carding schools
  154. # links.append('https://cardingleaks.ws/forums/help-desk-carding-school.35/')
  155. # # carding discussion
  156. # links.append('https://cardingleaks.ws/forums/carding-discussion-desk.58/')
  157. # # carding tutorials
  158. # links.append('https://cardingleaks.ws/forums/carding-tutorials.13/')
  159. # # carding tools and software
  160. # links.append('https://cardingleaks.ws/forums/carding-tools-softwares.10/')
  161. # # exploits and cracking tools
  162. # links.append('https://cardingleaks.ws/forums/exploits-cracking-tools.22/')
  163. return links
  164. def crawlForum(driver):
  165. print("Crawling the Cardingleaks 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. #variable to check if there is a next page for the topic
  193. has_next_topic_page = True
  194. counter = 1
  195. # check if there is a next page for the topics
  196. while has_next_topic_page:
  197. # try to access next page of th topic
  198. itemURL = urlparse.urljoin(baseURL, str(item))
  199. try:
  200. driver.get(itemURL)
  201. except:
  202. driver.refresh()
  203. savePage(driver.page_source, item)
  204. # if there is a next page then go and save....
  205. # Spec
  206. try:
  207. # temp = driver.find_element(By.XPATH, '/html/body/div[2]/div[4]/div/div[5]/div[2]/div/div[1]/div[1]/div/nav/div[1]') # /html/body/div/div[2]/div/div[2]/div/
  208. item = driver.find_element(by=By.LINK_TEXT, value='Next').get_attribute('href') #/html/body/div/div[2]/div/div[2]/div
  209. if item == "":
  210. raise NoSuchElementException
  211. else:
  212. counter += 1
  213. except NoSuchElementException:
  214. has_next_topic_page = False
  215. # end of loop
  216. for i in range(counter):
  217. driver.back()
  218. # comment out
  219. break
  220. # comment out
  221. if count == 1:
  222. count = 0
  223. break
  224. try:
  225. # temp = driver.find_element(by=By.XPATH, value = '/html/body/div[2]/div[4]/div/div[5]/div[2]/div/div/div[1]/div/nav/div[1]')
  226. link = driver.find_element(by=By.LINK_TEXT, value='Next').get_attribute('href')
  227. if link == "":
  228. raise NoSuchElementException
  229. try:
  230. driver.get(link)
  231. except:
  232. driver.refresh()
  233. html = driver.page_source
  234. savePage(html, link)
  235. count += 1
  236. except NoSuchElementException:
  237. has_next_page = False
  238. except Exception as e:
  239. print(link, e)
  240. i += 1
  241. # finalTime = time.time()
  242. # print finalTime - initialTime
  243. input("Crawling Cardingleaks forum done successfully. Press ENTER to continue\n")
  244. # Returns 'True' if the link is Topic link, may need to change for every website
  245. def isDescriptionLink(url):
  246. if 'threads' in url:
  247. return True
  248. return False
  249. # Returns True if the link is a listingPage link, may need to change for every website
  250. def isListingLink(url):
  251. if 'forums' in url:
  252. return True
  253. return False
  254. # calling the parser to define the links
  255. def topicPages(html):
  256. soup = BeautifulSoup(html, "html.parser")
  257. return cardingleaks_links_parser(soup)
  258. def crawler():
  259. startCrawling()
  260. # print("Crawling and Parsing BestCardingWorld .... DONE!")