Skip to content

Commit

Permalink
Changes made:
Browse files Browse the repository at this point in the history
- Added regions to all files for descriptions and also to allow for collapsing of function

- Also added the -v, --VERBOSE option for optional printing to command line when the program runs currently a boolean, at some point there may been to be different levels to the printing
  • Loading branch information
abaker2010 committed Aug 4, 2019
1 parent a42a77b commit ea198ee
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 192 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,6 @@ ASALocalRun/
.localhistory/

# BeatPulse healthcheck temp database
healthchecksdb
healthchecksdb
/bustaPcap/pcaps
/bustaPcap/pcapsdir
47 changes: 40 additions & 7 deletions bustaPcap/bustaPcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from classes.Writer import Writer
from classes.FolderStruct import FolderStruct

#region Option Parse
parser = OptionParser()

parser.add_option("-q", "--FQDN", dest="do_fqdn",
Expand All @@ -29,12 +30,19 @@
parser.add_option("-p", "--PCAP", dest="pcap_file",
help="PCAP File that will be parsed. Include whole destination path: Allowed file types are: .pcap, .cap, .pcapng")

parser.add_option("-v", "--VERBOSE", dest="verbose",
help="Verbose setting allowing for optional printing to screen", default=False)

options, args = parser.parse_args()
#endregion

#region Usage
def Usage():
parser.print_help()
return
#endregion

#region Print Title
def Print_Title():
print(Fore.LIGHTGREEN_EX + "\n\t::::::::: ::: ::: :::::::: ::::::::::: ::: ::::::::: :::::::: ::: :::::::::")
print("\t:+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+:")
Expand All @@ -46,9 +54,10 @@ def Print_Title():
print("\n\t================================================================================================")
print("\t= Zedo & Moose =")
print("\t================================================================================================\n\n" + Style.RESET_ALL)

return
#endregion

#region Arg Checker
def Arg_Check():
if options.pcap_file:
if not options.pcap_file.endswith('.pcap') | options.pcap_file.endswith('.cap') | options.pcap_file.endswith('.pcapng'):
Expand All @@ -71,17 +80,30 @@ def Arg_Check():
print(Fore.RED + "\t[!] " + Stlye.RESET_ALL + "Invalid -q option! Accepts True or False")
exit()

if options.verbose:
if options.verbose.lower() == "true":
options.verbose = True
elif options.verbose.lower() == "false":
options.verbose = False
else:
print(Fore.RED + "\t[!] " + Stlye.RESET_ALL + "Invalid -v option! Accepts True or False")
exit()

if not options.pcap_file and not options.dir_path:
print(Fore.RED + "\t[!] " + Style.RESET_ALL + "Please use -p <pcap> or -d <directory>")
exit()
return
#endregion

#region Check Folders
def Check_Folders():
print(Fore.LIGHTGREEN_EX + "\t[-] " + Style.RESET_ALL + "Checking Folders")
folders = FolderStruct(os.path.dirname(os.path.abspath(__file__)))
folders.Check_Folders()
return
#endregion

#region Single PCAP
def Single_PCAP():
now = time.time()

Expand All @@ -90,15 +112,19 @@ def Single_PCAP():
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_All()

if bool(options.verbose) is True:
caps.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
else:
return None
#endregion

#region Directory PCAP
def Dir_PCAPS():
folders = []
files = []
Expand All @@ -125,15 +151,19 @@ def Dir_PCAPS():
capture = Collector(captures, FileName=file, FolderName = os.path.dirname(os.path.abspath(__file__)))
total_collection.Add_Collector(capture)
print(Fore.LIGHTCYAN_EX + "\n\t[?] " + Style.RESET_ALL + "Time Spent: " + Fore.LIGHTYELLOW_EX + "{0:.2f}".format(time.time() - now) + " seconds.." + Style.RESET_ALL)

#Print(total_collection, options.do_fqdn).Print_All()

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

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

if options.save_file:
return total_collection
else:
return None
#endregion

#region Save Capture Information To File
def SaveCaptToFile(capt, folders):

print(Fore.LIGHTGREEN_EX + "\t\t-------------------------------" + Style.RESET_ALL)
Expand Down Expand Up @@ -169,7 +199,9 @@ def SaveCaptToFile(capt, folders):
fileWriter = Writer(options.save_file, capt, "w+", infoname = "All Data", path = folders.Get_Path())
fileWriter.Save()
return
#endregion

#region Main
def Main():
colorama.init()
Arg_Check()
Expand All @@ -192,8 +224,6 @@ def Main():
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()))
#fileWriter = Writer(options.save_file, Print(pkt, options.do_fqdn), "a")
#fileWriter.Save()
SaveCaptToFile(Print(pkt, options.do_fqdn), folders)
fileWriter = Writer(options.save_file, Print(collected, options.do_fqdn), "a", path = folder.Get_Path())
fileWriter.Save_Totals()
Expand All @@ -202,7 +232,9 @@ def Main():
folders.Create_Report_Folder(collected.collection.Get_Name().split('.')[0])
SaveCaptToFile(collected, folders)
return
#endregion

#region Main named if for keyboard interrupt
if __name__ == "__main__":
try:
Main()
Expand All @@ -212,4 +244,5 @@ def Main():
except Exception as e:
print(e)
finally:
exit()
exit()
#endregion
58 changes: 51 additions & 7 deletions bustaPcap/classes/Collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,40 @@

class Collector:
def __init__(self, capts, *args, **kwargs):
#print(Fore.GREEN + "\n\t[+] " + Style.RESET_ALL + "Initializing Protocol Dictionary\n")
#region Class Variables
#region Passed
self.captureName = kwargs.get("FileName", None)
self.folderPath = kwargs.get("FolderName", None)
self.capts = capts
#endregion

#region Numerical
self.packetCount = 0
self.udp = 0
self.tcp = 0
self.llc = 0
self.other = 0
#endregion

#region Dictionaries
self.protocols = {}
self.ipAddresses = {}
self.ip_fqdn = {}
self.httpInfo = {}
self.httpMalformedHeaders = {}

self.capts = capts
self.tls = {}
self.llcList = ["llc", "stp", "dtp", "cdp"]
self.udpList = ["udp", "ntp", "dns", "mdns", "ssdp", "browser", "nbns", "smb", "gquic", "dhcpv6"]
self.tcpList = ["http", "tcp", "data-text-lines", "tls"]
self.lDict = {"TCP" : {}, "UDP" : {}, "LLC" : {}, "OTHER" : {} }
self.tlsversion = {"0x00000002":"SSLv2", "0x00000300":"SSLv3", "0x00000301":"TLSv1.0",
"0x00000302":"TLSv1.1", "0x00000303":"TLSv1.2", "0x00000304":"TLSv1.3"}
#endregion

#region Arrays
self.llcList = ["llc", "stp", "dtp", "cdp"]
self.udpList = ["udp", "ntp", "dns", "mdns", "ssdp", "browser", "nbns", "smb", "gquic", "dhcpv6"]
self.tcpList = ["http", "tcp", "data-text-lines", "tls"]
#endregion
#endregion


for pkt in self.capts:
self.packetCount += 1
Expand Down Expand Up @@ -161,31 +173,48 @@ def __init__(self, capts, *args, **kwargs):
sys.stdout.flush()
return

#region Set Collected Name
def Set_Name(self, name):
self.captureName = name
return
#endregion

#region Get Collected Name Retruns String
def Get_Name(self):
return self.captureName
#endregion

#region Get HTTP Information Returns Dictionary
def getHttpInfo(self):
return self.httpInfo
#endregion

#region Get HTTP Malformed Headers Returns Dictionary
def getHttpMalformedHeaders(self):
return self.httpMalformedHeaders
#endregion

#region Get Total UDP Count Returns Int
def totalUDP(self):
return self.udp
#endregion

#region Get Total TCP Count Returns Int
def totalTCP(self):
return self.tcp
#endregion

#region Get Total LLC Count Returns Int
def totalLLC(self):
return self.llc
#endregion

#region Get Total Other Protocol Count Returns Int
def totalOTHER(self):
return self.other
#endregion

#region Get Filtered Protocols Returns Dictionary
def filtered_protocols(self):
self.lDict = {"TCP" : {}, "UDP" : {}, "LLC" : {}, "OTHER" : {} }
self.udp = 0
Expand Down Expand Up @@ -222,7 +251,9 @@ def filtered_protocols(self):
self.other += self.protocols[pkt]

return self.lDict
#endregion

#region Get IP Addresses Only Returns Array
def ip_addresses_only(self):
ipList = []
for k in self.ipAddresses.keys():
Expand All @@ -232,7 +263,9 @@ def ip_addresses_only(self):
if ips[1] not in ipList:
ipList.append(ips[1])
return ipList
#endregion

#region Get Filtered IP Addresses Returns Dictionary
def ip_addresses_filtered(self):
newDict = {}
for k in self.ipAddresses.keys():
Expand All @@ -246,7 +279,9 @@ def ip_addresses_filtered(self):
newDict[rev] = 0
pass
return newDict
#endregion

#region Get FQDN Returns Dictionary
def fqdn(self):
if not self.ip_fqdn:
for snt in self.ip_addresses_only():
Expand All @@ -260,15 +295,24 @@ def fqdn(self):
else:
self.ip_fqdn[snt] = dn
return self.ip_fqdn
#endregion

#region Get SSL/TLS Returns Dictionary
def ssltls(self):
return self.tls
#endregion

#region Get All Protocols Returns Dictionary
def all_protocols(self):
return self.protocols
#endregion

#region Get Packet Count Returns Int
def packet_count(self):
return self.packetCount
#endregion

#region Get IP Addresses Returns Dictionary
def ip_addresses(self):
return self.ipAddresses
return self.ipAddresses
#endregion
9 changes: 9 additions & 0 deletions bustaPcap/classes/FolderStruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
from colorama import Fore, Back, Style

class FolderStruct:
#region Init For Class
def __init__(self, path):
self.path = path
self.folders = ["\\Reports"]
return
#endregion

#region Check Folders
def Check_Folders(self):
for f in self.folders:
path = self.path + f
Expand All @@ -21,6 +24,9 @@ def Check_Folders(self):
else:
print(Fore.LIGHTGREEN_EX + "\t\t[-] " + Style.RESET_ALL + "All folders are present")
return
#endregion

#region Check For Report Folder
def Create_Report_Folder(self, name):
path = self.path + self.folders[0] + "\\" + name + "\\"
if platform.system() != "windows":
Expand All @@ -32,6 +38,9 @@ def Create_Report_Folder(self, name):
else:
print(Fore.LIGHTGREEN_EX + "\t\t[-] " + Style.RESET_ALL + "Report Subfolder Is Present")
return
#endregion

#region Get Path
def Get_Path(self):
return self.path + "\\"
#endregion
Loading

0 comments on commit ea198ee

Please sign in to comment.