³ò
‰ŸFc        	   @   sf   d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k l Z d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   Resumet   Requestc           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 HTTP requests

    @author: Bernardo Damele
    c         C   s#   t  i d ƒ |  _ t i d ƒ d  S(   Nt	   sqlmapLogi   (   t   loggingt	   getLoggert   loggert   sockett   setdefaulttimeout(   t   self(    (    s5   /usr/local/www/apache22/data/stuff/sql/lib/request.pyt   __init__   s    c         C   sG  h  d d <d d <d d <d d <d	 d
 <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d  <d! d" <d# d$ <d% d& <d' d( <d) d* <d+ d, <d- d. <d/ d0 <d1 d2 <d3 d4 <d5 d6 <d7 d8 <d9 d: <d; d< <} x, | i  ƒ  D] \ } } | i | | ƒ } q!W| S(=   s   
        This method encodes and returns the url parameters special
        characters in their corresponding HTML hexadecimal value
        s   %20t    s   %21t   !s   %22t   "s   %23t   #s   %24t   $s   %27t   's   %28t   (s   %29t   )s   %2At   *s   %2Bt   +s   %2Ct   ,s   %2Dt   -s   %2Et   .s   %2Ft   /s   %3At   :s   %3Bt   ;s   %3Ct   <s   %3Et   >s   %3Ft   ?s   %40t   @s   %5Bt   [s   %5Cs   \s   %5Dt   ]s   %5Et   ^s   %5Ft   _s   %60t   `s   %7Bt   {s   %7Ct   |s   %7Dt   }s   %7Et   ~(   t   itemst   replace(   R   t   paramst   charListt   chart   encChar(    (    s5   /usr/local/www/apache22/data/stuff/sql/lib/request.pyt   encodeParams   s    $$$$$$$ c         C   s>  d | } |  i  i | ƒ | i d d ƒ \ } } |  i | ƒ } d | | f } yt |  i i d j o t i | ƒ } n? |  i i d j o+ | i d ƒ \ } } t i | | ƒ } n | i ƒ  } Wnr t i	 j
 o } | i ƒ  } nP d } |  i i
 o" | d 7} |  i  i | ƒ d
 Sq:| d	 7} t | ‚ n X| S(   sq   
        This method connects to the target url or proxy and returns the
        target url page content
        s   requesting url: %sR   i   s   %s?%st   GETt   POSTs#   unable to connect to the target urls   , skipping to next urls	    or proxyN(   R   t   debugt   splitR-   t   argst
   httpMethodt   urllib2t   urlopent   readt	   HTTPErrort
   googleDorkt   warnt   Nonet	   Exception(   R   t   urlt   debugMsgR)   t   connt   paget   et   warnMsg(    (    s5   /usr/local/www/apache22/data/stuff/sql/lib/request.pyt   getPage1   s.    


c         C   sV   |  i  | ƒ } |  i i p t i | ƒ i ƒ  Sn  |  i i | j o t Sn t Sd S(   sé   
        This method calls self.getPage() function to get the target url
        page content and returns its page MD5 hash or a boolean value
        in case of string match check ('--string' command line
        parameter)
        N(   RB   R2   t   stringt   md5t   newt	   hexdigestt   Truet   False(   R   R<   R?   (    (    s5   /usr/local/www/apache22/data/stuff/sql/lib/request.pyt	   queryPageW   s    c   
      C   s}  d | } |  i  i | ƒ t i ƒ  } |  i | ƒ } |  i ƒ  } |  i d | ƒ } |  i i o‡ |  i i |  i i i	 ƒ  j od | |  i i |  i i i	 ƒ  j o= |  i
 | | ƒ } | o  | i d d ƒ i d d ƒ Sqß qã qç n |  i i o7 |  i i i d |  i i | f ƒ |  i i i ƒ  n |  i | | ƒ \ } } t t i ƒ  | ƒ }	 d | |	 f } |  i  i | ƒ | S(	   s#  
        This method retrieves the output of a SQL statement character
        by character taking advantage of a blind SQL injection
        vulnerability on the afftected url parameter. The algorithm
        used is a bisection algorithm defined into
        algorithm.Algorithm()
        s	   query: %st   newValuet   __NEWLINE__s   
t   __TAB__s   	s   %s][%s][s"   performed %d queries in %d seconds(   R   t   infot   timet   unescapet	   createStmt
   urlReplaceR2   t   resumedQueriesR<   t   keyst   resumeValueR(   t	   writeFilet   writet   flusht   bisectionAlgorithmt   int(
   R   t
   expressiont   logMsgt   startt   expressionUnescapedt   evilStmt   baseUrlt   valuet   countt   duration(    (    s5   /usr/local/www/apache22/data/stuff/sql/lib/request.pyt   getValuei   s(    	
#,#(   t   __name__t
   __module__t   __doc__R	   R-   RB   RI   Rc   (    (    (    s5   /usr/local/www/apache22/data/stuff/sql/lib/request.pyR      s   			&	(   R   RD   R   R4   RN   t
   lib.resumeR    R   (    (    (    s5   /usr/local/www/apache22/data/stuff/sql/lib/request.pys   <module>   s   
