2019-05-08 13:47:52 +03:00
|
|
|
#!/usr/bin/env python
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
"""
|
2021-09-08 22:01:41 +03:00
|
|
|
Copyright (c) 2006-2021 sqlmap developers (https://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
|
|
|
"""
|
2010-05-30 18:53:13 +04:00
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.core.common import checkFile
|
2015-09-10 16:51:33 +03:00
|
|
|
from lib.core.common import getSafeExString
|
2014-11-26 15:38:21 +03:00
|
|
|
from lib.core.common import openFile
|
2012-04-03 18:46:09 +04:00
|
|
|
from lib.core.common import unArrayizeValue
|
2010-05-28 19:57:43 +04:00
|
|
|
from lib.core.common import UnicodeRawConfigParser
|
2019-05-06 01:54:21 +03:00
|
|
|
from lib.core.convert import getUnicode
|
2016-02-23 13:46:04 +03:00
|
|
|
from lib.core.data import cmdLineOptions
|
2011-02-02 17:06:40 +03:00
|
|
|
from lib.core.data import conf
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.core.data import logger
|
2017-01-18 12:33:54 +03:00
|
|
|
from lib.core.enums import OPTION_TYPE
|
2012-12-06 17:14:19 +04:00
|
|
|
from lib.core.exception import SqlmapMissingMandatoryOptionException
|
|
|
|
from lib.core.exception import SqlmapSyntaxException
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.core.optiondict import optDict
|
|
|
|
|
|
|
|
config = None
|
|
|
|
|
2017-01-18 12:33:54 +03:00
|
|
|
def configFileProxy(section, option, datatype):
|
2008-10-15 19:38:22 +04:00
|
|
|
"""
|
|
|
|
Parse configuration file and save settings into the configuration
|
|
|
|
advanced dictionary.
|
|
|
|
"""
|
|
|
|
|
|
|
|
if config.has_option(section, option):
|
2014-04-07 22:22:51 +04:00
|
|
|
try:
|
2017-01-18 12:33:54 +03:00
|
|
|
if datatype == OPTION_TYPE.BOOLEAN:
|
2014-04-07 22:22:51 +04:00
|
|
|
value = config.getboolean(section, option) if config.get(section, option) else False
|
2017-01-18 12:33:54 +03:00
|
|
|
elif datatype == OPTION_TYPE.INTEGER:
|
2014-04-07 22:22:51 +04:00
|
|
|
value = config.getint(section, option) if config.get(section, option) else 0
|
2017-01-18 12:33:54 +03:00
|
|
|
elif datatype == OPTION_TYPE.FLOAT:
|
|
|
|
value = config.getfloat(section, option) if config.get(section, option) else 0.0
|
2014-04-07 22:22:51 +04:00
|
|
|
else:
|
|
|
|
value = config.get(section, option)
|
2019-01-22 02:40:48 +03:00
|
|
|
except ValueError as ex:
|
2014-04-07 22:22:51 +04:00
|
|
|
errMsg = "error occurred while processing the option "
|
2014-12-15 15:36:08 +03:00
|
|
|
errMsg += "'%s' in provided configuration file ('%s')" % (option, getUnicode(ex))
|
2014-04-07 22:22:51 +04:00
|
|
|
raise SqlmapSyntaxException(errMsg)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
if value:
|
|
|
|
conf[option] = value
|
|
|
|
else:
|
|
|
|
conf[option] = None
|
|
|
|
else:
|
2011-04-30 17:20:05 +04:00
|
|
|
debugMsg = "missing requested option '%s' (section " % option
|
2008-10-15 19:38:22 +04:00
|
|
|
debugMsg += "'%s') into the configuration file, " % section
|
|
|
|
debugMsg += "ignoring. Skipping to next."
|
|
|
|
logger.debug(debugMsg)
|
|
|
|
|
|
|
|
def configFileParser(configFile):
|
|
|
|
"""
|
|
|
|
Parse configuration file and save settings into the configuration
|
|
|
|
advanced dictionary.
|
|
|
|
"""
|
|
|
|
|
|
|
|
global config
|
|
|
|
|
|
|
|
debugMsg = "parsing configuration file"
|
|
|
|
logger.debug(debugMsg)
|
|
|
|
|
|
|
|
checkFile(configFile)
|
2014-11-26 15:38:21 +03:00
|
|
|
configFP = openFile(configFile, "rb")
|
2011-06-03 15:01:26 +04:00
|
|
|
|
|
|
|
try:
|
|
|
|
config = UnicodeRawConfigParser()
|
|
|
|
config.readfp(configFP)
|
2019-01-22 02:40:48 +03:00
|
|
|
except Exception as ex:
|
2015-09-10 16:51:33 +03:00
|
|
|
errMsg = "you have provided an invalid and/or unreadable configuration file ('%s')" % getSafeExString(ex)
|
2013-01-04 02:20:55 +04:00
|
|
|
raise SqlmapSyntaxException(errMsg)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2008-12-04 20:40:03 +03:00
|
|
|
if not config.has_section("Target"):
|
2011-06-03 15:01:26 +04:00
|
|
|
errMsg = "missing a mandatory section 'Target' in the configuration file"
|
2013-01-04 02:20:55 +04:00
|
|
|
raise SqlmapMissingMandatoryOptionException(errMsg)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2016-02-23 13:46:04 +03:00
|
|
|
mandatory = False
|
2008-12-04 20:40:03 +03:00
|
|
|
|
2021-09-14 10:17:21 +03:00
|
|
|
for option in ("direct", "url", "logFile", "bulkFile", "googleDork", "requestFile", "wizard", "swaggerFile"):
|
2016-02-23 13:46:04 +03:00
|
|
|
if config.has_option("Target", option) and config.get("Target", option) or cmdLineOptions.get(option):
|
|
|
|
mandatory = True
|
|
|
|
break
|
|
|
|
|
|
|
|
if not mandatory:
|
2011-05-11 12:46:40 +04:00
|
|
|
errMsg = "missing a mandatory option in the configuration file "
|
2021-09-14 10:17:21 +03:00
|
|
|
errMsg += "(direct, url, logFile, bulkFile, googleDork, requestFile, wizard or swaggerFile)"
|
2013-01-04 02:20:55 +04:00
|
|
|
raise SqlmapMissingMandatoryOptionException(errMsg)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
for family, optionData in optDict.items():
|
2010-05-28 19:57:43 +04:00
|
|
|
for option, datatype in optionData.items():
|
2012-04-03 18:46:09 +04:00
|
|
|
datatype = unArrayizeValue(datatype)
|
2017-01-18 12:33:54 +03:00
|
|
|
configFileProxy(family, option, datatype)
|