def _list_arp_table(self): cmd = "arp -a" p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) output, errors = p.communicate() output = utils.get_terminal_decoded_string(output) item = output.split("\n") for i in item: yield i
def _list_arp_table(self): cmd="arp -a" p=subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) output, errors = p.communicate() output = utils.get_terminal_decoded_string(output) item = output.split("\n") for i in item: yield i
def csv_list_scheduled_jobs(self): self.logger.info('Health : Listing scheduled jobs') file_tasks=self.output_dir + '_tasks.csv' with open(file_tasks, 'wb') as tasks_logs: proc=subprocess.Popen(["schtasks.exe",'/query','/fo','CSV'],stdout=subprocess.PIPE) res = proc.communicate() res = get_terminal_decoded_string(res[0]) write_to_output(res, tasks_logs, self.logger) with open(file_tasks, "r") as fr, open(self.output_dir,'ab') as fw: csv_writer = get_csv_writer(fw) for l in fr.readlines(): l = l.decode('utf8')[:-1].replace('"', '') if l.find(',') !=-1: write_to_csv([self.computer_name, 'Scheduled jobs'] + l.split(','), csv_writer)
def _list_network_adapters(self): net = self.wmi.Win32_NetworkAdapter() for n in net: netcard = n.Caption IPv4 = '' IPv6 = '' DHCP_server = '' DNS_server = '' adapter_type = '' nbtstat_value = '' if n.AdapterTypeID: adapter_type = NETWORK_ADAPTATER[int(n.AdapterTypeID)] net_enabled = n.NetEnabled mac_address = n.MACAddress description = n.Description physical_adapter = unicode(n.PhysicalAdapter) product_name = n.ProductName speed = n.Speed database_path = '' if net_enabled: nic = self.wmi.Win32_NetworkAdapterConfiguration( MACAddress=mac_address) for nc in nic: database_path = nc.DatabasePath if nc.IPAddress: try: IPv4 = nc.IPAddress[0] IPv6 = nc.IPAddress[1] except IndexError as e: self.logger.error('Error to catch IP Address %s ' % str(nc.IPAddress)) if IPv4: nbtstat = 'nbtstat -A ' + IPv4 p = subprocess.Popen(nbtstat, shell=True, stdout=subprocess.PIPE) output, errors = p.communicate() #output=utils.decode_output_cmd(output) output = utils.get_terminal_decoded_string(output) nbtstat_value = output.split('\r\n') nbtstat_value = ' '.join( [n.replace('\n', '') for n in nbtstat_value]) if nc.DNSServerSearchOrder: DNS_server = nc.DNSServerSearchOrder[0] if nc.DHCPEnabled: if nc.DHCPServer: DHCP_server = nc.DHCPServer yield netcard, adapter_type, description, mac_address, product_name, physical_adapter, product_name, speed, IPv4, IPv6, DHCP_server, DNS_server, database_path, nbtstat_value
def csv_list_scheduled_jobs(self): self.logger.info('Health : Listing scheduled jobs') file_tasks = self.output_dir + '_tasks.csv' with open(file_tasks, 'wb') as tasks_logs: proc = subprocess.Popen(["schtasks.exe", '/query', '/fo', 'CSV'], stdout=subprocess.PIPE) res = proc.communicate() res = get_terminal_decoded_string(res[0]) write_to_output(res, tasks_logs, self.logger) with open(file_tasks, "r") as fr, open(self.output_dir, 'ab') as fw: csv_writer = get_csv_writer(fw) for l in fr.readlines(): l = l.decode('utf8')[:-1].replace('"', '') if l.find(',') != -1: write_to_csv([self.computer_name, 'Scheduled jobs'] + l.split(','), csv_writer)
def _csv_list_scheduled_jobs(self): self.logger.info('Health : Listing scheduled jobs') file_tasks=self.output_dir + '_tasks.csv' with open(file_tasks,'wb') as tasks_logs: proc=subprocess.Popen(["schtasks.exe",'/query','/fo','CSV'], stdout=subprocess.PIPE) res = proc.communicate() res = get_terminal_decoded_string(res[0]) write_to_output(res, tasks_logs, self.logger) with open(file_tasks,"r") as fr, open(self.output_dir + "_scheduled_jobs.csv",'wb') as fw: csv_writer = get_csv_writer(fw) #fw.write('"Computer Name"|"Type"|"Name"|"Time"|"State"\r\n') for l in fr.readlines(): l = l.decode('utf8') if l.find('\\') > 0: l = l[:-1].replace('"', '') # remove the end of line arr_write = [self.computer_name, 'Scheduled jobs'] + l.split(',') write_to_csv(arr_write, csv_writer) record_sha256_logs(self.output_dir +'_scheduled_jobs.csv',self.output_dir +'_sha256.log')
def _list_network_adapters(self): net=self.wmi.Win32_NetworkAdapter() for n in net: netcard=n.Caption IPv4='' IPv6='' DHCP_server='' DNS_server='' adapter_type='' nbtstat_value='' if n.AdapterTypeID: adapter_type=NETWORK_ADAPTATER[int(n.AdapterTypeID)] net_enabled=n.NetEnabled mac_address=n.MACAddress description=n.Description physical_adapter=unicode(n.PhysicalAdapter) product_name=n.ProductName speed=n.Speed database_path='' if net_enabled: nic=self.wmi.Win32_NetworkAdapterConfiguration(MACAddress=mac_address) for nc in nic: database_path=nc.DatabasePath if nc.IPAddress: try: IPv4=nc.IPAddress[0] IPv6=nc.IPAddress[1] except IndexError as e: self.logger.error('Error to catch IP Address %s ' % str(nc.IPAddress)) if IPv4: nbtstat='nbtstat -A '+ IPv4 p=subprocess.Popen(nbtstat, shell=True, stdout=subprocess.PIPE) output, errors = p.communicate() #output=utils.decode_output_cmd(output) output = utils.get_terminal_decoded_string(output) nbtstat_value=output.split('\r\n') nbtstat_value=' '.join([n.replace('\n','') for n in nbtstat_value]) if nc.DNSServerSearchOrder: DNS_server=nc.DNSServerSearchOrder[0] if nc.DHCPEnabled: if nc.DHCPServer: DHCP_server=nc.DHCPServer yield netcard,adapter_type,description,mac_address,product_name,physical_adapter,product_name,speed,IPv4,IPv6,DHCP_server,DNS_server,database_path,nbtstat_value
def _csv_list_scheduled_jobs(self): self.logger.info('Health : Listing scheduled jobs') file_tasks = self.output_dir + '_tasks.csv' with open(file_tasks, 'wb') as tasks_logs: proc = subprocess.Popen(["schtasks.exe", '/query', '/fo', 'CSV'], stdout=subprocess.PIPE) res = proc.communicate() res = get_terminal_decoded_string(res[0]) write_to_output(res, tasks_logs, self.logger) with open(file_tasks, "r") as fr, open(self.output_dir + "_scheduled_jobs.csv", 'wb') as fw: csv_writer = get_csv_writer(fw) #fw.write('"Computer Name"|"Type"|"Name"|"Time"|"State"\r\n') for l in fr.readlines(): l = l.decode('utf8') if l.find('\\') > 0: l = l[:-1].replace('"', '') # remove the end of line arr_write = [self.computer_name, 'Scheduled jobs' ] + l.split(',') write_to_csv(arr_write, csv_writer) record_sha256_logs(self.output_dir + '_scheduled_jobs.csv', self.output_dir + '_sha256.log')