aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAda Isopods <me@bathynomus.xyz>2025-05-22 15:14:42 -0600
committerAda Isopods <me@bathynomus.xyz>2026-10-21 23:04:41 -0600
commit987780503bfd69b8d8759d58ba1273a135fe3b1a (patch)
tree2ef65d34f9a534aae0ebc20eb79d583e8900cc66
parentda9c9fa7f773edfe5ae7a59837f266c21e7e79db (diff)
make it track log size
-rw-r--r--cowrieder.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/cowrieder.py b/cowrieder.py
index 2f778ee..4162a40 100644
--- a/cowrieder.py
+++ b/cowrieder.py
@@ -190,7 +190,15 @@ def session_pingcmds(session): # Return array of all "command ping" commands use
ra.append(event['input'])
return ra
-# Loading da file(s) into da master array
+# File loading stuff
+
+total_filesize = 0
+def sizeof_fmt(num, suffix="B"): # Shamelessly stolen from StackOverflow
+ for unit in ("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"):
+ if abs(num) < 1024.0:
+ return f"{num:3.1f}{unit}{suffix}"
+ num /= 1024.0
+ return f"{num:.1f}Yi{suffix}"
def load_json_to_array(fp):
with open(fp, "r") as logfile:
@@ -210,6 +218,7 @@ def load_json_to_array(fp):
if(os.path.isfile(filepath)):
load_json_to_array(filepath)
+ total_filesize += os.path.getsize(filepath)
elif(os.path.isdir(filepath)):
# run load_json_to_array for every json file in the directory
files = {}
@@ -219,6 +228,7 @@ elif(os.path.isdir(filepath)):
files.update({fi: os.path.getmtime(fi)})
for g in dict(sorted(files.items(), key=lambda item: item[1])):
load_json_to_array(g)
+ total_filesize += os.path.getsize(g)
else:
raise FileNotFoundError
@@ -462,7 +472,8 @@ if(verbosity == 3): # Maximum verbosity: literally just dump everything we have
'passwords_by_attempt_count': passwords_by_attempt_count,
'passwords_by_username': passwords_by_username,
'login_combos_by_ip': login_combos_by_ip,
- 'log_parsing_time': log_parsing_time
+ 'log_parsing_time': log_parsing_time,
+ 'total_log_size': total_filesize
}
outjson.update({'stats': all_stats})
@@ -495,7 +506,7 @@ elif(verbosity == 2): # High verbosity mode: print timestamp, event type and mes
print("\n--- Credential combos grouped by source IP: ---")
pprint(login_combos_by_ip, sort_dicts=False)
print_percentage_stats()
- print("Log took {}s to parse".format(str(log_parsing_time)[:4]))
+ print("---\nTook {}s to parse {} of logs".format(str(log_parsing_time)[:4], sizeof_fmt(total_filesize)))
@@ -575,4 +586,4 @@ else: # Default (low) verbosity: just the good stuff
print("\n--- Top IPs with credential combos tried: ---")
print_dict_of_lists(login_combos_by_ip, truncate=7, limit = 20, key_is_ip=True)
print_percentage_stats()
- print("Log took {}s to parse".format(str(log_parsing_time)[:4])) \ No newline at end of file
+ print("---\nTook {}s to parse {} of logs".format(str(log_parsing_time)[:4], sizeof_fmt(total_filesize))) \ No newline at end of file