preparing to handle logging calls by a separate file descriptor when sqlmap is executed by the REST API - issue #297

This commit is contained in:
Bernardo Damele 2013-01-09 22:08:50 +00:00
parent d120dc18d1
commit 794700eb37
2 changed files with 32 additions and 2 deletions

View File

@ -11,6 +11,7 @@ except:
import md5
import sha
import json
import pickle
import sys
import struct
@ -126,3 +127,6 @@ def stdoutencode(data):
retVal = data.encode(UNICODE_ENCODING)
return retVal
def jsonize(data):
return json.dumps(data, sort_keys=False, indent=4)

View File

@ -52,7 +52,9 @@ from lib.core.common import singleTimeWarnMessage
from lib.core.common import UnicodeRawConfigParser
from lib.core.common import urldecode
from lib.core.common import urlencode
from lib.core.convert import base64pickle
from lib.core.convert import base64unpickle
from lib.core.convert import jsonize
from lib.core.data import conf
from lib.core.data import kb
from lib.core.data import logger
@ -1804,6 +1806,31 @@ def _mergeOptions(inputOptions, overrideOptions):
if hasattr(conf, key) and conf[key] is None:
conf[key] = value
# Logger recorder object, which keeps the log structure
class LogRecorder(logging.StreamHandler):
"""
Logging handler class which only records CUSTOM_LOGGING.PAYLOAD entries
to a global list.
"""
loghist = []
def emit(self, record):
"""
Simply record the emitted events.
"""
self.loghist.append({'levelname': record.levelname,
'text': record.message % record.args if record.args else record.message,
'id': len(self.loghist)})
if conf.fdLog:
os.write(conf.fdLog, base64pickle(self.loghist))
def _setRestAPILog():
if hasattr(conf, "fdLog") and conf.fdLog:
#logger.removeHandler(LOGGER_HANDLER)
LOGGER_RECORDER = LogRecorder()
logger.addHandler(LOGGER_RECORDER)
def _setTrafficOutputFP():
if conf.trafficFile:
infoMsg = "setting file for logging HTTP traffic"
@ -2069,14 +2096,13 @@ def init(inputOptions=AttribDict(), overrideOptions=False):
if not inputOptions.disableColoring:
coloramainit()
elif hasattr(LOGGER_HANDLER, "disable_coloring"):
LOGGER_HANDLER.disable_coloring = True
_setConfAttributes()
_setKnowledgeBaseAttributes()
_mergeOptions(inputOptions, overrideOptions)
_useWizardInterface()
setVerbosity()
_setRestAPILog()
_saveCmdline()
_setRequestFromFile()
_cleanupOptions()