Browse Source

advancing flow tasks + more fancy output results

pull/3/head
psy 11 years ago
parent
commit
7a3ac0a823
  1. 83
      main.py
  2. 7
      webserver.py

83
main.py

@ -67,6 +67,13 @@ class bc(object):
traceback.print_exc() traceback.print_exc()
sys.exit(2) sys.exit(2)
def check_root(self):
"""
Check root permissions
"""
if not os.geteuid()==0:
sys.exit("\nOnly root can run this script...\n")
def check_browser(self): def check_browser(self):
""" """
Check browsers used by system Check browsers used by system
@ -125,22 +132,21 @@ class bc(object):
elif os.path.exists(chromium_lin): elif os.path.exists(chromium_lin):
self.browser = "CHROMIUM" self.browser = "CHROMIUM"
self.browser_path = chromium_lin self.browser_path = chromium_lin
print "Browser Options:\n" + '='*45 + "\n"
print "Current browser:", self.browser, "\n" print "On use:", self.browser, "\n"
print "Browser database:", self.browser_path, "\n" print "Version:", "\n"
print "History path:", self.browser_path, "\n"
def getURL(self): def getURL(self):
""" """
Set urls to visit Set urls to visit
""" """
if self.browser == "F": #Firefox history database if self.browser == "F": #Firefox history database
conn = sqlite3.connect(self.browser_path) conn = sqlite3.connect(self.browser_path)
c = conn.cursor() c = conn.cursor()
c.execute('select url, last_visit_date from moz_places ORDER BY last_visit_date DESC') c.execute('select url, last_visit_date from moz_places ORDER BY last_visit_date DESC')
url = c.fetchone() url = c.fetchone()
elif self.browser == "C" or self.browser == "CHROMIUM": #Chrome/Chromium history database elif self.browser == "C" or self.browser == "CHROMIUM": #Chrome/Chromium history database
#Hack that makes a copy of the locked database to access it while Chrome is running. #Hack that makes a copy of the locked database to access it while Chrome is running.
#Removes the copied database afterwards #Removes the copied database afterwards
@ -161,7 +167,7 @@ class bc(object):
elif self.browser == "S": #Safari history database elif self.browser == "S": #Safari history database
try: try:
from biplist import * from biplist import readPlist
except: except:
print "\nError importing: biplist lib. \n\nTo run BC with Safari you need the biplist Python Library:\n\n $ pip install biplist\n" print "\nError importing: biplist lib. \n\nTo run BC with Safari you need the biplist Python Library:\n\n $ pip install biplist\n"
@ -175,21 +181,47 @@ class bc(object):
self.url = url self.url = url
return url[0] return url[0]
def traces(self): def traces(self):
while True: # Set database (GeoLiteCity)
self.geoip= pygeoip.GeoIP('GeoLiteCity.dat')
print "Fetching URL:", self.url[0], "\n" print "Fetching URL:", self.url[0], "\n"
#url = urlparse(self.url[0]).netloc #url = urlparse(self.url[0]).netloc
url = urlparse(self.getURL()).netloc #changed this for prototyping url = urlparse(self.getURL()).netloc #changed this for prototyping
url = url.replace('www.','') #--> doing a tracert to example.com and www.example.com yields different results. url = url.replace('www.','') #--> doing a tracert to example.com and www.example.com yields different results.
url_ip = socket.gethostbyname(url) url_ip = socket.gethostbyname(url)
print url print '='*45 + "\n", "Current target:\n" + '='*45 + "\n"
print "Host:", url, "\n"
if url != self.old_url: if url != self.old_url:
count = 0 count = 1
#a = subprocess.Popen(['lft', '-S', '-n', '-E', url_ip], stdout=subprocess.PIPE) # -> using tcp if sys.platform.startswith('linux'):
a = subprocess.Popen(['lft', '-S', '-n', '-u', url_ip], stdout=subprocess.PIPE) # -> using udp # using udp
try:
print "Method: udp\n"
a = subprocess.Popen(['lft', '-S', '-n', url_ip], stdout=subprocess.PIPE)
# using tcp
except:
try:
print "Method: tcp\n"
a = subprocess.Popen(['lft', '-S', '-n', '-E', url_ip], stdout=subprocess.PIPE)
except:
print "Error: network is not responding correctly. Aborting...\n"
sys.exit(2)
else:
# using udp
try:
print "Method: udp\n"
a = subprocess.Popen(['lft', '-S', '-n', '-u', url_ip], stdout=subprocess.PIPE)
# using tcp
except:
try:
print "Method: tcp\n"
a = subprocess.Popen(['lft', '-S', '-n', '-E', url_ip], stdout=subprocess.PIPE)
except:
print "Error: network is not responding correctly. Aborting...\n"
sys.exit(2)
logfile = open('logfile', 'a') logfile = open('logfile', 'a')
print '='*45 + "\n" + "Packages Route:\n" + '='*45
for line in a.stdout: for line in a.stdout:
logfile.write(line) logfile.write(line)
parts = line.split() parts = line.split()
@ -201,20 +233,18 @@ class bc(object):
if record.has_key('country_name') and record['city'] is not '': if record.has_key('country_name') and record['city'] is not '':
country = record['country_name'] country = record['country_name']
city = record['city'] city = record['city']
print count, "While surfing you got to "+ip+" which is in "+city+", "+country print "Trace:", count, "->", ip, "->", city, "->", country
count+=1
elif record.has_key('country_name'): elif record.has_key('country_name'):
country = record['country_name'] country = record['country_name']
print count, "While surfing you got to "+ip+" which is in "+country print "Trace:", count, "->", ip, "->", country
time.sleep(0.3)
count+=1 count+=1
except: except:
print "Not more records. Aborting...", "\n" print "Trace:", count, "->", "Not allowed"
exit() count+=1
self.old_url = url
print "old url = ", self.old_url
logfile.close() logfile.close()
time.sleep(5) print '='*45 + "\n"
print "Status: Waiting for new urls ...\n"
def getGEO(self): def getGEO(self):
""" """
@ -242,9 +272,6 @@ class bc(object):
os.remove('GeoLiteCity.gz') os.remove('GeoLiteCity.gz')
# Set database (GeoLiteCity)
self.geoip= pygeoip.GeoIP('GeoLiteCity.dat')
def run(self, opts=None): def run(self, opts=None):
""" """
Run BorderCheck Run BorderCheck
@ -259,16 +286,18 @@ class bc(object):
print('='*75) print('='*75)
print(str(p.version)) print(str(p.version))
print('='*75) print('='*75)
# root checker
root = self.try_running(self.check_root, "\nInternal error checking root permissions.")
# extract browser type and path # extract browser type and path
browser = self.try_running(self.check_browser, "\nInternal error checking browser files path.") browser = self.try_running(self.check_browser, "\nInternal error checking browser files path.")
# extract url # extract url
url = self.try_running(self.getURL, "\nInternal error getting urls from browser's database.") url = self.try_running(self.getURL, "\nInternal error getting urls from browser's database.")
# set geoip database # set geoip database
geo = self.try_running(self.getGEO, "\nInternal error setting geoIP database.") geo = self.try_running(self.getGEO, "\nInternal error setting geoIP database.")
# run traceroutes
traces = self.try_running(self.traces, "\nInternal error tracerouting.")
# start web mode # start web mode
BorderCheckWebserver(self) #child process or another thread BorderCheckWebserver(self) #child process or another thread
# run traceroutes
traces = self.try_running(self.traces, "\nInternal error tracerouting.")
if __name__ == "__main__": if __name__ == "__main__":
app = bc() app = bc()

7
webserver.py

@ -117,8 +117,13 @@ class BorderCheckWebserver():
def __init__(self, ref, *args): def __init__(self, ref, *args):
HttpHandler.ref = ref HttpHandler.ref = ref
httpd = HTTPServer(('', port), HttpHandler) httpd = HTTPServer(('', port), HttpHandler)
print "http://127.0.0.1:%d/ : Serving directory '%s/web'" % (port, os.getcwd()) print '='*45 + "\n", "Data Visualization:\n" + '='*45 + "\n"
print "Mode: Webserver\n"
print "Host: http://127.0.0.1:%d/\n\nPath: '%s/web'" % (port, os.getcwd()), "\n"
try:
webbrowser.open('http://127.0.0.1:8080', new=1) webbrowser.open('http://127.0.0.1:8080', new=1)
except:
print "Error: Browser is not responding correctly.\n"
try: try:
httpd.serve_forever() httpd.serve_forever()
except KeyboardInterrupt: except KeyboardInterrupt:

Loading…
Cancel
Save