I am trying to write a simple VBS script to download and execute a file. From wireshark I can verify that the file is being retrieved form the webserver, but it is not getting executed upon download. I am getting a "Invalid Character" on the "Execute" line. What am I doing wrong?
Set x=CreateObject("Microsoft.XMLHTTP")
x.Open "GET","http://website/file.exe",False
x.Send
Execute x.responseText
I would also like to remove the "If-Modified-Since" header from the GET request.
You aren't saving it to disk, therefore nothing to execute. Other things are wrong. Can't use text for binary, text gets auto converted. Likewise have to use binary streams to save it.
Put the following lines into a text file. Name it safetyscanner.vbs and put on desktop.
For 32 Bit Windows
Set fso = CreateObject("Scripting.FileSystemObject")
Set Outp = Wscript.Stdout
On Error Resume Next
Set File = WScript.CreateObject("Microsoft.XMLHTTP")
File.Open "GET", "http://definitionupdates.microsoft.com/download/definitionupdates/safetyscanner/x86/msert.exe", False
File.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C; .NET4.0E; BCD2000; BCD2000)"
File.Send
If err.number <> 0 then
Outp.writeline ""
Outp.writeline "Error getting file"
Outp.writeline "=================="
Outp.writeline ""
Outp.writeline "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description
Outp.writeline "Source " & err.source
Outp.writeline ""
Outp.writeline "HTTP Error " & File.Status & " " & File.StatusText
Outp.writeline File.getAllResponseHeaders
Outp.writeline Arg(1)
End If
On Error Goto 0
Set BS = CreateObject("ADODB.Stream")
BS.type = 1
BS.open
BS.Write File.ResponseBody
BS.SaveToFile "c:\users\safetyscanner.exe", 2