main.py 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-"
  3. """
  4. [pArAnoIA_Browser] by /psy (03c8.net)/ - 2019
  5. You should have received a copy of the GNU General Public License along
  6. with pArAnoIA; if not, write to the Free Software Foundation, Inc., 51
  7. Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  8. """
  9. import os, sys, gi, re, random, socket, requests, time, pygeoip, urlparse, urllib2
  10. from uuid import getnode
  11. gi.require_version('Gtk', '3.0')
  12. gi.require_version('WebKit', '3.0')
  13. from gi.repository import Gtk, WebKit
  14. from gi.repository import Gdk
  15. Gdk.threads_init()
  16. class Browser(object):
  17. def __init__(self):
  18. self.check_ip_service1 = 'https://ip.42.pl/ra' # set external check ip service-backup 1 [OK! 23/06/2019]
  19. self.home_website = "https://check.torproject.org" # Home website
  20. self.https_strict = "ON" # HTTPS(strict)
  21. self.navigation_mode = "EXPLORER" # Navigation mode
  22. self.logs_mode = "OFF" # logging mode
  23. self.tor_mode = "OFF" # TOR mode
  24. self.dns_prefetching = "ON" # DNS Prefetching
  25. self.javascript = "ON" # Javascript(flag) = No-Javascript [*]
  26. self.java = "ON" # Java*
  27. self.flash = "ON" # Flash*
  28. self.webaudio = "ON" # WebAudio*
  29. self.webgl = "ON" # WebGL/WebVideo*
  30. self.xss = "ON" # XSS audit
  31. self.cache = "ON" # Cache*
  32. self.styles = "ON" # Styles/Fonts*
  33. self.logs = [] # logged urls
  34. self.logo = "core/images/paranoia.jpeg" # set source path for logo img
  35. self.agents_file = "core/user-agents.txt" # set source path to retrieve user-agents
  36. self.geodb = "core/geo/GeoLiteCity.dat" # set source for geoip-DB
  37. self.agents = [] # generating available user-agents
  38. f = open(self.agents_file)
  39. agents = f.readlines()
  40. f.close()
  41. for agent in agents:
  42. self.agents.append(agent)
  43. self.builder = Gtk.Builder()
  44. self.builder.add_from_file("core/browser.glade")
  45. self.builder.connect_signals(self)
  46. self.toolbar1 = self.builder.get_object("toolbar1")
  47. self.back = self.builder.get_object("back")
  48. self.forward = self.builder.get_object("forward")
  49. self.refresh = self.builder.get_object("refresh")
  50. self.stop = self.builder.get_object("stop")
  51. self.url = self.builder.get_object("url")
  52. self.spinner = self.builder.get_object("spinner")
  53. self.progressbar = self. builder.get_object("progressbar")
  54. self.scrolledwindow = self.builder.get_object("scrolledwindow")
  55. self.scrolledwindowinspector = self.builder.get_object("scrolledwindowinspector")
  56. self.scrolledwindowlogs = self.builder.get_object("scrolledwindowlogs")
  57. self.navigation_mode_img = self.builder.get_object("navigation_mode_img")
  58. self.navigation_mode_button = self.builder.get_object("navigation_mode_button")
  59. self.source_code_img = self.builder.get_object("source_code_img")
  60. self.source_code_button = self.builder.get_object("source_code_button")
  61. self.logs_img = self.builder.get_object("logs_img")
  62. self.logs_button = self.builder.get_object("logs_button")
  63. self.logs_view_buffer = self.builder.get_object("logs_view_buffer")
  64. self.top_panel = self.builder.get_object("top_panel")
  65. self.top_domain = self.builder.get_object("top_domain")
  66. self.hide_top_panel_img = self.builder.get_object("hide_top_panel_img")
  67. self.hide_top_panel_button = self.builder.get_object("hide_top_panel_button")
  68. self.toolbar = self.builder.get_object("toolbar")
  69. self.fullscreen_img = self.builder.get_object("fullscreen_img")
  70. self.fullscreen_button = self.builder.get_object("fullscreen_button")
  71. self.max_screen_img = self.builder.get_object("max_screen_img")
  72. self.max_screen_button = self.builder.get_object("max_screen_button")
  73. self.source_code_view_buffer = self.builder.get_object("source_code_view_buffer")
  74. self.source_code_text_view = self.builder.get_object("source_code_text_view")
  75. self.main_view_box_top = self.builder.get_object("main_view_box_top")
  76. self.main_view_box_foot = self.builder.get_object("main_view_box_foot")
  77. self.main_view_box_left = self.builder.get_object("main_view_box_left")
  78. self.https_mode_img = self.builder.get_object("https_mode_img")
  79. self.https_mode_button = self.builder.get_object("https_mode_button")
  80. self.tor_mode_img = self.builder.get_object("tor_mode_img")
  81. self.dns_img = self.builder.get_object("dns_img")
  82. self.dns_button = self.builder.get_object("dns_button")
  83. self.javascript_img = self.builder.get_object("javascript_img")
  84. self.javascript_button = self.builder.get_object("javascript_button")
  85. self.java_img = self.builder.get_object("java_img")
  86. self.java_button = self.builder.get_object("java_button")
  87. self.webaudio_img = self.builder.get_object("webaudio_img")
  88. self.webaudio_button = self.builder.get_object("webaudio_button")
  89. self.webgl_img = self.builder.get_object("webgl_img")
  90. self.webgl_button = self.builder.get_object("webgl_button")
  91. self.xss_img = self.builder.get_object("xss_img")
  92. self.xss_button = self.builder.get_object("xss_button")
  93. self.cache_img = self.builder.get_object("cache_img")
  94. self.cache_button = self.builder.get_object("cache_button")
  95. self.styles_img = self.builder.get_object("styles_img")
  96. self.styles_button = self.builder.get_object("styles_button")
  97. self.mac = self.builder.get_object("mac")
  98. self.ip_internal = self.builder.get_object("ip_internal")
  99. self.ip_external = self.builder.get_object("ip_external")
  100. self.ip_location = self.builder.get_object("ip_location")
  101. self.domain_name = self.builder.get_object("domain_name")
  102. self.domain_location = self.builder.get_object("domain_location")
  103. self.domain_lat = self.builder.get_object("domain_lat")
  104. self.domain_long = self.builder.get_object("domain_long")
  105. self.domain_code = self.builder.get_object("domain_code")
  106. self.useragent = self.builder.get_object("useragent")
  107. self.referer = self.builder.get_object("referer")
  108. self.windowsize = self.builder.get_object("windowsize")
  109. self.window = self.builder.get_object("window1")
  110. self.window.connect('destroy', lambda w: Gtk.main_quit())
  111. self.window.show_all()
  112. self.webview = WebKit.WebView()
  113. self.set_useragent()
  114. self.set_referer()
  115. self.set_navigation_settings()
  116. self.set_browser_settings()
  117. self.scrolledwindow.add(self.webview)
  118. self.webview.connect('title-changed', self.change_title)
  119. self.webview.connect('load-committed', self.change_url)
  120. self.webview.connect('load-committed', self.spinner_on)
  121. self.webview.connect('load_finished',self.spinner_off)
  122. self.webview.show() # start the whole show! ;-)
  123. self.get_mac() # get/set our MAC
  124. self.get_ip_internal() # get/set our IP(internal)
  125. self.get_ip_external() # get/set our IP(external)
  126. self.get_windowsize() # get/set our Window(size)
  127. self.main_view_box_top.show() # Websites (main view)
  128. self.main_view_box_foot.hide() # Shell
  129. self.main_view_box_left.hide() # Logs
  130. self.check_requests_tor() # at init and via urllib2
  131. def run(self, opts=None):
  132. Gtk.main()
  133. def set_navigation_settings(self):
  134. settings = WebKit.WebSettings()
  135. settings.set_property('user-agent', self.useragent.get_text()) # set User-agent
  136. self.webview.set_settings(settings)
  137. self.refresh_website()
  138. def set_browser_settings(self):
  139. settings = WebKit.WebSettings()
  140. settings.set_property('enable-frame-flattening', 'False')
  141. settings.set_property('enable-fullscreen', 'False')
  142. settings.set_property('enable-html5-database', 'False')
  143. settings.set_property('enable-html5-local-storage', 'False')
  144. settings.set_property('enable-hyperlink-auditing', 'False')
  145. settings.set_property('media-playback-allows-inline', 'False')
  146. settings.set_property('media-playback-requires-user-gesture', 'False')
  147. settings.set_property('auto-load-images', 'False')
  148. settings.set_property('enable-caret-browsing', 'False')
  149. settings.set_property('enable-site-specific-quirks', 'False')
  150. settings.set_property('enable-smooth-scrolling', 'False')
  151. settings.set_property('print-backgrounds', 'False')
  152. settings.set_property('enable-dns-prefetching', 'True')
  153. settings.set_property('enable-scripts', 'False') # javascript
  154. settings.set_property('javascript-can-access-clipboard', 'False')
  155. settings.set_property('javascript-can-open-windows-automatically', 'False')
  156. settings.set_property("enable-java-applet", 'False')
  157. settings.set_property('enable-offline-web-application-cache', 'False')
  158. settings.set_property('enable-page-cache', 'False')
  159. settings.set_property('enable-private-browsing', 'True')
  160. settings.set_property('enable-webaudio', 'False')
  161. settings.set_property('enable-webgl', 'False')
  162. settings.set_property('enable-xss-auditor', 'True')
  163. settings.set_property('enable-page-cache', 'False')
  164. settings.set_property('enable-offline-web-application-cache', 'False')
  165. settings.set_property("enable-file-access-from-file-uris", "False") # hack.it! >;-)
  166. #settings.set_property('allow-modal-dialogs', 'False')
  167. #settings.set_property('enable-write-console-messages-to-stdout', 'False')
  168. #settings.set_property('draw-compositing-indicators', 'False')
  169. #settings.set_property('enable-accelerated-2d-canvas', 'False')
  170. #settings.set_property('enable-resizable-text-areas', 'False')
  171. #settings.set_property('enable-tabs-to-links', 'False')
  172. #settings.set_property('load-icons-ignoring-image-load-setting', 'False')
  173. self.webview.set_settings(settings)
  174. self.ipData = pygeoip.GeoIP(self.geodb) # load geodb
  175. def on_url_backspace(self, widget):
  176. url = widget.get_text()
  177. self.url.set_text("") # remove text from url-bar when focus-in-event
  178. def on_url_activate(self, widget):
  179. url = widget.get_text()
  180. url = self.check_url_spelling(url) # check for 'hints' when spelling at url bar
  181. self.url.set_text(url) # set url to bar
  182. self.set_domain_name(url) # set url to domain_name
  183. self.set_useragent() # set user-agent
  184. self.set_navigation_settings() # set navigation settings
  185. self.webview.open(url) # visit website
  186. self.check_geoip_visited_website(url) # set geoip (visited link)
  187. if self.home_website in url: # Home website
  188. self.on_visit_home_website()
  189. if self.logs_mode == "ON": # when logging mode in ON
  190. self.main_view_box_left.show() # be sure that logs view is also ON
  191. if url not in self.logs:
  192. self.logs.append(url) # add to logs list
  193. self.refresh_log() # refresh logs
  194. self.get_mac() # get/set our MAC
  195. self.get_ip_internal() # get/set our IP(internal)
  196. self.get_ip_external() # get/set our IP(external)
  197. self.set_useragent() # we want to change our HTTP User-Agent used to visit a site, on each request... and randomnly!
  198. self.get_windowsize() # get/set our window size
  199. html = self.get_html(url) # get source code from visited website
  200. def set_domain_name(self, url):
  201. domain_url = '.'.join(urlparse.urlparse(url).netloc.split('.')[-2:])
  202. self.domain_name.set_text("["+domain_url+"]")
  203. def check_url_spelling(self, url): # [rev: 26/06/2019]
  204. if self.home_website in url: # Home website
  205. url = self.home_website
  206. elif "!0" in url: # !0 = 03c8.net(author) / just link!
  207. url = 'https://03c8.net' # ;-)
  208. elif "!deep" in url: # !deep = Torch(content) / just link!
  209. url = 'http://xmh57jrzrnw6insl.onion/'
  210. elif "!start" in url: # !start = StartPage(tems)
  211. url = str(url.split(' ',1)[1])
  212. url = 'https://www.startpage.com/do/search?limit=10&lang=english&format=html&query=' + url
  213. elif "!s" in url: # !s = DuckDuckGo(terms)
  214. if self.tor_mode == "OFF":
  215. url = str(url.split(' ',1)[1])
  216. url = "https://duckduckgo.com/?q=" + url
  217. else:
  218. url = "https://3g2upl4pq6kufc4m.onion/" # duckduckGO (via TOR)
  219. elif "!dict" in url: # !dict = Cambridge Dictionary(words)
  220. url = str(url.split(' ',1)[1])
  221. url = 'https://dictionary.cambridge.org/dictionary/english/' + url
  222. elif "!map" in url: # !map = OpenStreetMaps(locations)
  223. url = str(url.split(' ',1)[1])
  224. url = 'https://www.openstreetmap.org/search?query=' + url
  225. elif "!w" in url: # !w = Wikipedia(terms)
  226. url = str(url.split(' ',1)[1])
  227. url = 'https://en.wikipedia.org/wiki/' + url
  228. elif "!video" in url: # !video = PeerTube(videos)
  229. url = str(url.split(' ',1)[1])
  230. url = 'https://peertube.cpy.re/search?search=' + url
  231. elif "!image" in url: # !image = DevianARt(images)
  232. url = str(url.split(' ',1)[1])
  233. url = 'https://www.deviantart.com/search?q=' + url
  234. elif "!nasa" in url: # !nasa = NASA(images)
  235. url = str(url.split(' ',1)[1])
  236. url = 'https://images.nasa.gov/search-results?q=' + url
  237. elif "!porn" in url: # !porn = PornHub(adult content)
  238. url = str(url.split(' ',1)[1])
  239. url = 'https://www.pornhub.com/video/search?search=' + url
  240. else:
  241. if url.startswith('https://'):
  242. url = url
  243. else:
  244. if url.startswith('http://'):
  245. if self.https_strict is "ON":
  246. url = url.replace('http://', "")
  247. url = 'https://' + url
  248. self.url.set_icon_from_stock(0, "gtk-dialog-authentication")
  249. else:
  250. url = url
  251. self.url.set_icon_from_stock(0, "gtk-dialog-warning")
  252. else:
  253. if self.https_strict is "ON":
  254. url = 'https://' + url
  255. self.url.set_icon_from_stock(0, "gtk-dialog-authentication")
  256. else:
  257. url = self.home_website # when non-supported go to Home
  258. return url
  259. def on_hide_top_panel_button_clicked(self, widget):
  260. hide_top_panel_img = self.hide_top_panel_img.get_stock()
  261. if hide_top_panel_img.stock_id == "gtk-remove":
  262. self.hide_top_panel_img.set_from_stock("gtk-add", 4)
  263. self.top_panel.hide()
  264. self.top_domain.hide()
  265. else:
  266. self.hide_top_panel_img.set_from_stock("gtk-remove", 4)
  267. self.top_panel.show()
  268. self.top_domain.show()
  269. def on_fullscreen_button_clicked(self, widget):
  270. fullscreen_img = self.fullscreen_img.get_stock()
  271. if fullscreen_img.stock_id == "gtk-zoom-fit":
  272. self.fullscreen_img.set_from_stock("gtk-leave-fullscreen", 4)
  273. self.top_panel.hide()
  274. self.top_domain.hide()
  275. self.toolbar.hide()
  276. else:
  277. self.fullscreen_img.set_from_stock("gtk-zoom-fit", 4)
  278. self.top_panel.show()
  279. self.top_domain.show()
  280. self.toolbar.show()
  281. self.get_windowsize() # get/set our window size
  282. def on_max_screen_button_toggled(self, widget):
  283. max_screen_img = self.max_screen_img.get_stock()
  284. if max_screen_img.stock_id == "gtk-fullscreen":
  285. self.max_screen_img.set_from_stock("gtk-leave-fullscreen", 4)
  286. self.window.fullscreen()
  287. self.get_warning_fixed_window() # get warning when maximized(fixed) size for Window
  288. else:
  289. self.max_screen_img.set_from_stock("gtk-fullscreen", 4)
  290. self.window.unfullscreen()
  291. self.get_windowsize() # get/set our window size
  292. def get_warning_fixed_window(self):
  293. msg = ("\n\nWait... ;-)\n\npArAnoIA is trying to evade screen/monitor tracking techniques.\n\nFullscreen mode will disable related contrameasures...\n\nAre you sure about keeping a fixed size?")
  294. dlg_img = Gtk.Image()
  295. dlg_img.set_from_file(os.path.join(self.logo))
  296. dlg_img.show()
  297. dlg = Gtk.MessageDialog(message_format=msg, image=dlg_img, parent=self.window)
  298. dlg.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
  299. dlg.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK)
  300. dlg.set_default_response(Gtk.ResponseType.OK)
  301. dlg.set_title('Warning: Setting a fixed size for Window...')
  302. dlg.run()
  303. dlg.destroy()
  304. def get_html(self, website):
  305. self.webview.execute_script('oldtitle=document.title;document.title=document.documentElement.innerHTML;')
  306. html = self.webview.get_main_frame().get_title()
  307. self.webview.execute_script('document.title=oldtitle;')
  308. return html
  309. def get_mac(self):
  310. current_mac = self.mac.get_text() # we want to be sure about our MAC at init
  311. if current_mac == "255.255.255.255": # set by default at GUI level
  312. self.set_mac()
  313. def set_mac(self):
  314. mac = getnode() # to get physical address
  315. hex_mac = str(":".join(re.findall('..', '%012x' % mac)))
  316. self.mac.set_text(hex_mac)
  317. def get_ip_internal(self):
  318. current_ip_internal = self.ip_internal.get_text() # we want to be sure about our private IP (for internal LAN)
  319. if current_ip_internal == "127.0.0.1": # set by default at GUI level
  320. self.set_ip_internal()
  321. def set_ip_internal(self):
  322. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  323. try:
  324. s.connect(("1.1.1.1", 1)) # black magic! /23-06-2019/ [UFONet+LoVe] ;-)
  325. except:
  326. print "\n[Info] Network is unaccesible: Aborting!\n"
  327. sys.exit(2)
  328. private_ip = s.getsockname()[0]
  329. s.close()
  330. self.ip_internal.set_text(private_ip)
  331. def get_ip_external(self):
  332. current_ip_external = self.ip_external.get_text() # we want to be sure about our public IP (for the Internet)
  333. if current_ip_external == "127.0.0.1": # set by default at GUI level
  334. self.set_ip_external()
  335. def set_ip_external(self):
  336. try:
  337. public_ip = self.external_ip # method 1: extracted from Home website
  338. except:
  339. try:
  340. public_ip = requests.get(self.check_ip_service1).text # method 2: direct request to third-party services
  341. except:
  342. public_ip = "127.0.0.1"
  343. if public_ip is not "127.0.0.1": # check for geolocation
  344. self.check_geoip_ip_external(public_ip)
  345. self.ip_external.set_text(public_ip)
  346. def check_geoip_ip_external(self, ip):
  347. try:
  348. record = self.ipData.record_by_addr(ip)
  349. self.ip_location.set_text("["+str(record['country_name'])+"]")
  350. except:
  351. self.ip_location.set_text('[Unknown]')
  352. def check_geoip_visited_website(self, ip):
  353. domain_url = '.'.join(urlparse.urlparse(ip).netloc.split('.')[-2:])
  354. try:
  355. record = self.ipData.record_by_name(domain_url)
  356. self.domain_location.set_text("["+str(record['country_name'])+"]")
  357. self.domain_lat.set_text("(Lat: "+str(record['latitude'])+")")
  358. self.domain_long.set_text("(Long: "+str(record['longitude'])+")")
  359. self.domain_code.set_text("["+str(record['country_code'])+"]")
  360. except:
  361. self.domain_location.set_text('[Unknown]')
  362. self.domain_lat.set_text("(Lat: ?)")
  363. self.domain_long.set_text("(Long: ?)")
  364. self.domain_code.set_text("[?]")
  365. def set_useragent(self):
  366. user_agent = random.choice(self.agents).strip()
  367. self.useragent.set_text(user_agent)
  368. def get_windowsize(self):
  369. windowsize = self.window.get_size()
  370. w, h = windowsize
  371. windowsize = str(w)+"x"+str(h)
  372. self.windowsize.set_text(windowsize) # set to 1024x768 by default
  373. def on_refresh_clicked(self, widget):
  374. self.webview.reload()
  375. def on_back_clicked(self, widget):
  376. self.webview.go_back()
  377. def on_forward_clicked(self, widget):
  378. self.webview.go_forward()
  379. def on_stop_clicked(self, widget):
  380. self.webview.stop_loading()
  381. def change_title(self, widget, frame, title):
  382. self.window.set_title('/pArAnoIA Browser/ | ' + title)
  383. def change_url(self, widget, frame):
  384. uri = frame.get_uri()
  385. self.url.set_text(uri)
  386. self.back.set_sensitive(self.webview.can_go_back() )
  387. self.forward.set_sensitive(self.webview.can_go_forward() )
  388. def on_navigation_mode_button_toggled(self, widget):
  389. self.on_navigation_mode_img_button_press_event(self)
  390. def on_navigation_mode_img_button_press_event(self, widget):
  391. navigation_img = self.navigation_mode_img.get_stock()
  392. if navigation_img.stock_id == "gtk-orientation-landscape":
  393. self.navigation_mode_img.set_from_stock("gtk-find-and-replace", 4)
  394. self.navigation_mode = "INSPECTOR" # set navigation mode to: INSPECTOR
  395. self.start_inspector()
  396. else:
  397. self.navigation_mode_img.set_from_stock("gtk-orientation-landscape", 4)
  398. self.navigation_mode = "EXPLORER" # set navigation mode to: EXPLORER
  399. settings = WebKit.WebSettings()
  400. settings.set_property('enable-developer-extras', False)
  401. self.webview.set_settings(settings)
  402. self.main_view_box_foot.hide()
  403. self.set_referer() # set referer according to Navigation mode
  404. def start_inspector(self):
  405. view = self.webview
  406. self.webview = WebKit.WebView()
  407. settings = WebKit.WebSettings()
  408. settings.set_property('enable-developer-extras', True)
  409. view.set_settings(settings)
  410. self.inspector = view.get_inspector()
  411. self.inspector.connect("inspect-web-view", self.inspect)
  412. self.webview = WebKit.WebView()
  413. self.scrolledwindowinspector.add(self.webview)
  414. self.scrolledwindowinspector.show()
  415. self.source_code_text_view.hide()
  416. self.main_view_box_foot.show()
  417. def inspect(self, inspector, view):
  418. self.scrolledwindowinspector.show_all()
  419. self.webview.show()
  420. return self.webview
  421. def on_logs_button_toggled(self, widget):
  422. self.on_logs_img_button_press_event(self)
  423. def on_logs_img_button_press_event(self, widget):
  424. settings = WebKit.WebSettings()
  425. logs_img = self.logs_img.get_stock()
  426. if logs_img.stock_id == "gtk-no":
  427. self.logs_img.set_from_stock("gtk-yes", 4)
  428. self.logs_mode = "OFF" # set logging mode to: OFF
  429. settings.set_property('enable-private-browsing', 'True')
  430. self.main_view_box_left.hide()
  431. else:
  432. self.logs_img.set_from_stock("gtk-no", 4)
  433. self.logs_mode = "ON" # set logging mode to: ON
  434. settings.set_property('enable-private-browsing', 'False')
  435. self.main_view_box_left.show()
  436. self.webview.set_settings(settings)
  437. def refresh_log(self):
  438. self.logs_view_buffer.set_text("")
  439. for log in self.logs:
  440. iter = self.logs_view_buffer.get_end_iter()
  441. self.logs_view_buffer.insert(iter, log + "\n")
  442. def show_source_code(self, url):
  443. self.webviewsource = WebKit.WebView()
  444. self.webviewsource.open(url)
  445. def get_source(webobj, frame):
  446. source = self.webviewsource.get_main_frame().get_data_source().get_data()
  447. code_buffer = str(self.source_code_view_buffer.set_text(source.str))
  448. self.webviewsource.connect("load-finished", get_source)
  449. browser_settings = self.webviewsource.get_settings()
  450. browser_settings.set_property('enable-default-context-menu', True)
  451. browser_settings.set_property('enable-accelerated-compositing', True)
  452. browser_settings.set_property('enable-file-access-from-file-uris', True)
  453. self.webviewsource.set_settings(browser_settings)
  454. self.set_source_code_on_url_icon() # set source_code at url bar
  455. self.scrolledwindowinspector.hide()
  456. self.source_code_text_view.show()
  457. self.main_view_box_foot.show()
  458. def set_referer(self):
  459. referer = self.referer.get_text()
  460. if self.navigation_mode == "INSPECTOR":
  461. self.referer.set_text("127.0.0.1") # turn referer into INSPECTOR mode
  462. else:
  463. self.referer.set_text("-") # turn referer into EXPLORER mode
  464. def refresh_website(self):
  465. url = self.url.get_text()
  466. self.webview.open(url)
  467. def on_styles_button_toggled(self, widget):
  468. self.on_styles_button_press_event(self)
  469. def on_styles_button_press_event(self, widget):
  470. settings = WebKit.WebSettings()
  471. styles_img = self.styles_img.get_stock()
  472. if styles_img.stock_id == "gtk-yes":
  473. self.styles_img.set_from_stock("gtk-no", 4)
  474. self.styles = "OFF"
  475. settings.set_property('enable-frame-flattening', 'True')
  476. settings.set_property('enable-fullscreen', 'True')
  477. settings.set_property('enable-html5-database', 'True')
  478. settings.set_property('enable-html5-local-storage', 'True')
  479. settings.set_property('enable-hyperlink-auditing', 'True')
  480. settings.set_property('media-playback-allows-inline', 'True')
  481. settings.set_property('media-playback-requires-user-gesture', 'True')
  482. settings.set_property('auto-load-images', 'True')
  483. settings.set_property('enable-caret-browsing', 'True')
  484. settings.set_property('enable-site-specific-quirks', 'True')
  485. settings.set_property('enable-smooth-scrolling', 'True')
  486. else:
  487. self.styles_img.set_from_stock("gtk-yes", 4)
  488. self.styles = "ON"
  489. settings.set_property('enable-frame-flattening', 'False')
  490. settings.set_property('enable-fullscreen', 'False')
  491. settings.set_property('enable-html5-database', 'False')
  492. settings.set_property('enable-html5-local-storage', 'False')
  493. settings.set_property('enable-hyperlink-auditing', 'False')
  494. settings.set_property('media-playback-allows-inline', 'False')
  495. settings.set_property('media-playback-requires-user-gesture', 'False')
  496. settings.set_property('auto-load-images', 'False')
  497. settings.set_property('enable-caret-browsing', 'False')
  498. settings.set_property('enable-site-specific-quirks', 'False')
  499. settings.set_property('enable-smooth-scrolling', 'False')
  500. self.webview.set_settings(settings)
  501. self.refresh_website()
  502. def on_cache_button_toggled(self, widget):
  503. self.on_cache_button_press_event(self)
  504. def on_cache_button_press_event(self, widget):
  505. settings = WebKit.WebSettings()
  506. cache_img = self.cache_img.get_stock()
  507. if cache_img.stock_id == "gtk-yes":
  508. self.cache_img.set_from_stock("gtk-no", 4)
  509. self.cache = "OFF"
  510. settings.set_property('enable-page-cache', 'True')
  511. settings.set_property('enable-offline-web-application-cache', 'True')
  512. else:
  513. self.cache_img.set_from_stock("gtk-yes", 4)
  514. self.cache = "ON"
  515. settings.set_property('enable-page-cache', 'False')
  516. settings.set_property('enable-offline-web-application-cache', 'False')
  517. self.webview.set_settings(settings)
  518. self.refresh_website()
  519. def on_xss_button_toggled(self, widget):
  520. self.on_xss_button_press_event(self)
  521. def on_xss_button_press_event(self, widget):
  522. settings = WebKit.WebSettings()
  523. xss_img = self.xss_img.get_stock()
  524. if xss_img.stock_id == "gtk-yes":
  525. self.xss_img.set_from_stock("gtk-no", 4)
  526. self.xss = "OFF"
  527. settings.set_property('enable-xss-auditor', 'False')
  528. else:
  529. self.xss_img.set_from_stock("gtk-yes", 4)
  530. self.xss = "ON"
  531. settings.set_property('enable-xss-auditor', 'True')
  532. self.webview.set_settings(settings)
  533. self.refresh_website()
  534. def on_webgl_button_toggled(self, widget):
  535. self.on_webgl_button_press_event(self)
  536. def on_webgl_button_press_event(self, widget):
  537. settings = WebKit.WebSettings()
  538. webgl_img = self.webgl_img.get_stock()
  539. if webgl_img.stock_id == "gtk-yes":
  540. self.webgl_img.set_from_stock("gtk-no", 4)
  541. self.webgl = "OFF"
  542. settings.set_property("enable-webgl", 'False')
  543. else:
  544. self.webgl_img.set_from_stock("gtk-yes", 4)
  545. self.webgl = "ON"
  546. settings.set_property("enable-webgl", 'True')
  547. self.webview.set_settings(settings)
  548. self.refresh_website()
  549. def on_webaudio_button_toggled(self, widget):
  550. self.on_webaudio_button_press_event(self)
  551. def on_webaudio_button_press_event(self, widget):
  552. settings = WebKit.WebSettings()
  553. webaudio_img = self.webaudio_img.get_stock()
  554. if webaudio_img.stock_id == "gtk-yes":
  555. self.webaudio_img.set_from_stock("gtk-no", 4)
  556. self.webaudio = "OFF"
  557. settings.set_property("enable-webaudio", 'False')
  558. else:
  559. self.webaudio_img.set_from_stock("gtk-yes", 4)
  560. self.webaudio = "ON"
  561. settings.set_property("enable-webaudio", 'True')
  562. self.webview.set_settings(settings)
  563. self.refresh_website()
  564. def on_java_button_toggled(self, widget):
  565. self.on_java_button_press_event(self)
  566. def on_java_button_press_event(self, widget):
  567. settings = WebKit.WebSettings()
  568. java_img = self.java_img.get_stock()
  569. if java_img.stock_id == "gtk-yes":
  570. self.java_img.set_from_stock("gtk-no", 4)
  571. self.java = "OFF"
  572. self.flash = "OFF"
  573. settings.set_property("enable-java-applet", 'False')
  574. else:
  575. self.java_img.set_from_stock("gtk-yes", 4)
  576. self.java = "ON"
  577. self.flash = "ON"
  578. settings.set_property("enable-java-applet", 'True')
  579. self.webview.set_settings(settings)
  580. self.refresh_website()
  581. def on_javascript_button_toggled(self, widget):
  582. self.on_javascript_button_press_event(self)
  583. def on_javascript_button_press_event(self, widget):
  584. settings = WebKit.WebSettings()
  585. javascript_img = self.javascript_img.get_stock()
  586. if javascript_img.stock_id == "gtk-yes":
  587. self.javascript_img.set_from_stock("gtk-no", 4)
  588. self.javascript = "OFF"
  589. settings.set_property('enable-scripts', 'False')
  590. settings.set_property('javascript-can-access-clipboard', 'False')
  591. settings.set_property('javascript-can-open-windows-automatically', 'False')
  592. else:
  593. self.javascript_img.set_from_stock("gtk-yes", 4)
  594. self.javascript = "ON"
  595. settings.set_property('enable-scripts', 'True')
  596. settings.set_property('javascript-can-access-clipboard', 'False')
  597. settings.set_property('javascript-can-open-windows-automatically', 'True')
  598. self.webview.set_settings(settings)
  599. self.refresh_website()
  600. def on_dns_button_toggled(self, widget):
  601. self.on_dns_button_press_event(self)
  602. def on_dns_button_press_event(self, widget):
  603. settings = WebKit.WebSettings()
  604. dns_img = self.dns_img.get_stock()
  605. if dns_img.stock_id == "gtk-yes":
  606. self.dns_img.set_from_stock("gtk-no", 4)
  607. self.dns_prefetching = "OFF"
  608. settings.set_property('enable-dns-prefetching', 'False')
  609. else:
  610. self.dns_img.set_from_stock("gtk-yes", 4)
  611. self.dns_prefetching = "ON"
  612. settings.set_property('enable-dns-prefetching', 'True')
  613. self.webview.set_settings(settings)
  614. def on_https_mode_button_toggled(self, widget):
  615. self.on_https_mode_img_button_press_event(self)
  616. def on_https_mode_img_button_press_event(self, widget):
  617. https_img = self.https_mode_img.get_stock()
  618. if https_img.stock_id == "gtk-yes":
  619. self.https_mode_img.set_from_stock("gtk-no", 4)
  620. self.https_strict = "OFF"
  621. else:
  622. self.https_mode_img.set_from_stock("gtk-yes", 4)
  623. self.https_strict = "ON"
  624. self.set_warning_on_url_icon() # set warning at url bar
  625. self.refresh_website()
  626. def on_source_code_button_toggled(self, widget):
  627. self.on_source_code_img_button_press_event(self)
  628. def on_source_code_img_button_press_event(self, widget):
  629. url = self.url.get_text()
  630. if url.startswith("http") or url.startswith("source-code"):
  631. self.show_source_code(url)
  632. def set_source_code_on_url_icon(self):
  633. uri = self.url.get_text()
  634. url_primary_icon_name = self.url.get_icon_stock(0)
  635. if url_primary_icon_name == "gtk-dialog-authentication" or url_primary_icon_name == "gtk-home" or url_primary_icon_name == "gtk-warning":
  636. self.url.set_icon_from_stock(0, "gtk-properties")
  637. if uri.startswith("http://"):
  638. uri = uri.replace("http://", "")
  639. elif uri.startswith("https://"):
  640. uri = uri.replace("https://", "")
  641. url = "source-code: " + uri
  642. if "/" in url:
  643. url = url.replace("/", "")
  644. self.url.set_text(url)
  645. self.main_view_box_top.hide()
  646. self.main_view_box_foot.show()
  647. else:
  648. if "source-code" in uri:
  649. uri = uri.replace("source-code: ", "")
  650. check_default = "https://" + uri
  651. if check_default == self.home_website: # Home site detected! ;-)
  652. self.url.set_icon_from_stock(0, "gtk-home")
  653. uri = 'https://' + uri
  654. else:
  655. if self.https_strict is "ON":
  656. self.url.set_icon_from_stock(0, "gtk-dialog-authentication")
  657. uri = 'https://' + uri
  658. else:
  659. self.url.set_icon_from_stock(0, "gtk-dialog-warning")
  660. uri = 'http://' + uri
  661. self.url.set_text(uri)
  662. self.main_view_box_top.show()
  663. self.main_view_box_foot.hide()
  664. self.set_useragent()
  665. self.set_navigation_settings()
  666. self.webview.open(uri) # re-visit website after review source code
  667. def set_warning_on_url_icon(self):
  668. url_primary_icon_name = self.url.get_icon_stock(0)
  669. if url_primary_icon_name == "gtk-dialog-authentication" or url_primary_icon_name == "gtk-home" or url_primary_icon_name == "gtk-properties":
  670. self.url.set_icon_from_stock(0, "gtk-dialog-warning")
  671. else:
  672. self.url.set_icon_from_stock(0, "gtk-dialog-authentication")
  673. def on_visit_home_website(self):
  674. url_primary_icon_name = self.url.get_icon_stock(0)
  675. self.url.set_icon_from_stock(0, "gtk-home") # sweet home-lab ;-)
  676. html = self.get_html(self.home_website)
  677. self.check_html_tor(html) # check TOR via html
  678. self.extract_ip_external_from_home_website(html) # extract public IP from Home website
  679. self.check_geoip_visited_website(self.home_website) # set geoip (Home)
  680. def check_requests_tor(self): # check for TOR via direct request
  681. tor_reply = urllib2.urlopen(self.home_website).read() # check if TOR is enabled
  682. if not tor_reply or 'Congratulations' not in tor_reply:
  683. self.tor_mode = "OFF"
  684. self.tor_mode_img.set_from_stock("gtk-no", 4)
  685. else:
  686. self.tor_mode = "ON"
  687. self.tor_mode_img.set_from_stock("gtk-yes", 4)
  688. self.set_useragent()
  689. self.set_navigation_settings()
  690. self.set_domain_name(self.home_website) # set url to domain_name
  691. self.webview.open(self.home_website) # open Home website by default
  692. self.check_geoip_visited_website(self.home_website) # set geoip (Home)
  693. url_primary_icon_name = self.url.get_icon_stock(0)
  694. self.url.set_icon_from_stock(0, "gtk-home") # sweet home-lab ;-)
  695. def check_html_tor(self, html):
  696. tor_mode_img = self.tor_mode_img.get_stock() # check for TOR 'network circuit'
  697. if 'Congratulations' not in html:
  698. self.tor_mode = "OFF"
  699. self.tor_mode_img.set_from_stock("gtk-no", 4)
  700. else:
  701. self.tor_mode = "ON"
  702. self.tor_mode_img.set_from_stock("gtk-yes", 4)
  703. def extract_ip_external_from_home_website(self, html):
  704. try:
  705. self.external_ip = html.split('<strong>')[1].split('</strong>')[0].strip()
  706. except:
  707. pass # other methods supported... ;-)
  708. def spinner_on(self,widget,frame):
  709. self.spinner.start()
  710. def spinner_off(self, widget,frame):
  711. self.spinner.stop()
  712. if __name__ == "__main__":
  713. app = Browser()
  714. app.run()