|
Usage
IntroductionFill Database and API Key
Preparing DbUsage of the List Preparation script >>> from safebrowsing.prepare_db import Google_Blacklist
>>>
# "malware" and "black" are valid options
>>> g = Google_Blacklist("malware")
>>> g.fetch_data()For information regarding the SQL schema used for the database, click here. Looking up URLUsage of the lookup library is very simple. >>> from safebrowsing.query_lookup import Lookup
>>>
>>> l = Lookup()
>>> l.lookup_by_url("http://thejaswi.info/")
>>>
>>> l.lookup_by_url("www.somemalwaresite.com")
'M'
>>>Using Django Newforms Safe_URLFieldUsage of Safe_URLField >>> from safe_url_django.forms import Safe_URLField
>>> from django import newforms as forms
>>> class Test_Form(forms.Form):
... url_field = Safe_URLField()
...
>>> data={"url_field": u"http://thejaswi.info/"}
>>> f=Test_Form(data)
>>> f.is_valid()
True
>>> f.errors
{}
>>> f.cleaned_data
{'url_field': u'http://thejaswi.info/'}
>>> data2={"url_field": u"www.somemalwaresite.com"}
>>> g=Test_Form(data2)
>>> g.is_valid()
False
>>> g.errors
{'url_field': [u'A verbose malware detected error.'}Using Django Models Field>>> from safe_url_django.fields import Safe_URLField >>> from django.db import models >>> class URL_Model(models.Model): ... badware_url_test = Safe_URLField(verify_exists=True, verbose_name="URL Field", badware_check=True) |
► Sign in to add a comment
I added a bit of code to build the necessary tables in sqlite for this.
Check it out at http://github.com/nod/boombot/tree/master/plugins/Goog/safebrowsing/prepare_db.py
I'm new to Python/SQLite/Unix so please bear with me.
I've followed all your instructions to the letter. However, when I try to follow your above instructions for using the List Preparation script Python returns '0'. Trying to go through with looking up a URL yields this error:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "query_lookup.py", line 57, in lookup_by_url hostname_comp = hostname.split(".") AttributeError??: 'NoneType??' object has no attribute 'split'`Any help would be greatly appreciated.
You still can use it, but you need to pass full addresses to the method
Try Lookup().lookup_by_url('http://domain.name') Instead of Lookup().lookup_by_url('domain.name')
No dice. No matter what I input, I can't get any output. The errors are gone, but querying malware domains (taken from this list http://www.malwaredomainlist.com/mdl.php) don't return an 'M'. For example:
>>> l.lookup_by_url("http://www.fxmp3.com") >>> >>> l.lookup_by_url("http://www.0755mp3.com") >>> >>> Lookup().lookup_by_url("http://fxmp3.com") >>>Any ideas?
Never mind - turns out none of those domains are actually in Google's list :P. Works great now - thanks, serjant.
You should consider using some other library or make some big changes on this one before using it.
1. md5 hashes + index on varchar(32) (WTF) is an inefficient way of storing data and making queries. Unsigned int or unsigned bigint would be much better.
2. it requires fixes to work with MySQLdb
3. initial data parsing + insert (343593 rows, prepare_db) requires about 30 sec - 1 minute at 100% CPU on my box (50:50 python & mysql). Updating, however, requires some indefinite time, too long to wait, at 100% mysql.
@Serjant: I am open to accepting patches! I have accepted patches in the past and am willing to do so now and in the future.
i get this error when following your instructions
sqlite3.OperationalError?: no such table: malware_version
@slaveriq: you do not seem to have created the tables mentioned at http://code.google.com/p/safebrowsing-python/wiki/SQLSchema. Please do not use this page for support requests. Please get in touch by mail or send an email to the safebrowsing group.
Anyone have a few domain names that are actually on the list for testing purposes?
hxxp:// them for safety :)