aboutsummaryrefslogtreecommitdiff
path: root/cowrieder.py
diff options
context:
space:
mode:
authorAda Isopods <me@bathynomus.xyz>2025-05-17 02:52:27 -0600
committerAda Isopods <me@bathynomus.xyz>2026-10-21 23:04:29 -0600
commit481cb1e457c3951b3b7385859572b8d6d16a7cdb (patch)
tree6be9f09071873b967adfbbcc42c27c04736dd46c /cowrieder.py
parent0deb8ecec9b874d58f6c46f6351d401464d1c061 (diff)
directory support
Diffstat (limited to 'cowrieder.py')
-rw-r--r--cowrieder.py50
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