1919from lib .controller .controller import start
2020from lib .core .common import unArrayizeValue
2121from lib .core .convert import base64pickle
22+ from lib .core .convert import base64unpickle
2223from lib .core .convert import hexencode
24+ from lib .core .convert import jsonize
2325from lib .core .convert import stdoutencode
2426from lib .core .data import paths
25- from lib .core .datatype import AttribDict
2627from lib .core .data import kb
2728from lib .core .data import logger
29+ from lib .core .datatype import AttribDict
2830from 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
3231from lib .core .exception import SqlmapMissingDependence
3332from lib .core .optiondict import optDict
3433from lib .core .option import init
4948
5049# Local global variables
5150adminid = ""
51+ pipes = dict ()
5252procs = dict ()
5353tasks = AttribDict ()
5454
5555# Generic functions
56- def jsonize (data ):
57- return json .dumps (data , sort_keys = False , indent = 4 )
58-
5956def 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" )
295298def 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