好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

用.htaccess限制执行文件类型 - 网站安全 - 自学p

 

现在一般都是使用黑名单的方法过滤非法字符,不过黑名单也有它的不足。怎么才能用白名单过滤呢

在.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

查看更多关于用.htaccess限制执行文件类型 - 网站安全 - 自学p的详细内容...

  阅读:43次