30 文件安全

 作者:老葛,北京亚艾元软件有限责任公司,http://www.yaiyuan.com

在以前,如果你把Drupal站点安装在了IIS上,由于Drupal没有提供IIS下面的配置文件,假定你又不熟悉IIS的配置的话,那么有可能其它用户能将你的module文件下载到本地。通过查看页面源代码,就能看到JS的路径信息,如果JS没有压缩,就可以推测出来module文件的所在,直接访问.module文件,便可以将其下载到本地。

Drupal自带的.htaccess文件包含了以下代码,可以保护后台程序文件不被他人下载:

# Protect files and directories from prying eyes.

<FilesMatch "\.(engine|inc|info|install|module|profile|po

|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(code-style\.pl

|Entries.*|Repository|Root|Tag|Template)$">

Order allow,deny

</FilesMatch>

 

Order指令设为了allow,deny,这意味着默认的行为是拒绝。对于匹配上述规则的文件的请求,都会被拒绝访问。如果直接我们访问:http://localhost/thinkindrupal/sites/all/modules/custom/sql_injection/sql_injection.module。此时会得到一个拒绝访问页面。

图片1.png 

 

如果我们将“Order allow,deny”修改为“Order deny,allow”,此时再访问这个页面,我们竟可以下载这个文件了。

图片2.png 

 

对于IIS服务器,Drupal7自带的web.config里面也包含和.htaccess对应的规则:

<rule name="Protect files and directories from prying eyes" stopProcessing="true">

<match url="\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$" />

<action type="CustomResponse" statusCode="403" subStatusCode="0" statusReason="Forbidden" statusDescription="Access is forbidden." />

</rule>


 


Drupal版本: