{"id":2386,"date":"2011-11-11T10:43:57","date_gmt":"2011-11-11T09:43:57","guid":{"rendered":"http:\/\/blog.beufa.net\/?p=15"},"modified":"2011-11-11T10:43:57","modified_gmt":"2011-11-11T09:43:57","slug":"perl-verifier-vos-sites-automatiquement-avec-safebrowsing","status":"publish","type":"post","link":"https:\/\/beufa.net\/fr\/blog\/perl-verifier-vos-sites-automatiquement-avec-safebrowsing\/","title":{"rendered":"[Perl] V\u00e9rifier vos sites automatiquement avec SafeBrowsing"},"content":{"rendered":"<p>SafeBrowsing est la base anti malware \/ anti phishing de Google. Int\u00e9gr\u00e9 \u00e0 Firefox et Google Chrome, il permet de valider que le site n&#8217;est pas un nid \u00e0 malware ou tentative de phishing.<\/p>\n<figure id=\"attachment_12\" aria-describedby=\"caption-attachment-12\" style=\"width: 499px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/beufa.net\/wordpress\/wp-content\/uploads\/2011\/11\/url.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-12\" title=\"url\" src=\"https:\/\/beufa.net\/wordpress\/wp-content\/uploads\/2011\/11\/url.jpeg\" alt=\"\" width=\"499\" height=\"278\" \/><\/a><figcaption id=\"caption-attachment-12\" class=\"wp-caption-text\">Exemple SafeBrowsing<\/figcaption><\/figure>\n<p>Pour tester par site :<\/p>\n<p><span><a class=\"smarterwiki-linkify\" href=\"http:\/\/www.google.com\/safebrowsing\/diagnostic?site=beufa.net\">http:\/\/www.google.com\/safebrowsing\/diagnostic?site=beufa.net<\/a><\/span><\/p>\n<p>Ou par AS :<\/p>\n<p><span><a class=\"smarterwiki-linkify\" href=\"http:\/\/www.google.com\/safebrowsing\/diagnostic?site=AS:15069\">http:\/\/www.google.com\/safebrowsing\/diagnostic?site=AS:15069<\/a><\/span><\/p>\n<p>Des modules existent en Perl pour automatiser ces v\u00e9rifications :<\/p>\n<pre class=\"brush:perl\">use Net::Google::SafeBrowsing2;\nuse Net::Google::SafeBrowsing2::Storage;\nuse Net::Google::SafeBrowsing2::Sqlite;<\/pre>\n<p>Ensuite, quelques lignes de Perl suffit \u00e0 v\u00e9rifier une liste de sites (qu&#8217;il est possible d&#8217;inclure depuis une base MySQL !)<\/p>\n<pre class=\"brush:perl\">my @sites =(\n\t\t'http:\/\/flashupdate.co.cc\/',\n\t\t'https:\/\/beufa.net\/',\n\t\t'http:\/\/www.fortinet.com\/',\n\t\t'http:\/\/www.gumblar.cn'\n\t\t);<\/pre>\n<p>Cr\u00e9er une base locale, qui permettra de stocker les hashs localement<\/p>\n<pre class=\"brush:perl\"> my $storage_malware_db = Net::Google::SafeBrowsing2::Sqlite-&gt;new(file =&gt; 'goog-malware-shavar.db');\n  my $malware_db = Net::Google::SafeBrowsing2-&gt;new(\n        key     =&gt; \"YOUR_KEY\",\n        storage =&gt; $storage_malware_db,\n\terror\t=&gt; 1,\n##      debug   =&gt; 1,\n##      mac     =&gt; 1,\n        list    =&gt; MALWARE,\n##\tforce\t=&gt; 1\n  );<\/pre>\n<p>Il est possible de t\u00e9l\u00e9charger 2 bases (param\u00e8tre LIST) : MALWARE (goog-malware-shava.db) ou PHISHING (googpub-phish-shavar.db)<\/p>\n<p>V\u00e9rifier les mises \u00e0 jour :<\/p>\n<pre class=\"brush:perl\">  my $last_db1 = $storage_malware_db-&gt;last_update(list =&gt; 'goog-malware-shavar')-&gt;{time};\n  my $next_db1 = $last_db1+$storage_malware_db-&gt;last_update(list =&gt; 'goog-malware-shavar')-&gt;{wait};\n  my $last_db2 = $storage_phishing_db-&gt;last_update(list =&gt; 'googpub-phish-shavar')-&gt;{time};\n  my $next_db2 = $last_db2+$storage_phishing_db-&gt;last_update(list =&gt; 'googpub-phish-shavar')-&gt;{wait};\n\n  print color 'reset'; print color 'bold yellow';\n  print \"---   ----------------------------------   ----n\";\n  print \"---   Updates of Google SafeBrowsing DBs   ----n\";\n  print \"---   ----------------------------------   ----n\";\n  print color 'reset';  print color 'cyan';\n  print \"t &gt; Last Up. (google-malware-shavar) : \".scalar(localtime($last_db1)).\"n\";\n  print \"t &gt; Next Up. (google-malware-shavar) : \".scalar(localtime($next_db1)).\"n\";\n  print \"t &gt; Last Up. (googpub-phish-shavar)  : \".scalar(localtime($last_db2)).\"n\";\n  print \"t &gt; Next Up. (googpub-phish-shavar)  : \".scalar(localtime($next_db2)).\"n\";\n  print color 'reset';<\/pre>\n<p>V\u00e9rifiez ensuite que chacun des sites n&#8217;est pas dans les hashs Google SafeBrowsing :<\/p>\n<pre class=\"brush:perl\">print color 'reset'; print color 'bold yellow';\n  print \"--- -------------------------------------- ----n\";\n  print \"--- Checking for Malwares Distribution URL ----n\";\n  print \"--- -------------------------------------- ----n\";\n  foreach $site (@sites) {\n\tmy $match_malware = $malware_db-&gt;lookup(url =&gt; $site);\n\tif ($match_malware eq MALWARE) {\n\t\tprint color 'reset'; print color 'bold red';\n        \tprint \"t(MAL)tNOK =&gt; \".$site.\" =&gt; MALWARE n\";\n\t}\n\telse {\n\t\tprint color 'reset'; print color 'green';\n        \tprint \"ttOK  =&gt; \".$site.\"n\";\n\t}\n  }\n  print color 'reset';\n  print color 'reset'; print color 'red';\n  print \"--- Errors for Malwares Distribution Check ----n\";\n  print \"Last malware_db error: \", $malware_db-&gt;last_error(), \"n\";\n  print \"--- -------------------------------------- ----n\";\n  $storage_malware_db-&gt;close();<\/pre>\n<p>Le r\u00e9sultat :<\/p>\n<pre class=\"brush:shell\">user@pc:~$ perl Bureau\/safeb\n---   ----------------------------------   ----\n---   Updates of Google SafeBrowsing DBs   ----\n---   ----------------------------------   ----\n\t &gt; Last Up. (google-malware-shavar) : Fri Nov 11 10:44:43 2011\n\t &gt; Next Up. (google-malware-shavar) : Fri Nov 11 11:14:49 2011\n\t &gt; Last Up. (googpub-phish-shavar)  : Fri Nov 11 10:44:57 2011\n\t &gt; Next Up. (googpub-phish-shavar)  : Fri Nov 11 11:16:36 2011\n--- -------------------------------------- ----\n--- Checking for Malwares Distribution URL ----\n--- -------------------------------------- ----\n\t(MAL)\tNOK =&gt; http:\/\/flashupdate.co.cc\/ =&gt; MALWARE\n\t\tOK  =&gt; https:\/\/beufa.net\n\t\tOK  =&gt; http:\/\/fortinet.com\n\t\tOK  =&gt; http:\/\/gumblar.cn\n--- Errors for Malwares Distribution Check ----\nLast malware_db error:\n--- -------------------------------------- ----\n--- -------------------------------------- ----\n--- Checking for Phishing Distribution URL ----\n--- -------------------------------------- ----\n\t\tOK  =&gt; http:\/\/flashupdate.co.cc\/\n\t\tOK  =&gt; https:\/\/beufa.net\n\t\tOK  =&gt; http:\/\/fortinet.com\n\t\tOK  =&gt; http:\/\/gumblar.cn\n--- Errors for Phishing Distribution Check ----\nLast phishing_db error:\n--- -------------------------------------- ----<\/pre>\n<p>Bon amusement !<\/p>\n<p>A venir : scan de pages avec ClamAV et son module <a href=\"http:\/\/search.cpan.org\/~cfaber\/File-Scan-ClamAV-1.06\/lib\/File\/Scan\/ClamAV.pm\" target=\"_blank\">File::Scan::ClamAV<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>SafeBrowsing est la base anti malware \/ anti phishing de Google. Int\u00e9gr\u00e9 \u00e0 Firefox et Google Chrome, il permet de valider que le site n&#8217;est&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/beufa.net\/fr\/blog\/perl-verifier-vos-sites-automatiquement-avec-safebrowsing\/\">Continue reading<span class=\"screen-reader-text\">[Perl] V\u00e9rifier vos sites automatiquement avec SafeBrowsing<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[37,49,66,76,79],"class_list":["post-2386","post","type-post","status-publish","format-standard","hentry","category-perl-script","tag-automatisation","tag-google","tag-perl","tag-safebrowsing","tag-securite","entry"],"_links":{"self":[{"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/posts\/2386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/comments?post=2386"}],"version-history":[{"count":0,"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/posts\/2386\/revisions"}],"wp:attachment":[{"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/media?parent=2386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/categories?post=2386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/tags?post=2386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}