³ò
‰ŸFc           @   s’   d  d k  Z  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  d k l Z d  d k	 l
 Z
 d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   version(   t   Common(   t   Googlet   Optionc           B   s°   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  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, parse and set options
    based upon command line parameters values and extra file

    @author: Bernardo Damele
    c         C   s   t  i d ƒ |  _ d  S(   Nt	   sqlmapLog(   t   loggingt	   getLoggert   logger(   t   self(    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   __init__   s    c         C   s5   t  i |  i |  i ƒ } |  i | _ t  i | ƒ d S(   s^   
        This method creates and installs the urllib2 OpenerDirector
        globally
        N(   t   urllib2t   build_openert   proxyHandlert   authHandlert   httpHeaderst
   addheaderst   install_opener(   R   t   opener(    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   __urllib2Opener   s    c         C   s‘  d } |  i  i | ƒ t |  i ƒ } | i ƒ  } | o. | i ƒ  d } d | } |  i  i | ƒ n d } | d 7} t | ‚ | i |  i i	 ƒ } | p d } | d 7} t | ‚ n | i
 ƒ  |  i _ |  i i o d t | ƒ } | d	 7} t | ƒ t |  i i ƒ j o | d
 7} n | d t |  i i ƒ 7} | d 7} |  i  i | ƒ n8 d t | ƒ } | d 7} | d 7} | d 7} t | ‚ d S(   sM   
        This method checks and set the Google dorking functionality
        s1   first request to Google to get the session cookiei    s!   sqlmap got '%s' as session cookies'   unable to parse Google response header s&   'set-cookie' to get the session cookies    unable to find results for your s   Google dork expressions   sqlmap got %d results for your s   Google dork expression, t   alls   %d s   of them are testable hostss   sqlmap got %d results s*   for your Google dork expression, but none s'   of them has parameters to test for SQL t	   injectionN(   R   t   infoR   R   t	   getCookiet   groupst	   Exceptiont   searcht   argst
   googleDorkt   getTestableHostst   testableHostst   len(   R   t   logMsgt	   googleObjt   googleCookiet   errMsgt   matches(    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   __setGoogleDorking'   s<    

	





c      	   C   sF  |  i  i o2 |  i  i o$ d } | d 7} |  i i | ƒ n|  i  i oöt i i |  i  i ƒ o€t |  i  i d ƒ |  i  _	 xN|  i  i	 i
 ƒ  D]:} | i d ƒ d j o| i d ƒ } t | ƒ d j o q“ n | \ } } } | p q“ n | d d j o | d  } n | |  i  i i ƒ  j o( h  |  i  i | <| |  i  i | | <qÍ| |  i  i | i ƒ  j o | |  i  i | | <qÍt | ƒ t |  i  i | | ƒ j o | |  i  i | | <qÍq“ q“ W|  i  i	 i ƒ  n yO t |  i  i d	 ƒ |  i  _	 |  i  i	 i d
 t i d ƒ ƒ |  i  i	 i ƒ  WqBqBXn d S(   sl   
        This method checks and set the output text file and '--resume'
        command line option
        s%   you did not provide the text file to s   resume queries output fromt   rs   ][i   i   iÿÿÿÿs   
t   as   
[%s]
s   %X %xN(   R   t   resumet
   outputFileR   t   warnt   ost   patht   existst   filet	   writeFilet	   readlinest   countt   splitR   t   resumedQueriest   keyst   closet   writet   timet   strftimet   flush(   R   t   warnMsgt   linet   urlt
   expressiont   value(    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   __setOutputResumeX   s@    
 '  c         C   s×   |  i  i i ƒ  |  i  _ t i d |  i  i ƒ |  i  _ |  i  i o, d |  i  _ |  i  i i ƒ  d |  i  _ n d |  i  _ |  i  i d j oE d } | d 7} | d 7} | d	 7} | d
 7} | d 7} t | ‚ n d S(   s\   
        This method checks the command line argument '--remote-dbms'
        value
        s   mysql ([\d\.]+)t   mysqli    t
   postgresqls   microsoft sql servers,   you provided an unsupported remote database s*   management system. The supported DBMS are s)   'MySQL', 'PostgreSQL' and 'Microsoft SQL s'   Server'. If you do not know the remote s(   DBMS, do not provide it and sqlmap will s   fingerprint it for youN(   R?   R@   s   microsoft sql server(	   R   t   dbmst   lowert   reR   t   MySQLVerR   t   NoneR   (   R   R"   (    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   __setRemoteDBMSˆ   s     




c         C   s£   t  i d |  i i t  i ƒ p d } | d 7} t | ‚ nd t  i d |  i i t  i ƒ } | i ƒ  d } | i ƒ  d } t i h  d | | f d <ƒ |  _	 d	 S(
   sQ   
        This method defines the HTTP proxy to pass by all HTTP requests
        s   http://[\w\:\/\.\-\_]+\:[\d]+s   proxy value must be in format s   'http://url:port's   ([\w\:\/\.\-\_\:]+)\:([\d]+)i    i   s   %s:%st   httpN(
   RC   R   R   t   proxyt   IR   R   R
   t   ProxyHandlerR   (   R   R"   t   proxyRegExpt   proxyUrlt	   proxyPort(    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   __setHTTPProxy¡   s    
c         C   s0   |  i  i d ƒ |  i  i d |  i i f ƒ d S(   s8   
        This method set the HTTP Cookie header
        t
   Connections
   Keep-Alivet   CookieN(   s
   Connections
   Keep-Alive(   R   t   appendR   t   cookie(   R   (    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   __setHTTPCookies±   s    c         C   sF   | i  ƒ  d } | i  ƒ  d } t i ƒ  } | i d | | | ƒ | S(   sm   
        This method initializes and returns an urllib2 HTTP
        authentication password manager
        i    i   N(   R   R
   t   HTTPPasswordMgrWithDefaultRealmt   add_passwordRE   (   R   t   linkt
   authRegExpt   authUsernamet   authPasswordt   passwordMgr(    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   __setHTTPPasswordMgrº   s
    c         C   s  |  i  i o t i d |  i  i ƒ } n* |  i  i o t i d |  i  i ƒ } n |  i  i o | p |  i  i o% | o d } | d 7} t | ‚ ny |  i  i o/ | o( |  i t | ƒ } t i	 | ƒ |  _
 n= |  i  i o/ | o( |  i t | ƒ } t i | ƒ |  _
 n d S(   s|   
        This method checks and set the HTTP authentication method
        (Basic or Digest), username and password
        s
   (.*)\:(.*)s"   HTTP Authentication value must be s   in format 'username:password'N(   R   t   bAuthRC   R   t   dAuthR   t   _Option__setHTTPPasswordMgrRV   R
   t   HTTPBasicAuthHandlerR   t   HTTPDigestAuthHandler(   R   t   bAuthRegExpt   dAuthRegExpR"   RZ   (    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   __setHTTPAuthenticationÉ   s    *
c         C   sX  |  i  i o) |  i  i d j o |  i ƒ  \ } } nQ |  i  i oC |  i  i d j o0 |  i  i o |  i  i } q† d } t | ‚ n |  i  i o |  i  i i d ƒ |  i  _ n g  |  i  _ |  i  i o |  i | ƒ |  i  _	 n |  i  i oc |  i  i d j oP d |  i  i j o# |  i  i i d ƒ d |  i  _ n |  i  i d | 7_ n d S(   s”   
        This method checks, set the url parameters and performs checks
        on 'data' command line parameter value for HTTP method POST
        t   GETt   POSTs*   HTTP POST method depends on '--data' valuet   ,t   ?i    N(
   R   R;   t
   httpMethodt   roughParameterst   dataR   t   urlParameterR1   t	   paramDictt
   parameters(   R   R;   Rm   R"   (    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   __setURLParametersà   s        #c         C   ss   |  i  i i ƒ  |  i  _ |  i  i d j oD d |  i  i } | d 7} | d 7} |  i i | ƒ d |  i  _ n d S(   sb   
        This method checks and set the HTTP method to perform HTTP
        requests with
        Rd   Re   s   '%s' s   is an unsupported HTTP method, s   setting to default method, GETN(   s   GETs   POST(   R   Rh   t   upperR   R)   (   R   R9   (    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   __setHTTPMethod  s    

c         C   s   d t  S(   s^   
        This method returns the default sqlmap HTTP User-Agent
        header string
        s)   sqlmap/%s (http://sqlmap.sourceforge.net)(   R    (   R   (    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   __defaultHTTPUserAgent  s    c         C   sd  d } | d |  i  i 7} |  i i | ƒ y t |  i  i ƒ } WnQ d } | d |  i  i 7} |  i i | ƒ |  i i d |  i ƒ  f ƒ d Sn Xd } g  } x; t	 o3 | i
 ƒ  } | p Pn | i | ƒ | d 7} q£ W| i ƒ  | t i d | d ƒ } | i d d	 ƒ i d
 d	 ƒ } |  i i d | f ƒ d } | d |  i  i 7} |  i i | ƒ d S(   sf   
        This method extracts a random HTTP User-Agent header string
        from a text file
        s,   fetching random HTTP User-Agent header from s	   file '%s's&   unable to read HTTP User-Agent header s
   User-AgentNi    i   s   
t    s   s+   fetched random HTTP User-Agent header from (   R   t   userAgentsFileR   R   t   openR)   R   RQ   t   _Option__defaultHTTPUserAgentt   Truet   readlineR4   t   randomt   randintt   replace(   R   R   t   fdR9   R0   t
   userAgentsR:   t	   userAgent(    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   __setHTTPUserAgent  s4    

c         C   sº  t  i d |  i i t  i ƒ pŠ t  i d |  i i ƒ } | oQ t | i ƒ  d ƒ d j o d |  i i |  i _ q¥ d |  i i |  i _ q© d |  i i |  i _ n t  i d |  i i t  i ƒ i ƒ  d } t  i d |  i i t  i ƒ } t  i d	 |  i i t  i ƒ } | o | i ƒ  d } n? | o1 t | i ƒ  d ƒ d j o
 d
 } qfd } n d } | o  t | i ƒ  d ƒ |  i _ n* | d j o d |  i _ n d |  i _ d S(   sD   
        This method checks and set the target url and port
        s   ^http[s]*://[\w\.\-\_]+s   ^[\w\.\-\_]+:([\d]+)i    i»  s   https://s   http://s   ^http[s]*://([\w\.\-\_]+)s   ^(http[s]*)://[\w\.\-\_]+s   ^http[s]*://[\w\.\-\_]+:([\d]+)t   httpsRG   iP   N(   RC   R   R   R;   RI   t   intR   t   port(   R   R   RV   t	   transport(    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   __setURLG  s,    (

 c         C   s^   t  |  i i ƒ } | d j o |  i i t i ƒ n% | d j o |  i i t i ƒ n d S(   sI   
        This method set the verbosity of sqlmap output messages
        i   N(   R€   R   t   verboseR   t   setLevelR   t   INFOt   DEBUG(   R   R„   (    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   __setVerbosem  s
    c         C   sR  |  i  i o |  i ƒ  n |  i  i o |  i ƒ  n |  i  i o |  i ƒ  n |  i i d |  i	 ƒ  f ƒ |  i  i
 o |  i ƒ  n d |  i  _
 |  i ƒ  |  i  i p |  i  i o |  i ƒ  n
 d |  _ |  i  i o |  i ƒ  n |  i  i o |  i ƒ  n
 d |  _ |  i  i o |  i ƒ  n |  i ƒ  |  i  i o |  i ƒ  n d S(   s}   
        This method checks, parses and set options based upon command
        line parameters values and extra file
        s
   User-AgentRd   Rr   N(   R   R„   t   _Option__setVerboseR;   t   _Option__setURLRs   t   _Option__setHTTPUserAgentR   RQ   Ru   Rh   t   _Option__setHTTPMethodt   _Option__setURLParametersR\   R]   t   _Option__setHTTPAuthenticationR   RR   t   _Option__setHTTPCookiesRH   t   _Option__setHTTPProxyR   RA   t   _Option__setRemoteDBMSt   _Option__setOutputResumeR   t   _Option__setGoogleDorking(   R   (    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   __effectiveRunz  s0    
		
c         C   sU   d |  i _ h  |  i _ h  |  i _ d |  i _ d |  i _ d |  i _ g  |  _ d S(   s7   
        This method set some needed variables
        N(	   RE   R   t   fingerprintRm   R2   t   unionCommentt
   unionCountR.   R   (   R   (    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   __setVariables¨  s    c         C   s.   | |  _  |  i ƒ  |  i ƒ  |  i ƒ  |  i  S(   sx   
        This method is the core of this class and call three other
        main methods which perform the work
        (   R   t   _Option__setVariablest   _Option__effectiveRunt   _Option__urllib2Opener(   R   t	   shellArgs(    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyt   run¶  s
    	


(   t   __name__t
   __module__t   __doc__R	   R›   R“   R’   R‘   R   R   R^   RŽ   R   RŒ   Ru   R‹   RŠ   R‰   Rš   R™   R   (    (    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pyR      s&   			1	0							#				*	&		.	(   R   R*   Rx   RC   R6   R
   t
   lib.commonR    R   t
   lib.googleR   R   (    (    (    s4   /usr/local/www/apache22/data/stuff/sql/lib/option.pys   <module>   s   
