³ò
Fc           @   sB   d  d k  Z  d  d k Z d  d k l Z d e f d     YZ d S(   iÿÿÿÿN(   t   Commont   Googlec           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s   
    This class defines methods used to perform Google dorking (command
    line option '-g <google dork>'

    @author: Bernardo Damele
    c         C   s   t  i |  |  _ d  S(   N(   t   urllib2t   build_openert   opener(   t   selft   proxyHandler(    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/google.pyt   __init__   s    c         C   sL   g  } y) d } t  i | | t  i t  i B } Wn d } t |  n X| S(   sa   
        Parse Google dork search results page to get the list of
        HTTP addresses
        s,   ><a href="([\w\:\.\/\$\%\?\=\;\ ]+)" class=ls#   unable to parse Google results page(   t   ret   findallt   It   Mt	   Exception(   R   t   paget   matchest   regExprt   errMsg(    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/google.pyt   __parsePage   s    #c         C   sT   g  } x; |  i  D]0 } t i d | t i  o | i |  q q Wt t |   S(   sv   
        This method returns the list of hosts with parameters out of
        your Google dork search results
        s
   (.*)\?(.+)(   R   R   t   searchR
   t   appendt   tuplet   set(   R   t   testableHostst   match(    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/google.pyt   getTestableHosts(   s    
 c         C   s   y" |  i  i d  } | i   } Wn9 t i j
 o } | i   } n d } t |  n Xt | i d   } t i	 d | t i
  |  _ |  i S(   så   
        This method is the first to be called when initializing a
        Google dorking object through this library. It is used to
        retrieve the Google session cookie needed to perform the
        further search
        s   http://www.google.com/ncrs   unable to connect to Googles
   set-cookies   ([\w\.\:\=]+)(   R   t   opent   infoR   t	   HTTPErrorR   t   strt	   getheaderR   R   R
   t   googleCookie(   R   t   connt   headerst   eR   t   googleSetCookie(    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/google.pyt	   getCookie7   s    c         C   sÅ   | p d Sn d } | d |  i |  7} | d 7} y: d |  i f g |  i _ |  i i |  } | i   } Wn9 t i j
 o } | i   } n d } t	 |  n X|  i
 |  |  _ |  i S(   s   
        This method performs the effective search on Google providing
        the google dork and the Google session cookie
        s   http://www.google.com/search?s   q=%s&s+   num=100&hl=en&safe=off&filter=0&btnG=Searcht   Cookies   unable to connect to GoogleN(   t   Nonet   encodeParamsR   R   t
   addheadersR   t   readR   R   R   t   _Google__parsePageR   (   R   t
   googleDorkt   urlR   R   R!   R   (    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/google.pyR   N   s     
(   t   __name__t
   __module__t   __doc__R   R)   R   R#   R   (    (    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/google.pyR   
   s   				(   R   R   t
   lib.commonR    R   (    (    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/google.pys   <module>   s   
