This commit is contained in:
Miroslav Stampar 2010-09-26 14:56:55 +00:00
parent 35f35605df
commit dc11ae0d65
5 changed files with 71 additions and 10 deletions

View File

@ -92,7 +92,7 @@ def start():
""" """
if not conf.start: if not conf.start:
return return False
if conf.optimize: if conf.optimize:
conf.useCommonPrediction = conf.useNullConnection = conf.keepAlive = True conf.useCommonPrediction = conf.useNullConnection = conf.keepAlive = True
@ -101,8 +101,7 @@ def start():
initTargetEnv() initTargetEnv()
setupTargetEnv() setupTargetEnv()
action() action()
return True
return
if conf.url: if conf.url:
kb.targetUrls.add(( conf.url, conf.method, conf.data, conf.cookie )) kb.targetUrls.add(( conf.url, conf.method, conf.data, conf.cookie ))
@ -111,6 +110,7 @@ def start():
errMsg = "you did not edit the configuration file properly, set " errMsg = "you did not edit the configuration file properly, set "
errMsg += "the target url, list of targets or google dork" errMsg += "the target url, list of targets or google dork"
logger.error(errMsg) logger.error(errMsg)
return False
if kb.targetUrls and len(kb.targetUrls) > 1: if kb.targetUrls and len(kb.targetUrls) > 1:
infoMsg = "sqlmap got a total of %d targets" % len(kb.targetUrls) infoMsg = "sqlmap got a total of %d targets" % len(kb.targetUrls)
@ -287,7 +287,9 @@ def start():
logger.error(e) logger.error(e)
else: else:
logger.error(e) logger.error(e)
return return False
if conf.loggedToOut: if conf.loggedToOut:
logger.info("Fetched data logged to text files under '%s'" % conf.outputPath) logger.info("Fetched data logged to text files under '%s'" % conf.outputPath)
return True

View File

@ -66,6 +66,9 @@ class Dump:
self.__outputFile = "%s%slog" % (conf.outputPath, os.sep) self.__outputFile = "%s%slog" % (conf.outputPath, os.sep)
self.__outputFP = codecs.open(self.__outputFile, "ab", conf.dataEncoding) self.__outputFP = codecs.open(self.__outputFile, "ab", conf.dataEncoding)
def getOutputFile(self):
return self.__outputFile
def string(self, header, data, sort=True): def string(self, header, data, sort=True):
if isinstance(data, (list, tuple, set)): if isinstance(data, (list, tuple, set)):
self.lister(header, data, sort) self.lister(header, data, sort)

View File

@ -39,6 +39,7 @@ from lib.core.data import conf
from lib.core.data import logger from lib.core.data import logger
from lib.core.data import paths from lib.core.data import paths
from lib.core.option import init from lib.core.option import init
from lib.core.option import __setVerbosity
from lib.parse.cmdline import cmdLineParser from lib.parse.cmdline import cmdLineParser
def smokeTest(): def smokeTest():
@ -80,9 +81,9 @@ def smokeTest():
dataToStdout("\r%s\r" % (" "*(getConsoleWidth()-1))) dataToStdout("\r%s\r" % (" "*(getConsoleWidth()-1)))
if retVal: if retVal:
logger.info("smoke test result: passed") logger.info("smoke test final result: passed")
else: else:
logger.info("smoke test result: failed") logger.info("smoke test final result: failed")
return retVal return retVal
@ -90,6 +91,8 @@ def liveTest():
""" """
This will run the test of a program against the live testing environment This will run the test of a program against the live testing environment
""" """
retVal = True
count = 0
vars = {} vars = {}
xfile = codecs.open(paths.LIVE_TESTS_XML, 'r', conf.dataEncoding) xfile = codecs.open(paths.LIVE_TESTS_XML, 'r', conf.dataEncoding)
livetests = minidom.parse(xfile).documentElement livetests = minidom.parse(xfile).documentElement
@ -106,6 +109,7 @@ def liveTest():
log = [] log = []
session = [] session = []
switches = {} switches = {}
count += 1
if case.getElementsByTagName("switches"): if case.getElementsByTagName("switches"):
for child in case.getElementsByTagName("switches")[0].childNodes: for child in case.getElementsByTagName("switches")[0].childNodes:
@ -122,7 +126,18 @@ def liveTest():
if item.hasAttribute("value"): if item.hasAttribute("value"):
session.append(replaceVars(item.getAttribute("value"), vars)) session.append(replaceVars(item.getAttribute("value"), vars))
runCase(switches, log, session) result = runCase(switches, log, session)
if not result:
errMsg = "live test failed at case #%d" % count
logger.error(errMsg)
retVal &= result
if retVal:
logger.info("live test final result: passed")
else:
logger.info("live test final result: failed")
return retVal
def initCase(): def initCase():
paths.SQLMAP_OUTPUT_PATH = tempfile.mkdtemp() paths.SQLMAP_OUTPUT_PATH = tempfile.mkdtemp()
@ -130,15 +145,50 @@ def initCase():
paths.SQLMAP_FILES_PATH = os.path.join(paths.SQLMAP_OUTPUT_PATH, "%s", "files") paths.SQLMAP_FILES_PATH = os.path.join(paths.SQLMAP_OUTPUT_PATH, "%s", "files")
cmdLineOptions = cmdLineParser() cmdLineOptions = cmdLineParser()
cmdLineOptions.liveTest = cmdLineOptions.smokeTest = False cmdLineOptions.liveTest = cmdLineOptions.smokeTest = False
cmdLineOptions.verbose = 0
init(cmdLineOptions) init(cmdLineOptions)
conf.suppressOutput = True __setVerbosity()
logger.setLevel(logging.CRITICAL)
def cleanCase():
#remove dir: paths.SQLMAP_OUTPUT_PATH
paths.SQLMAP_OUTPUT_PATH = os.path.join(paths.SQLMAP_ROOT_PATH, "output")
paths.SQLMAP_DUMP_PATH = os.path.join(paths.SQLMAP_OUTPUT_PATH, "%s", "dump")
paths.SQLMAP_FILES_PATH = os.path.join(paths.SQLMAP_OUTPUT_PATH, "%s", "files")
conf.verbose = 1
__setVerbosity()
def runCase(switches, log=None, session=None): def runCase(switches, log=None, session=None):
retVal = True
initCase() initCase()
for key, value in switches.items(): for key, value in switches.items():
conf[key] = value conf[key] = value
start()
result = start()
if result == False: #if None ignore
retVal = False
if session and retVal:
file = open(conf.sessionFile, 'r')
content = file.read()
file.close()
for item in session:
#if not re.search(item, content):
if content.find(item) < 0:
retVal = False
break
if log and retVal:
file = open(conf.dumper.getOutputFile(), 'r')
content = file.read()
file.close()
for item in log:
#if not re.search(item, content):
if content.find(item) < 0:
retVal = False
break
cleanCase()
return retVal
def replaceVars(item, vars): def replaceVars(item, vars):
retVal = item retVal = item

View File

@ -502,6 +502,9 @@ class XMLDump:
except IOError, e: except IOError, e:
raise sqlmapFilePathException("Wrong filename provided for saving the xml file: %s" % conf.xmlFile) raise sqlmapFilePathException("Wrong filename provided for saving the xml file: %s" % conf.xmlFile)
def getOutputFile(self):
return self.__outputFile
def finish(self, resultStatus, resultMsg=""): def finish(self, resultStatus, resultMsg=""):
''' '''
Finishes the dumper operation: Finishes the dumper operation:

View File

@ -10,6 +10,9 @@
<url value="http://${host}/sqlmap/mysql/get_int.php?id=1"/> <url value="http://${host}/sqlmap/mysql/get_int.php?id=1"/>
<getBanner value="True"/> <getBanner value="True"/>
</switches> </switches>
<log>
<item value="5.1.41-3~bpo50+1"/>
</log>
</case> </case>
<!-- Oracle <!-- Oracle
<case> <case>