Skip to content

damyanpazvanski/MalwareDomains

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Webmaster Tool | Check Malware Domains

Google Safe-Browsing API

The MalwareDomain class is checked with 100 000 domains and it works correctly. It is created for much domains and really big files, because of that every time it reads the entire file and cannot save the read domains in the memory. For every N iterations it creates a new request, but you must know that google does not allow more than 500 urls on a time and by default they are 480, but if you want you can change the cumber in the config array, which is applied to the constructor.

Class Methods

  • Check domains from the given file. If you have to add more domains first add them after that execute this function, because every time it reads the entire file.

     /*
     * @throws Exception
     * @return boolean
     */
     ->checkDomains();
    
  • Save new domains in the file

     /*
     * @param array $domains // array with new domains
     * @return boolean
     */
     ->addDomain($domains)
    
  • Get all domains with their errors

     /*
     * @return array
     */
     ->getAllErrors()
    
  • Get all domains with errors

     /*
     * @return array
     */
     ->getDomainsWithErrors()
    
  • Get all errors for the given domain

     /*
     * @param string $domain
     * @return array
     */
     ->getDomainErrors($domain)
    

Example $config:

$config = array(
	'api_key' => 'API_KEY',							//google api key
	'file.path' => __DIR__ . DIRECTORY_SEPARATOR . 'domains.txt',		//full path to the file with domains
	'file.iterationLimit' => 480,                                           //number of domains for every request to google - The maximum allowed by Google is 500
	'request.data' => array(						//the body for every request to google
		'client' => array(						//client information which is necessary, but the values are custom-made by the company
			'clientId' => 'TestClient',
			'clientVersion' => '0.0.1'
		),
		'threatInfo' => array(
			'threatTypes' => array('MALWARE', 'SOCIAL_ENGINEERING', 'THREAT_TYPE_UNSPECIFIED', 'UNWANTED_SOFTWARE', 'POTENTIALLY_HARMFUL_APPLICATION'),
			'platformTypes' => array('LINUX', 'WINDOWS', 'ANDROID', 'OSX', 'IOS', 'ANY_PLATFORM', 'ALL_PLATFORMS', 'CHROME', 'PLATFORM_TYPE_UNSPECIFIED'),
			'threatEntryTypes' => array('URL', 'IP_RANGE', 'THREAT_ENTRY_TYPE_UNSPECIFIED', 'EXECUTABLE'),
		)
	),
	'request.urls' => array(												//urls for the requests
		'find' => 'https://safebrowsing.googleapis.com/v4/threatMatches:find'
	)
);

Example of usage

    require_once __DIR__ . '/MalwareDomain.php';
    
    $config = array(
		'api_key' => 'API_KEY',
		'file.path' => __DIR__ . DIRECTORY_SEPARATOR . 'domains.txt',
		'request.data' => array(
			'client' => array(
				'clientId' => 'TestClient',
				'clientVersion' => '0.0.1'
			),
			'threatInfo' => array(
				'threatTypes' => array('MALWARE', 'SOCIAL_ENGINEERING', 'THREAT_TYPE_UNSPECIFIED', 'UNWANTED_SOFTWARE', 'POTENTIALLY_HARMFUL_APPLICATION'),
				'platformTypes' => array('LINUX', 'WINDOWS', 'ANDROID', 'OSX', 'IOS', 'ANY_PLATFORM', 'ALL_PLATFORMS', 'CHROME', 'PLATFORM_TYPE_UNSPECIFIED'),
				'threatEntryTypes' => array('URL', 'IP_RANGE', 'THREAT_ENTRY_TYPE_UNSPECIFIED', 'EXECUTABLE'),
			)
		),
		'request.urls' => array(
			'find' => 'https://safebrowsing.googleapis.com/v4/threatMatches:find'
		)
	);
    
    $md = new MalwareDomain($config);

	$md->checkDomains();
	var_dump($md->getAllErrors());

Releases

No releases published

Packages

No packages published

Languages