mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2026-08-03 22:31:34 +00:00
Adding 'safe string cmp' to API
This commit is contained in:
parent
5e5629cd7a
commit
dec5a82077
4 changed files with 31 additions and 5 deletions
|
|
@ -13,6 +13,7 @@ import contextlib
|
|||
import copy
|
||||
import functools
|
||||
import getpass
|
||||
import hmac
|
||||
import hashlib
|
||||
import inspect
|
||||
import io
|
||||
|
|
@ -5654,3 +5655,28 @@ def checkSums():
|
|||
break
|
||||
|
||||
return retVal
|
||||
|
||||
def safeCompareStrings(a, b):
|
||||
"""
|
||||
Constant-time string comparison to prevent timing attacks.
|
||||
>>> safeCompareStrings("test", "test")
|
||||
True
|
||||
>>> safeCompareStrings("test", None)
|
||||
False
|
||||
>>> safeCompareStrings("test1", "test2")
|
||||
False
|
||||
"""
|
||||
if a is None or b is None:
|
||||
return a == b
|
||||
|
||||
if hasattr(hmac, "compare_digest"):
|
||||
return hmac.compare_digest(a, b)
|
||||
|
||||
# Fallback for Python < 2.7.7 and < 3.3
|
||||
if len(a) != len(b):
|
||||
return False
|
||||
|
||||
result = 0
|
||||
for x, y in zip(a, b):
|
||||
result |= ord(x) ^ ord(y)
|
||||
return result == 0
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ from lib.core.enums import OS
|
|||
from thirdparty import six
|
||||
|
||||
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
|
||||
VERSION = "1.10.4.8"
|
||||
VERSION = "1.10.4.9"
|
||||
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
|
||||
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
|
||||
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
|
||||
|
|
|
|||
|
|
@ -293,7 +293,7 @@ def setRestAPILog():
|
|||
|
||||
# Generic functions
|
||||
def is_admin(token):
|
||||
return DataStore.admin_token == token
|
||||
return safeCompareStrings(DataStore.admin_token, token)
|
||||
|
||||
@hook('before_request')
|
||||
def check_authentication():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue