2013-02-14 15:25:04 +04:00
|
|
|
#!/usr/bin/env python2
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
"""
|
2013-01-18 18:07:51 +04:00
|
|
|
Copyright (c) 2006-2013 sqlmap developers (http://sqlmap.org/)
|
2010-10-15 03:18:29 +04:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
2008-10-15 19:38:22 +04:00
|
|
|
"""
|
2010-05-30 18:53:13 +04:00
|
|
|
|
2010-05-28 18:04:34 +04:00
|
|
|
import codecs
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2011-06-03 15:01:26 +04:00
|
|
|
from ConfigParser import MissingSectionHeaderError
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
from lib.core.common import checkFile
|
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
|
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
|
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
|
2011-01-30 14:36:03 +03:00
|
|
|
from lib.core.settings import UNICODE_ENCODING
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
config = None
|
|
|
|
|
|
|
|
def configFileProxy(section, option, boolean=False, integer=False):
|
|
|
|
"""
|
|
|
|
Parse configuration file and save settings into the configuration
|
|
|
|
advanced dictionary.
|
|
|
|
"""
|
|
|
|
|
|
|
|
global config
|
|
|
|
|
|
|
|
if config.has_option(section, option):
|
2010-05-28 19:57:43 +04:00
|
|
|
if boolean:
|
2012-01-20 15:13:25 +04:00
|
|
|
value = config.getboolean(section, option) if config.get(section, option) else False
|
2010-05-28 19:57:43 +04:00
|
|
|
elif integer:
|
2012-01-20 15:13:25 +04:00
|
|
|
value = config.getint(section, option) if config.get(section, option) else 0
|
2010-05-28 19:57:43 +04:00
|
|
|
else:
|
|
|
|
value = config.get(section, option)
|
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)
|
2011-01-30 14:36:03 +03:00
|
|
|
configFP = codecs.open(configFile, "rb", UNICODE_ENCODING)
|
2011-06-03 15:01:26 +04:00
|
|
|
|
|
|
|
try:
|
|
|
|
config = UnicodeRawConfigParser()
|
|
|
|
config.readfp(configFP)
|
|
|
|
except MissingSectionHeaderError:
|
2011-06-08 20:08:20 +04:00
|
|
|
errMsg = "you have provided an invalid configuration file"
|
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
|
|
|
|
2011-04-30 17:20:05 +04:00
|
|
|
condition = not config.has_option("Target", "url")
|
2011-05-11 12:46:40 +04:00
|
|
|
condition &= not config.has_option("Target", "logFile")
|
|
|
|
condition &= not config.has_option("Target", "bulkFile")
|
2008-12-04 20:40:03 +03:00
|
|
|
condition &= not config.has_option("Target", "googleDork")
|
2011-05-11 12:46:40 +04:00
|
|
|
condition &= not config.has_option("Target", "requestFile")
|
|
|
|
condition &= not config.has_option("Target", "wizard")
|
2008-12-04 20:40:03 +03:00
|
|
|
|
|
|
|
if condition:
|
2011-05-11 12:46:40 +04:00
|
|
|
errMsg = "missing a mandatory option in the configuration file "
|
|
|
|
errMsg += "(url, logFile, bulkFile, googleDork, requestFile or wizard)"
|
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)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2012-04-03 18:46:09 +04:00
|
|
|
boolean = datatype == "boolean"
|
|
|
|
integer = datatype == "integer"
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
configFileProxy(family, option, boolean, integer)
|