Skip to content

Commit ab1efed

Browse files
committed
Harden REST API option handling and require authentication credentials (#6073)
1 parent ecf8ccc commit ab1efed

4 files changed

Lines changed: 17 additions & 6 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-
b0b0b170613ed0ff8235adebbc342cf2bfb69ad054a5fd48971eb851dcfd3b8f lib/core/settings.py
191+
341a90f1ac0b438d3b5f4f3532e70e4cf50385340c9ca2027a122cbcf0dc5683 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-
3a418628622cf1f09346ecea12ae13a22341c8211815e01c839c9c1ab01fb12a lib/utils/api.py
244+
c8f1037cacae1068bdc050d44dfa29132051006d4ad022299509234427ca6a41 lib/utils/api.py
245245
442555ab85277aff7c9e0cf465ea5b0d28395c326f68363449b2d3941f4b6de2 lib/utils/brute.py
246246
da5bcbcda3f667582adf5db8c1b5d511b469ac61b55d387cec66de35720ed718 lib/utils/crawler.py
247247
a94958be0ec3e9d28d8171813a6a90655a9ad7e6aa33c661e8d8ebbfcf208dbb lib/utils/deps.py
@@ -489,7 +489,7 @@ cedf45d33461bd7e5400d06611a63c8a4ffae1a4510030c5696b9d46ed6a9883 plugins/generi
489489
45bfd00f09557e20115e6ce7fb52ff507930d705db215e535f991e5fbf7464de plugins/generic/users.py
490490
1966ca704961fb987ab757f0a4afddbf841d1a880631b701487c75cef63d60c3 plugins/__init__.py
491491
5d72f0af46ff3c9e3fe80300e83cb78749132278e8db88915764a94d7130a04c README.md
492-
c6ad39bfd1810413402dedfc275fc805fa13f85fc490e236c1e725bde4e5100b sqlmapapi.py
492+
7ef0d0ea10d4b19283b1e380d521abb0fdd4c6bf1443b88f7b00af7947fc5e27 sqlmapapi.py
493493
4e993cfe2889bf0f86ad0abafd9a6a25849580284ea279b2115e99707e14bb97 sqlmapapi.yaml
494494
627d90f1194335b800cbc9cc78db6697cf9e02e193a83598e0d4d0abb55b63b8 sqlmap.conf
495495
65159b82795604069a2d14ccbd1f66e888a26b05db0401a1ddadb40c665c93dc sqlmap.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.51"
23+
VERSION = "1.10.6.52"
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,11 @@ def option_set(taskid):
490490
logger.warning("[%s] Invalid JSON options provided to option_set()" % taskid)
491491
return jsonize({"success": False, "message": "Invalid JSON options"})
492492

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})
497+
493498
for option, value in request.json.items():
494499
DataStore.tasks[taskid].set_option(option, value)
495500

@@ -687,6 +692,9 @@ def server(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, adapter=REST
687692
REST-JSON API server
688693
"""
689694

695+
if not all((username, password)):
696+
logger.critical("REST-JSON API server requires both username and password")
697+
690698
DataStore.admin_token = encodeHex(os.urandom(16), binary=False)
691699
DataStore.username = username
692700
DataStore.password = password

sqlmapapi.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,13 @@ def main():
101101
apiparser.add_argument("-p", "--port", help="Port of the REST-JSON API server (default %d)" % RESTAPI_DEFAULT_PORT, default=RESTAPI_DEFAULT_PORT, type=int)
102102
apiparser.add_argument("--adapter", help="Server (bottle) adapter to use (default \"%s\")" % RESTAPI_DEFAULT_ADAPTER, default=RESTAPI_DEFAULT_ADAPTER)
103103
apiparser.add_argument("--database", help="Set IPC database filepath (optional)")
104-
apiparser.add_argument("--username", help="Basic authentication username (optional)")
105-
apiparser.add_argument("--password", help="Basic authentication password (optional)")
104+
apiparser.add_argument("--username", help="Basic authentication username")
105+
apiparser.add_argument("--password", help="Basic authentication password")
106106
(args, _) = apiparser.parse_known_args() if hasattr(apiparser, "parse_known_args") else apiparser.parse_args()
107107

108+
if (args.server or args.client) and not all((args.username, args.password)):
109+
apiparser.error("--username and --password are mandatory for REST-JSON API server/client usage")
110+
108111
# Start the client or the server
109112
if args.server:
110113
server(args.host, args.port, adapter=args.adapter, username=args.username, password=args.password, database=args.database)

0 commit comments

Comments
 (0)