Отправка файла на анализ virustotal

usergeyv

Знаток
Регистрация
5 Июл 2013
Сообщения
152
Реакции
25
Есть Код загрузчика файла на сервер upload.php
PHP:
<?php


////////////////////////////////////////////////////////

require_once("./config.php");
include("./header.php");

if(in_array($language, $LANGUAGE_LIST)) {
  include('./lang/'.$language.'.php');
} else {
  include('./lang/'.$LANGUAGE_LIST[0].'.php');
}

$junk = array('.' , ',' , '/' , '\\' , '`' , ';' , '[' , ']' , '-', "'", '*', '&', '^', '%', '$', '@', '!', '~', '+', '(', ')', '|', '{', '}', ' ', '?', ':', '"', '=', "<", ">", " &");
$multi = array('__', '___', '____', '_____', '______');

$filename = $_FILES['upfile']['1'];
$filename = str_replace("'",'',"$filename");
$filename = str_replace("&",'',"$filename");
//$filename = str_replace(" ",'%20',"$filename");
$filename = stripslashes("$filename");
$filesize = $_FILES['upfile']['size'];
$fancyurl=rand('1','999');
$rand2=("$fancyurl$filename");

$m=$shourturl;
if ($m=="true")
  $short= "";
else
  $short= "download.php?file=";

$bans=file("./secure/bans.mfh");
foreach($bans as $line)
{
  if ($line==$rand2."\n"){
?> <center><table style="margin-top:0px;width:790px;height:400px;"><tr><td style="border:1px #AAAAAA solid;height:100%;background-color:#FFFFFF;padding:20px;text-align:left;" valign=top>
<?
    echo "$lang[noallow]";
?></center></td></tr></table><p style="margin:3px;text-align:center"><?
    include("./footer.php");
    die();
  }
  if ($line==$_SERVER['REMOTE_ADDR']."\n"){
?><center><table style="margin-top:0px;width:790px;height:400px;"><tr><td style="border:1px #AAAAAA solid;height:100%;background-color:#FFFFFF;padding:20px;text-align:left;" valign=top>
   <? echo "$lang[nallow]";
?></center></td></tr></table><p style="margin:3px;text-align:center"><?
    include("./footer.php");
    die();
  }
}

if(isset($allowedtypes)){
$allowed = 0;
foreach($allowedtypes as $ext) {
  if(substr($filename, (0 - (strlen($ext)+1) )) == ".".$ext)
    $allowed = 1;
}
if($allowed==0) {
?><center><table style="margin-top:0px;width:790px;height:400px;"><tr><td style="border:1px #AAAAAA solid;height:100%;background-color:#FFFFFF;padding:20px;text-align:left;" valign=top><?
   echo "$lang[itype]";
   ?></center></td></tr></table><p style="margin:3px;text-align:center"><?
include("./footer.php");
   die();
}
}

if(isset($categorylist)){
$validcat = 0;
foreach($categories as $cat) {
  if($_POST['category']==$cat || $_POST['category'] = ""){ $validcat = 1; }
}
if($validcat==0) {
?><center><table style="margin-top:0px;width:790px;height:400px;"><tr><td style="border:1px #AAAAAA solid;height:100%;background-color:#FFFFFF;padding:20px;text-align:left;" valign=top><?
   echo "$lang[icat]";
?></center></td></tr></table><p style="margin:3px;text-align:center"><?
   include("./footer.php");
   die();
}
$cat = $_POST['category'];
} else { $cat = ""; }

if($filesize==0) {
?><center><table style="margin-top:0px;width:790px;height:400px;"><tr><td style="border:1px #AAAAAA solid;height:100%;background-color:#FFFFFF;padding:20px;text-align:left;" valign=top><?
echo "$lang[dpick]";
?></center></td></tr></table><p style="margin:3px;text-align:center"><?
include("./footer.php");
die();
}

$filesize = $filesize / 1048576;

if($filesize > $maxfilesize) {
?><center><table style="margin-top:0px;width:790px;height:400px;"><tr><td style="border:1px #AAAAAA solid;height:100%;background-color:#FFFFFF;padding:20px;text-align:left;" valign=top><?
echo "$lang[tlarge]";
?></center></td></tr></table><p style="margin:3px;text-align:center"><?
include("./footer.php");
die();
}

$userip = $_SERVER['REMOTE_ADDR'];
$time = time();

if($filesize > $nolimitsize)
{
$newfile = "./uploader/".$userip.".mfh";
$f=fopen($newfile, "w");
fwrite ($f,$userip."|".$time."|");
fclose($f);
chmod($newfile,0777);
}

$passkey = rand(100000, 999999);

if($emailoption && isset($_POST['myemail']) && $_POST['myemail']!="") {
$rand2 = urlencode($rand2);
$uploadmsg = "$lang[ufile] (".$filename.") $lang[wup].\n  ". $lang[udownfile] . ":" . $scripturl . "$short" . $rand2 . "\n ". $lang[udeletefile] . ":" . $scripturl . "$short" . $rand2 . "&del=" . $passkey . "&ignore=" . "\n $lang[thank]";
mail($_POST['myemail'],"Your Uploaded File",$uploadmsg,"From: ". $email ."\n");
$rand2 = urldecode($rand2);
}

if($passwordoption && isset($_POST['pprotect'])) {
  $passwerd = md5($_POST['pprotect']);
} else { $passwerd = md5(""); }

if($descriptionoption && isset($_POST['descr'])) {
  $description = strip_tags($_POST['descr']);
} else { $description = ""; }

$filelist = fopen("./files/".$rand2.".mfh","w");
fwrite($filelist, $rand2 ."|". basename($_FILES['upfile']['name']) ."|". $passkey ."|". $userip ."|". $time."|0|".$description."|".$passwerd."|".$cat."|".$_POST['pprotect']."|\n");

$movefile = "./storage/" . $rand2;
move_uploaded_file($_FILES['upfile']['tmp_name'], $movefile);
?>
<center><table style="margin-top:0px;width:790px;height:400px;"><tr><td style="border:1px #AAAAAA solid;height:100%;background-color:#FFFFFF;padding:20px;text-align:left;" valign=top>

<?
include("./ads.php");
echo "<center><b> $lang[yupfile] </b></center><br />";
echo "<center> $lang[udownfile] </center> <p><center> <a href=\"" . $scripturl . "$short" . $rand2 . "\">". $scripturl . "$short" . $rand2 . "</a><br />";
echo "<p><center> $lang[udeletefile] </center> <p><center> <a href=\"" . $scripturl . "$short" . $rand2 . "&del=" . $passkey . "&ignore=" . " \">". $scripturl . "$short" . $rand2 . "&del=" . $passkey . "&ignore=" . "</a><br />";
echo "<p><center> $lang[uremfile]."; ?><p><?
include("./bottomads.php");
?>

  </td></tr></table></center>
<?

include("./footer.php");


?>

Как к нему прикрутить отправку загружаемого файла на virustotal, вот весь код с выводом результата,а нужно только отправить
virustotal_api.php
PHP:
<?php


/*
PHP code for scanning files for viruses using virustotal.com API
File coded by Adrian at www.TheWebHelp.com
*/

header("Content-Type: text/plain");

// edit the virustotal.com api key, get one from the site
$virustotal_api_key = "f885fb3502";

// enter here the path of the file to be scanned
$file_to_scan = "some_files/file.exe";

// get the file size in mb, we will use it to know at what url to send for scanning (it's a different URL for over 30MB)
$file_size_mb = filesize($file_to_scan)/1024/1024;

// calculate a hash of this file, we will use it as an unique ID when quering about this file
$file_hash = hash('sha256', file_get_contents($file_to_scan));


// [PART 1] hecking if a report for this file already exists (check by providing the file hash (md5/sha1/sha256)
// or by providing a scan_id that you receive when posting a new file for scanning
// !!! NOTE that scan_id is the only one that indicates file is queued/pending, the others will only report once scan is completed !!!
$report_url = 'https://www.virustotal.com/vtapi/v2/file/report?apikey='.$virustotal_api_key."&resource=".$file_hash;

$api_reply = file_get_contents($report_url);

// convert the json reply to an array of variables
$api_reply_array = json_decode($api_reply, true);



// your resource is queued for analysis
if($api_reply_array['response_code']==-2){
    echo $api_reply_array['verbose_msg'];
}

// reply is OK (it contains an antivirus report)
// use the variables from $api_reply_array to process the antivirus data
if($api_reply_array['response_code']==1){
    echo "\nWe got an antivirus report, there were ".$api_reply_array['positives']." positives found. Here is the full data: \n\n";
    print_r($api_reply_array);
    exit;
}



// [PART 2] a report for this file was not found, upload file for scanning
if($api_reply_array['response_code']=='0'){

    // default url where to post files
    $post_url = 'https://www.virustotal.com/vtapi/v2/file/scan';

    // get a special URL for uploading files larger than 32MB (up to 200MB)
    if($file_size_mb >= 32){
        $api_reply = @file_get_contents('https://www.virustotal.com/vtapi/v2/file/scan/upload_url?apikey='.$virustotal_api_key);
        $api_reply_array = json_decode($api_reply, true);
        if(isset($api_reply_array['upload_url']) and $api_reply_array['upload_url']!=''){
            $post_url = $api_reply_array['upload_url'];
        }
    }
 
    // send a file for checking

    // curl will accept an array here too:
   
    $api_reply_array = json_decode($api_reply, true);
 
   if($api_reply_array['response_code']==1){
        echo "\nfile queued OK, you can use this scan_id to check the scan progress:\n".$api_reply_array['scan_id'];
        echo "\nor just keep checking using the file hash, but it will only report once it is completed (no 'PENDING/QUEUED' reply will be given).";
    }

}

?>
Прошу показать готовый код
 
Последнее редактирование:
Делаю в upload.php вот так :
PHP:
// edit the virustotal.com api key, get one from the site
$virusTotalAPI = 'f885fb35025382c67ec';

// Query VirusTotal
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, 'https://www.virustotal.com/vtapi/v2/file/scan');
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, 'file=' . $_FILES["file"] . '&apikey=' . $virusTotalAPI);
curl_exec($ch);
curl_close($ch);
sleep(3);
?>
не хочет отправлять , вставлял $_FILES["file"] и $_FILES и $_POST['file']
 
Попробуй $_FILES['file']['tmp_name'] или $_FILES['upfile']['tmp_name'] — я не вижу какой там «name» у Вас в форме у input type="file"
не хочет .
Другим скриптом отправлять пытался
PHP:
<?php
$VTAPIKEY="f885fb35025382c";
$apiEndPoint="http://www.virustotal.com/vtapi/v2/file/scan";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$apiEndPoint);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$json = curl_exec ($ch);
$j=  json_decode($json);
if($j->response_code==1){
    $md5=$j->md5;
    echo "File Queued Wating for Results
";
    echo "The MD5 hash of the file is $md5";
    //Wait for 2 Minutes and check againg
    //with the first approach describe above
    //using the MD5 hash.
}else{
    echo "Something went wrong. Receive Error: $j->verbose_msg";
}
?>
Пишет
Код:
Something went wrong. Receive Error: Invalid submission format, the uploaded file must travel as a multipart MIME message, please review the documentation
 
Последнее редактирование:
Something went wrong. Receive Error: Invalid submission format, the uploaded file must travel as a multipart MIME message, please review the documentation
Так выж походу мультипарт к форме забыли добавить.
Я советую приводить код целиком. Третий раз пишете, а код формы зажали.
В форме для загрузки файлов должно быть обязательно
HTML:
 enctype="multipart/form-data"
Подробнее — Для просмотра ссылки Войди или Зарегистрируйся
 
Так выж походу мультипарт к форме забыли добавить.
Я советую приводить код целиком. Третий раз пишете, а код формы зажали.
В форме для загрузки файлов должно быть обязательно
HTML:
 enctype="multipart/form-data"
Подробнее — Для просмотра ссылки Войди или Зарегистрируйся

Решено
 
Назад
Сверху