我的网站最近遭到了攻击,在我看来,这是一个无辜的代码:
<?php
if ( isset( $ _GET['page'] ) ) {
include( $ _GET['page'] . ".php" );
} else {
include("home.php");
}
?>
那里没有 SQL 调用,所以我不担心 SQL 注入。但显然,SQL 并不是唯一的注入方式。
这个网站有一个解释和一些避免代码注入的例子:http://www.theserverpages.com/articles/webmasters/php/security/Code_Injection_Vulnerability_Explained.html http://www.theserverpages.com/articles/webmasters/php/security/Code_Injection_Vulnerabilities_Explained.html
您将如何保护此代码免遭代码注入?
使用白名单并确保页面在白名单中:
$whitelist = array('home', 'page');
if (in_array($_GET['page'], $whitelist)) {
include($_GET['page'].'.php');
} else {
include('home.php');
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)