I am trying to use the public VirusTotal API to scan files. This is my code:
$post_url = 'https://www.virustotal.com/vtapi/v2/file/scan';
$filemime = exec("file -b --mime-type '$file_to_scan'");
$post = array('apikey' => $virustotal_api_key, 'file' => '@' . realpath($file_to_scan) . ';type=' . $filemime . ';filename=' . $name);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$post_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Expect:'));
$api_reply = curl_exec($ch);
curl_close($ch);
$api_reply_array = json_decode($api_reply, true);
Whenever I run this code, I get the following error:
[response_code] => 0
[verbose_msg] => Invalid submission format, the uploaded file must travel as a multipart MIME message, please review the documentation
I spent several hours trying to figure it out, but it just won't work. Can someone point me in the right direction?
This is print_rof $postin the code above:
[apikey] => xxx
[file] => @/absolute/path/to/file.exe;type=application/octet-stream;filename=file.exe
Thank!
source
share