| 45 | raise NotImplementedError |
| 46 | |
| 47 | class SQLAlchemy(GenericConnector): |
| 48 | def __init__(self, dialect=None): |
| 49 | GenericConnector.__init__(self) |
| 50 | |
| 51 | self.dialect = dialect |
| 52 | self.address = conf.direct |
| 53 | |
| 54 | if conf.dbmsUser: |
| 55 | self.address = self.address.replace("'%s':" % conf.dbmsUser, "%s:" % _urllib.parse.quote(conf.dbmsUser)) |
| 56 | self.address = self.address.replace("%s:" % conf.dbmsUser, "%s:" % _urllib.parse.quote(conf.dbmsUser)) |
| 57 | |
| 58 | if conf.dbmsPass: |
| 59 | self.address = self.address.replace(":'%s'@" % conf.dbmsPass, ":%s@" % _urllib.parse.quote(conf.dbmsPass)) |
| 60 | self.address = self.address.replace(":%s@" % conf.dbmsPass, ":%s@" % _urllib.parse.quote(conf.dbmsPass)) |
| 61 | |
| 62 | if self.dialect: |
| 63 | self.address = re.sub(r"\A.+://", "%s://" % self.dialect, self.address) |
| 64 | |
| 65 | def connect(self): |
| 66 | if _sqlalchemy: |
| 67 | self.initConnection() |
| 68 | |
| 69 | try: |
| 70 | if not self.port and self.db: |
| 71 | if not os.path.exists(self.db): |
| 72 | raise SqlmapFilePathException("the provided database file '%s' does not exist" % self.db) |
| 73 | |
| 74 | _ = self.address.split("//", 1) |
| 75 | self.address = "%s////%s" % (_[0], os.path.abspath(self.db)) |
| 76 | |
| 77 | if self.dialect == "sqlite": |
| 78 | engine = _sqlalchemy.create_engine(self.address, connect_args={"check_same_thread": False}) |
| 79 | elif self.dialect == "oracle": |
| 80 | engine = _sqlalchemy.create_engine(self.address) |
| 81 | else: |
| 82 | engine = _sqlalchemy.create_engine(self.address, connect_args={}) |
| 83 | |
| 84 | self.connector = engine.connect() |
| 85 | except (TypeError, ValueError): |
| 86 | if "_get_server_version_info" in traceback.format_exc(): |
| 87 | try: |
| 88 | import pymssql |
| 89 | if int(pymssql.__version__[0]) < 2: |
| 90 | raise SqlmapConnectionException("SQLAlchemy connection issue (obsolete version of pymssql ('%s') is causing problems)" % pymssql.__version__) |
| 91 | except ImportError: |
| 92 | pass |
| 93 | elif "invalid literal for int() with base 10: '0b" in traceback.format_exc(): |
| 94 | raise SqlmapConnectionException("SQLAlchemy connection issue ('https://bitbucket.org/zzzeek/sqlalchemy/issues/3975')") |
| 95 | else: |
| 96 | pass |
| 97 | except SqlmapFilePathException: |
| 98 | raise |
| 99 | except Exception as ex: |
| 100 | raise SqlmapConnectionException("SQLAlchemy connection issue ('%s')" % getSafeExString(ex)) |
| 101 | |
| 102 | self.printConnected() |
| 103 | else: |
| 104 | raise SqlmapMissingDependence("SQLAlchemy not available (e.g. 'pip%s install SQLAlchemy')" % ('3' if six.PY3 else "")) |
no outgoing calls
no test coverage detected
searching dependent graphs…