2013-02-14 15:32:17 +04:00
|
|
|
#!/usr/bin/env python
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
"""
|
2019-01-05 23:38:52 +03:00
|
|
|
Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
|
2017-10-11 15:50:46 +03:00
|
|
|
See the file 'LICENSE' for copying permission
|
2008-10-15 19:38:22 +04:00
|
|
|
"""
|
|
|
|
|
|
|
|
from lib.controller.handler import setHandler
|
2011-01-28 19:36:09 +03:00
|
|
|
from lib.core.common import Backend
|
|
|
|
from lib.core.common import Format
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.core.data import conf
|
|
|
|
from lib.core.data import kb
|
2012-10-05 12:49:31 +04:00
|
|
|
from lib.core.data import logger
|
2010-09-30 16:35:45 +04:00
|
|
|
from lib.core.data import paths
|
2013-01-30 19:30:34 +04:00
|
|
|
from lib.core.enums import CONTENT_TYPE
|
2012-12-06 17:14:19 +04:00
|
|
|
from lib.core.exception import SqlmapNoneDataException
|
|
|
|
from lib.core.exception import SqlmapUnsupportedDBMSException
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.core.settings import SUPPORTED_DBMS
|
2017-04-18 14:53:41 +03:00
|
|
|
from lib.utils.brute import columnExists
|
|
|
|
from lib.utils.brute import tableExists
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
def action():
|
|
|
|
"""
|
|
|
|
This function exploit the SQL injection on the affected
|
2013-04-09 13:48:42 +04:00
|
|
|
URL parameter and extract requested data from the
|
2008-10-15 19:38:22 +04:00
|
|
|
back-end database management system or operating system
|
|
|
|
if possible
|
|
|
|
"""
|
|
|
|
|
|
|
|
# First of all we have to identify the back-end database management
|
|
|
|
# system to be able to go ahead with the injection
|
2010-03-27 02:23:25 +03:00
|
|
|
setHandler()
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2011-01-28 19:36:09 +03:00
|
|
|
if not Backend.getDbms() or not conf.dbmsHandler:
|
|
|
|
htmlParsed = Format.getErrorParsedDBMSes()
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2011-04-30 17:20:05 +04:00
|
|
|
errMsg = "sqlmap was not able to fingerprint the "
|
2008-10-15 19:38:22 +04:00
|
|
|
errMsg += "back-end database management system"
|
|
|
|
|
|
|
|
if htmlParsed:
|
|
|
|
errMsg += ", but from the HTML error page it was "
|
|
|
|
errMsg += "possible to determinate that the "
|
2012-05-09 14:06:23 +04:00
|
|
|
errMsg += "back-end DBMS is %s" % htmlParsed
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
if htmlParsed and htmlParsed.lower() in SUPPORTED_DBMS:
|
|
|
|
errMsg += ". Do not specify the back-end DBMS manually, "
|
|
|
|
errMsg += "sqlmap will fingerprint the DBMS for you"
|
2010-11-05 16:14:12 +03:00
|
|
|
elif kb.nullConnection:
|
|
|
|
errMsg += ". You can try to rerun without using optimization "
|
|
|
|
errMsg += "switch '%s'" % ("-o" if conf.optimize else "--null-connection")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2013-01-04 02:20:55 +04:00
|
|
|
raise SqlmapUnsupportedDBMSException(errMsg)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2012-12-17 17:02:09 +04:00
|
|
|
conf.dumper.singleString(conf.dbmsHandler.getFingerprint())
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
# Enumeration options
|
|
|
|
if conf.getBanner:
|
2010-05-28 20:43:04 +04:00
|
|
|
conf.dumper.banner(conf.dbmsHandler.getBanner())
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
if conf.getCurrentUser:
|
2010-05-28 20:43:04 +04:00
|
|
|
conf.dumper.currentUser(conf.dbmsHandler.getCurrentUser())
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
if conf.getCurrentDb:
|
2010-05-28 20:43:04 +04:00
|
|
|
conf.dumper.currentDb(conf.dbmsHandler.getCurrentDb())
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2012-07-12 03:01:57 +04:00
|
|
|
if conf.getHostname:
|
|
|
|
conf.dumper.hostname(conf.dbmsHandler.getHostname())
|
|
|
|
|
2008-12-18 23:41:11 +03:00
|
|
|
if conf.isDba:
|
2010-05-28 20:43:04 +04:00
|
|
|
conf.dumper.dba(conf.dbmsHandler.isDba())
|
2008-12-18 23:41:11 +03:00
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
if conf.getUsers:
|
2010-05-28 20:43:04 +04:00
|
|
|
conf.dumper.users(conf.dbmsHandler.getUsers())
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
if conf.getPasswordHashes:
|
2012-10-05 12:49:31 +04:00
|
|
|
try:
|
2016-09-02 17:10:11 +03:00
|
|
|
conf.dumper.userSettings("database management system users password hashes", conf.dbmsHandler.getPasswordHashes(), "password hash", CONTENT_TYPE.PASSWORDS)
|
2012-12-06 17:14:19 +04:00
|
|
|
except SqlmapNoneDataException, ex:
|
2012-10-05 12:49:31 +04:00
|
|
|
logger.critical(ex)
|
|
|
|
except:
|
|
|
|
raise
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
if conf.getPrivileges:
|
2012-10-05 12:49:31 +04:00
|
|
|
try:
|
2016-09-02 17:10:11 +03:00
|
|
|
conf.dumper.userSettings("database management system users privileges", conf.dbmsHandler.getPrivileges(), "privilege", CONTENT_TYPE.PRIVILEGES)
|
2012-12-06 17:14:19 +04:00
|
|
|
except SqlmapNoneDataException, ex:
|
2012-10-05 12:49:31 +04:00
|
|
|
logger.critical(ex)
|
|
|
|
except:
|
|
|
|
raise
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-03-25 18:46:06 +03:00
|
|
|
if conf.getRoles:
|
2012-10-05 12:49:31 +04:00
|
|
|
try:
|
2016-09-02 17:10:11 +03:00
|
|
|
conf.dumper.userSettings("database management system users roles", conf.dbmsHandler.getRoles(), "role", CONTENT_TYPE.ROLES)
|
2012-12-06 17:14:19 +04:00
|
|
|
except SqlmapNoneDataException, ex:
|
2012-10-05 12:49:31 +04:00
|
|
|
logger.critical(ex)
|
|
|
|
except:
|
|
|
|
raise
|
2010-03-25 18:46:06 +03:00
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
if conf.getDbs:
|
2010-05-28 20:43:04 +04:00
|
|
|
conf.dumper.dbs(conf.dbmsHandler.getDbs())
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
if conf.getTables:
|
2010-05-28 20:43:04 +04:00
|
|
|
conf.dumper.dbTables(conf.dbmsHandler.getTables())
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2011-04-30 01:09:07 +04:00
|
|
|
if conf.commonTables:
|
|
|
|
conf.dumper.dbTables(tableExists(paths.COMMON_TABLES))
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2011-04-29 03:59:00 +04:00
|
|
|
if conf.getSchema:
|
2013-01-30 19:30:34 +04:00
|
|
|
conf.dumper.dbTableColumns(conf.dbmsHandler.getSchema(), CONTENT_TYPE.SCHEMA)
|
2010-11-09 19:15:55 +03:00
|
|
|
|
2011-04-30 01:09:07 +04:00
|
|
|
if conf.getColumns:
|
2013-01-30 19:30:34 +04:00
|
|
|
conf.dumper.dbTableColumns(conf.dbmsHandler.getColumns(), CONTENT_TYPE.COLUMNS)
|
2011-04-30 01:09:07 +04:00
|
|
|
|
2011-04-30 04:22:22 +04:00
|
|
|
if conf.getCount:
|
|
|
|
conf.dumper.dbTablesCount(conf.dbmsHandler.getCount())
|
|
|
|
|
2011-04-30 01:09:07 +04:00
|
|
|
if conf.commonColumns:
|
|
|
|
conf.dumper.dbTableColumns(columnExists(paths.COMMON_COLUMNS))
|
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
if conf.dumpTable:
|
2011-05-08 06:08:18 +04:00
|
|
|
conf.dbmsHandler.dumpTable()
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
if conf.dumpAll:
|
|
|
|
conf.dbmsHandler.dumpAll()
|
|
|
|
|
2010-05-07 17:40:57 +04:00
|
|
|
if conf.search:
|
|
|
|
conf.dbmsHandler.search()
|
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
if conf.query:
|
2010-05-28 20:43:04 +04:00
|
|
|
conf.dumper.query(conf.query, conf.dbmsHandler.sqlQuery(conf.query))
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
if conf.sqlShell:
|
|
|
|
conf.dbmsHandler.sqlShell()
|
|
|
|
|
2012-07-10 03:27:08 +04:00
|
|
|
if conf.sqlFile:
|
|
|
|
conf.dbmsHandler.sqlFile()
|
|
|
|
|
2009-09-26 03:03:45 +04:00
|
|
|
# User-defined function options
|
|
|
|
if conf.udfInject:
|
|
|
|
conf.dbmsHandler.udfInjectCustom()
|
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
# File system options
|
2018-08-28 15:31:20 +03:00
|
|
|
if conf.fileRead:
|
|
|
|
conf.dumper.rFile(conf.dbmsHandler.readFile(conf.fileRead))
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2018-08-28 15:31:20 +03:00
|
|
|
if conf.fileWrite:
|
|
|
|
conf.dbmsHandler.writeFile(conf.fileWrite, conf.fileDest, conf.fileWriteType)
|
2009-04-22 15:48:07 +04:00
|
|
|
|
|
|
|
# Operating system options
|
|
|
|
if conf.osCmd:
|
|
|
|
conf.dbmsHandler.osCmd()
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
if conf.osShell:
|
|
|
|
conf.dbmsHandler.osShell()
|
2009-04-22 15:48:07 +04:00
|
|
|
|
|
|
|
if conf.osPwn:
|
|
|
|
conf.dbmsHandler.osPwn()
|
|
|
|
|
|
|
|
if conf.osSmb:
|
|
|
|
conf.dbmsHandler.osSmb()
|
|
|
|
|
|
|
|
if conf.osBof:
|
|
|
|
conf.dbmsHandler.osBof()
|
|
|
|
|
2009-09-26 03:03:45 +04:00
|
|
|
# Windows registry options
|
|
|
|
if conf.regRead:
|
2010-05-28 20:43:04 +04:00
|
|
|
conf.dumper.registerValue(conf.dbmsHandler.regRead())
|
2009-09-26 03:03:45 +04:00
|
|
|
|
|
|
|
if conf.regAdd:
|
|
|
|
conf.dbmsHandler.regAdd()
|
|
|
|
|
|
|
|
if conf.regDel:
|
|
|
|
conf.dbmsHandler.regDel()
|
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
# Miscellaneous options
|
|
|
|
if conf.cleanup:
|
|
|
|
conf.dbmsHandler.cleanup()
|
2010-03-27 02:23:25 +03:00
|
|
|
|
|
|
|
if conf.direct:
|
|
|
|
conf.dbmsConnector.close()
|