From 3cae76627cf281b3a1db96365edb295614c74caf Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Tue, 23 Nov 2010 13:58:01 +0000 Subject: [PATCH] code refactoring regarding dictionary attack --- lib/core/common.py | 10 ++++++++++ lib/core/enums.py | 1 - lib/utils/hash.py | 5 +++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 1f937772c..3836c49c1 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -26,6 +26,7 @@ from ConfigParser import DEFAULTSECT from ConfigParser import RawConfigParser from StringIO import StringIO from difflib import SequenceMatcher +from inspect import getmembers from subprocess import PIPE from subprocess import Popen as execute from tempfile import NamedTemporaryFile @@ -1604,3 +1605,12 @@ def logHTTPTraffic(requestLogMsg, responseLogMsg): dataToTrafficFile("\n%s\n\n" % (76 * '#')) kb.locks.reqLock.release() + +def getPublicTypeMembers(type_): + retVal = [] + + for name, value in getmembers(type_): + if not name.startswith('__'): + retVal.append((name, value)) + + return retVal \ No newline at end of file diff --git a/lib/core/enums.py b/lib/core/enums.py index f50e02d6d..215be6f36 100644 --- a/lib/core/enums.py +++ b/lib/core/enums.py @@ -53,4 +53,3 @@ class HASH: ORACLE_OLD = r'(?i)\A[0-9a-f]{16}\Z' MD5_GENERIC = r'(?i)\A[0-9a-f]{32}\Z' SHA1_GENERIC = r'(?i)\A[0-9a-f]{40}\Z' - __all__ = (MYSQL, MYSQL_OLD, POSTGRES, MSSQL, MSSQL_OLD, ORACLE, ORACLE_OLD, MD5_GENERIC, SHA1_GENERIC) diff --git a/lib/utils/hash.py b/lib/utils/hash.py index 0caed37eb..68c5735a9 100644 --- a/lib/utils/hash.py +++ b/lib/utils/hash.py @@ -12,13 +12,14 @@ import time from hashlib import md5 from hashlib import sha1 -from zipfile import ZipFile +from zipfile import ZipFile from extra.pydes.pyDes import des from extra.pydes.pyDes import CBC from lib.core.common import conf from lib.core.common import dataToStdout from lib.core.common import getFileItems +from lib.core.common import getPublicTypeMembers from lib.core.common import paths from lib.core.common import readInput from lib.core.convert import hexdecode @@ -190,7 +191,7 @@ def dictionaryAttack(): hash_ = hash_.split()[0] - for regex in HASH.__all__: + for _, regex in getPublicTypeMembers(HASH): if re.match(regex, hash_): rehash = regex break