@@ -2606,26 +2606,63 @@ def run_ssh_command(self, host, port, user_name, private_key_file_id, password,
26062606
26072607 return {"success" :"true" ,"output" : stdout .read ().decode (errors = 'ignore' )}
26082608
2609+ def cleanup_ioc_data (self , input_data ):
2610+ # Remove unecessary parts like { and }, quotes etc
2611+ input_data = str (input_data )
2612+ input_data = input_data .replace ("{" , "" )
2613+ input_data = input_data .replace ("}" , "" )
2614+ input_data = input_data .replace ("\" " , "" )
2615+ input_data = input_data .replace ("'" , "" )
2616+ input_data = input_data .replace (" " , "" )
2617+ input_data = input_data .replace ("\t " , "" )
2618+ input_data = input_data .replace ("\n " , "" )
2619+
2620+ # Remove html tags
2621+ input_data = re .sub (r'<[^>]*>' , '' , input_data )
2622+
2623+ return input_data
2624+
2625+
26092626 def parse_ioc (self , input_string , input_type = "all" ):
26102627 ioc_types = ["domains" , "urls" , "email_addresses" , "ipv4s" , "ipv4_cidrs" , "md5s" , "sha256s" , "sha1s" , "cves" ]
2628+ #ioc_types = ["ipv4s"]
2629+
2630+ try :
2631+ input_string = self .cleanup_ioc_data (input_string )
2632+ except Exception as e :
2633+ self .logger .info ("[ERROR] Failed to cleanup ioc data: %s" % e )
26112634
26122635 # Remember overriding ioc types we care about
26132636 if input_type == "" or input_type == "all" :
26142637 input_type = "all"
26152638 else :
26162639 input_type = input_type .split ("," )
2640+
2641+ new_input_types = []
26172642 for i in range (len (input_type )):
26182643 item = input_type [i ]
26192644
26202645 item = item .strip ()
26212646 if not item .endswith ("s" ):
26222647 item = "%ss" % item
26232648
2624- input_type [i ] = item
2649+ if item not in ioc_types :
2650+ continue
2651+
2652+ new_input_types .append (item )
26252653
2626- ioc_types = input_type
2654+ ioc_types = new_input_types
2655+
2656+ # Not used for anything after cleanup fixes
2657+ max_size = 7500000
2658+ #if len(input_string) > max_size:
2659+ # input_string = input_string[:max_size]
2660+
2661+ self .logger .info ("[DEBUG] Parsing data of length %d with types %s. Max size: %d" % (len (input_string ), ioc_types , max_size ))
26272662
26282663 iocs = find_iocs (str (input_string ), included_ioc_types = ioc_types )
2664+ self .logger .info ("[DEBUG] Found %d iocs" % len (iocs ))
2665+
26292666 newarray = []
26302667 for key , value in iocs .items ():
26312668 if input_type != "all" :
0 commit comments