Esempio n. 1
0
def __setOutputResume():
    """
    Check and set the output text file and the resume functionality.
    """

    if not conf.sessionFile:
        conf.sessionFile = "%s%ssession" % (conf.outputPath, os.sep)

    logger.info("using '%s' as session file" % conf.sessionFile)

    if os.path.exists(conf.sessionFile):
        if not conf.flushSession:
            readSessionFP = codecs.open(conf.sessionFile, "r", conf.dataEncoding, 'replace')
            __url_cache = set()
            __expression_cache = {}

            for line in readSessionFP.readlines(): # xreadlines doesn't return unicode strings when codec.open() is used
                if line.count("][") == 4:
                    line = line.split("][")

                    if len(line) != 5:
                        continue

                    url, _, _, expression, value = line

                    if not value:
                        continue

                    if url[0] == "[":
                        url = url[1:]

                    value = value.rstrip('\r\n') # Strips both chars independently

                    if url not in ( conf.url, conf.hostname ):
                        continue

                    if url not in __url_cache:
                        kb.resumedQueries[url] = {}
                        kb.resumedQueries[url][expression] = value
                        __url_cache.add(url)
                        __expression_cache[url] = set(expression)

                    resumeConfKb(expression, url, value)

                    if expression not in __expression_cache[url]:
                        kb.resumedQueries[url][expression] = value
                        __expression_cache[url].add(value)
                    elif len(value) >= len(kb.resumedQueries[url][expression]):
                        kb.resumedQueries[url][expression] = value

            readSessionFP.close()
        else:
            try:
                os.remove(conf.sessionFile)
                logger.info("flushing session file")
            except OSError, msg:
                errMsg = "unable to flush the session file (%s)" % msg
                raise sqlmapFilePathException, errMsg
Esempio n. 2
0
def __setOutputResume():
    """
    Check and set the output text file and the resume functionality.
    """

    if not conf.sessionFile:
        conf.sessionFile = "%s%ssession" % (conf.outputPath, os.sep)

    logger.info("using '%s' as session file" % conf.sessionFile)

    if os.path.exists(conf.sessionFile):
        if not conf.flushSession:
            readSessionFP = open(conf.sessionFile, "r")
            lines = readSessionFP.readlines()
    
            for line in lines:
                if line.count("][") == 4:
                    line = line.split("][")
    
                    if len(line) != 5:
                        continue
    
                    url, _, _, expression, value = line
    
                    if not value:
                        continue
    
                    if url[0] == "[":
                        url = url[1:]
    
                    if value[-1] == "\n":
                        value = value[:-1]
    
                    if url != conf.url:
                        continue
    
                    if url not in kb.resumedQueries.keys():
                        kb.resumedQueries[url] = {}
                        kb.resumedQueries[url][expression] = value
    
                    resumeConfKb(expression, url, value)
    
                    if expression not in kb.resumedQueries[url].keys():
                        kb.resumedQueries[url][expression] = value
                    elif len(value) >= len(kb.resumedQueries[url][expression]):
                        kb.resumedQueries[url][expression] = value
    
            readSessionFP.close()
        else:
            try:
                os.remove(conf.sessionFile)
                logger.info("flushing session file")
            except OSError, msg:
                errMsg = "unable to flush the session file (%s)" % msg
                raise sqlmapFilePathException, errMsg
Esempio n. 3
0
def __setOutputResume():
    """
    Check and set the output text file and the resume functionality.
    """

    if conf.sessionFile and os.path.exists(conf.sessionFile):
        readSessionFP = open(conf.sessionFile, "r")
        lines = readSessionFP.readlines()

        for line in lines:
            if line.count("][") == 4:
                line = line.split("][")

                if len(line) != 5:
                    continue

                url, _, _, expression, value = line

                if not value:
                    continue

                if url[0] == "[":
                    url = url[1:]

                if value[-1] == "\n":
                    value = value[:-1]

                if url != conf.url:
                    continue

                if url not in kb.resumedQueries.keys():
                    kb.resumedQueries[url] = {}
                    kb.resumedQueries[url][expression] = value

                resumeConfKb(expression, url, value)

                if expression not in kb.resumedQueries[url].keys():
                    kb.resumedQueries[url][expression] = value
                elif len(value) >= len(kb.resumedQueries[url][expression]):
                    kb.resumedQueries[url][expression] = value

        readSessionFP.close()

    if conf.sessionFile:
        try:
            conf.sessionFP = open(conf.sessionFile, "a")
            dataToSessionFile("\n[%s]\n" % time.strftime("%X %x"))
        except IOError:
            errMsg = "unable to write on the session file specified"
            raise sqlmapFilePathException, errMsg
Esempio n. 4
0
def __setOutputResume():
    """
    Check and set the output text file and the resume functionality.
    """

    if not conf.sessionFile:
        conf.sessionFile = "%s%ssession" % (conf.outputPath, os.sep)

    logger.info("using '%s' as session file" % conf.sessionFile)

    if os.path.exists(conf.sessionFile):
        if not conf.flushSession:
            readSessionFP = codecs.open(conf.sessionFile, "r",
                                        UNICODE_ENCODING, 'replace')
            __url_cache = set()
            __expression_cache = {}

            for line in readSessionFP.readlines(
            ):  # xreadlines doesn't return unicode strings when codec.open() is used
                if line.count("][") == 4:
                    line = line.split("][")

                    if len(line) != 5:
                        continue

                    url, _, _, expression, value = line

                    if not value:
                        continue

                    if url[0] == "[":
                        url = url[1:]

                    value = value.rstrip(
                        '\r\n')  # Strips both chars independently

                    if url not in (conf.url, conf.hostname):
                        continue

                    if url not in __url_cache:
                        kb.resumedQueries[url] = {}
                        kb.resumedQueries[url][expression] = value
                        __url_cache.add(url)
                        __expression_cache[url] = set(expression)

                    resumeConfKb(expression, url, value)

                    if expression not in __expression_cache[url]:
                        kb.resumedQueries[url][expression] = value
                        __expression_cache[url].add(value)
                    elif len(value) >= len(kb.resumedQueries[url][expression]):
                        kb.resumedQueries[url][expression] = value

            if kb.injection.place is not None and kb.injection.parameter is not None:
                kb.injections.append(kb.injection)

            readSessionFP.close()
        else:
            try:
                os.remove(conf.sessionFile)
                logger.info("flushing session file")
            except OSError, msg:
                errMsg = "unable to flush the session file (%s)" % msg
                raise sqlmapFilePathException, errMsg