private function forceScanFileOnVirusTotal(&$file) { $api = new VirusTotalAPIV2($_ENV['VT_API_KEY']); $report = $api->scanFile($this->getFilePath($file)); if (isset($report->response_code)) { $this->setVTScannedStatus($file, $report->response_code); } if (isset($report->permalink)) { $file->vtlink = $report->permalink; } }
<?php require_once 'VirusTotalApiV2.php'; /* Initialize the VirusTotalApi class. */ $api = new VirusTotalAPIV2('myKey'); /* Upload and scan a local file. */ $result = $api->scanFile('/tmp/xxx'); $scanId = $api->getScanID($result); /* Can be used to check for the report later on. */ $api->displayResult($result); /* Get a file report. */ // $report = $api->getFileReport('Hash-of-a-file-to-check-for-a-report'); // $api->displayResult($report); // print($api->getSubmissionDate($report) . '<br>'); // print($api->getReportPermalink($report, TRUE) . '<br>'); // /* Scan an URL. */ // $result = $api->scanURL('URL-to-scan'); // $scanId = $api->getScanID($result); /* Can be used to check for the report later on. */ // $api->displayResult($result); // /* Get an URL report. */ // $report = $api->getURLReport('URL-to-check-for-a-report'); // $api->displayResult($report); // print($api->getTotalNumberOfChecks($report) . '<br>'); // print($api->getNumberHits($report) . '<br>'); // print($api->getReportPermalink($report, FALSE) . '<br>'); // /* Comment on a file. */ // $report = $api->makeComment('Hash-of-a-file-to-comment-on', 'Your-comment'); // $api->displayResult($report); // /* Comment on an URL. */ // $report = $api->makeComment('URL-to-comment-on', 'Your-comment'); // $api->displayResult($report);
function ForceScanFileOnVirusTotal($file, $send_file = true) { // Run it in a thread, so that info is updated silently //$vtworker = new ASyncVTScan($file); //$vtworker->start(); $api = new VirusTotalAPIV2($GLOBALS["config"]["virustotal"]["key"]); if ($send_file) { $result = $api->scanFile($file->path); } else { $result = $api->rescanFile($file->name); } if (isset($result->response_code)) { $file->scanned = $result->response_code; // If file has been sent for analysis, we set the result to according response code if ($file->scanned == 1) { $file->scanned = -2; } } if (isset($result->permalink)) { $file->vtlink = $result->permalink; $file->scan_id = $result->scan_id; } SetVTResults($file); }
ini_set('max_execution_time', 300); $obj = new VirusTotalAPIV2("be6591b7ba93d10e26c18baf69e46b8769960676b09dfaf383d48430ffa92abb"); if (isset($_POST['scan_button'])) { if (!isset($_POST['scan_file'])) { die("No File Selected"); } $data = $_POST['scan_file']; foreach ($data as $id) { $query = "SELECT `name` from `file_scan` WHERE `id`=" . $id; //echo $query; if (!($result = $db->query($query))) { $db->error; } $row = $result->fetch_assoc(); $file_dest = "data/" . $row['name']; if (!($scanFile = $obj->scanFile($file_dest))) { die("It`s not working, Try again later"); } //var_dump($scanFile); $scan_id = $scanFile->scan_id; $query = "UPDATE `file_scan` SET `scan_id` ='" . $scan_id . "',`sha1`='" . $scanFile->sha1 . "',`resource`='" . $scanFile->resource . "',`response_code`='" . $scanFile->response_code . "',`sha256`='" . $scanFile->sha256 . "',`permalink`='" . $scanFile->permalink . "',`md5`='" . $scanFile->md5 . "',`verbose_msg`='" . $scanFile->verbose_msg . "',`report`=0 WHERE `id` =" . $id; if (!($result = $db->query($query))) { die($db->error); } else { echo "File," . $row['name'] . " Queued Successfully, Refresh page.<br>"; } } } if (isset($_POST['report_button'])) { $antivirus_array = array(); $data = $_POST['report_file'];