2024年3月7日发(作者:)

1 VBS

VBS脚本病毒的大量流行使我们对VBS的功能有了一个全新的认识,现在大家对它也开始重视起来。VBS代码在本地是通过Windows Script Host(WSH)解释执行的。VBS脚本的执行离不开WSH,WSH是微软提供的一种基于32位Windows平台的、与语言无关的脚本解释机制,它使得脚本能够直接在Windows桌面或命令提示符下运行。利用WSH,用户能够操纵WSH对象、ActiveX对象、注册表和文件系统。在Windows 2000下,还可用WSH来访问Windows NT活动目录服务。

用VBS编写的脚本程序在窗口界面是由wscript。exe文件解释执行的,在字符界面由cscript。exe文件解释执行。是一个脚本语言解释器,正是它使得脚本可以被执行,就象执行批处理一样。关于VBS大家一定比我熟悉多了,所以再不废话,直接进入主题,看看我总结的VBS在系统安全中的八则妙用吧。

一、给注册表编辑器解锁

用记事本编辑如下内容:

DIM WSH

SET WSH=Object("”) '击活对象

WSH。POPUP(”解锁注册表编辑器!”)

’显示弹出信息“解锁注册表编辑器!”

WSH。Regwrite"HKCU/Software/Microsoft/Windows/CurrentVersion

/Policies/System/DisableRegistryTools",0,”REG_DWORD”

’给注册表编辑器解锁

(”注册表解锁成功!")

’显示弹出信息“注册表解锁成功!"

保存为以.vbs为扩展名的文件,使用时双击即可。

二、关闭Win NT/2000的默认共享

用记事本编辑如下内容:

Dim WSHShell’定义变量

set WSHShell=CreateObject(””) ’创建一个能与操作系统沟通的对象WSHShell

Dim fso,dc

Set fso=CreateObject("Scripting。FileSystemObject”)’创建文件系统对象

set dc= ’获取所有驱动器盘符

For Each d in dc

Dim str

(”net share”&etter &"$ /delete")’关闭所有驱动器的隐藏共享

next

("net share admin$ /delete”)

("net share ipc$ /delete")’关闭admin$和ipc$管道共享

现在来测试一下,先打开,输入net share命令就可以看到自己机子上的共享.双击执行stopshare。vbs后,会看见窗口一闪而过.然后再在cmd里输入net share命令,这时候没有发现共享列表了

三、显示本机IP地址

有许多时候,我们需要知道本机的IP地址,使用各种软件虽然可以办到,但用VBS脚本也非常的方便.用记事本编辑如下内容:

Dim WS

Set WS=CreateObject(”k”)

IPAddress=P

MsgBox ”Local IP=” & IPAddress

将上面的内容保存为,双击执行即可得到本机IP地址。

四、利用脚本编程删除日志

入侵系统成功后黑客做的第一件事便是清除日志,如果以图形界面远程控制对方机器或是从终端登陆进入,删除日志不是一件困难的事,由于日志虽然也是作为一种服务运行,但不同于http,ftp这样的服务,可以在命令行下先停止,再删除,在命令行下用net stop eventlog是不能停止的,所以有人认为在命令行下删除日志是很困难的,实际上不是这样,比方说利用脚本编程中的VMI就可以删除日志,而且非常的简单方便。源代码如下:

strComputer= ”。”

Set objWMIService = GetObject(”winmgmts:" _

& ”{impersonationLevel=impersonate,(Backup)}!//" & _

strComputer & ”/root/cimv2")

dim mylogs(3)

mylogs(1)="application"

mylogs(2)=”system"

mylogs(3)=”security"

for Each logs in mylogs

Set colLogFiles=ery _

("Select * from Win32_NTEventLogFile where LogFileName='"&logs&”’")

For Each objLogfile in colLogFiles

objLogFile。ClearEventLog()

2 VBS

Next

next

将上面的代码保存为cleanevent。vbs文件即可。在上面的代码中,首先获得object对象,然后利用其clearEventLog()方法删除日志.建立一个数组,application,security,system,如果还有其他日志也可以加入数组。然后用一个for循环,删除数组中的每一个元素,即各个日志。

五、利用脚本伪造日志

删除日志后,任何一个有头脑的管理员面对空空的日志,马上就会反应过来被入侵了,所以一个聪明的黑客的学会如何伪造日志。利用脚本编程中的eventlog方法创造日志非常简单,请看下面的代码:

set ws=wscript。createobject(”")

nt 0 ,"write log success” ’创建一个成功执行日志

将上面的代码保存为即可。这段代码很容易理解,首先获得wscript的一个shell对象,然后利用shell对象的logevent方法。logevent的用法:logevent eventtype,"description"

[,remote system],其中eventtype为日志类型,可以使用的参数如下:0代表成功执行,1执行出错,2警告,4信息,8成功审计,16故障审计。所以上面代码中,把0改为1,2,4,8,16均可,引号中的内容为日志描述。利用这种方法写的日志有一个缺点,即只能写到应用程序日志,而且日志来源只能为WSH,即Windows Scripting Host,所以不能起太多的隐蔽作用,

在此仅供大家参考。

六、禁用开始菜单选项

用记事本编辑如下内容:

Dim ChangeStartMenu

Set ChangeStartMenu=Object("WScript。Shell”)

RegPath="HKCR/Software/Microsoft/Windows/CurrentVersion/Policies/”

Type_Name="REG_DWORD"

Key_Data=1

StartMenu_Run="NoRun"

StartMenu_Find="NoFind”

StartMenu_Close="NoClose"

Sub Change(Argument)

te RegPath&Argument,Key_Data,Type_Name

MsgBox(”Success!”)

End Sub

Call Change(StartMenu_Run) ’禁用“开始”菜单中的“运行”功能

Call Change(StartMenu_Find) ’禁用“开始”菜单中的“查找”功能

Call Change(StartMenu_Close) ’禁用“开始”菜单中的“关闭系统"功能

将以上代码保存为ChangeStartMenu。vbs文件,使用时双击即可.

七、执行外部程序

用记事本编辑如下内容:

DIM objShell

set objShell=Object("wscript。shell")

iReturn=(”cmd。exe /C set var=world”, 1, TRUE)

保存为.vbs文件即可。在这段代码中,我们首先设置了一个环境变量,其名为var,而值为world,用户可以使用%Comspec%来代替,并且可以把命令:set var=world改成其它的命令,这样就可以使它可以运行任意的命令。

八、重新启动指定的IIS服务

用记事本编辑如下内容:

Const ADS_SERVICE_STOPPED = 1

Set objComputer = GetObject(”WinNT://MYCOMPUTER,computer”)

Set objService = objComputer。GetObject("Service","MYSERVICE")

If ( = ADS_SERVICE_STOPPED) Then

objService。Start

End If

将它以startsvc。vbs为名保存在C盘根目录.并通过如下命令执行:cscript c:/。运行后,经你指定的IIS服务项将被重新开启。

最后,我们再说说开篇时提到的VBS脚本病毒的防范方法.VBS病毒的执行离不开WSH,在带给人们便利的同时,WSH也为病毒的传播留下可乘之机。所以要想防范VBS病毒,可以选择将WSH卸载,只要打开控制面板,找到“添加/删除程序”,点选“Windows安装程序”,再鼠标双击其中的“附件”一项,然后再在打开的窗口中将“Windows Scripting Host"一项

的“√”去掉,然后连续点两次“确定"就可以将WSH卸载。或者,你也可以点击“我的电脑”→“查看”→“文件夹选项”,在弹出的对话框中,点击“文件类型”,然后删除VBS、VBE、JS、JSE文件后缀名与应用程序的映射,都可以达到防范VBS脚本病毒的目的。

3 如何确定哪些 USB 设备已连接到计算机上?

strComputer = ”."

Set objWMIService = GetObject("winmgmts://” & strComputer & "/root/cimv2")

Set colDevices = ery _

("Select * From Win32_USBControllerDevice")

For Each objDevice in colDevices

strDeviceName = objDevice。Dependent

strQuotes = Chr(34)

strDeviceName = Replace(strDeviceName, strQuotes, ””)

arrDeviceNames = Split(strDeviceName, "=")

strDeviceName = arrDeviceNames(1)

Set colUSBDevices = objWMIService。ExecQuery _

("Select * From Win32_PnPEntity Where DeviceID = ’” & strDeviceName & ”'")

For Each objUSBDevice in colUSBDevices

objUSBDevice。Description

Next

Next

4 如何在指定的一段时间后自动消除消息框?

Const wshYes = 6

Const wshNo = 7

Const wshYesNoDialog = 4

Const wshQuestionMark = 32

Set objShell = CreateObject(”Wscript。Shell")

intReturn = ("Do you want to delete this file?", _

10, ”Delete File", wshYesNoDialog + wshQuestionMark)

If intReturn = wshYes Then

”You clicked the Yes button.”

ElseIf intReturn = wshNo Then

”You clicked the No button。”

Else

Wscript。Echo "The popup timed out.”

End If

5 回复 4:如何在指定的一段时间后自动消除消息框?

Const wshYes = 6

Const wshNo = 7

Const wshYesNoDialog = 4

Const wshQuestionMark = 32

Set objShell = CreateObject(”")

Set objFSO = CreateObject(”Scripting。FileSystemObject”)

intReturn = (”Do you want to delete this file?", _

10, "Delete File", wshYesNoDialog + wshQuestionMark)

If intReturn = wshNo Then

Wscript。Quit

End If

File(”c:/scripts/test。vbs")

6 回复:VBS

http://oft。com/china/technet/community/scriptcenter/resources/qanda/

7 如何在脚本中使用多选对话框?

Set objDialog = CreateObject("UserAccounts。CommonDialog")

= ”VBScript Scripts|*。vbs|All Files|*.*"

objDialog。Flags = &H0200

Index = 1

objDialog。InitialDir = "C:/Scripts”

intResult = objDialog。ShowOpen

If intResult = 0 Then

Wscript。Quit

Else

arrFiles = Split(me, ” ”)

For i = 1 to Ubound(arrFiles)

strFile = arrFiles(0) & arrFiles(i)

strFile

Next

End If

8 如何确定计算机上是否存在某个文件夹?

Set objNetwork = CreateObject("k”)

strUser = objNetwork。UserName

strPath = ”C:/Documents and Settings/” & strUser & "/Application Data/Microsoft/Templates”

Set objFSO = CreateObject(”stemObject")

If Exists(strPath) Then

"The folder exists."

Else

”The folder does not exist."

End If

9 如何列出文件夹及其所有子文件夹中的文件?

strComputer = "。"

Set objWMIService = GetObject("winmgmts://" & strComputer & ”/root/cimv2”)

strFolderName = ”c:/scripts"

Set colSubfolders = objWMIService。ExecQuery _

("Associators of {Win32_='" & strFolderName & "’} " _

& "Where AssocClass = Win32_Subdirectory " _

& "ResultRole = PartComponent”)

For Each objFolder in colSubfolders

GetSubFolders strFolderName

Next

Sub GetSubFolders(strFolderName)

Set colSubfolders2 = ery _

("Associators of {Win32_Directory。Name='” & strFolderName & "’} " _

& ”Where AssocClass = Win32_Subdirectory ” _

& ”ResultRole = PartComponent")

For Each objFolder2 in colSubfolders2

strFolderName =

GetSubFolders strFolderName

Next

End Sub

10 回复 9:如何列出文件夹及其所有子文件夹中的文件?

strComputer = "。”

Set objWMIService = GetObject(”winmgmts://" & strComputer & ”/root/cimv2")

strFolderName = ”c:/scripts”

Set colSubfolders = objWMIService。ExecQuery _

("Associators of {Win32_Directory。Name=’” & strFolderName & "'} " _

& "Where AssocClass = Win32_Subdirectory ” _

& ”ResultRole = PartComponent”)

strFolderName

arrFolderPath = Split(strFolderName, ”/”)

strNewPath = ””

For i = 1 to Ubound(arrFolderPath)

strNewPath = strNewPath & "//” & arrFolderPath(i)

Next

strPath = strNewPath & ”//”

Set colFiles = ery _

("Select * from CIM_DataFile where Path = '” & strPath & "’")

For Each objFile in colFiles

objFile。Name

Next

For Each objFolder in colSubfolders

GetSubFolders strFolderName

Next

Sub GetSubFolders(strFolderName)

Set colSubfolders2 = ery _

("Associators of {Win32_Directory。Name='" & strFolderName & ”'} " _

& "Where AssocClass = Win32_Subdirectory " _

& ”ResultRole = PartComponent”)

For Each objFolder2 in colSubfolders2

strFolderName = objFolder2。Name

arrFolderPath = Split(strFolderName, "/")

strNewPath = ”"

For i = 1 to Ubound(arrFolderPath)

strNewPath = strNewPath & ”//” & arrFolderPath(i)

Next

strPath = strNewPath & "//"

Set colFiles = objWMIService。ExecQuery _

(”Select * from CIM_DataFile where Path = ’” & strPath & ”'")

For Each objFile in colFiles

Wscript。Echo objFile。Name

Next

GetSubFolders strFolderName

Next

End Sub

11 如何在脚本播放一个声音?

strSoundFile = "C:/Windows/Media/"

Set objShell = CreateObject(”Wscript。Shell”)

strCommand = "sndrec32 /play /close ” & chr(34) & strSoundFile & chr(34)

objShell。Run strCommand, 0, True

12 如何在消息框中显示一个超链接?

Set objShell = CreateObject(””)

intMessage = Msgbox(”Would you like to apply for access to this resource?", _

vbYesNo, "Access Denied")

If intMessage = vbYes Then

(”http://www。microsoft。com")

Else

End If