Skip to content

Commit

Permalink
Changes made:
Browse files Browse the repository at this point in the history
- Added Saver Class

- Removed items from the Printer to the Saver Class

- Changed the bustaPcap.py to use the Saver Class when writing
  • Loading branch information
abaker2010 committed Aug 4, 2019
1 parent 3e9f3c2 commit 602edeb
Show file tree
Hide file tree
Showing 5 changed files with 263 additions and 264 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,4 @@ ASALocalRun/
healthchecksdb
/bustaPcap/pcaps
/bustaPcap/pcapsdir
/bustaPcap/Reports
16 changes: 8 additions & 8 deletions bustaPcap/bustaPcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import colorama
from colorama import Fore, Back, Style

from classes.Print import Print
from classes.Collector import Collector
from classes.Print import Print
from classes.Totals import Totals
from classes.Writer import Writer
from classes.Saver import Saver
from classes.FolderStruct import FolderStruct

#region Option Parse
Expand Down Expand Up @@ -111,15 +112,15 @@ def Single_PCAP():
folders = FolderStruct(os.path.dirname(os.path.abspath(__file__)))
folders.Create_Report_Folder((os.path.basename(options.pcap_file)).split('.')[0])
capture = Collector(captures, FileName=(os.path.basename(options.pcap_file)), FolderName = os.path.dirname(os.path.abspath(__file__)))
caps = Print(capture, options.do_fqdn)
#caps = Print(capture, options.do_fqdn)

if bool(options.verbose) is True:
caps.Print_All()
Print(capture, options.do_fqdn).Print_All()

print(Fore.LIGHTCYAN_EX + "\n\t\t[?] " + Style.RESET_ALL + "Total Time Spent: " + Fore.LIGHTYELLOW_EX + "{0:.2f}".format(time.time() - now) + " seconds.." + Style.RESET_ALL)

if options.save_file:
return caps
return Saver(capture, options.do_fqdn)
else:
return None
#endregion
Expand Down Expand Up @@ -219,17 +220,16 @@ def Main():
print(Fore.LIGHTGREEN_EX + "\t-----------------" + Style.RESET_ALL)
if type(collected) is Totals:
folder = FolderStruct(os.path.dirname(os.path.abspath(__file__)))
print(folder.Get_Path())
for pkt in collected.All_Collected():
folders = FolderStruct(os.path.dirname(os.path.abspath(__file__)))
folders.Create_Report_Folder(pkt.Get_Name().split('.')[0])
print("\t\t- %s : %s" % ("Saving data from", pkt.Get_Name()))
SaveCaptToFile(Print(pkt, options.do_fqdn), folders)
fileWriter = Writer(options.save_file, Print(collected, options.do_fqdn), "a", path = folder.Get_Path())
SaveCaptToFile(Saver(pkt, options.do_fqdn), folders)
fileWriter = Writer(options.save_file, Saver(collected, options.do_fqdn), "a", path = folder.Get_Path())
fileWriter.Save_Totals()
else:
folders = FolderStruct(os.path.dirname(os.path.abspath(__file__)))
folders.Create_Report_Folder(collected.collection.Get_Name().split('.')[0])
folders.Create_Report_Folder(collected.capts.Get_Name().split('.')[0])
SaveCaptToFile(collected, folders)
return
#endregion
Expand Down
255 changes: 2 additions & 253 deletions bustaPcap/classes/Print.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,6 @@ def Print_Dir(self):
return
#endregion

#region Save Printer Returns String
def Save_Printer(self):
toSave = ""
toSave += "%s\n" % self.Save_Header()
toSave += "\n%s" % self.Save_TCP()
toSave += "\n%s" % self.Save_SSLTLS()
toSave += "\n%s" % self.Save_UDP()
toSave += "\n%s" % self.Save_LLC()
toSave += "\n%s" % self.Save_Other_Protocols()
toSave += "\n%s" % self.Save_IPS_Filtered()
if self.fqdnbool is True:
toSave += "\n%s" % self.Save_FQDN()
toSave += "\n%s" % self.Save_HttpInfo()
toSave += "\n%s" % self.Save_HttpMalformedHeaders()
return toSave
#endregion

#region Print Header
def Print_Header(self):
if type(self.collection) is Collector:
Expand Down Expand Up @@ -114,7 +97,7 @@ def Print_HttpInfo(self):
return
#endregion

#regino Print Http Malformed Headers
#region Print Http Malformed Headers
def Print_HttpMalformedHeaders(self):
if type(self.collection) is Collector:
if bool(self.collection.getHttpMalformedHeaders()) is not False:
Expand Down Expand Up @@ -277,238 +260,4 @@ def Print_FQDN(self):
for k, v in sorted(self.collection.Capture_IP_FQDN().items()):
print("\t\t\t%s : %s" % (k, v))
return
#endregion

#region Save Header Returns String
def Save_Header(self):
toSave = ""
if type(self.collection) is Collector:
toSave += "\n\t%s: %s" % ("Processed Information", self.collection.Get_Name())
toSave += "\n\t-----------------------"
toSave += "\n\t\t%s: %s" % ("[?] Total Packets", self.collection.packet_count())
else:
toSave += "\n\t%s" % ("Total Directory Information")
toSave += "\n\t-----------------------"
toSave += "\n\t\t%s: %s" % ("[?] Total Packets", self.collection.Capture_Total_Count())
return toSave
#endregion

#region Save FQDN Information Returns String
def Save_FQDN(self):
toSave = ""
toSave += "\n\t\t[-] IP Addresses -> FQDN"
toSave += "\n\t\t-------------"
if type(self.collection) is Collector:
for k, v in sorted(self.collection.fqdn().items()):
toSave += "\n\t\t\t%s : %s" % (k, v)
else:
for k, v in sorted(self.collection.Capture_IP_FQDN().items()):
toSave += "\n\t\t\t%s : %s" % (k, v)
return toSave
#endregion

#region Save Http Info Returns String
def Save_HttpInfo(self):
toSave = ""
toSave += "\n\t\t-------------"
toSave += "\n\t\t[-] HTTP Information"
toSave += "\n\t\t-------------"
if type(self.collection) is Collector:
if bool(self.collection.getHttpInfo()) is not False:
httpInfo = self.collection.getHttpInfo()
for url in httpInfo:
toSave += "\n\n\t\tURL: %s" % (url)
toSave += "\n\t\tIP Addresses: %s: " % (httpInfo[url]["IP"])
toSave += "\n\t\t\t[-] Header Information: Sent"
toSave += "\n\t\t\t-------------"
for header in httpInfo[url]["Sent"]:
for line in header:
toSave += "\n\t\t\t\t%s : %s" % (line, header[line])
toSave += "\n"

toSave += "\n\t\t\t[-] Header Information: Received"
toSave += "\n\t\t\t-------------"
for header in httpInfo[url]["Recv"]:
for line in header:
toSave += "\n\t\t\t\t%s : %s" % (line, header[line])
toSave += "\n"

if len(httpInfo[url]["Data-Text-Line"]) is not 0:
toSave += "\n\t\t\t[-] Header Information: Data"
toSave += "\n\t\t\t-------------"
for header in httpInfo[url]["Data-Text-Line"]:
for head in header:
toSave += "\n\t\t\t\t%s" % (head)
toSave += "\n"
else:
toSave += "\n\t\t\tNo Information Found"

toSave += "\n\n"

return toSave
#endregion

#region Save Http Malformed Headers Returns String
def Save_HttpMalformedHeaders(self):
toSave = ""
if type(self.collection) is Collector:
if bool(self.collection.getHttpMalformedHeaders()) is not False:
toSave += "\n\t\t-------------"
toSave += "\n\t\t[-] HTTP Malformed Headers"
toSave += "\n\t\t-------------"
headersMalformed = self.collection.getHttpMalformedHeaders()
for url in headersMalformed:
toSave += "\n\t\t\tURL: %s" % (url)
toSave += "\n\t\t\t----------------------"
if bool(headersMalformed[url]["login"]) is not False:
toSave += "\n\t\t\t\tLog In Headers"
toSave += "\n\t\t\t\t-------------"
for pktnum in headersMalformed[url]["login"]:
toSave += "\n\t\t\t\t\tLog In: PKT Num: %s : %s" % (pktnum, headersMalformed[url]["login"][pktnum])
if bool(headersMalformed[url]["job"]) is not False:
toSave += "\n\n\t\t\t\tJob In Headers"
toSave += "\n\t\t\t\t-------------"
for pktnum in headersMalformed[url]["job"]:
toSave += "\n\t\t\t\t\tJob: PKT Num: %s : %s" % (pktnum, headersMalformed[url]["job"][pktnum])
if bool(headersMalformed[url]["keepalived"]) is not False:
toSave += "\n\n\t\t\t\tKeep Alive In Headers"
toSave += "\n\t\t\t\t-------------"
for pktnum in headersMalformed[url]["keepalived"]:
toSave += "\n\t\t\t\t\tKeep Alive: PKT Num: %s : %s" % (pktnum, headersMalformed[url]["keepalived"][pktnum])
if bool(headersMalformed[url]["submit"]) is not False:
toSave += "\n\n\t\t\t\tSubmit In Headers"
toSave += "\n\t\t\t\t-------------"
for pktnum in headersMalformed[url]["submit"]:
toSave += "\n\t\t\t\t\tSubmit: PKT Num: %s : %s" % (pktnum, headersMalformed[url]["submit"][pktnum])
if bool(headersMalformed[url]["error"]) is not False:
toSave += "\n\n\t\t\t\tError In Headers"
toSave += "\n\t\t\t\t-------------"
for pktnum in headersMalformed[url]["error"]:
toSave += "\n\t\t\t\t\tError: PKT Num: %s : %s" % (pktnum, headersMalformed[url]["error"][pktnum])
toSave += "\n\n"
return toSave
#endregion


#region Save TCP Information
def Save_TCP(self):
toSave = ""
toSave += "\n\t\t-------------"
toSave += "\n\t\t[-] TCP"
toSave += "\n\t\t-------------"
if type(self.collection) is Collector:
fp = self.collection.filtered_protocols()
for t in fp["TCP"].keys():
toSave += "\n\t\t\t%s -> %s" % (t, fp["TCP"][t])
toSave += "\n\t\t\t{0:.2f}%".format((fp["TCP"][t] / self.collection.totalTCP() * 100))
else:
fp = self.collection.Capture_Filtered_Protocols()
for t in fp["TCP"].keys():
toSave += "\n\t\t\t%s -> %s" % (t, fp["TCP"][t])
toSave += "\n\t\t\t{0:.2f}%".format((fp["TCP"][t] / self.collection.Total_TCP() * 100))
return toSave
#endregion

#region Save SSL/TLS Information Returns String
def Save_SSLTLS(self):
toSave = ""
toSave += "\n\t\t[-] SSL/TLS Version"
toSave += "\n\t\t-------------"
if type(self.collection) is Collector:
for k, v in self.collection.ssltls().items():
toSave += "\n\t\t\t%s -> %s" % (k, v)
else:
for k, v in self.collection.Capture_TLS().items():
toSave += "\n\t\t\t%s -> %s" % (k, v)
return toSave
#endregion


#region Save UDP Information Returns String
def Save_UDP(self):
toSave = ""
toSave += "\n\t\t[-] UDP"
toSave += "\n\t\t-------------"
if type(self.collection) is Collector:
up = self.collection.filtered_protocols()
for t in up["UDP"].keys():
toSave += "\n\t\t\t%s -> %s" % (t, up["UDP"][t])
toSave += "\n\t\t\t{0:.2f}%".format((up["UDP"][t] / self.collection.totalUDP() * 100))
else:
fp = self.collection.Capture_Filtered_Protocols()
for t in self.collection.Capture_Filtered_Protocols()["UDP"].keys():
toSave += "\n\t\t\t%s -> %s" % (t, fp["UDP"][t])
toSave += "\n\t\t\t{0:.2f}%".format((fp["UDP"][t] / self.collection.Total_UDP() * 100))
return toSave
#endregion

#region Save LLC Information Returns String
def Save_LLC(self):
toSave = ""
toSave += "\n\t\t[-] LLC"
toSave += "\n\t\t-------------"
if type(self.collection) is Collector:
up = self.collection.filtered_protocols()
for t in up["LLC"].keys():
toSave += "\n\t\t\t%s -> %s" % (t, up["LLC"][t])
toSave += "\n\t\t\t{0:.2f}%".format((up["LLC"][t] / self.collection.totalLLC() * 100))
else:
fp = self.collection.Capture_Filtered_Protocols()
for t in self.collection.Capture_Filtered_Protocols()["LLC"].keys():
toSave += "\n\t\t\t%s -> %s" % (t, fp["LLC"][t])
toSave += "\n\t\t\t{0:.2f}%".format((fp["LLC"][t] / self.collection.Total_LLC() * 100))
return toSave
#endregion

#region Save Other Protocols Returns String
def Save_Other_Protocols(self):
toSave = ""
toSave += "\n\t\t[-] In Depth View (All Protocols)"
toSave += "\n\t\t-------------"
if type(self.collection) is Collector:
fp = self.collection.filtered_protocols()
for t in fp["OTHER"].keys():
toSave += "\n\t\t\t%s -> %s" % (t, fp["OTHER"][t])
toSave += "\n\t\t\t{0:.2f}%".format((fp["OTHER"][t] / self.collection.packet_count() * 100))
else:
fp = self.collection.Capture_Filtered_Protocols()
for t in self.collection.Capture_Filtered_Protocols()["OTHER"].keys():
toSave += "\n\t\t\t%s -> %s" % (t, fp["OTHER"][t])
toSave += "\n\t\t\t{0:.2f}%".format((fp["OTHER"][t] / self.collection.Capture_Total_Count() * 100))
return toSave
#endregions

#region Save IPS Information Returns String
def Save_IPS(self):
toSave = ""
toSave += "\n\t\t[-] IP Addresses"
toSave += "\n\t\t-------------"
for snt in self.collection.ip_addresses_only():
toSave += "\n\t\t\t%s" % (snt)
return toSave
#endregion

#region Save IPS Filtered Information Returns String
def Save_IPS_Filtered(self):
toSave = ""
toSave += "\n\t\t[-] IP Addresses (Filtered)"
toSave += "\n\t\t-------------"
if type(self.collection) is Collector:
evn = 0
for snt in self.collection.ip_addresses_filtered().keys():
toSave += "\n\t\t\t%s : %s" % (snt, self.collection.ip_addresses_filtered()[snt])
evn += 1
if (evn % 2) == 0:
toSave += "\n"
else:
evn = 0
for snt in self.collection.Capture_IP_Filtered().keys():
toSave += "\n\t\t\t%s : %s" % (snt, self.collection.Capture_IP_Filtered()[snt])
evn += 1
if (evn % 2) == 0:
toSave += "\n"
return toSave
#endregion



#endregion
Loading

0 comments on commit 602edeb

Please sign in to comment.