Ejemplo n.º 1
0
def fileExists(pathFile):
    retVal = []
    paths = getFileItems(pathFile, unique=True)

    kb.bruteMode = True

    try:
        conf.dbmsHandler.readFile(randomStr())
    except SqlmapNoneDataException:
        pass
    except:
        kb.bruteMode = False
        raise

    threadData = getCurrentThreadData()
    threadData.shared.count = 0
    threadData.shared.limit = len(paths)
    threadData.shared.value = []

    def fileExistsThread():
        threadData = getCurrentThreadData()

        while kb.threadContinue:
            kb.locks.count.acquire()
            if threadData.shared.count < threadData.shared.limit:
                path = paths[threadData.shared.count]
                threadData.shared.count += 1
                kb.locks.count.release()
            else:
                kb.locks.count.release()
                break

            try:
                result = unArrayizeValue(conf.dbmsHandler.readFile(path))
            except SqlmapNoneDataException:
                result = None

            kb.locks.io.acquire()

            if not isNoneValue(result):
                threadData.shared.value.append(result)

                if conf.verbose in (1, 2) and not conf.api:
                    clearConsoleLine(True)
                    infoMsg = "[%s] [INFO] retrieved: '%s'\n" % (
                        time.strftime("%X"), path)
                    dataToStdout(infoMsg, True)

            if conf.verbose in (1, 2):
                status = '%d/%d items (%d%%)' % (
                    threadData.shared.count, threadData.shared.limit,
                    round(100.0 * threadData.shared.count /
                          threadData.shared.limit))
                dataToStdout(
                    "\r[%s] [INFO] tried %s" % (time.strftime("%X"), status),
                    True)

            kb.locks.io.release()

    try:
        pushValue(logger.getEffectiveLevel())
        logger.setLevel(logging.CRITICAL)

        runThreads(conf.threads, fileExistsThread, threadChoice=True)
    except KeyboardInterrupt:
        warnMsg = "user aborted during file existence "
        warnMsg += "check. sqlmap will display partial output"
        logger.warn(warnMsg)
    finally:
        kb.bruteMode = False
        logger.setLevel(popValue())

    clearConsoleLine(True)
    dataToStdout("\n")

    if not threadData.shared.value:
        warnMsg = "no file(s) found"
        logger.warn(warnMsg)
    else:
        retVal = threadData.shared.value

    return retVal
Ejemplo n.º 2
0
 def test_logger(self):
     self.assertEqual(['__class__', '__delattr__', '__dict__', '__doc__',
                       '__format__', '__getattribute__', '__hash__', '__init__',
                       '__module__', '__new__', '__reduce__', '__reduce_ex__',
                       '__repr__', '__setattr__', '__sizeof__', '__str__',
                       '__subclasshook__', '__weakref__', '_log', 'addFilter',
                       'addHandler', 'callHandlers', 'critical', 'debug',
                       'disabled', 'error', 'exception', 'fatal', 'filter',
                       'filters', 'findCaller', 'getChild', 'getEffectiveLevel',
                       'handle', 'handlers', 'info', 'isEnabledFor', 'level', 'log',
                       'makeRecord', 'manager', 'name', 'parent', 'propagate',
                       'removeFilter', 'removeHandler', 'root', 'setLevel', 'warn',
                       'warning'], dir(logger))
     logger.debug("DEBUG message goes")
     logger.info("INFO message goes")
     self.assertEqual(False, logger == logger.root)
     self.assertEqual("sqlmapLog", logger.name)
     self.assertEqual(30, logger.level)
     self.assertEqual(30, logger.getEffectiveLevel())
     self.assertEqual(False, logger.isEnabledFor(29))
     self.assertEqual(True, logger.isEnabledFor(31))
     self.assertEqual(1, logger.propagate)
     # logging.Manager
     self.assertEqual(['__class__', '__delattr__', '__dict__', '__doc__',
                       '__format__', '__getattribute__', '__hash__', '__init__',
                       '__module__', '__new__', '__reduce__', '__reduce_ex__',
                       '__repr__', '__setattr__', '__sizeof__', '__str__',
                       '__subclasshook__', '__weakref__', '_fixupChildren',
                       '_fixupParents', 'disable', 'emittedNoHandlerWarning',
                       'getLogger', 'loggerClass', 'loggerDict', 'root', 'setLoggerClass'],
                      dir(logger.manager))
     self.assertEqual(True, logger.manager.loggerDict['sqlmapLog'] == logger)
     self.assertEqual(30, logger.manager.loggerDict['ClientForm'].getEffectiveLevel())
     self.assertEqual(0, logger.manager.loggerDict['ClientForm'].level)
     self.assertEqual(False, logger.manager.loggerDict['ClientForm'] == logger.root)
     # logging.filters
     self.assertEqual([], logger.filters)
     # ColorizingStreamHandler
     from thirdparty.ansistrm.ansistrm import ColorizingStreamHandler
     self.assertEqual(['__class__', '__delattr__', '__dict__', '__doc__',
                       '__format__', '__getattribute__', '__hash__', '__init__',
                       '__module__', '__new__', '__reduce__', '__reduce_ex__',
                       '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__',
                       '__weakref__', '_name', 'acquire', 'addFilter', 'close',
                       'color_map','colorize', 'createLock', 'csi', 'disable_coloring',
                       'emit', 'filter','filters', 'flush', 'format', 'formatter',
                       'get_name', 'handle', 'handleError', 'is_tty', 'level',
                       'level_map', 'lock', 'name', 'output_colorized', 'release',
                       'removeFilter', 'reset', 'setFormatter', 'setLevel',
                       'set_name', 'stream'], dir(logger.handlers[0]))
     self.assertEqual(True, logger.handlers[0].is_tty)
     # CRITICAL = 50
     # FATAL = CRITICAL
     # ERROR = 40
     # WARNING = 30 --default
     # WARN = WARNING
     # INFO = 20
     # DEBUG = 10
     # NOTSET = 0
     # LOGGER_HANDLER.level_map[logging.getLevelName("PAYLOAD")] = (None, "cyan", False)
     # LOGGER_HANDLER.level_map[logging.getLevelName("TRAFFIC OUT")] = (None, "magenta", False)
     # LOGGER_HANDLER.level_map[logging.getLevelName("TRAFFIC IN")] = ("magenta", None, False)
     self.assertEqual({7: ('magenta', None, False),
                       40: (None, 'red', False),
                       9: (None, 'cyan', False),
                       10: (None, 'blue', False),
                       8: (None, 'magenta', False),
                       50: ('red', 'white', False),
                       20: (None, 'green', False),
                       30: (None, 'yellow', False)},
                      logger.handlers[0].level_map)