Skip to content

Commit e12d7a2

Browse files
committed
Minor patch of API calls
1 parent 74b5ffd commit e12d7a2

4 files changed

Lines changed: 41 additions & 15 deletions

File tree

data/txt/sha256sums.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ c03dc585f89642cfd81b087ac2723e3e1bb3bfa8c60e6f5fe58ef3b0113ebfe6 lib/core/data.
188188
48797d6c34dd9bb8a53f7f3794c85f4288d82a9a1d6be7fcf317d388cb20d4b3 lib/core/replication.py
189189
0b8c38a01bb01f843d94a6c5f2075ee47520d0c4aa799cecea9c3e2c5a4a23a6 lib/core/revision.py
190190
888daba83fd4a34e9503fe21f01fef4cc730e5cde871b1d40e15d4cbc847d56c lib/core/session.py
191-
74df13374f7058ba09ce9e7c5cec9e79f8a59a4a6f73d79ba4a6fa972a75961f lib/core/settings.py
191+
78a7197b843f1766159e803ccc5724880bea795ad6bd2e06eddb746db3324129 lib/core/settings.py
192192
cd5a66deee8963ba8e7e9af3dd36eb5e8127d4d68698811c29e789655f507f82 lib/core/shell.py
193193
bcb5d8090d5e3e0ef2a586ba09ba80eef0c6d51feb0f611ed25299fbb254f725 lib/core/subprocessng.py
194194
70ea3768f1b3062b22d20644df41c86238157ec80dd43da40545c620714273c6 lib/core/target.py
@@ -241,7 +241,7 @@ f552b6140d4069be6a44792a08f295da8adabc1c4bb6a5e100f222f87144ca9d lib/techniques
241241
1966ca704961fb987ab757f0a4afddbf841d1a880631b701487c75cef63d60c3 lib/techniques/union/__init__.py
242242
30cae858e2a5a75b40854399f65ad074e6bb808d56d5ee66b94d4002dc6e101b lib/techniques/union/test.py
243243
a8a795f29ec6fd66482926f04b054ed492a033982c3b7837c5d2ea32368acec0 lib/techniques/union/use.py
244-
c771212c97b534f47e74e972e12ada7d341a170c637ed2638cee6546f7b754d2 lib/utils/api.py
244+
ab5132ff9605a7e795293ce10eec7f8d1a98a36dabb3432b9c805535afe054ac lib/utils/api.py
245245
442555ab85277aff7c9e0cf465ea5b0d28395c326f68363449b2d3941f4b6de2 lib/utils/brute.py
246246
da5bcbcda3f667582adf5db8c1b5d511b469ac61b55d387cec66de35720ed718 lib/utils/crawler.py
247247
a94958be0ec3e9d28d8171813a6a90655a9ad7e6aa33c661e8d8ebbfcf208dbb lib/utils/deps.py
@@ -490,7 +490,7 @@ cedf45d33461bd7e5400d06611a63c8a4ffae1a4510030c5696b9d46ed6a9883 plugins/generi
490490
1966ca704961fb987ab757f0a4afddbf841d1a880631b701487c75cef63d60c3 plugins/__init__.py
491491
5d72f0af46ff3c9e3fe80300e83cb78749132278e8db88915764a94d7130a04c README.md
492492
7ef0d0ea10d4b19283b1e380d521abb0fdd4c6bf1443b88f7b00af7947fc5e27 sqlmapapi.py
493-
69ca771751f9d996cc07c2cd3f082667949148792ba9db26d08dc953fbf17815 sqlmapapi.yaml
493+
5b73370e455ee5d4cfd72db7485223528d3ede2637e74469fac9ba9f8a2b9d13 sqlmapapi.yaml
494494
627d90f1194335b800cbc9cc78db6697cf9e02e193a83598e0d4d0abb55b63b8 sqlmap.conf
495495
65159b82795604069a2d14ccbd1f66e888a26b05db0401a1ddadb40c665c93dc sqlmap.py
496496
eb37a88357522fd7ad00d90cdc5da6b57442b4fec49366aadb2944c4fbf8b804 tamper/0eunion.py

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from thirdparty import six
2121

2222
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
23-
VERSION = "1.10.6.78"
23+
VERSION = "1.10.6.79"
2424
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2525
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2626
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

lib/utils/api.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class DataStore(object):
7878
username = None
7979
password = None
8080

81+
RESTAPI_READONLY_OPTIONS = ("api", "taskid", "database")
82+
8183
# API objects
8284
class Database(object):
8385
filepath = None
@@ -296,6 +298,19 @@ def setRestAPILog():
296298
def is_admin(token):
297299
return safeCompareStrings(DataStore.admin_token, token)
298300

301+
def validate_task_options(taskid, options, caller):
302+
if not isinstance(options, dict):
303+
logger.warning("[%s] Invalid JSON options provided to %s()" % (taskid, caller))
304+
return "Invalid JSON options"
305+
306+
for key in options:
307+
if key in RESTAPI_UNSUPPORTED_OPTIONS or key in RESTAPI_READONLY_OPTIONS:
308+
logger.warning("[%s] Unsupported option '%s' provided to %s()" % (taskid, key, caller))
309+
return "Unsupported option '%s'" % key
310+
elif key not in DataStore.tasks[taskid].options:
311+
logger.warning("[%s] Unknown option '%s' provided to %s()" % (taskid, key, caller))
312+
return "Unknown option '%s'" % key
313+
299314
@hook('before_request')
300315
def check_authentication():
301316
if not any((DataStore.username, DataStore.password)):
@@ -490,10 +505,9 @@ def option_set(taskid):
490505
logger.warning("[%s] Invalid JSON options provided to option_set()" % taskid)
491506
return jsonize({"success": False, "message": "Invalid JSON options"})
492507

493-
for key in request.json:
494-
if key in RESTAPI_UNSUPPORTED_OPTIONS:
495-
logger.warning("[%s] Unsupported option '%s' provided to option_set()" % (taskid, key))
496-
return jsonize({"success": False, "message": "Unsupported option '%s'" % key})
508+
message = validate_task_options(taskid, request.json, "option_set")
509+
if message:
510+
return jsonize({"success": False, "message": message})
497511

498512
for option, value in request.json.items():
499513
DataStore.tasks[taskid].set_option(option, value)
@@ -516,10 +530,13 @@ def scan_start(taskid):
516530
logger.warning("[%s] Invalid JSON options provided to scan_start()" % taskid)
517531
return jsonize({"success": False, "message": "Invalid JSON options"})
518532

519-
for key in request.json:
520-
if key in RESTAPI_UNSUPPORTED_OPTIONS:
521-
logger.warning("[%s] Unsupported option '%s' provided to scan_start()" % (taskid, key))
522-
return jsonize({"success": False, "message": "Unsupported option '%s'" % key})
533+
if DataStore.tasks[taskid].engine_process() is not None and not DataStore.tasks[taskid].engine_has_terminated():
534+
logger.warning("[%s] Scan already running" % taskid)
535+
return jsonize({"success": False, "message": "Scan already running"})
536+
537+
message = validate_task_options(taskid, request.json, "scan_start")
538+
if message:
539+
return jsonize({"success": False, "message": message})
523540

524541
# Initialize sqlmap engine's options with user's provided options, if any
525542
for option, value in request.json.items():
@@ -601,7 +618,7 @@ def scan_data(taskid):
601618
json_data_message.append({"status": status, "type": content_type, "value": dejsonize(value)})
602619

603620
# Read all error messages from the IPC database
604-
for error in DataStore.current_db.execute("SELECT error FROM errors WHERE taskid = ? ORDER BY id ASC", (taskid,)):
621+
for error, in DataStore.current_db.execute("SELECT error FROM errors WHERE taskid = ? ORDER BY id ASC", (taskid,)):
605622
json_errors_message.append(error)
606623

607624
logger.debug("(%s) Retrieved scan data and error messages" % taskid)

sqlmapapi.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,9 +726,9 @@ components:
726726

727727
OptionValue:
728728
description: Value accepted by sqlmap options. The exact type depends on the option.
729-
nullable: true
730729
oneOf:
731730
- type: string
731+
nullable: true
732732
- type: boolean
733733
- type: integer
734734
- type: number
@@ -826,7 +826,16 @@ components:
826826
description: Numeric content type stored by sqlmap.
827827
example: 0
828828
value:
829-
nullable: true
829+
oneOf:
830+
- type: string
831+
nullable: true
832+
- type: boolean
833+
- type: integer
834+
- type: number
835+
- type: array
836+
items: {}
837+
- type: object
838+
additionalProperties: true
830839
description: JSON-decoded scan output value. Shape depends on the content type.
831840
additionalProperties: true
832841

0 commit comments

Comments
 (0)