王新阳

wangxinyang

因网站漏洞被上传木马的解决方法

网站被上传木马,导致页面被植入恶意链接,如果找不到漏洞,可以用 .htaccess 或 web.config 屏蔽木马程序的运行,确保网站的"相对"安全。

.htaccess

RewriteEngine on
RewriteRule (uploadfile.+\.(php|asp|aspx|jsp))$ /rec.php?uri=$1 [R,NC,L]

web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="规则 1" stopProcessing="true">
                    <match url="(uploadfile.+\.(php|asp|aspx|jsp))$" />
                    <action type="Redirect" url="/rec.php?uri={R:1}" appendQueryString="false" redirectType="Found" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

上面规则是阻止上传文件目录 uploadfile 中 php/asp/aspx/jsp 等类型文件的运行,并跳转到 /rec.php 进行记录(也可以重定向到百度……)。虽然没有解决漏洞,至少确保了木马文件不能运行。

2018-01-18
2024-05-03 星期五 农历三月二十五