Retreive External files Via HTTP using WHS Scritps


Sorry guys for being this much late in writing this blog entry. Was busy with lot of stuffs in between and was feeling bad. Anyways, starting with WHS scripts, and would keep on writing abou more things which i had learnt in between these days.


Windows Script Host (WSH) is a scripting environment developed by Microsoft
for automation of tasks in the Windows operating system. It has been used extensively by
Windows system and network administrators. WSH scripts have also been shipped by
Microsoft as an integral part of various Windows operating systems and products such as
the IIS web server. In contrast to well-known hacking tools, text based WSH scripts are
less likely to be flagged by signature based virus scanners as malware—a desirable
attribute for an attacker trying to avoid detection.


The following script utilizes the XMLHTTP COM object (Microsoft), which is
present on most Windows systems, to download files via the HTTP protocol. This can be
a useful tool to retrieve binaries since firewall rules usually permit inbound HTTP traffic.



' XmlHttpGetBinary.vbs
' This script invokes the XMLHTTP object to download the file specified
' in the URL passed on the command line and saves it to the specified
' file name.
dim XmlHttp, Args, StdOut, URL, FileName, AsynchRequest, OutputStream
const BINARY_STREAM_TYPE = 1
const CREATE_OVERWRITE_SAVE_MODE = 2

set StdOut = WScript.StdOut
set Args = WScript.Arguments
if Args.Count <> 2 then
StdOut.WriteLine "Usage: xmlhttpGetBinary "
WScript.Quit
end if
URL = Args.Item(0)
FileName = Args.Item(1)
set XmlHttp = WScript.CreateObject("MSXML2.XMLHTTP")
set OutputStream = WScript.CreateObject("ADODB.Stream")
AsynchRequest = false
XmlHttp.Open "GET", URL, AsynchRequest
XmlHttp.Send
OutputStream.Type = BINARY_STREAM_TYPE
OutputStream.Open
OutputStream.Write XmlHttp.responseBody
OutputStream.SaveToFile FileName, CREATE_OVERWRITE_SAVE_MODE
OutputStream.Close
StdOut.Close
set XmlHttp = nothing
set AsynchRequest = nothing
set OutputStream = nothing


In Order to compile these scripts,we need WSH Interpreters. here i amwriting a little overview of WSH Interpreters.



WSH can be run in protected-mode using the Wscript.exe interpreter (typically
used for scripts that require user interaction via popup dialog windows) or in real-mode
using the command line Cscript.exe (Microsoft, 2007). Unless otherwise noted, scripts
mentioned in this paper are intended to be executed via the command line Cscript.exe
interpreter.
WSH scripts are written in either JScript or VBScript as uncompiled text files
with extensions of “.js” or “.vbs” respectively. The Microsoft TechNet
extensive documentation and examples of WSH scripting.





0 Responses to “Retreive External files Via HTTP using WHS Scritps”

Post a Comment