Skip to content

Commit 7adaffa

Browse files
committed
fixed options initiation
1 parent b0635bd commit 7adaffa

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

lib/core/option.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,7 @@ def _mergeOptions(inputOptions, overrideOptions):
17841784
kb.explicitSettings.add(key)
17851785

17861786
for key, value in defaults.items():
1787-
if conf[key] is None:
1787+
if hasattr(conf, key) and conf[key] is None:
17881788
conf[key] = value
17891789

17901790
def _setTrafficOutputFP():

lib/core/optiondict.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
"hexConvert": "boolean",
184184
"oDir": "string",
185185
"parseErrors": "boolean",
186+
"saveCmdline": "boolean",
186187
"updateAll": "boolean",
187188
"tor": "boolean",
188189
"torPort": "integer",
@@ -202,6 +203,7 @@
202203
"hpp": "boolean",
203204
"mobile": "boolean",
204205
"pageRank": "boolean",
206+
"purgeOutput": "boolean",
205207
"smart": "boolean",
206208
"testFilter": "string",
207209
"wizard": "boolean",

lib/utils/api.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import json
99
import logging
10-
import optparse
1110
import os
1211
import shutil
1312
import sys
@@ -27,20 +26,21 @@
2726
from extra.bottle.bottle import static_file
2827
from extra.bottle.bottle import template
2928
from lib.controller.controller import start
29+
from lib.core.common import unArrayizeValue
3030
from lib.core.convert import hexencode
3131
from lib.core.convert import stdoutencode
3232
from lib.core.data import paths
3333
from lib.core.datatype import AttribDict
34-
from lib.core.data import cmdLineOptions
3534
from lib.core.data import kb
3635
from lib.core.data import logger
36+
from lib.core.defaults import _defaults
3737
from lib.core.log import FORMATTER
3838
from lib.core.log import LOGGER_HANDLER
3939
from lib.core.log import LOGGER_OUTPUT
4040
from lib.core.exception import SqlmapMissingDependence
41+
from lib.core.optiondict import optDict
4142
from lib.core.option import init
4243
from lib.core.settings import UNICODE_ENCODING
43-
from lib.parse.cmdline import cmdLineParser
4444

4545
RESTAPI_SERVER_HOST = "127.0.0.1"
4646
RESTAPI_SERVER_PORT = 8775
@@ -60,6 +60,21 @@ def is_admin(taskid):
6060
else:
6161
return True
6262

63+
def init_options():
64+
dataype = {"boolean": False, "string": "", "integer": 0, "float": 0.0}
65+
options = AttribDict()
66+
67+
for _ in optDict:
68+
for name, type_ in optDict[_].items():
69+
type_ = unArrayizeValue(type_)
70+
options[name] = _defaults.get(name, dataype[type_])
71+
72+
# Enforce batch mode and disable coloring
73+
options.batch = True
74+
options.disableColoring = True
75+
76+
return options
77+
6378
@hook("after_request")
6479
def security_headers():
6580
"""
@@ -106,10 +121,8 @@ def task_new():
106121
"""
107122
global tasks
108123

109-
optset()
110-
111124
taskid = hexencode(os.urandom(16))
112-
tasks[taskid] = AttribDict(cmdLineOptions)
125+
tasks[taskid] = init_options()
113126

114127
return jsonize({"taskid": taskid})
115128

@@ -247,7 +260,7 @@ def scan_start(taskid):
247260
for key, value in request.json.items():
248261
tasks[taskid][key] = value
249262

250-
print "TASKS:", tasks
263+
print "DEBUG TASKS:", tasks
251264

252265
# Overwrite output directory (oDir) value to a temporary directory
253266
tasks[taskid].oDir = tempfile.mkdtemp(prefix="sqlmap-")
@@ -328,23 +341,15 @@ def download(taskid, target, filename):
328341
else:
329342
abort(500)
330343

331-
def optset():
332-
# Store original command line options for possible later restoration
333-
cmdLineOptions.update(cmdLineParser().__dict__)
334-
335344
def server(host="0.0.0.0", port=RESTAPI_SERVER_PORT):
336345
"""
337346
REST-JSON API server
338347
"""
339348
global adminid
340349
global tasks
341350

342-
# Enforce batch mode and disable coloring
343-
cmdLineOptions.batch = True
344-
cmdLineOptions.disableColoring = True
345-
346351
adminid = hexencode(os.urandom(16))
347-
tasks[adminid] = AttribDict(cmdLineOptions)
352+
tasks[adminid] = init_options()
348353

349354
logger.info("running REST-JSON API server at '%s:%d'.." % (host, port))
350355
logger.info("the admin task ID is: %s" % adminid)

sqlmapapi.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@
2525
# Set default logging level to debug
2626
logger.setLevel(logging.DEBUG)
2727

28+
# Initialize path variable
2829
paths.SQLMAP_ROOT_PATH = modulePath()
2930
setPaths()
3031

32+
# Parse command line options
3133
apiparser = optparse.OptionParser()
32-
apiparser.add_option("--server", help="Act as a REST-JSON API server", default=RESTAPI_SERVER_PORT, action="store_true")
34+
apiparser.add_option("-s", "--server", help="Act as a REST-JSON API server", default=RESTAPI_SERVER_PORT, action="store_true")
3335
apiparser.add_option("-c", "--client", help="Act as a REST-JSON API client", default=RESTAPI_SERVER_PORT, action="store_true")
3436
apiparser.add_option("-H", "--host", help="Host of the REST-JSON API server", default=RESTAPI_SERVER_HOST, action="store")
3537
apiparser.add_option("-p", "--port", help="Port of the the REST-JSON API server", default=RESTAPI_SERVER_PORT, type="int", action="store")
3638
(args, _) = apiparser.parse_args()
3739

40+
# Start the client or the server
3841
if args.server is True:
3942
server(args.host, args.port)
4043
elif args.client is True:

0 commit comments

Comments
 (0)