无法从php脚本执行curl命令?

时间:2017-02-27 16:08:16

标签: php python python-2.7 curl post

我尝试创建一个PHP脚本,当有人点击某个按钮时会调用该脚本并将被带到vt.php现在我想根据现在从以前的PHP页面收到的VT哈希来下载样本我尝试使用这种逻辑,但它无法正常工作。

<?php


$fileHash = $_POST['hash'];

echo $fileHash;
#$command = escapeshellcmd("python vt_download.py $fileHash");
$command = escapeshellcmd("curl -v --location https://www.virustotal.com/vtapi/v2/file/download?apikey=APIKEY\&hash=$fileHash -o $fileHash");
$output = shell_exec($command);
echo $output;

?>

输出 c75b5e2ca63adb462f4bb941e0c9f509

预期输出 c75b5e2ca63adb462f4bb941e0c9f509 文件下行过程-------卷曲输出

当调用此页面时,它只打印哈希而不下载文件。有什么建议可以解决这个问题吗?

P.S:Error in downloading file from VirusTotal only on server? - 之前在这里问过这个问题,无论是使用python还是使用python都会有所帮助。

1 个答案:

答案 0 :(得分:1)

您可以直接使用PHP cURL library,而不是使用shell_exec功能,这可能会在使用用户输入的数据时迅速导致安全问题。

<?php
    $fileHash = $_POST['hash'];

    // Initializing cURL, we can put the URL in the curl_init function
    $ch = curl_init("https://www.virustotal.com/vtapi/v2/file/download?apikey=AP‌​IKEY&hash=$fileHash")

    // We need to retrieve the response, setting appropriate options :
    curl_setopt($ch , CURLOPT_RETURNTRANSFERT , true);

    // Executing the request
    $result = curl_exec($ch);

    // Error verification
    if (!$result){
        echo('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
    }
    curl_close($ch);
?>
相关问题