diff options
Diffstat (limited to 'cowrieder.py')
| -rw-r--r-- | cowrieder.py | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/cowrieder.py b/cowrieder.py index 75be8c1..01d93fe 100644 --- a/cowrieder.py +++ b/cowrieder.py @@ -174,25 +174,37 @@ def session_pingcmds(session): # Return array of all "command ping" commands use ra.append(argv0) return ra - - - -with open(filepath, "r") as logfile: # Load da file and populate da master array - for line in logfile: - entry = json.loads(line) - - if( - (not args.filter_ip or entry['src_ip'] == args.filter_ip or hashgen(entry['src_ip']) == args.filter_ip) # If it's not the IP we're filtering for don't even bother man - ): - session_id = entry['session'] - - if(args.redact_ip): - entry['src_ip'] = hashgen(entry['src_ip']) - - if(session_id not in sessions): - sessions.update({session_id: [entry]}) - else: - sessions[session_id].append(entry) +def load_json_to_array(fp): + with open(fp, "r") as logfile: # Load da file and populate da master array + for line in logfile: + entry = json.loads(line) + + if( + (not args.filter_ip or entry['src_ip'] == args.filter_ip or hashgen(entry['src_ip']) == args.filter_ip) # If it's not the IP we're filtering for don't even bother man + ): + session_id = entry['session'] + + if(args.redact_ip): + entry['src_ip'] = hashgen(entry['src_ip']) + + if(session_id not in sessions): + sessions.update({session_id: [entry]}) + else: + sessions[session_id].append(entry) + +if(os.path.isfile(filepath)): + load_json_to_array(filepath) +elif(os.path.isdir(filepath)): + # run load_json_to_array for every json file in the directory + files = {} + for f in os.listdir(filepath): + if(f[:11] == "cowrie.json" or f[-5:] == ".json"): + fi = os.path.join(filepath, f) + files.update({fi: os.path.getmtime(fi)}) + for g in dict(sorted(files.items(), key=lambda item: item[1])): + load_json_to_array(g) +else: + raise FileNotFoundError # Filtering |
