mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2024-11-23 01:56:36 +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 md5
|
||||||
import sha
|
import sha
|
||||||
|
|
||||||
|
import json
|
||||||
import pickle
|
import pickle
|
||||||
import sys
|
import sys
|
||||||
import struct
|
import struct
|
||||||
|
@ -126,3 +127,6 @@ def stdoutencode(data):
|
||||||
retVal = data.encode(UNICODE_ENCODING)
|
retVal = data.encode(UNICODE_ENCODING)
|
||||||
|
|
||||||
return retVal
|
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 UnicodeRawConfigParser
|
||||||
from lib.core.common import urldecode
|
from lib.core.common import urldecode
|
||||||
from lib.core.common import urlencode
|
from lib.core.common import urlencode
|
||||||
|
from lib.core.convert import base64pickle
|
||||||
from lib.core.convert import base64unpickle
|
from lib.core.convert import base64unpickle
|
||||||
|
from lib.core.convert import jsonize
|
||||||
from lib.core.data import conf
|
from lib.core.data import conf
|
||||||
from lib.core.data import kb
|
from lib.core.data import kb
|
||||||
from lib.core.data import logger
|
from lib.core.data import logger
|
||||||
|
@ -1804,6 +1806,31 @@ def _mergeOptions(inputOptions, overrideOptions):
|
||||||
if hasattr(conf, key) and conf[key] is None:
|
if hasattr(conf, key) and conf[key] is None:
|
||||||
conf[key] = value
|
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():
|
def _setTrafficOutputFP():
|
||||||
if conf.trafficFile:
|
if conf.trafficFile:
|
||||||
infoMsg = "setting file for logging HTTP traffic"
|
infoMsg = "setting file for logging HTTP traffic"
|
||||||
|
@ -2069,14 +2096,13 @@ def init(inputOptions=AttribDict(), overrideOptions=False):
|
||||||
|
|
||||||
if not inputOptions.disableColoring:
|
if not inputOptions.disableColoring:
|
||||||
coloramainit()
|
coloramainit()
|
||||||
elif hasattr(LOGGER_HANDLER, "disable_coloring"):
|
|
||||||
LOGGER_HANDLER.disable_coloring = True
|
|
||||||
|
|
||||||
_setConfAttributes()
|
_setConfAttributes()
|
||||||
_setKnowledgeBaseAttributes()
|
_setKnowledgeBaseAttributes()
|
||||||
_mergeOptions(inputOptions, overrideOptions)
|
_mergeOptions(inputOptions, overrideOptions)
|
||||||
_useWizardInterface()
|
_useWizardInterface()
|
||||||
setVerbosity()
|
setVerbosity()
|
||||||
|
_setRestAPILog()
|
||||||
_saveCmdline()
|
_saveCmdline()
|
||||||
_setRequestFromFile()
|
_setRequestFromFile()
|
||||||
_cleanupOptions()
|
_cleanupOptions()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user