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.7 KiB

  1. __author__ = 'DarkWeb'
  2. '''
  3. Cardingleaks Forum Crawler (Selenium)
  4. Crawler updated and fixed
  5. The site has this thing sometime where you'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://leaks.ws/'
  26. # Opens Tor Browser, crawls the website
  27. def startCrawling():
  28. # opentor()
  29. forumName = getForumName()
  30. # driver = getAccess()
  31. #
  32. # if driver != 'down':
  33. # try:
  34. # login(driver)
  35. # crawlForum(driver)
  36. # except Exception as e:
  37. # print(driver.current_url, e)
  38. # closetor(driver)
  39. new_parse(forumName, baseURL, True)
  40. # Opens Tor Browser
  41. def opentor():
  42. from Forums.Initialization.forums_mining import config
  43. global pid
  44. print("Connecting Tor...")
  45. pro = subprocess.Popen(config.get('TOR', 'firefox_binary_path'))
  46. pid = pro.pid
  47. time.sleep(7.5)
  48. input('Tor Connected. Press ENTER to continue\n')
  49. return
  50. # Login using premade account credentials and do login captcha manually
  51. def login(driver):
  52. #click login button
  53. login_link = driver.find_element(
  54. by=By.XPATH, value='/html/body/div[2]/div[1]/nav/div/div[3]/div[1]/a[1]').\
  55. get_attribute('href')
  56. driver.get(login_link)# open tab with url
  57. #entering username and password into input boxes
  58. usernameBox = driver.find_element(by=By.NAME, value='login')
  59. #Username here
  60. usernameBox.send_keys('somanyfrogs')#sends string to the username box
  61. passwordBox = driver.find_element(by=By.NAME, value='password')
  62. #Password here
  63. passwordBox.send_keys('therearewaytoomanyherehowwhy')# sends string to passwordBox
  64. login = driver.find_element(by=By.CLASS_NAME, value='block-container')
  65. login_link = login.find_element(by=By.TAG_NAME, value='button')
  66. login_link.click()
  67. # input('input')
  68. # wait for listing page show up (This Xpath may need to change based on different seed url)
  69. # wait for 50 sec until id = tab_content is found, then cont
  70. WebDriverWait(driver, 50).until(EC.visibility_of_element_located(
  71. (By.CLASS_NAME, 'p-body-pageContent')))
  72. # Returns the name of the website
  73. def getForumName() -> str:
  74. name = 'Cardingleaks'
  75. return name
  76. # Return the link of the website
  77. def getFixedURL():
  78. url = 'https://leaks.ws/'
  79. return url
  80. # Closes Tor Browser
  81. def closetor(driver):
  82. # global pid
  83. # os.system("taskkill /pid " + str(pro.pid))
  84. # os.system("taskkill /t /f /im tor.exe")
  85. print('Closing Tor...')
  86. driver.close() #close tab
  87. time.sleep(3)
  88. return
  89. # Creates FireFox 'driver' and configure its 'Profile'
  90. # to use Tor proxy and socket
  91. def createFFDriver():
  92. from Forums.Initialization.forums_mining import config
  93. ff_binary = FirefoxBinary(config.get('TOR', 'firefox_binary_path'))
  94. ff_prof = FirefoxProfile(config.get('TOR', 'firefox_profile_path'))
  95. ff_prof.set_preference("places.history.enabled", False)
  96. ff_prof.set_preference("privacy.clearOnShutdown.offlineApps", True)
  97. ff_prof.set_preference("privacy.clearOnShutdown.passwords", True)
  98. ff_prof.set_preference("privacy.clearOnShutdown.siteSettings", True)
  99. ff_prof.set_preference("privacy.sanitize.sanitizeOnShutdown", True)
  100. ff_prof.set_preference("signon.rememberSignons", False)
  101. ff_prof.set_preference("network.cookie.lifetimePolicy", 2)
  102. ff_prof.set_preference("network.dns.disablePrefetch", True)
  103. ff_prof.set_preference("network.http.sendRefererHeader", 0)
  104. ff_prof.set_preference("permissions.default.image", 3)
  105. ff_prof.set_preference("browser.download.folderList", 2)
  106. ff_prof.set_preference("browser.download.manager.showWhenStarting", False)
  107. ff_prof.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain")
  108. ff_prof.set_preference('network.proxy.type', 1)
  109. ff_prof.set_preference("network.proxy.socks_version", 5)
  110. ff_prof.set_preference('network.proxy.socks', '127.0.0.1')
  111. ff_prof.set_preference('network.proxy.socks_port', 9150)
  112. ff_prof.set_preference('network.proxy.socks_remote_dns', True)
  113. ff_prof.set_preference("javascript.enabled", True)
  114. ff_prof.update_preferences()
  115. service = Service(config.get('TOR', 'geckodriver_path'))
  116. driver = webdriver.Firefox(firefox_binary=ff_binary, firefox_profile=ff_prof, service=service)
  117. return driver
  118. def getAccess():
  119. url = getFixedURL()
  120. driver = createFFDriver()
  121. try:
  122. driver.get(url)
  123. return driver
  124. except:
  125. driver.close()
  126. return 'down'
  127. # Saves the crawled html page
  128. def savePage(page, url):
  129. cleanPage = cleanHTML(driver, page)
  130. filePath = getFullPathName(url)
  131. os.makedirs(os.path.dirname(filePath), exist_ok=True)
  132. open(filePath, 'wb').write(cleanPage.encode('utf-8'))
  133. return
  134. # Gets the full path of the page to be saved along with its appropriate file name
  135. def getFullPathName(url):
  136. from Forums.Initialization.forums_mining import config, CURRENT_DATE
  137. mainDir = os.path.join(config.get('Project', 'shared_folder'), "Forums/" + getForumName() + "/HTML_Pages")
  138. fileName = getNameFromURL(url)
  139. if isDescriptionLink(url):
  140. fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Description\\' + fileName + '.html')
  141. else:
  142. fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Listing\\' + fileName + '.html')
  143. return fullPath
  144. # Creates the file name from passed URL
  145. def getNameFromURL(url):
  146. global counter
  147. name = ''.join(e for e in url if e.isalnum())
  148. if name == '':
  149. name = str(counter)
  150. counter = counter + 1
  151. return name
  152. def getInterestedLinks():
  153. links = []
  154. # # carding methods
  155. links.append('https://leaks.ws/forums/carding-methods.82/')
  156. # # carding schools
  157. # links.append('https://leaks.ws/forums/help-desk-carding-school.35/')
  158. # # carding discussion
  159. # links.append('https://leaks.ws/forums/carding-discussion-desk.58/')
  160. # # carding tutorials
  161. # links.append('https://leaks.ws/forums/carding-tutorials.13/')
  162. # # carding tools and software
  163. # links.append('https://leaks.ws/forums/carding-tools-softwares.10/')
  164. # # exploits and cracking tools
  165. # links.append('https://leaks.ws/forums/exploits-cracking-tools.22/')
  166. return links
  167. def crawlForum(driver):
  168. print("Crawling the Cardingleaks forum")
  169. linksToCrawl = getInterestedLinks()
  170. i = 0
  171. while i < len(linksToCrawl):
  172. link = linksToCrawl[i]
  173. print('Crawling :', link)
  174. try:
  175. has_next_page = True
  176. count = 0
  177. while has_next_page:
  178. try:
  179. driver.get(link)
  180. except:
  181. driver.refresh()
  182. html = driver.page_source
  183. savePage(driver, html, link)
  184. topics = topicPages(html)
  185. for topic in topics:
  186. has_next_topic_page = True
  187. counter = 1
  188. page = topic
  189. while has_next_topic_page:
  190. itemURL = urlparse.urljoin(baseURL, str(page))
  191. try:
  192. driver.get(itemURL)
  193. except:
  194. driver.refresh()
  195. savePage(driver.page_source, topic + f"page{counter}") # very important
  196. # comment out
  197. if counter == 2:
  198. break
  199. try:
  200. page = driver.find_element(by=By.LINK_TEXT, value='Next').get_attribute('href')
  201. if page == "":
  202. raise NoSuchElementException
  203. counter += 1
  204. except NoSuchElementException:
  205. has_next_topic_page = False
  206. for i in range(counter):
  207. driver.back()
  208. # comment out
  209. break
  210. # comment out
  211. if count == 1:
  212. break
  213. try:
  214. link = driver.find_element(by=By.LINK_TEXT, value='Next').get_attribute('href')
  215. if link == "":
  216. raise NoSuchElementException
  217. count += 1
  218. except NoSuchElementException:
  219. has_next_page = False
  220. except Exception as e:
  221. print(link, e)
  222. i += 1
  223. print("Crawling the Cardingleaks forum done.")
  224. # Returns 'True' if the link is Topic link, may need to change for every website
  225. def isDescriptionLink(url):
  226. if 'threads' in url:
  227. return True
  228. return False
  229. # Returns True if the link is a listingPage link, may need to change for every website
  230. def isListingLink(url):
  231. if 'forums' in url:
  232. return True
  233. return False
  234. # calling the parser to define the links
  235. def topicPages(html):
  236. soup = BeautifulSoup(html, "html.parser")
  237. return cardingleaks_links_parser(soup)
  238. def crawler():
  239. startCrawling()
  240. # print("Crawling and Parsing BestCardingWorld .... DONE!")