diff --git a/lib/core/common.py b/lib/core/common.py index 5c0ceff3a27..af13edee962 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -2444,7 +2444,7 @@ def isHexEncodedString(subject): False """ - return re.match(r"\A[0-9a-fA-Fx]+\Z", subject) is not None + return re.match(r"\A(?:0[xX])?[0-9a-fA-F]+\Z", subject) is not None @cachedmethod def getConsoleWidth(default=80): diff --git a/tests/test_hex_prefix_regression.py b/tests/test_hex_prefix_regression.py new file mode 100644 index 00000000000..7b82fd24349 --- /dev/null +++ b/tests/test_hex_prefix_regression.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +""" +Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org) +See the file 'LICENSE' for copying permission +""" + +import os +import sys +import unittest + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from _testutils import bootstrap + +bootstrap() + +from lib.core.common import isHexEncodedString + + +class TestHexPrefixDetection(unittest.TestCase): + def test_bare_x_is_not_a_hex_prefix(self): + self.assertFalse(isHexEncodedString("x4142")) + self.assertFalse(isHexEncodedString("4142x")) + + def test_prefix_requires_digits(self): + self.assertFalse(isHexEncodedString("0x")) + self.assertFalse(isHexEncodedString("0X")) + + def test_valid_hex_is_still_detected(self): + self.assertTrue(isHexEncodedString("4142")) + self.assertTrue(isHexEncodedString("0x4142")) + self.assertTrue(isHexEncodedString("0X4142")) + + +if __name__ == "__main__": + unittest.main()