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.

305 lines
9.6 KiB

  1. __author__ = 'DarkWeb'
  2. '''
  3. Cardingleaks Forum Crawler (Selenium)
  4. Crawler updated and 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 Cardinglinks forum")
  166. linksToCrawl = getInterestedLinks()
  167. i = 0
  168. while i < len(linksToCrawl):
  169. link = linksToCrawl[i]
  170. print('Crawling :', link)
  171. try:
  172. has_next_page = True
  173. count = 0
  174. while has_next_page:
  175. try:
  176. driver.get(link)
  177. except:
  178. driver.refresh()
  179. html = driver.page_source
  180. savePage(html, link)
  181. topics = topicPages(html)
  182. for topic in topics:
  183. has_next_topic_page = True
  184. counter = 1
  185. page = topic
  186. while has_next_topic_page:
  187. itemURL = urlparse.urljoin(baseURL, str(page))
  188. try:
  189. driver.get(itemURL)
  190. except:
  191. driver.refresh()
  192. savePage(driver.page_source, topic + f"page{counter}") # very important
  193. # comment out
  194. if counter == 2:
  195. break
  196. try:
  197. page = driver.find_element(by=By.LINK_TEXT, value='Next').get_attribute('href')
  198. if page == "":
  199. raise NoSuchElementException
  200. counter += 1
  201. except NoSuchElementException:
  202. has_next_topic_page = False
  203. for i in range(counter):
  204. driver.back()
  205. # comment out
  206. break
  207. # comment out
  208. if count == 1:
  209. break
  210. try:
  211. link = driver.find_element(by=By.LINK_TEXT, value='Next').get_attribute('href')
  212. if link == "":
  213. raise NoSuchElementException
  214. count += 1
  215. except NoSuchElementException:
  216. has_next_page = False
  217. except Exception as e:
  218. print(link, e)
  219. i += 1
  220. input("Crawling Cardingleaksforum done successfully. Press ENTER to continue\n")
  221. # Returns 'True' if the link is Topic link, may need to change for every website
  222. def isDescriptionLink(url):
  223. if 'threads' in url:
  224. return True
  225. return False
  226. # Returns True if the link is a listingPage link, may need to change for every website
  227. def isListingLink(url):
  228. if 'forums' in url:
  229. return True
  230. return False
  231. # calling the parser to define the links
  232. def topicPages(html):
  233. soup = BeautifulSoup(html, "html.parser")
  234. return cardingleaks_links_parser(soup)
  235. def crawler():
  236. startCrawling()
  237. # print("Crawling and Parsing BestCardingWorld .... DONE!")