PHP library for VirusTotal.COM
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Izzy 0837b71398
use APIv3 for scheduling rescans
4 months ago
README.md use APIv3 for scheduling rescans 4 months ago
virustotal.class.php use APIv3 for scheduling rescans 4 months ago

README.md

virustotal

This is a PHP library for the VirusTotal.COM public API version 2.0. It's based upon the work of Adrian at www.TheWebHelp.com. As Adrian didn't include a license with his work, I didn't either (I cannot put part of his work under a license of my choice, after all).

Starting 5/2021, this PHP library moves towards VirusTotal.COM public API version 3 while still trying to keep the interface stable (i.e. at least for now, if you're using a previous version, you should be able to use this as drop-in replacement). Advantages are e.g. that you can use some features which are "private" with v2 without the requirement of the "private option". This e.g. affects the upload of large files (bigger than 32M), or scheduling rescans.

If for some reason you prefer using the "plain v2 API", the last version of this PHP library supporting that can be found at the last_v2 tag.

Requirements

  • PHP (of course; tested with 7.2) with CURL support.
  • an API key (available for free at the VirusTotal website)

Usage

Usage is pretty easy. Best demonstrated using an example:

require_once('virustotal.class.php');
$vt = new virustotal($apikey);
$res = $vt->checkFile($filename,$hash); // $hash is optional. Pass the $scan_id if you have it, or the file hash
switch($res) {
  case -99: // API limit exceeded
    // deal with it here – best by waiting a little before trying again :)
    break;
  case  -1: // an error occured
    // deal with it here
    break;
  case   0: // no results (yet) – but the file is already enqueued at VirusTotal
    $scan_id = $vt->getScanId();
    $json_response = $vt->getResponse();
    break;
  case   1: // results are available
    $json_response = $vt->getResponse();
    break;
  default : // you should not reach this point if you've placed the break before :)
}
// deal with the JSON response here

For details on the JSON response (both on enqueuing a file and when getting the final scan results), please consult the VirusTotal API documentation. For details on the PHP class in this repository, consult the code. You should find it well documented :)

Contribute

You like this library and want to contribute?

  • Pull Requests are welcome!
  • Motivate me e.g. by sending me some mBTC to 1FsfvUGUpoPkLvJboKAnuBXHZ1zN3hbBL1 :)