Fixing an TypeError issue with a crypto.crypt()

This commit is contained in:
Miroslav Štampar
2026-09-20 11:59:21 +02:00
parent 0c491b7551
commit 31005fe4df
3 changed files with 19 additions and 1 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ from lib.core.enums import OS
from thirdparty import six
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.10.9.18"
VERSION = "1.10.9.19"
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)
+2
View File
@@ -406,6 +406,8 @@ def crypt_generic_passwd(password, salt, **kwargs):
'rl.3StKT.4T8M'
"""
password = getUnicode(password) # stdlib crypt.crypt() requires str, unlike the hashlib-based functions here
return getText(crypt(password, salt))
def unix_md5_passwd(password, salt, magic="$1$", **kwargs):
+16
View File
@@ -87,6 +87,22 @@ class TestDbmsSpecificVectors(unittest.TestCase):
self.assertEqual(H.oracle_old_passwd("tiger", "scott", uppercase=True), "F894844C34402B67")
class TestCryptGenericBytesInput(unittest.TestCase):
"""
The dictionary-attack workers (_bruteProcessVariantA/B in lib/utils/hash.py) always pass
'password' as bytes (getBytes(word)), regardless of which hash function gets dispatched. Every
other function here hashes via hashlib (bytes-friendly), but crypt_generic_passwd forwards
straight to the stdlib crypt.crypt(), which requires str - raising 'TypeError: crypt() argument
1 must be str, not bytes' on Linux/macOS (reported via a user's cracked-hash session).
"""
def test_bytes_password_does_not_raise(self):
self.assertEqual(H.crypt_generic_passwd(password=b"rasmuslerdorf", salt="rl", uppercase=False), "rl.3StKT.4T8M")
def test_str_password_unaffected(self):
self.assertEqual(H.crypt_generic_passwd(password="rasmuslerdorf", salt="rl", uppercase=False), "rl.3StKT.4T8M")
class TestMssqlUnicodePassword(unittest.TestCase):
"""MSSQL hashes the password as UCS-2/UTF-16LE. A per-char 'utf-8 + NUL' approximation is only
correct for ASCII, so non-ASCII passwords (cafe, etc.) hashed WRONG and were uncrackable. The