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.

304 lines
10 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. __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.OnniForums.parser import onniForums_links_parser
  21. from Forums.Utilities.utilities import cleanHTML
  22. counter = 1
  23. baseURL = 'http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/'
  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. #click login button
  50. login_link = driver.find_element(
  51. by=By.XPATH, value='/html/body/div/div[2]/div/table/tbody/tr[2]/td/center/pre/strong/a').\
  52. get_attribute('href')
  53. driver.get(login_link)
  54. #entering username and password into input boxes
  55. usernameBox = driver.find_element(by=By.XPATH, value='/html/body/div/div[2]/div/form/table/tbody/tr[2]/td[2]/input')
  56. #Username here
  57. usernameBox.send_keys('purely_cabbage')
  58. passwordBox = driver.find_element(by=By.XPATH, value='/html/body/div/div[2]/div/form/table/tbody/tr[3]/td[2]/input')
  59. #Password here
  60. passwordBox.send_keys('$ourP@tchK1ds')
  61. input("Press ENTER when log in is completed\n")
  62. # wait for listing page show up (This Xpath may need to change based on different seed url)
  63. WebDriverWait(driver, 50).until(EC.visibility_of_element_located(
  64. (By.XPATH, '//*[@id="content"]')))
  65. # Returns the name of the website
  66. def getForumName():
  67. name = 'OnniForums'
  68. return name
  69. # Return the link of the website
  70. def getFixedURL():
  71. url = 'http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/'
  72. return url
  73. # Closes Tor Browser
  74. def closetor(driver):
  75. # global pid
  76. # os.system("taskkill /pid " + str(pro.pid))
  77. # os.system("taskkill /t /f /im tor.exe")
  78. print('Closing Tor...')
  79. driver.close()
  80. time.sleep(3)
  81. return
  82. # Creates FireFox 'driver' and configure its 'Profile'
  83. # to use Tor proxy and socket
  84. def createFFDriver():
  85. file = open('../../path.txt', 'r')
  86. lines = file.readlines()
  87. ff_binary = FirefoxBinary(lines[0].strip())
  88. ff_prof = FirefoxProfile(lines[1].strip())
  89. ff_prof.set_preference("places.history.enabled", False)
  90. ff_prof.set_preference("privacy.clearOnShutdown.offlineApps", True)
  91. ff_prof.set_preference("privacy.clearOnShutdown.passwords", True)
  92. ff_prof.set_preference("privacy.clearOnShutdown.siteSettings", True)
  93. ff_prof.set_preference("privacy.sanitize.sanitizeOnShutdown", True)
  94. ff_prof.set_preference("signon.rememberSignons", False)
  95. ff_prof.set_preference("network.cookie.lifetimePolicy", 2)
  96. ff_prof.set_preference("network.dns.disablePrefetch", True)#
  97. ff_prof.set_preference("network.http.sendRefererHeader", 0)
  98. ff_prof.set_preference("permissions.default.image", 3)
  99. ff_prof.set_preference("browser.download.folderList", 2)
  100. ff_prof.set_preference("browser.download.manager.showWhenStarting", False)
  101. ff_prof.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain")
  102. ff_prof.set_preference('network.proxy.type', 1)
  103. ff_prof.set_preference("network.proxy.socks_version", 5)
  104. ff_prof.set_preference('network.proxy.socks', '127.0.0.1')
  105. ff_prof.set_preference('network.proxy.socks_port', 9150)
  106. ff_prof.set_preference('network.proxy.socks_remote_dns', True)
  107. ff_prof.set_preference("javascript.enabled", True)
  108. ff_prof.update_preferences()
  109. service = Service(lines[2].strip())
  110. driver = webdriver.Firefox(firefox_binary=ff_binary, firefox_profile=ff_prof, service=service)
  111. return driver
  112. def getAccess():
  113. url = getFixedURL()
  114. driver = createFFDriver()
  115. try:
  116. driver.get(url)
  117. return driver
  118. except:
  119. driver.close()
  120. return 'down'
  121. # Saves the crawled html page
  122. def savePage(page, url):
  123. cleanPage = cleanHTML(page)
  124. filePath = getFullPathName(url)
  125. os.makedirs(os.path.dirname(filePath), exist_ok=True)
  126. open(filePath, 'wb').write(cleanPage.encode('utf-8'))
  127. return
  128. # Gets the full path of the page to be saved along with its appropriate file name
  129. def getFullPathName(url):
  130. fileName = getNameFromURL(url)
  131. if isDescriptionLink(url):
  132. #..\CryptBB\HTML_Pages\\
  133. fullPath = r'..\OnniForums\HTML_Pages\\' + str(
  134. "%02d" % date.today().month) + str("%02d" % date.today().day) + str(
  135. "%04d" % date.today().year) + r'\\' + r'Description\\' + fileName + '.html'
  136. else:
  137. fullPath = r'..\OnniForums\HTML_Pages\\' + str(
  138. "%02d" % date.today().month) + str("%02d" % date.today().day) + str(
  139. "%04d" % date.today().year) + r'\\' + 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. # Hacking & Cracking tutorials
  152. links.append('http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/Forum-Hacking-Cracking-tutorials')
  153. # Hacking & Cracking questions
  154. links.append('http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/Forum-Hacking-Cracking-questions')
  155. # Exploit PoCs
  156. links.append('http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/Forum-Exploit-PoCs')
  157. # Cracked software
  158. links.append('http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/Forum-Cracked-software')
  159. # Malware-development
  160. links.append('http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/Forum-Malware-development')
  161. # Carding & Fraud
  162. links.append('http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/Forum-Carding-Fraud')
  163. # Darknet Discussions
  164. links.append('http://cryptbbtg65gibadeeo2awe3j7s6evg7eklserehqr4w4e2bis5tebid.onion/forumdisplay.php?fid=88')
  165. # OPSEC
  166. links.append('http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/Forum-OPSEC')
  167. # Databases
  168. links.append('http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/Forum-Databases')
  169. # Proxies
  170. links.append('http://onnii6niq53gv3rvjpi7z5axkasurk2x5w5lwliep4qyeb2azagxn4qd.onion/Forum-Proxies')
  171. return links
  172. def crawlForum(driver):
  173. print("Crawling the OnniForums forum")
  174. linksToCrawl = getInterestedLinks()
  175. visited = set(linksToCrawl)
  176. initialTime = time.time()
  177. i = 0
  178. count = 0
  179. while i < len(linksToCrawl):
  180. link = linksToCrawl[i]
  181. print('Crawling :', link)
  182. try:
  183. try:
  184. driver.get(link)
  185. except:
  186. driver.refresh()
  187. html = driver.page_source
  188. savePage(html, link)
  189. has_next_page = True
  190. while has_next_page:
  191. list = topicPages(html)
  192. for item in list:
  193. itemURL = urlparse.urljoin(baseURL, str(item))
  194. try:
  195. driver.get(itemURL)
  196. except:
  197. driver.refresh()
  198. savePage(driver.page_source, item)
  199. driver.back()
  200. # comment out, one topic per page
  201. # break
  202. # comment out, go through all pages
  203. #if count == 1:
  204. # count = 0
  205. # break
  206. try:
  207. temp = driver.find_element(by=By.XPATH, value=
  208. '/html/body/div/div[2]/div/div[3]/div') # /html/body/div/div[2]/div/div[3]/div
  209. link = temp.find_element(by=By.CLASS_NAME, value='pagination_next').get_attribute('href')
  210. if link == "":
  211. raise NoSuchElementException
  212. try:
  213. driver.get(link)
  214. except:
  215. driver.refresh()
  216. html = driver.page_source
  217. savePage(html, link)
  218. count += 1
  219. except NoSuchElementException:
  220. has_next_page = False
  221. except Exception as e:
  222. print(link, e)
  223. i += 1
  224. # finalTime = time.time()
  225. # print finalTime - initialTime
  226. input("Crawling OnniForums forum done sucessfully. Press ENTER to continue\n")
  227. # Returns 'True' if the link is Topic link
  228. def isDescriptionLink(url):
  229. if 'Thread' in url:
  230. return True
  231. return False
  232. # Returns True if the link is a listingPage link
  233. def isListingLink(url):
  234. if 'Forum' in url:
  235. return True
  236. return False
  237. # calling the parser to define the links
  238. def topicPages(html):
  239. soup = BeautifulSoup(html, "html.parser")
  240. #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)
  241. return onniForums_links_parser(soup)
  242. def crawler():
  243. startCrawling()
  244. # print("Crawling and Parsing BestCardingWorld .... DONE!")