SIGN IN SIGN UP
sqlmapproject / sqlmap UNCLAIMED

Automatic SQL injection and database takeover tool

0 0 6 Python
#!/usr/bin/env python
2008-10-15 15:38:22 +00:00
"""
2014-01-13 17:24:49 +00:00
Copyright (c) 2006-2014 sqlmap developers (http://sqlmap.org/)
2010-10-14 23:18:29 +00:00
See the file 'doc/COPYING' for copying permission
2008-10-15 15:38:22 +00:00
"""
2010-05-30 14:53:13 +00:00
2010-05-28 14:04:34 +00:00
import codecs
2008-10-15 15:38:22 +00:00
from ConfigParser import MissingSectionHeaderError
from ConfigParser import ParsingError
2008-10-15 15:38:22 +00:00
from lib.core.common import checkFile
2014-11-26 13:38:21 +01:00
from lib.core.common import openFile
2012-04-03 14:46:09 +00:00
from lib.core.common import unArrayizeValue
2010-05-28 15:57:43 +00:00
from lib.core.common import UnicodeRawConfigParser
2011-02-02 14:06:40 +00:00
from lib.core.data import conf
2008-10-15 15:38:22 +00:00
from lib.core.data import logger
from lib.core.exception import SqlmapMissingMandatoryOptionException
from lib.core.exception import SqlmapSyntaxException
2008-10-15 15:38:22 +00:00
from lib.core.optiondict import optDict
2011-01-30 11:36:03 +00:00
from lib.core.settings import UNICODE_ENCODING
2008-10-15 15:38:22 +00: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):
try:
if boolean:
value = config.getboolean(section, option) if config.get(section, option) else False
elif integer:
value = config.getint(section, option) if config.get(section, option) else 0
else:
value = config.get(section, option)
except ValueError, ex:
errMsg = "error occurred while processing the option "
errMsg += "'%s' in provided configuration file ('%s')" % (option, str(ex))
raise SqlmapSyntaxException(errMsg)
2008-10-15 15:38:22 +00:00
if value:
conf[option] = value
else:
conf[option] = None
else:
2011-04-30 13:20:05 +00:00
debugMsg = "missing requested option '%s' (section " % option
2008-10-15 15:38:22 +00: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 13:38:21 +01:00
configFP = openFile(configFile, "rb")
try:
config = UnicodeRawConfigParser()
config.readfp(configFP)
2014-12-11 00:35:51 +01:00
except Exception, ex:
errMsg = "you have provided an invalid and/or unreadable configuration file ('%s')" % str(ex)
raise SqlmapSyntaxException(errMsg)
2008-10-15 15:38:22 +00:00
if not config.has_section("Target"):
errMsg = "missing a mandatory section 'Target' in the configuration file"
raise SqlmapMissingMandatoryOptionException(errMsg)
2008-10-15 15:38:22 +00:00
condition = not config.has_option("Target", "direct")
condition &= not config.has_option("Target", "url")
condition &= not config.has_option("Target", "logFile")
condition &= not config.has_option("Target", "bulkFile")
condition &= not config.has_option("Target", "googleDork")
condition &= not config.has_option("Target", "requestFile")
2014-07-02 22:27:51 +02:00
condition &= not config.has_option("Target", "sitemapUrl")
condition &= not config.has_option("Target", "wizard")
if condition:
errMsg = "missing a mandatory option in the configuration file "
2014-07-02 22:27:51 +02:00
errMsg += "(direct, url, logFile, bulkFile, googleDork, requestFile, sitemapUrl or wizard)"
raise SqlmapMissingMandatoryOptionException(errMsg)
2008-10-15 15:38:22 +00:00
for family, optionData in optDict.items():
2010-05-28 15:57:43 +00:00
for option, datatype in optionData.items():
2012-04-03 14:46:09 +00:00
datatype = unArrayizeValue(datatype)
2008-10-15 15:38:22 +00:00
2012-04-03 14:46:09 +00:00
boolean = datatype == "boolean"
integer = datatype == "integer"
2008-10-15 15:38:22 +00:00
configFileProxy(family, option, boolean, integer)