My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Usage  
Howto use the python library.
Featured, Phase-Deploy
Updated Feb 4, 2010 by thejaswi...@gmail.com

Introduction

Fill Database and API Key

  • Fill the safebrowsing/conf.py parameters.

Preparing Db

Usage 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 URL

Usage 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_URLField

Usage 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)
Comment by nodswo...@gmail.com, Dec 21, 2008

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

Comment by OliverW...@gmail.com, Jun 15, 2010

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.

Comment by serj...@gmail.com, Jun 16, 2010

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')

Comment by OliverW...@gmail.com, Jun 16, 2010

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?

Comment by OliverW...@gmail.com, Jun 16, 2010

Never mind - turns out none of those domains are actually in Google's list :P. Works great now - thanks, serjant.

Comment by serj...@gmail.com, Jun 17, 2010

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.

Comment by project member thejaswi...@gmail.com, Jun 18, 2010

@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.

Comment by slave...@gmail.com, Sep 14, 2010

i get this error when following your instructions

self.cursor.execute("select from %s_version;" %(badware_type))

sqlite3.OperationalError?: no such table: malware_version

Comment by project member thejaswi...@gmail.com, Sep 14, 2010

@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.

Comment by disko.ko...@gmail.com, Nov 25, 2011

Anyone have a few domain names that are actually on the list for testing purposes?

hxxp:// them for safety :)


Sign in to add a comment
Powered by Google Project Hosting