mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2024-11-22 17:46:37 +03:00
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:
parent
d120dc18d1
commit
794700eb37
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user