()
Parse target dbms and set some attributes into the configuration singleton.
Parse target dbms and set some attributes into the configuration singleton.
Parse target dbms and set some attributes into the configuration singleton .
def parseTargetDirect():
    """
    Parse target dbms and set some attributes into the configuration singleton.
    """

    if not conf.direct:
        return

    details = None
    remote = False

    for dbms in SUPPORTED_DBMS:
        details = re.search("^(?P<dbms>%s)://(?P<credentials>(?P<user>.+?)\:(?P<pass>.*)\@)?(?P<remote>(?P<hostname>.+?)\:(?P<port>[\d]+)\/)?(?P<db>[\w\d\ \:\.\_\-\/\\\\]+?)$" % dbms, conf.direct, re.I)

        if details:
            conf.dbms = details.group("dbms")

            if details.group('credentials'):
                conf.dbmsUser = details.group("user")
                conf.dbmsPass = details.group("pass")
            else:
                if conf.dbmsCred:
                    conf.dbmsUser, conf.dbmsPass = conf.dbmsCred.split(':')
                else:
                    conf.dbmsUser = unicode()
                    conf.dbmsPass = unicode()

            if not conf.dbmsPass:
                conf.dbmsPass = None

            if details.group("remote"):
                remote = True
                conf.hostname = details.group("hostname").strip()
                conf.port = int(details.group("port"))
            else:
                conf.hostname = "localhost"
                conf.port = 0

            conf.dbmsDb = details.group("db")
            conf.parameters[None] = "direct connection"

            break

    if not details:
        errMsg = "invalid target details, valid syntax is for instance "
        errMsg += "'mysql://USER:PASSWORD@DBMS_IP:DBMS_PORT/DATABASE_NAME' "
        errMsg += "or 'access://DATABASE_FILEPATH'"
        raise SqlmapSyntaxException(errMsg)

    for dbmsName, data in DBMS_DICT.items():
        if dbmsName == conf.dbms or conf.dbms.lower() in data[0]:
            try:
                if dbmsName in (DBMS.ACCESS, DBMS.SQLITE, DBMS.FIREBIRD):
                    if remote:
                        warnMsg = "direct connection over the network for "
                        warnMsg += "%s DBMS is not supported" % dbmsName
                        logger.warn(warnMsg)

                        conf.hostname = "localhost"
                        conf.port = 0
                elif not remote:
                    errMsg = "missing remote connection details (e.g. "
                    errMsg += "'mysql://USER:PASSWORD@DBMS_IP:DBMS_PORT/DATABASE_NAME' "
                    errMsg += "or 'access://DATABASE_FILEPATH')"
                    raise SqlmapSyntaxException(errMsg)

                if dbmsName in (DBMS.MSSQL, DBMS.SYBASE):
                    import _mssql
                    import pymssql

                    if not hasattr(pymssql, "__version__") or pymssql.__version__ < "1.0.2":
                        errMsg = "'%s' third-party library must be " % data[1]
                        errMsg += "version >= 1.0.2 to work properly. "
                        errMsg += "Download from '%s'" % data[2]
                        raise SqlmapMissingDependence(errMsg)

                elif dbmsName == DBMS.MYSQL:
                    import pymysql
                elif dbmsName == DBMS.PGSQL:
                    import psycopg2
                elif dbmsName == DBMS.ORACLE:
                    import cx_Oracle
                elif dbmsName == DBMS.SQLITE:
                    import sqlite3
                elif dbmsName == DBMS.ACCESS:
                    import pyodbc
                elif dbmsName == DBMS.FIREBIRD:
                    import kinterbasdb
            except ImportError:
                if _sqlalchemy and data[3] in _sqlalchemy.dialects.__all__:
                    pass
                else:
                    errMsg = "sqlmap requires '%s' third-party library " % data[1]
                    errMsg += "in order to directly connect to the DBMS "
                    errMsg += "%s. You can download it from '%s'" % (dbmsName, data[2])
                    errMsg += ". Alternative is to use a package 'python-sqlalchemy' "
                    errMsg += "with support for dialect '%s' installed" % data[3]
                    raise SqlmapMissingDependence(errMsg)
def parseTargetDirect ( ) : if not conf . direct : return details = None remote = False for dbms in SUPPORTED_DBMS : details = re . search ( "^(?P<dbms>%s)://(?P<credentials>(?P<user>.+?)\:(?P<pass>.*)\@)?(?P<remote>(?P<hostname>.+?)\:(?P<port>[\d]+)\/)?(?P<db>[\w\d\ \:\.\_\-\/\\\\]+?)$" % dbms , conf . direct , re . I ) if details : conf . dbms = details . group ( "dbms" ) if details . group ( 'credentials' ) : conf . dbmsUser = details . group ( "user" ) conf . dbmsPass = details . group ( "pass" ) else : if conf . dbmsCred : conf . dbmsUser , conf . dbmsPass = conf . dbmsCred . split ( ':' ) else : conf . dbmsUser = unicode ( ) conf . dbmsPass = unicode ( ) if not conf . dbmsPass : conf . dbmsPass = None if details . group ( "remote" ) : remote = True conf . hostname = details . group ( "hostname" ) . strip ( ) conf . port = int ( details . group ( "port" ) ) else : conf . hostname = "localhost" conf . port = 0 conf . dbmsDb = details . group ( "db" ) conf . parameters [ None ] = "direct connection" break if not details : errMsg = "invalid target details, valid syntax is for instance " errMsg += "'mysql://USER:PASSWORD@DBMS_IP:DBMS_PORT/DATABASE_NAME' " errMsg += "or 'access://DATABASE_FILEPATH'" raise SqlmapSyntaxException ( errMsg ) for dbmsName , data in DBMS_DICT . items ( ) : if dbmsName == conf . dbms or conf . dbms . lower ( ) in data [ 0 ] : try : if dbmsName in ( DBMS . ACCESS , DBMS . SQLITE , DBMS . FIREBIRD ) : if remote : warnMsg = "direct connection over the network for " warnMsg += "%s DBMS is not supported" % dbmsName logger . warn ( warnMsg ) conf . hostname = "localhost" conf . port = 0 elif not remote : errMsg = "missing remote connection details (e.g. " errMsg += "'mysql://USER:PASSWORD@DBMS_IP:DBMS_PORT/DATABASE_NAME' " errMsg += "or 'access://DATABASE_FILEPATH')" raise SqlmapSyntaxException ( errMsg ) if dbmsName in ( DBMS . MSSQL , DBMS . SYBASE ) : import _mssql import pymssql if not hasattr ( pymssql , "__version__" ) or pymssql . __version__ < "1.0.2" : errMsg = "'%s' third-party library must be " % data [ 1 ] errMsg += "version >= 1.0.2 to work properly. " errMsg += "Download from '%s'" % data [ 2 ] raise SqlmapMissingDependence ( errMsg ) elif dbmsName == DBMS . MYSQL : import pymysql elif dbmsName == DBMS . PGSQL : import psycopg2 elif dbmsName == DBMS . ORACLE : import cx_Oracle elif dbmsName == DBMS . SQLITE : import sqlite3 elif dbmsName == DBMS . ACCESS : import pyodbc elif dbmsName == DBMS . FIREBIRD : import kinterbasdb except ImportError : if _sqlalchemy and data [ 3 ] in _sqlalchemy . dialects . __all__ : pass else : errMsg = "sqlmap requires '%s' third-party library " % data [ 1 ] errMsg += "in order to directly connect to the DBMS " errMsg += "%s. You can download it from '%s'" % ( dbmsName , data [ 2 ] ) errMsg += ". Alternative is to use a package 'python-sqlalchemy' " errMsg += "with support for dialect '%s' installed" % data [ 3 ] raise SqlmapMissingDependence ( errMsg )