现在一般都是使用黑名单的方法过滤非法字符,不过黑名单也有它的不足。怎么才能用白名单过滤呢
在.htaccess里定义
<</>Files ~ “.*”>
Deny from all
<</>/Files>
<</>FilesMatch “(1\.txt)|(2\.txt)”>
Allow from all
<</>/FilesMatch>
这样就只允许访问1.txt和2.txt
不过在wordpress环境下如何进行设置呢,(因为本站用的就是WP)
<</>Files ~ “.*”>
Deny from all
<</>/Files>
<</>FilesMatch “(.*\.jpg)|(.*.gif)|(.*\.png)|(.*\.bmp)|(wp\-.*)|(index\.php)”>
Allow from all
<</>/FilesMatch>
这样设置就是只允许访问 *.jpg *.gif *.png *.bmp wp-* 以及 index.php
这样设置和WP结构一样,因为WP的结构就是wp-*
如果有人非法上传了例如 1fhds034hj2k4234.php的非法文件,也无法运行,因为他不在白名单里,在
<</>Files ~ “.*”>
Deny from all
<</>/Files>
的时候就已经过滤掉了

转载请注明来自WebShell'S Blog,本文地址:https://www.webshell.cc/2325.html