Ejemplo n.º 1
1
 /**
  * Scan one or multiple urls via VirusTotal
  * @param  string|array $urls The urls to scan
  * @return array  The information returned by VirusTotal
  */
 public static function scanUrl($urls)
 {
     // The api key must be set!
     $apikey = config("virus-total-api.api_key");
     if (!$apikey) {
         throw new \Exception("Please setup your VirusTotal api key to use the api.", 1);
     }
     // Prepare the url scanner
     $urlscan = new \VirusTotal\Url($apikey);
     // Try/Catch to get rate limit exceptions thrown by the api wrapper
     try {
         $scanResults = $urlscan->getReport($urls);
         if ($scanResults['response_code'] == 0) {
             $scanResults = $urlscan->scan($urls);
         }
     } catch (\Exception $e) {
         if ($e instanceof \VirusTotal\Exceptions\RateLimitException) {
             return ['success' => false, 'error' => 'rate limit exceeded'];
         } else {
             throw new \Exception("Please setup a valid VirusTotal api key to use the api.", 1);
         }
     }
     return array_merge(['success' => true], $scanResults);
 }
Ejemplo n.º 2
0
<?php

require_once '../Vendors/autoload.php';
require_once 'config.php';
// hacky, should replace with a micro-framework
$callback = $_GET['callback'];
if (empty($_GET['url'])) {
    $errMsg = array('verbose_msg' => 'Please provide an url');
    echo renderJsonp($callback, $errMsg);
    return;
}
$url = $_GET['url'];
$apiKey = API_KEY;
$urlInst = new \VirusTotal\Url($apiKey);
$scanResponse = $urlInst->scan($url);
if (isset($scanResponse['resource'])) {
    $reportResponse = $urlInst->getReport($scanResponse['resource']);
    echo $callback . '(' . json_encode($reportResponse) . ');';
    echo renderJsonp($callback, $reportResponse);
    return;
}
echo renderJsonp($callback, $scanResponse);
function renderJsonp($callback, $response)
{
    return $callback . '(' . json_encode($response) . ');';
}