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

2024-10-02 10:21:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图创建一个PHP脚本,当有人点击一个按钮时,它将被调用,并将被带到vt.php现在我想下载基于VT散列的示例,这是从以前的PHP页面收到的,现在我尝试使用这个逻辑,但它不起作用。在

<?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;

?>

输出 C75B5E2CA63ADB462F4B941E0C9F509

预期输出 C75B5E2CA63ADB462F4B941E0C9F509 文件下移过程-----curl输出

当调用此页时,它只打印哈希而不下载文件。任何解决这个问题的建议?在

注意:Error in downloading file from VirusTotal only on server?——前面在这里问过这个问题,使用python这个或那个都会有帮助。在


Tags: 文件echo脚本outputdownloadhashcurlcommand
1条回答
网友
1楼 · 发布于 2024-10-02 10:21:18

您可以直接使用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);
?>

相关问题 更多 >

    热门问题