bil*_*rky 11 php security file-upload
堆,
我想用clam anti-virus的clamscan工具扫描每个通过我的php上传脚本上传的文件.我想我写了一个很好的剧本,但我想把它跑过你们.
假设我发送到这个php上传脚本的文件被命名为"uploadedfile",下面的代码是否有意义?
<?php
$safe_path = escapeshellarg('/tmp/' . $_FILES['uploadedfile']['tmp_name']);
$command = 'clamscan ' . $safe_path;
$out = '';
$int = -1;
exec($command, $out, $int);
if ($int == 0) {
// all good, code goes here uploads file as normal IE move to
permanent directory etc;
} else {
unlink('/tmp/' . $_FILES['uploadedfile']['tmp_name']);
header(Location: http://www.domain.com/uploadform.php?error=your-file-was-infected-pal);
}
?>
Run Code Online (Sandbox Code Playgroud)
还有,clamscan会发现php shell以及传统的旧恶意软件吗?
谢谢!
我回答了自己的问题,但没有正式的声誉.这是anser:
对于那些追求的人.我已经使用EICAR测试病毒文件http://eicar.org/86-0-Intended-use.html测试了这个脚本,经过一些调整后它可以工作.返回变量$ int是告诉您文件是否安全的原因.如果$ int为0,则未发现病毒,如果$ int为1,则发现病毒.但是,我必须进行一些更改才能使脚本工作(我更新了$ safe_path变量是正确的),这是工作脚本:
<?php
$safe_path = escapeshellarg($_FILES['uploadedfile']['tmp_name']);
$command = 'clamscan ' . $safe_path;
$out = '';
$int = -1;
exec($command, $out, $int);
if ($int == 0) {
// all good, code goes here uploads file as normal IE move to
permanent directory etc;
} else {
//whatever you need to do if a virus is found.
}
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8775 次 |
| 最近记录: |