mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-02-16 19:40:37 +03:00
Minor bug fixes and code refactoring
This commit is contained in:
parent
919a8345d6
commit
a138dbe5f6
|
@ -37,6 +37,8 @@ import ntpath
|
||||||
import posixpath
|
import posixpath
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from ConfigParser import DEFAULTSECT
|
||||||
|
from ConfigParser import RawConfigParser
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
from subprocess import PIPE
|
from subprocess import PIPE
|
||||||
from subprocess import Popen as execute
|
from subprocess import Popen as execute
|
||||||
|
@ -1365,3 +1367,22 @@ def getBruteUnicode(string):
|
||||||
for char in string:
|
for char in string:
|
||||||
retVal += unichr(ord(char))
|
retVal += unichr(ord(char))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
|
class UnicodeRawConfigParser(RawConfigParser):
|
||||||
|
def write(self, fp):
|
||||||
|
"""Write an .ini-format representation of the configuration state."""
|
||||||
|
if self._defaults:
|
||||||
|
fp.write("[%s]\n" % DEFAULTSECT)
|
||||||
|
for (key, value) in self._defaults.items():
|
||||||
|
fp.write("%s = %s\n" % (key, unicode(value).replace('\n', '\n\t')))
|
||||||
|
fp.write("\n")
|
||||||
|
for section in self._sections:
|
||||||
|
fp.write("[%s]\n" % section)
|
||||||
|
for (key, value) in self._sections[section].items():
|
||||||
|
if key != "__name__":
|
||||||
|
if value is None:
|
||||||
|
fp.write("%s\n" % (key))
|
||||||
|
else:
|
||||||
|
fp.write("%s = %s\n" %
|
||||||
|
(key, unicode(value).replace('\n', '\n\t')))
|
||||||
|
fp.write("\n")
|
||||||
|
|
|
@ -33,9 +33,6 @@ import socket
|
||||||
import urllib2
|
import urllib2
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
from ConfigParser import DEFAULTSECT
|
|
||||||
from ConfigParser import RawConfigParser
|
|
||||||
|
|
||||||
from lib.core.common import getConsoleWidth
|
from lib.core.common import getConsoleWidth
|
||||||
from lib.core.common import getFileType
|
from lib.core.common import getFileType
|
||||||
from lib.core.common import normalizePath
|
from lib.core.common import normalizePath
|
||||||
|
@ -45,6 +42,7 @@ from lib.core.common import parseTargetUrl
|
||||||
from lib.core.common import paths
|
from lib.core.common import paths
|
||||||
from lib.core.common import randomRange
|
from lib.core.common import randomRange
|
||||||
from lib.core.common import sanitizeStr
|
from lib.core.common import sanitizeStr
|
||||||
|
from lib.core.common import UnicodeRawConfigParser
|
||||||
from lib.core.data import conf
|
from lib.core.data import conf
|
||||||
from lib.core.data import kb
|
from lib.core.data import kb
|
||||||
from lib.core.data import logger
|
from lib.core.data import logger
|
||||||
|
@ -77,26 +75,6 @@ authHandler = urllib2.BaseHandler()
|
||||||
proxyHandler = urllib2.BaseHandler()
|
proxyHandler = urllib2.BaseHandler()
|
||||||
redirectHandler = SmartRedirectHandler()
|
redirectHandler = SmartRedirectHandler()
|
||||||
|
|
||||||
|
|
||||||
class UnicodeRawConfigParser(RawConfigParser):
|
|
||||||
def write(self, fp):
|
|
||||||
"""Write an .ini-format representation of the configuration state."""
|
|
||||||
if self._defaults:
|
|
||||||
fp.write("[%s]\n" % DEFAULTSECT)
|
|
||||||
for (key, value) in self._defaults.items():
|
|
||||||
fp.write("%s = %s\n" % (key, unicode(value).replace('\n', '\n\t')))
|
|
||||||
fp.write("\n")
|
|
||||||
for section in self._sections:
|
|
||||||
fp.write("[%s]\n" % section)
|
|
||||||
for (key, value) in self._sections[section].items():
|
|
||||||
if key != "__name__":
|
|
||||||
if value is None:
|
|
||||||
fp.write("%s\n" % (key))
|
|
||||||
else:
|
|
||||||
fp.write("%s = %s\n" %
|
|
||||||
(key, unicode(value).replace('\n', '\n\t')))
|
|
||||||
fp.write("\n")
|
|
||||||
|
|
||||||
def __urllib2Opener():
|
def __urllib2Opener():
|
||||||
"""
|
"""
|
||||||
This function creates the urllib2 OpenerDirector.
|
This function creates the urllib2 OpenerDirector.
|
||||||
|
@ -118,7 +96,7 @@ def __urllib2Opener():
|
||||||
urllib2.install_opener(opener)
|
urllib2.install_opener(opener)
|
||||||
|
|
||||||
def __feedTargetsDict(reqFile, addedTargetUrls):
|
def __feedTargetsDict(reqFile, addedTargetUrls):
|
||||||
fp = codecs.open(reqFile, "r", conf.dataEncoding)
|
fp = codecs.open(reqFile, "rb", conf.dataEncoding)
|
||||||
|
|
||||||
fread = fp.read()
|
fread = fp.read()
|
||||||
fread = fread.replace("\r", "")
|
fread = fread.replace("\r", "")
|
||||||
|
@ -856,6 +834,13 @@ def __cleanupOptions():
|
||||||
debugMsg = "cleaning up configuration parameters"
|
debugMsg = "cleaning up configuration parameters"
|
||||||
logger.debug(debugMsg)
|
logger.debug(debugMsg)
|
||||||
|
|
||||||
|
width = getConsoleWidth()
|
||||||
|
|
||||||
|
if conf.eta:
|
||||||
|
conf.progressWidth = width-26
|
||||||
|
else:
|
||||||
|
conf.progressWidth = width-46
|
||||||
|
|
||||||
if conf.testParameter:
|
if conf.testParameter:
|
||||||
conf.testParameter = conf.testParameter.replace(" ", "")
|
conf.testParameter = conf.testParameter.replace(" ", "")
|
||||||
conf.testParameter = conf.testParameter.split(",")
|
conf.testParameter = conf.testParameter.split(",")
|
||||||
|
@ -932,13 +917,6 @@ def __setConfAttributes():
|
||||||
conf.threadException = False
|
conf.threadException = False
|
||||||
conf.wFileType = None
|
conf.wFileType = None
|
||||||
|
|
||||||
width = getConsoleWidth()
|
|
||||||
|
|
||||||
if conf.eta:
|
|
||||||
conf.progressWidth = width-26
|
|
||||||
else:
|
|
||||||
conf.progressWidth = width-46
|
|
||||||
|
|
||||||
def __setKnowledgeBaseAttributes():
|
def __setKnowledgeBaseAttributes():
|
||||||
"""
|
"""
|
||||||
This function set some needed attributes into the knowledge base
|
This function set some needed attributes into the knowledge base
|
||||||
|
@ -989,7 +967,6 @@ def __setKnowledgeBaseAttributes():
|
||||||
kb.unionNegative = False
|
kb.unionNegative = False
|
||||||
kb.unionFalseCond = False
|
kb.unionFalseCond = False
|
||||||
|
|
||||||
|
|
||||||
def __saveCmdline():
|
def __saveCmdline():
|
||||||
"""
|
"""
|
||||||
Saves the command line options on a sqlmap configuration INI file
|
Saves the command line options on a sqlmap configuration INI file
|
||||||
|
@ -1019,6 +996,9 @@ def __saveCmdline():
|
||||||
optionData.sort()
|
optionData.sort()
|
||||||
|
|
||||||
for option, value, datatype in optionData:
|
for option, value, datatype in optionData:
|
||||||
|
if isinstance(datatype, (list, tuple, set)):
|
||||||
|
datatype = datatype[0]
|
||||||
|
|
||||||
if value is None:
|
if value is None:
|
||||||
if datatype == "boolean":
|
if datatype == "boolean":
|
||||||
value = "False"
|
value = "False"
|
||||||
|
@ -1037,10 +1017,8 @@ def __saveCmdline():
|
||||||
|
|
||||||
config.set(family, option, value)
|
config.set(family, option, value)
|
||||||
|
|
||||||
print 11111
|
confFP = codecs.open(paths.SQLMAP_CONFIG, "wb", conf.dataEncoding)
|
||||||
confFP = codecs.open(paths.SQLMAP_CONFIG, "wb", "UTF8")
|
|
||||||
config.write(confFP)
|
config.write(confFP)
|
||||||
print 22222
|
|
||||||
|
|
||||||
infoMsg = "saved command line options on '%s' configuration file" % paths.SQLMAP_CONFIG
|
infoMsg = "saved command line options on '%s' configuration file" % paths.SQLMAP_CONFIG
|
||||||
logger.info(infoMsg)
|
logger.info(infoMsg)
|
||||||
|
@ -1112,11 +1090,11 @@ def init(inputOptions=advancedDict()):
|
||||||
based upon command line and configuration file options.
|
based upon command line and configuration file options.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
__setConfAttributes()
|
||||||
|
__setKnowledgeBaseAttributes()
|
||||||
__mergeOptions(inputOptions)
|
__mergeOptions(inputOptions)
|
||||||
__setVerbosity()
|
__setVerbosity()
|
||||||
__saveCmdline()
|
__saveCmdline()
|
||||||
__setConfAttributes()
|
|
||||||
__setKnowledgeBaseAttributes()
|
|
||||||
__cleanupOptions()
|
__cleanupOptions()
|
||||||
__basicOptionValidation()
|
__basicOptionValidation()
|
||||||
__setRequestFromFile()
|
__setRequestFromFile()
|
||||||
|
|
|
@ -24,9 +24,9 @@ Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
import codecs
|
import codecs
|
||||||
|
|
||||||
from ConfigParser import NoSectionError
|
from ConfigParser import NoSectionError
|
||||||
from ConfigParser import RawConfigParser
|
|
||||||
|
|
||||||
from lib.core.common import checkFile
|
from lib.core.common import checkFile
|
||||||
|
from lib.core.common import UnicodeRawConfigParser
|
||||||
from lib.core.data import conf
|
from lib.core.data import conf
|
||||||
from lib.core.data import logger
|
from lib.core.data import logger
|
||||||
from lib.core.exception import sqlmapMissingMandatoryOptionException
|
from lib.core.exception import sqlmapMissingMandatoryOptionException
|
||||||
|
@ -43,17 +43,13 @@ def configFileProxy(section, option, boolean=False, integer=False):
|
||||||
global config
|
global config
|
||||||
|
|
||||||
if config.has_option(section, option):
|
if config.has_option(section, option):
|
||||||
|
if boolean:
|
||||||
|
value = config.getboolean(section, option)
|
||||||
|
elif integer:
|
||||||
|
value = config.getint(section, option)
|
||||||
|
else:
|
||||||
value = config.get(section, option)
|
value = config.get(section, option)
|
||||||
|
|
||||||
if not value:
|
|
||||||
value = None
|
|
||||||
elif value.isdigit():
|
|
||||||
value = int(value)
|
|
||||||
elif value in ("false", "False"):
|
|
||||||
value = False
|
|
||||||
elif value in ("true", "True"):
|
|
||||||
value = True
|
|
||||||
|
|
||||||
if value:
|
if value:
|
||||||
conf[option] = value
|
conf[option] = value
|
||||||
else:
|
else:
|
||||||
|
@ -76,8 +72,8 @@ def configFileParser(configFile):
|
||||||
logger.debug(debugMsg)
|
logger.debug(debugMsg)
|
||||||
|
|
||||||
checkFile(configFile)
|
checkFile(configFile)
|
||||||
config = RawConfigParser()
|
config = UnicodeRawConfigParser()
|
||||||
config.readfp(codecs.open(configFile, "r", "UTF8"))
|
config.readfp(codecs.open(configFile, "rb", conf.dataEncoding))
|
||||||
|
|
||||||
if not config.has_section("Target"):
|
if not config.has_section("Target"):
|
||||||
raise NoSectionError, "Target in the configuration file is mandatory"
|
raise NoSectionError, "Target in the configuration file is mandatory"
|
||||||
|
@ -92,16 +88,16 @@ def configFileParser(configFile):
|
||||||
raise sqlmapMissingMandatoryOptionException, errMsg
|
raise sqlmapMissingMandatoryOptionException, errMsg
|
||||||
|
|
||||||
for family, optionData in optDict.items():
|
for family, optionData in optDict.items():
|
||||||
for option, data in optionData.items():
|
for option, datatype in optionData.items():
|
||||||
boolean = False
|
boolean = False
|
||||||
integer = False
|
integer = False
|
||||||
|
|
||||||
if isinstance(data, (tuple, dict, set)):
|
if isinstance(datatype, (list, tuple, set)):
|
||||||
data = data[0]
|
datatype = datatype[0]
|
||||||
|
|
||||||
if data == "boolean":
|
if datatype == "boolean":
|
||||||
boolean = True
|
boolean = True
|
||||||
elif data == "integer":
|
elif datatype == "integer":
|
||||||
integer = True
|
integer = True
|
||||||
|
|
||||||
configFileProxy(family, option, boolean, integer)
|
configFileProxy(family, option, boolean, integer)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user