首页 » 后端 » Apache » 正文

IIS和Apache的安全特性,各一个

发布者:站点默认
2011/10/30 浏览数(2,015) 分类:Apache, Windows, 数据安全 IIS和Apache的安全特性,各一个已关闭评论

IIS 6.0

目录名里包含有“.asp”文件会导致其目录下任意文件当做 asp 文件来运行。如果把 webshell 保存为 webshell.gif,当访问http://xxxx.xxx/webshell.gif 时 webshell.gif 被当作asp文件来解析。

apache

apache 解析文件名时,后缀是从后面开始检查,按最后一个合法后缀执行。如:install.php.bak 因为 bak 不被 apache 解析,所以 apache 把这个文件当php文件解析了. 很多web程序安装后,默认会把install.php改名为install.php.lock,install.php.bak等……


IIS7的解决办法:

将 web.config、forbiden.php 放入网站根目录,代码如下:

<!-- web.config -->
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
	<system.webServer>
		<rewrite>
			<rules>
				<rule name="uploads">
					<match url="uploads/(.*).(php)$" />
					<action type="Rewrite" url="/forbiden.php?s={R:1}" /> </rule>
				<rule name="data">
					<match url="data/(.*).(php)$" />
					<action type="Rewrite" url="/forbiden.php?s={R:1}" /> </rule>
				<rule name="templets">
					<match url="templets/(.*).(php)$" />
					<action type="Rewrite" url="/forbiden.php?s={R:1}" /> </rule>
				<rule name="html">
					<match url="html/(.*).(php)$" />
					<action type="Rewrite" url="/forbiden.php?s={R:1}" /> </rule>
			</rules>
		</rewrite>
	</system.webServer>
</configuration>
// forbiden.php
<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="refresh" content="4; url=http://www.dstdaf.com/" />
	<title>404</title>
</head>
<body>
	<p>3秒后会转到首页...</p>
	<h1>没有找到您要查看的页面!</h1>
	<p>[回首页] [报告错误]</p>
</body>
</html>

Apache可以参考这个办法应对:

将以下代码放入“httpd.conf”或相应的虚拟主机配件文件中:

# 如果路径中同时存在 upload、js、image 和 .php、jsp、asp 就禁止访问
<DirectoryMatch "(upload(.*)\/|js(.*)\/|image(.*)\/)">
   <FilesMatch "\.((php.?|aspx?|jsp)|((php.?\.|jsp\.|aspx?\.).*))$">
      Order allow,deny
      Deny from all
   </FilesMatch>
</DirectoryMatch>

也给apache加个IIS的“漏洞”,让apache也把gif当php执行:

在当前目录放置一个.htaccess文件,内容如下:

AddType application/x-httpd-php .gif

<完>

点击返回顶部
  1. 留言
  2. 联系方式