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.

334 lines
12 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. __author__ = 'DarkWeb'
  2. '''
  3. OnniForums 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. from PIL import Image
  14. import urllib.parse as urlparse
  15. import os, re, time
  16. from datetime import date
  17. import subprocess
  18. from bs4 import BeautifulSoup
  19. from Forums.Initialization.prepare_parser import new_parse
  20. from Forums.CrackingPro.parser import crackingPro_links_parser
  21. from Forums.Utilities.utilities import cleanHTML
  22. counter = 1
  23. baseURL = 'https://www.crackingpro.com/'
  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, False)
  37. # Opens Tor Browser
  38. def opentor():
  39. global pid
  40. print("Connecting Tor...")
  41. path = open('../../path.txt').readline().strip()
  42. pro = subprocess.Popen(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. '''
  50. #click login button
  51. login_link = driver.find_element(
  52. by=By.ID, value='elUserSignIn').\
  53. get_attribute('href')
  54. driver.get(login_link)
  55. #entering username and password into input boxes
  56. usernameBox = driver.find_element(by=By.ID, value='auth')
  57. #Username here
  58. usernameBox.send_keys('cheese_pizza_man')
  59. passwordBox = driver.find_element(by=By.ID, value='password')
  60. #Password here
  61. passwordBox.send_keys('Gr33nSp@m&3ggs')
  62. '''
  63. input("Press ENTER when log in is completed\n")
  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.XPATH, '/html/body/main/div/div/div[1]/section/ol/li[8]')))
  67. # Returns the name of the website
  68. def getForumName():
  69. name = 'CrackingPro'
  70. return name
  71. # Return the link of the website
  72. def getFixedURL():
  73. url = 'https://www.crackingpro.com/'
  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()# close the current tab
  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)# open given url
  119. return driver
  120. except:
  121. driver.close()#close the current tab
  122. return 'down'
  123. # Saves the crawled html page
  124. def savePage(page, url):
  125. cleanPage = cleanHTML(page)
  126. filePath = getFullPathName(url)
  127. os.makedirs(os.path.dirname(filePath), exist_ok=True)
  128. open(filePath, 'wb').write(cleanPage.encode('utf-8'))
  129. return
  130. # Gets the full path of the page to be saved along with its appropriate file name
  131. def getFullPathName(url):
  132. fileName = getNameFromURL(url)
  133. if isDescriptionLink(url):
  134. #..\CryptBB\HTML_Pages\\
  135. fullPath = r'..\CrackingPro\HTML_Pages\\' + str(
  136. "%02d" % date.today().month) + str("%02d" % date.today().day) + str(
  137. "%04d" % date.today().year) + r'\\' + r'Description\\' + fileName + '.html'
  138. else:
  139. fullPath = r'..\CrackingPro\HTML_Pages\\' + str(
  140. "%02d" % date.today().month) + str("%02d" % date.today().day) + str(
  141. "%04d" % date.today().year) + r'\\' + 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. # exploiting tutorials
  154. links.append('https://www.crackingpro.com/forum/38-exploiting-tutorials/')
  155. # Hacking & Cracking questions
  156. # links.append('http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/Forum-Hacking-Cracking-questions')
  157. # Exploit PoCs
  158. # links.append('http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/Forum-Exploit-PoCs')
  159. # Cracked software
  160. # links.append('http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/Forum-Cracked-software')
  161. # Malware-development
  162. # links.append('http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/Forum-Malware-development')
  163. # Carding & Fraud
  164. # links.append('http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/Forum-Carding-Fraud')
  165. # Darknet Discussions
  166. # links.append('http://cryptbbtg65gibadeeo2awe3j7s6evg7eklserehqr4w4e2bis5tebid.onion/forumdisplay.php?fid=88')
  167. # OPSEC
  168. # links.append('http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/Forum-OPSEC')
  169. # Databases
  170. # links.append('http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/Forum-Databases')
  171. # Proxies
  172. # links.append('http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/Forum-Proxies')
  173. return links
  174. def crawlForum(driver):
  175. print("Crawling the CrackingPro forum")
  176. linksToCrawl = getInterestedLinks()
  177. visited = set(linksToCrawl)
  178. initialTime = time.time()
  179. i = 0
  180. count = 0
  181. while i < len(linksToCrawl):
  182. link = linksToCrawl[i]
  183. print('Crawling :', link)
  184. try:
  185. try:
  186. driver.get(link)
  187. except:
  188. driver.refresh()
  189. html = driver.page_source
  190. savePage(html, link)
  191. has_next_page = True
  192. while has_next_page:
  193. list = topicPages(html) # for multiple pages
  194. for item in list:
  195. # variable to check if there is a next page for the topic
  196. has_next_topic_page = True
  197. back_counter = 1
  198. # check if there is a next page for the topics
  199. while has_next_topic_page:
  200. # try to access next page of th topic
  201. itemURL = urlparse.urljoin(baseURL, str(item))
  202. try:
  203. driver.get(itemURL)
  204. except:
  205. driver.refresh()
  206. savePage(driver.page_source, item)
  207. # if there is a next page then go and save....
  208. # next page in the topic?
  209. try:
  210. temp = driver.find_element(by=By.ID, value='comments') #
  211. temp2 = temp.find_elements(by=By.XPATH, value='/html/body/main/div/div/div/div[4]/div[1]')
  212. temp3 = temp2.find_elements(by=By.CLASS_NAME, value='ipsPagination')#/html/body/main/div/div/div/div[4]/div[1]
  213. item = temp3.find_element(by=By.CLASS_NAME, value='ipsPagination_next').get_attribute('href') # /html/body/div/div[2]/div/div[2]/div
  214. if item == "":
  215. raise NoSuchElementException
  216. has_next_topic_page = False
  217. else:
  218. back_counter += 1
  219. except NoSuchElementException:
  220. has_next_topic_page = False
  221. # end of loop
  222. for i in range(back_counter):
  223. driver.back()
  224. # comment out
  225. break
  226. # comment out
  227. # if count == 1:
  228. # count = 0
  229. # break
  230. try: # change depending on web page, #next page
  231. temp = driver.find_element(by=By.XPATH, value='/html/body/main/div/div/div/div[4]/div/div[1]/div')#/html/body/main/div/div/div/div[4]/div/div[1]/div
  232. temp2 = temp.find_element(by=By.CLASS_NAME, value='ipsPagination')
  233. link = temp2.find_element(by=By.CLASS_NAME, value='ipsPagination_next').get_attribute('href')
  234. if link == "":
  235. raise NoSuchElementException
  236. try:
  237. driver.get(link)
  238. except:
  239. driver.refresh()
  240. html = driver.page_source
  241. savePage(html, link)
  242. count += 1
  243. except NoSuchElementException:
  244. has_next_page = False
  245. except Exception as e:
  246. print(link, e)
  247. i += 1
  248. # finalTime = time.time()
  249. # print finalTime - initialTime
  250. input("Crawling CrackingPro forum done sucessfully. Press ENTER to continue\n")
  251. # Returns 'True' if the link is Topic link
  252. def isDescriptionLink(url):
  253. if 'topic' in url:
  254. return True
  255. return False
  256. # Returns True if the link is a listingPage link
  257. def isListingLink(url):
  258. if 'forum' in url:
  259. return True
  260. return False
  261. # calling the parser to define the links
  262. def topicPages(html):
  263. soup = BeautifulSoup(html, "html.parser")
  264. #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)
  265. return crackingPro_links_parser(soup)
  266. def crawler():
  267. startCrawling()
  268. # print("Crawling and Parsing BestCardingWorld .... DONE!")