From 2172aea6e4f80098416e1c965c766c36c96df1cc Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Wed, 28 Jan 2026 21:39:24 +0100 Subject: [PATCH] Speed up of HashDB related operations --- data/txt/sha256sums.txt | 4 ++-- lib/core/settings.py | 2 +- lib/utils/hashdb.py | 11 ++++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/data/txt/sha256sums.txt b/data/txt/sha256sums.txt index c6fb403c3..4ff102413 100644 --- a/data/txt/sha256sums.txt +++ b/data/txt/sha256sums.txt @@ -188,7 +188,7 @@ c1cb56f2a43e9f2f6b25d5f3d504e856ea21df6fc14af5e37b1000feef2bdb5a lib/core/optio 48797d6c34dd9bb8a53f7f3794c85f4288d82a9a1d6be7fcf317d388cb20d4b3 lib/core/replication.py 0b8c38a01bb01f843d94a6c5f2075ee47520d0c4aa799cecea9c3e2c5a4a23a6 lib/core/revision.py 888daba83fd4a34e9503fe21f01fef4cc730e5cde871b1d40e15d4cbc847d56c lib/core/session.py -eef62463fa0e69928766368d1364cb999490a2f7e320d84cd295d2fcb8b19c8d lib/core/settings.py +0ee329c67d24169c161bcbce34a1ac8027f4ccec31d24219cef60da6629225c2 lib/core/settings.py cd5a66deee8963ba8e7e9af3dd36eb5e8127d4d68698811c29e789655f507f82 lib/core/shell.py bcb5d8090d5e3e0ef2a586ba09ba80eef0c6d51feb0f611ed25299fbb254f725 lib/core/subprocessng.py d35650179816193164a5f177102f18379dfbe6bb6d40fbb67b78d907b41c8038 lib/core/target.py @@ -248,7 +248,7 @@ a94958be0ec3e9d28d8171813a6a90655a9ad7e6aa33c661e8d8ebbfcf208dbb lib/utils/deps 51cfab194cd5b6b24d62706fb79db86c852b9e593f4c55c15b35f175e70c9d75 lib/utils/getch.py 853c3595e1d2efc54b8bfb6ab12c55d1efc1603be266978e3a7d96d553d91a52 lib/utils/gui.py 366e6fd5356fae7e3f2467c070d064b6695be80b50f1530ea3c01e86569b58b2 lib/utils/har.py -ca82ddc36d660c479bb47201182f47411b1f75a847a556229987f2d005fc5832 lib/utils/hashdb.py +873792c145c2e7f503632cb8f19290e56c833eaad644d0e9038664722c7b9ec0 lib/utils/hashdb.py 84bf572a9e7915e91dbffea996e1a7b749392725f1ad7f412d0ff48c636a2896 lib/utils/hash.py 1966ca704961fb987ab757f0a4afddbf841d1a880631b701487c75cef63d60c3 lib/utils/__init__.py 22ba65391b0a73b1925e5becf8ddab6ba73a196d86e351a2263509aad6676bd7 lib/utils/pivotdumptable.py diff --git a/lib/core/settings.py b/lib/core/settings.py index 4bc25aec8..eeae0bc36 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.1.75" +VERSION = "1.10.1.76" 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) diff --git a/lib/utils/hashdb.py b/lib/utils/hashdb.py index 63f816714..3975bdd39 100644 --- a/lib/utils/hashdb.py +++ b/lib/utils/hashdb.py @@ -20,6 +20,7 @@ from lib.core.compat import xrange from lib.core.convert import getBytes from lib.core.convert import getUnicode from lib.core.data import logger +from lib.core.datatype import LRUDict from lib.core.exception import SqlmapConnectionException from lib.core.settings import HASHDB_END_TRANSACTION_RETRIES from lib.core.settings import HASHDB_FLUSH_RETRIES @@ -33,6 +34,7 @@ class HashDB(object): def __init__(self, filepath): self.filepath = filepath self._write_cache = {} + self._read_cache = LRUDict(capacity=100) self._cache_lock = threading.Lock() self._connections = [] self._last_flush_time = time.time() @@ -91,6 +93,10 @@ class HashDB(object): if key and (self._write_cache or self._connections or os.path.isfile(self.filepath)): hash_ = HashDB.hashKey(key) retVal = self._write_cache.get(hash_) + + if retVal is None: + retVal = self._read_cache.get(hash_) + if not retVal: for _ in xrange(HASHDB_RETRIEVE_RETRIES): try: @@ -111,6 +117,9 @@ class HashDB(object): time.sleep(1) + if retVal is not None: + self._read_cache[hash_] = retVal + if retVal and unserialize: try: retVal = unserializeObject(retVal) @@ -126,7 +135,7 @@ class HashDB(object): if key: hash_ = HashDB.hashKey(key) with self._cache_lock: - self._write_cache[hash_] = getUnicode(value) if not serialize else serializeObject(value) + self._write_cache[hash_] = self._read_cache[hash_] = getUnicode(value) if not serialize else serializeObject(value) cache_size = len(self._write_cache) time_since_flush = time.time() - self._last_flush_time