Windows脚本功能可以通过一些简单的语句就可以完成对注册表、进程以及文件的操作。因此可以利用Windows脚本来编写一些简单病毒的专杀工具。
“简妮”病毒是最近流传比较广的QQ尾巴蠕虫之一,它会自动向用户的QQ好友发送内容为“!@#$%,给你看段经典的小电影! ;http://www.517ting.com/down/down.asp?id=XXXX”的消息,点击这个地址就会下载到这个病毒文件。
粗略的分析一下这个病毒,从网站下载的病毒文件名为:asdf.exe,采用RealOne播放器的图标。
病毒运行后会向系统目录中写入“gedit.exe”、“msscript.exe”、“systemr.exe”和“wups32.dll”几个文件。
同时添加两个注册表启动项目:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run:systemr和HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows:load。
手工清除这个病毒大致分为三步:1、结束病毒进程;2、删除病毒文件;3、删除/修复被病毒改写的注册表项目。Windows的脚本功能刚好提供了进程、注册表和文件的操作,因此我们可以编写一个脚本来查杀此类病毒。
程序模块:
1、 FoundVirus函数
该模块用于查找病毒,如果发现病毒则返回True,否则返回False。
'检查是否感染病毒
Function FoundVirus()
Dim fso,syspath,filepath1,filepath2,filepath3,filepath4
Set fso = CreateObject("Scripting.FileSystemObject")
Const SystemFolder = 1
syspath = fso.GetSpecialFolder(SystemFolder) 'GetSpecialFolder用于取特殊目录,参
'数为1时取系统目录
filepath1 = syspath + "\gedit.exe" 'filepath1到filepath4用于保存病毒文件的路径信息
filepath2 = syspath + "\msscript.exe"
filepath3 = syspath + "\systemr.exe"
filepath4 = syspath + "\wups32.dll"
If (fso.FileExists(filepath1) or fso.FileExists(filepath2) or fso.FileExists(filepath3) _or fso.FileExists(filepath4)) Then
FoundVirus = True '有病毒返回True
Else
FoundVirus = False '否则返回 False
End If
End Function
2、TermRAMVirus 函数
该模块用于结束病毒的进程。
Function TermRAMVirus()
Dim strComputer,objWMIService,objProcess,colProcessList
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'gedit.exe'") '从进程中查询gedit.exe
For Each objProcess in colProcessList
objProcess.Terminate() '结束病毒进程
Next
Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'msscript.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'systemr.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
WScript.Sleep (3000) '等待3秒 '等待三秒,使病毒进程完全被结束
End Function
3、DelVirusFiles 函数
该模块用户删除病毒文件。
Function DelVirusFiles()
Dim fso,syspath,filepath1,filepath2,filepath3,filepath4
Set fso = CreateObject("Scripting.FileSystemObject")
Const SystemFolder = 1
syspath = fso.GetSpecialFolder(SystemFolder)
filepath1 = syspath + "\gedit.exe"
filepath2 = syspath + "\msscript.exe"
filepath3 = syspath + "\systemr.exe"
filepath4 = syspath + "\wups32.dll"
fso.DeleteFile(filepath1) '删除病毒文件
fso.DeleteFile(filepath2)
fso.DeleteFile(filepath3)
fso.DeleteFile(filepath4)
End Function
4、FixReg函数
该模块用户修复被病毒改写的注册表信息。
Function FixReg()
dim WShell
set WShell=WScript.CreateObject("WScript.Shell")
On Error Resume Next
WShell.RegDelete _"HKLM\\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\systemr"
WShell.RegWrite "HKCU\Software\Microsoft\Windows _NT\CurrentVersion\Windows\load", "", "REG_SZ"
On Error Goto 0
set WShell=Nothing
End Function
主程序:
Option Explicit ‘强制变量必须声明后引用
IF FoundVirus = False THEN
MsgBox "没有发现病毒",64 '如果没有发现病毒,弹出提示框告知用户
Wscript.Quit(1) '退出程序
END IF
IF MsgBox ("发现病毒,是否清除?",36,"发现病毒") = 6 THEN '发现病毒后弹出对话框
'提示用户是否清除,当用户选择“是”,开始清除病毒。
TermRAMVirus() '结束病毒进程
DelVirusFiles() '删除病毒文件
FixReg() '修复注册表
IF FoundVirus = False THEN '再次检查病毒文件是否存在
MsgBox "病毒清除成功",64 '不存在则表示清除成功
ELSE
MsgBox "清除病毒失败",48 '否则清除失败
END IF
END IF
Windows的脚本还有其他很强大的功能,如果合理使用,可以为我们的日常工作带来很大方便。Trackback: http://tb.donews.net/TrackBack.aspx?PostId=462927