|
@ -35,12 +35,13 @@ class bc(object): |
|
|
Init defaults |
|
|
Init defaults |
|
|
""" |
|
|
""" |
|
|
self.browser = "" # "F" Firefox / "C" Chrome |
|
|
self.browser = "" # "F" Firefox / "C" Chrome |
|
|
self.browser_path = "" |
|
|
self.browser_path = "" #the path to the browser application |
|
|
self.browser_history_path = "" |
|
|
self.browser_history_path = "" # the path to the browser history file |
|
|
self.browser_version = "" |
|
|
self.browser_version = "" # the version of the browser |
|
|
self.url = "" |
|
|
self.url = "" |
|
|
self.old_url = "" |
|
|
self.old_url = "" |
|
|
self.ip = "" |
|
|
self.destination_ip = "" |
|
|
|
|
|
self.hop_ip = "" |
|
|
self.longitude = "" |
|
|
self.longitude = "" |
|
|
self.latitude = "" |
|
|
self.latitude = "" |
|
|
self.hop_host_name = "" |
|
|
self.hop_host_name = "" |
|
@ -48,6 +49,9 @@ class bc(object): |
|
|
self.country = "" |
|
|
self.country = "" |
|
|
self.server_name = "" |
|
|
self.server_name = "" |
|
|
self.hop_count = 1 # number of hops |
|
|
self.hop_count = 1 # number of hops |
|
|
|
|
|
self.result_list = [] |
|
|
|
|
|
self.vardict ={} |
|
|
|
|
|
self.asn = '' |
|
|
|
|
|
|
|
|
if os.path.exists('data.xml'): # removing xml data to has a new map each time that bc is launched |
|
|
if os.path.exists('data.xml'): # removing xml data to has a new map each time that bc is launched |
|
|
os.remove('data.xml') |
|
|
os.remove('data.xml') |
|
@ -183,7 +187,6 @@ class bc(object): |
|
|
print "Version:", self.browser_version, "\n" |
|
|
print "Version:", self.browser_version, "\n" |
|
|
print "History:", self.browser_history_path, "\n" |
|
|
print "History:", self.browser_history_path, "\n" |
|
|
|
|
|
|
|
|
#move the subprocesses to debug mode |
|
|
|
|
|
|
|
|
|
|
|
def getURL(self): |
|
|
def getURL(self): |
|
|
""" |
|
|
""" |
|
@ -236,7 +239,6 @@ class bc(object): |
|
|
# Set database (GeoLiteCity) |
|
|
# Set database (GeoLiteCity) |
|
|
self.geoip = pygeoip.GeoIP('GeoLiteCity.dat') |
|
|
self.geoip = pygeoip.GeoIP('GeoLiteCity.dat') |
|
|
self.geoasn = pygeoip.GeoIP('GeoIPASNum.dat') |
|
|
self.geoasn = pygeoip.GeoIP('GeoIPASNum.dat') |
|
|
self.hop_count = 1 |
|
|
|
|
|
|
|
|
|
|
|
print '='*45 + "\n", "Current target:\n" + '='*45 + "\n" |
|
|
print '='*45 + "\n", "Current target:\n" + '='*45 + "\n" |
|
|
print "URL:", self.url[0], "\n" |
|
|
print "URL:", self.url[0], "\n" |
|
@ -244,10 +246,10 @@ class bc(object): |
|
|
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) |
|
|
self.ip = url_ip |
|
|
self.destination_ip = url_ip |
|
|
print "Host:", url, "\n" |
|
|
print "Host:", url, "\n" |
|
|
if url != self.old_url: |
|
|
if url != self.old_url: |
|
|
count = 1 |
|
|
self.hop_count = 1 |
|
|
if sys.platform.startswith('linux'): |
|
|
if sys.platform.startswith('linux'): |
|
|
# using udp |
|
|
# using udp |
|
|
try: |
|
|
try: |
|
@ -265,7 +267,7 @@ class bc(object): |
|
|
# using udp |
|
|
# using udp |
|
|
try: |
|
|
try: |
|
|
print "Method: udp\n" |
|
|
print "Method: udp\n" |
|
|
a = subprocess.Popen(['lft', '-S', '-n', '-e', url_ip], stdout=subprocess.PIPE) |
|
|
a = subprocess.Popen(['lft', '-S', '-n', '-u', url_ip], stdout=subprocess.PIPE) |
|
|
# using tcp |
|
|
# using tcp |
|
|
except: |
|
|
except: |
|
|
try: |
|
|
try: |
|
@ -282,18 +284,19 @@ class bc(object): |
|
|
logfile.write(item) |
|
|
logfile.write(item) |
|
|
print '='*45 + "\n" + "Packages Route:\n" + '='*45 |
|
|
print '='*45 + "\n" + "Packages Route:\n" + '='*45 |
|
|
for line in a.stdout: |
|
|
for line in a.stdout: |
|
|
self.hop_count = self.hop_count + 1 |
|
|
|
|
|
|
|
|
|
|
|
if self.options.debug == True: |
|
|
if self.options.debug == True: |
|
|
logfile.write(line) |
|
|
logfile.write(line) |
|
|
parts = line.split() |
|
|
parts = line.split() |
|
|
|
|
|
|
|
|
for ip in parts: |
|
|
for ip in parts: |
|
|
if re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$",ip): |
|
|
if re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$",ip): |
|
|
|
|
|
self.hop_ip = ip |
|
|
record = self.geoip.record_by_addr(ip) |
|
|
record = self.geoip.record_by_addr(ip) |
|
|
try: |
|
|
try: |
|
|
asn = self.geoasn.org_by_addr(ip) |
|
|
self.asn = self.geoasn.org_by_addr(ip) |
|
|
except: |
|
|
except: |
|
|
asn = 'nothing' |
|
|
self.asn = 'No ASN provided' |
|
|
#print record |
|
|
#print record |
|
|
try: |
|
|
try: |
|
|
self.hop_host_name = socket.gethostbyaddr(ip)[0] |
|
|
self.hop_host_name = socket.gethostbyaddr(ip)[0] |
|
@ -311,21 +314,25 @@ 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 "Trace:", count, "->", ip, "->", longitude + ":" + latitude, "->", city, "->", country, "->", self.hop_host_name, asn |
|
|
print "Trace:", self.hop_count, "->", ip, "->", longitude + ":" + latitude, "->", city, "->", country, "->", self.hop_host_name, self.asn |
|
|
count+=1 |
|
|
#self.hop_count +=1 |
|
|
self.city = city |
|
|
self.city = city |
|
|
self.country = country |
|
|
self.country = country |
|
|
self.server_name = self.hop_host_name |
|
|
self.server_name = self.hop_host_name |
|
|
elif record.has_key('country_name'): |
|
|
elif record.has_key('country_name'): |
|
|
country = record['country_name'] |
|
|
country = record['country_name'] |
|
|
print "Trace:", count, "->", ip, "->", longitude + ":" + latitude, "->", country, "->", self.hop_host_name, asn |
|
|
print "Trace:", self.hop_count, "->", ip, "->", longitude + ":" + latitude, "->", country, "->", self.hop_host_name, self.asn |
|
|
self.country = country |
|
|
self.country = country |
|
|
|
|
|
self.city = '-' |
|
|
self.server_name = self.hop_host_name |
|
|
self.server_name = self.hop_host_name |
|
|
count+=1 |
|
|
#self.hop_count+=1 |
|
|
|
|
|
self.vardict = {'destination_ip': self.destination_ip, 'hop_count': self.hop_count,'hop_ip': self.hop_ip, 'server_name': self.server_name, 'country': self.country, 'city': self.city, 'longitude': self.longitude, 'latitude': self.latitude, 'asn' : self.asn} |
|
|
except: |
|
|
except: |
|
|
print "Trace:", count, "->", "Not allowed" |
|
|
print "Trace:", self.hop_count, "->", "Not allowed" |
|
|
count+=1 |
|
|
self.hop_count+=1 |
|
|
|
|
|
|
|
|
# write xml data to file |
|
|
# write xml data to file |
|
|
|
|
|
self.result_list.append(self.vardict) |
|
|
xml_results = xml_reporting(self) |
|
|
xml_results = xml_reporting(self) |
|
|
xml_results.print_xml_results('data.xml') |
|
|
xml_results.print_xml_results('data.xml') |
|
|
|
|
|
|
|
@ -349,7 +356,7 @@ class bc(object): |
|
|
try: |
|
|
try: |
|
|
print "Downloading GeoIP database...\n" |
|
|
print "Downloading GeoIP database...\n" |
|
|
if self.options.debug == True: |
|
|
if self.options.debug == True: |
|
|
print "Fetching from:", maxmind |
|
|
print "Fetching from:", maxmind, '\n' |
|
|
urllib.urlretrieve(maxmind, |
|
|
urllib.urlretrieve(maxmind, |
|
|
'GeoLiteCity.gz') |
|
|
'GeoLiteCity.gz') |
|
|
except: |
|
|
except: |
|
@ -376,8 +383,8 @@ class bc(object): |
|
|
try: |
|
|
try: |
|
|
print "Downloading GeoIP ASN database...\n" |
|
|
print "Downloading GeoIP ASN database...\n" |
|
|
if self.options.debug == True: |
|
|
if self.options.debug == True: |
|
|
print "Fetching from:", maxmind_asn |
|
|
print "Fetching from:", maxmind_asn,'\n' |
|
|
urllib.urlretrieve(maxmind, |
|
|
urllib.urlretrieve(maxmind_asn, |
|
|
'GeoIPASNum.gz') |
|
|
'GeoIPASNum.gz') |
|
|
except: |
|
|
except: |
|
|
print("[Error] - Something wrong fetching GeoIP maps from the Internet. Aborting..."), "\n" |
|
|
print("[Error] - Something wrong fetching GeoIP maps from the Internet. Aborting..."), "\n" |
|
|