Skip to content

Commit 42ef561

Browse files
committed
Automatically detecting RAW password hashes in table dumps
1 parent 9b6d30d commit 42ef561

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/core/settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from thirdparty.six import unichr as _unichr
1919

2020
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
21-
VERSION = "1.3.5.157"
21+
VERSION = "1.3.5.158"
2222
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2323
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2424
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
@@ -639,6 +639,9 @@
639639
# Give up on hash recognition if nothing was found in first given number of rows
640640
HASH_RECOGNITION_QUIT_THRESHOLD = 10000
641641

642+
# Regular expression used for automatic hex conversion and hash cracking of (RAW) binary column values
643+
HASH_BINARY_COLUMNS_REGEX = r"(?i)pass|psw|hash"
644+
642645
# Maximum number of redirections to any single URL - this is needed because of the state that cookies introduce
643646
MAX_SINGLE_URL_REDIRECTIONS = 4
644647

lib/utils/hash.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@
8282
from lib.core.settings import COMMON_USER_COLUMNS
8383
from lib.core.settings import DEV_EMAIL_ADDRESS
8484
from lib.core.settings import DUMMY_USER_PREFIX
85+
from lib.core.settings import HASH_BINARY_COLUMNS_REGEX
8586
from lib.core.settings import HASH_EMPTY_PASSWORD_MARKER
8687
from lib.core.settings import HASH_MOD_ITEM_DISPLAY
8788
from lib.core.settings import HASH_RECOGNITION_QUIT_THRESHOLD
89+
from lib.core.settings import INVALID_UNICODE_CHAR_FORMAT
8890
from lib.core.settings import IS_WIN
8991
from lib.core.settings import ITOA64
9092
from lib.core.settings import NULL
@@ -634,12 +636,24 @@ def attackDumpedTable():
634636
col_user = ''
635637
col_passwords = set()
636638
attack_dict = {}
639+
binary_fields = OrderedSet()
637640

638641
for column in sorted(columns, key=len, reverse=True):
639642
if column and column.lower() in COMMON_USER_COLUMNS:
640643
col_user = column
641644
break
642645

646+
for column in columns:
647+
if column != "__infos__":
648+
if all(INVALID_UNICODE_CHAR_FORMAT.split('%')[0] in value for value in table[column]["values"]):
649+
binary_fields.add(column)
650+
651+
if binary_fields:
652+
_ = ','.join(binary_fields)
653+
warnMsg = "potential binary fields detected ('%s'). You are " % _
654+
warnMsg += "advised to rerun table dump with '--fresh-queries --binary-fields=\"%s\"'" % _
655+
logger.warn(warnMsg)
656+
643657
for i in xrange(count):
644658
if not found and i > HASH_RECOGNITION_QUIT_THRESHOLD:
645659
break
@@ -653,6 +667,9 @@ def attackDumpedTable():
653667

654668
value = table[column]["values"][i]
655669

670+
if column in binary_fields and re.search(HASH_BINARY_COLUMNS_REGEX, column) is not None:
671+
value = encodeHex(value, binary=False)
672+
656673
if hashRecognition(value):
657674
found = True
658675

0 commit comments

Comments
 (0)