From 4d1b77486eeba32ac8a1b3ebaba7a5ca20b76c5b Mon Sep 17 00:00:00 2001 From: Vince Rose Date: Mon, 4 May 2020 21:55:14 -0700 Subject: [PATCH] fix reporting log when there's nulls by using a safe string cast --- .gitignore | 10 ++++++---- lib/common/empire.py | 11 ++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 012870336..56af0f730 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,12 @@ data/empire.db data/empire-chain.pem data/empire-priv.key +data/credentials.csv +data/master.log +data/sessions.csv +data/obfuscated_module_source/*.ps1 +data/misc/ToObfuscate.ps1 +data/misc/Obfuscated.ps1 empire.debug *.pyc downloads/* @@ -8,13 +14,9 @@ downloads/* .idea/* *.txt LastTask* -data/obfuscated_module_source/*.ps1 -data/misc/ToObfuscate.ps1 -data/misc/Obfuscated.ps1 setup/xar*/ setup/bomutils/ .venv .DS_Store venv/ addons/ -.gitignore diff --git a/lib/common/empire.py b/lib/common/empire.py index d41e7e5a9..5626bca23 100644 --- a/lib/common/empire.py +++ b/lib/common/empire.py @@ -48,6 +48,12 @@ from zlib_wrapper import compress from zlib_wrapper import decompress +def xstr(s): + """Safely cast to a string with a handler for None""" + if s is None: + return '' + return str(s) + # custom exceptions used for nested menu navigation class NavMain(Exception): """ @@ -138,7 +144,6 @@ def get_db_connection(self): self.lock.release() return self.conn - def handle_event(self, signal, sender): """ Whenver an event is received from the dispatcher, log it to the DB, @@ -1002,12 +1007,12 @@ def do_report(self, line): for n in range(len(row)): if isinstance(row[n], bytes): row[n] = row[n].decode('UTF-8') - f.write('\n' + row[0] + ' - ' + row[3] + ' (' + row[2] + ')> ' + str(row[5]) + '\n' + str(row[6]) + '\n' + str(row[7]) + '\n') + f.write('\n' + xstr(row[0]) + ' - ' + xstr(row[3]) + ' (' + xstr(row[2]) + ')> ' + xstr(row[5]) + '\n' + xstr(row[6]) + '\n' + xstr(row[7]) + '\n') f.close() cur.close() finally: self.lock.release() - + def complete_usemodule(self, text, line, begidx, endidx, language=None): "Tab-complete an Empire module path."