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.

308 lines
9.8 KiB

  1. __author__ = 'DarkWeb'
  2. '''
  3. Cardingleaks Forum Crawler (Selenium)
  4. Crawler updated and fixed
  5. The site has this thing sometime whereyou'll have to look at a new post everyday. makes sure
  6. you login first before crawling.
  7. '''
  8. from selenium import webdriver
  9. from selenium.common.exceptions import NoSuchElementException
  10. from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
  11. from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
  12. from selenium.webdriver.firefox.service import Service
  13. from selenium.webdriver.common.by import By
  14. from selenium.webdriver.support import expected_conditions as EC
  15. from selenium.webdriver.support.ui import WebDriverWait
  16. from PIL import Image
  17. import urllib.parse as urlparse
  18. import os, re, time
  19. import subprocess
  20. from bs4 import BeautifulSoup
  21. from Forums.Initialization.prepare_parser import new_parse
  22. from Forums.Cardingleaks.parser import cardingleaks_links_parser
  23. from Forums.Utilities.utilities import cleanHTML
  24. counter = 1
  25. baseURL = 'https://cardingleaks.ws/'
  26. # Opens Tor Browser, crawls the website
  27. def startCrawling():
  28. # opentor()
  29. forumName = getForumName()
  30. # driver = getAccess()
  31. # if driver != 'down':
  32. # try:
  33. # login(driver)
  34. # crawlForum(driver)
  35. # except Exception as e:
  36. # print(driver.current_url, e)
  37. # closetor(driver)
  38. new_parse(forumName, baseURL, False)
  39. # Opens Tor Browser
  40. def opentor():
  41. from Forums.Initialization.forums_mining import config
  42. global pid
  43. print("Connecting Tor...")
  44. pro = subprocess.Popen(config.get('TOR', 'firefox_binary_path'))
  45. pid = pro.pid
  46. time.sleep(7.5)
  47. input('Tor Connected. Press ENTER to continue\n')
  48. return
  49. # Login using premade account credentials and do login captcha manually
  50. def login(driver):
  51. #click login button
  52. login_link = driver.find_element(
  53. by=By.XPATH, value='/html/body/div[2]/div[1]/nav/div/div[3]/div[1]/a[1]').\
  54. get_attribute('href')
  55. driver.get(login_link)# open tab with url
  56. #entering username and password into input boxes
  57. usernameBox = driver.find_element(by=By.NAME, value='login')
  58. #Username here
  59. usernameBox.send_keys('somanyfrogs')#sends string to the username box
  60. passwordBox = driver.find_element(by=By.NAME, value='password')
  61. #Password here
  62. passwordBox.send_keys('therearewaytoomanyherehowwhy')# sends string to passwordBox
  63. login = driver.find_element(by=By.CLASS_NAME, value='block-container')
  64. login_link = login.find_element(by=By.TAG_NAME, value='button')
  65. login_link.click()
  66. # input('input')
  67. # wait for listing page show up (This Xpath may need to change based on different seed url)
  68. # wait for 50 sec until id = tab_content is found, then cont
  69. WebDriverWait(driver, 50).until(EC.visibility_of_element_located(
  70. (By.CLASS_NAME, 'p-body-pageContent')))
  71. # Returns the name of the website
  72. def getForumName() -> str:
  73. name = 'Cardingleaks'
  74. return name
  75. # Return the link of the website
  76. def getFixedURL():
  77. url = 'https://cardingleaks.ws/'
  78. return url
  79. # Closes Tor Browser
  80. def closetor(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.close() #close tab
  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 Forums.Initialization.forums_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", True)
  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. return driver
  117. def getAccess():
  118. url = getFixedURL()
  119. driver = createFFDriver()
  120. try:
  121. driver.get(url)
  122. return driver
  123. except:
  124. driver.close()
  125. return 'down'
  126. # Saves the crawled html page
  127. def savePage(page, url):
  128. cleanPage = cleanHTML(page)
  129. filePath = getFullPathName(url)
  130. os.makedirs(os.path.dirname(filePath), exist_ok=True)
  131. open(filePath, 'wb').write(cleanPage.encode('utf-8'))
  132. return
  133. # Gets the full path of the page to be saved along with its appropriate file name
  134. def getFullPathName(url):
  135. from Forums.Initialization.forums_mining import config, CURRENT_DATE
  136. mainDir = os.path.join(config.get('Project', 'shared_folder'), "Forums/" + getForumName() + "/HTML_Pages")
  137. fileName = getNameFromURL(url)
  138. if isDescriptionLink(url):
  139. fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Description\\' + fileName + '.html')
  140. else:
  141. fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Listing\\' + fileName + '.html')
  142. return fullPath
  143. # Creates the file name from passed URL
  144. def getNameFromURL(url):
  145. global counter
  146. name = ''.join(e for e in url if e.isalnum())
  147. if name == '':
  148. name = str(counter)
  149. counter = counter + 1
  150. return name
  151. def getInterestedLinks():
  152. links = []
  153. # # carding methods
  154. links.append('https://cardingleaks.ws/forums/carding-methods.82/')
  155. # # carding schools
  156. # links.append('https://cardingleaks.ws/forums/help-desk-carding-school.35/')
  157. # # carding discussion
  158. # links.append('https://cardingleaks.ws/forums/carding-discussion-desk.58/')
  159. # # carding tutorials
  160. # links.append('https://cardingleaks.ws/forums/carding-tutorials.13/')
  161. # # carding tools and software
  162. # links.append('https://cardingleaks.ws/forums/carding-tools-softwares.10/')
  163. # # exploits and cracking tools
  164. # links.append('https://cardingleaks.ws/forums/exploits-cracking-tools.22/')
  165. return links
  166. def crawlForum(driver):
  167. print("Crawling the Cardinglinks forum")
  168. linksToCrawl = getInterestedLinks()
  169. i = 0
  170. while i < len(linksToCrawl):
  171. link = linksToCrawl[i]
  172. print('Crawling :', link)
  173. try:
  174. has_next_page = True
  175. count = 0
  176. while has_next_page:
  177. try:
  178. driver.get(link)
  179. except:
  180. driver.refresh()
  181. html = driver.page_source
  182. savePage(html, link)
  183. topics = topicPages(html)
  184. for topic in topics:
  185. has_next_topic_page = True
  186. counter = 1
  187. page = topic
  188. while has_next_topic_page:
  189. itemURL = urlparse.urljoin(baseURL, str(page))
  190. try:
  191. driver.get(itemURL)
  192. except:
  193. driver.refresh()
  194. savePage(driver.page_source, topic + f"page{counter}") # very important
  195. # comment out
  196. if counter == 5:
  197. break
  198. try:
  199. page = driver.find_element(by=By.LINK_TEXT, value='Next').get_attribute('href')
  200. if page == "":
  201. raise NoSuchElementException
  202. counter += 1
  203. except NoSuchElementException:
  204. has_next_topic_page = False
  205. for i in range(counter):
  206. driver.back()
  207. # comment out
  208. break
  209. # comment out
  210. if count == 10:
  211. break
  212. try:
  213. link = driver.find_element(by=By.LINK_TEXT, value='Next').get_attribute('href')
  214. if link == "":
  215. raise NoSuchElementException
  216. count += 1
  217. except NoSuchElementException:
  218. has_next_page = False
  219. except Exception as e:
  220. print(link, e)
  221. i += 1
  222. input("Crawling Cardingleaksforum done successfully. Press ENTER to continue\n")
  223. # Returns 'True' if the link is Topic link, may need to change for every website
  224. def isDescriptionLink(url):
  225. if 'threads' in url:
  226. return True
  227. return False
  228. # Returns True if the link is a listingPage link, may need to change for every website
  229. def isListingLink(url):
  230. if 'forums' in url:
  231. return True
  232. return False
  233. # calling the parser to define the links
  234. def topicPages(html):
  235. soup = BeautifulSoup(html, "html.parser")
  236. return cardingleaks_links_parser(soup)
  237. def crawler():
  238. startCrawling()
  239. # print("Crawling and Parsing BestCardingWorld .... DONE!")