Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9766f60

Browse files
committed
logging is now handled in a separate file descriptor :) - issue #297
1 parent 794700e commit 9766f60

2 files changed

Lines changed: 19 additions & 21 deletions

File tree

lib/parse/cmdline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ def cmdLineParser():
664664
help="Simple wizard interface for beginner users")
665665

666666
# Hidden and/or experimental options
667-
parser.add_option("--pickle", dest="pickledOptions", help=SUPPRESS_HELP)
667+
parser.add_option("--pickled-options", dest="pickledOptions", help=SUPPRESS_HELP)
668668

669669
parser.add_option("--profile", dest="profile", action="store_true",
670670
help=SUPPRESS_HELP)

lib/utils/api.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@
1919
from lib.controller.controller import start
2020
from lib.core.common import unArrayizeValue
2121
from lib.core.convert import base64pickle
22+
from lib.core.convert import base64unpickle
2223
from lib.core.convert import hexencode
24+
from lib.core.convert import jsonize
2325
from lib.core.convert import stdoutencode
2426
from lib.core.data import paths
25-
from lib.core.datatype import AttribDict
2627
from lib.core.data import kb
2728
from lib.core.data import logger
29+
from lib.core.datatype import AttribDict
2830
from lib.core.defaults import _defaults
29-
from lib.core.log import FORMATTER
30-
from lib.core.log import LOGGER_HANDLER
31-
from lib.core.log import LOGGER_OUTPUT
3231
from lib.core.exception import SqlmapMissingDependence
3332
from lib.core.optiondict import optDict
3433
from lib.core.option import init
@@ -49,13 +48,11 @@
4948

5049
# Local global variables
5150
adminid = ""
51+
pipes = dict()
5252
procs = dict()
5353
tasks = AttribDict()
5454

5555
# Generic functions
56-
def jsonize(data):
57-
return json.dumps(data, sort_keys=False, indent=4)
58-
5956
def is_admin(taskid):
6057
global adminid
6158
if adminid != taskid:
@@ -254,6 +251,7 @@ def scan_start(taskid):
254251
"""
255252
global tasks
256253
global procs
254+
global pipes
257255

258256
if taskid not in tasks:
259257
abort(500, "Invalid task ID")
@@ -269,8 +267,13 @@ def scan_start(taskid):
269267
# Launch sqlmap engine in a separate thread
270268
logger.debug("starting a scan for task ID %s" % taskid)
271269

272-
procs[taskid] = Popen("python sqlmap.py --pickle %s" % base64pickle(tasks[taskid]), shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
273-
stdout, stderr = procs[taskid].communicate()
270+
pipes[taskid] = os.pipe()
271+
272+
# Provide sqlmap engine with the writable pipe for logging
273+
tasks[taskid]["fdLog"] = pipes[taskid][1]
274+
275+
# Launch sqlmap engine
276+
procs[taskid] = Popen("python sqlmap.py --pickled-options %s" % base64pickle(tasks[taskid]), shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False)
274277

275278
return jsonize({"success": True})
276279

@@ -279,17 +282,17 @@ def scan_output(taskid):
279282
"""
280283
Read the standard output of sqlmap core execution
281284
"""
285+
global pipes
282286
global tasks
283287

284288
if taskid not in tasks:
285289
abort(500, "Invalid task ID")
286290

287-
sys.stdout.seek(0)
288-
output = sys.stdout.read()
289-
sys.stdout.flush()
290-
sys.stdout.truncate(0)
291+
stdout, stderr = procs[taskid].communicate()
292+
293+
print "stderr:", stderr
291294

292-
return jsonize({"output": output})
295+
return jsonize({"stdout": stdout, "stderr": stderr})
293296

294297
@get("/scan/<taskid>/delete")
295298
def scan_delete(taskid):
@@ -315,12 +318,7 @@ def scan_log(taskid):
315318
if taskid not in tasks:
316319
abort(500, "Invalid task ID")
317320

318-
LOGGER_OUTPUT.seek(0)
319-
output = LOGGER_OUTPUT.read()
320-
LOGGER_OUTPUT.flush()
321-
LOGGER_OUTPUT.truncate(0)
322-
323-
return jsonize({"log": output})
321+
return jsonize({"log": base64unpickle(os.read(pipes[taskid][0], 100000))})
324322

325323
# Function to handle files inside the output directory
326324
@get("/download/<taskid>/<target>/<filename:path>")

0 commit comments

Comments
 (0)