From caae773b2d9a6ce50ef5681ec1d4b3218f9bb7d3 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Fri, 18 Jan 2013 10:44:57 +0100 Subject: [PATCH 1/6] Minor removal of redundant code --- lib/core/common.py | 7 ------- plugins/generic/users.py | 5 ++--- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 96eb25297..1f9c56102 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -768,13 +768,6 @@ def dataToOutFile(filename, data): return retVal -def strToHex(value): - """ - Converts string value to it's hexadecimal representation - """ - - return (value if not isinstance(value, unicode) else value.encode(UNICODE_ENCODING)).encode("hex").upper() - def readInput(message, default=None, checkBatch=True): """ Reads input from terminal diff --git a/plugins/generic/users.py b/plugins/generic/users.py index d849e0e99..a229b4baf 100644 --- a/plugins/generic/users.py +++ b/plugins/generic/users.py @@ -21,8 +21,8 @@ from lib.core.common import isTechniqueAvailable from lib.core.common import parsePasswordHash from lib.core.common import randomStr from lib.core.common import readInput -from lib.core.common import strToHex from lib.core.common import unArrayizeValue +from lib.core.convert import hexencode from lib.core.data import conf from lib.core.data import kb from lib.core.data import logger @@ -187,7 +187,6 @@ class Users: if retVal: for user, password in filterPairValues(zip(retVal[0]["%s.name" % randStr], retVal[0]["%s.password" % randStr])): - # password = "0x%s" % strToHex(password) if user not in kb.data.cachedUsersPasswords: kb.data.cachedUsersPasswords[user] = [password] else: @@ -229,7 +228,7 @@ class Users: if retVal: for user, password in filterPairValues(zip(retVal[0]["%s.name" % randStr], retVal[0]["%s.password" % randStr])): - password = "0x%s" % strToHex(password) + password = "0x%s" % hexencode(password).upper() if user not in kb.data.cachedUsersPasswords: kb.data.cachedUsersPasswords[user] = [password] From d1008b45b50d11d910e944f2970fddc03167d212 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Fri, 18 Jan 2013 10:46:06 +0100 Subject: [PATCH 2/6] Minor removal of unused function --- lib/core/common.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 1f9c56102..c9b3d887b 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -1463,18 +1463,6 @@ def ntToPosixSlashes(filepath): return filepath.replace('\\', '/') -def isBase64EncodedString(subject): - """ - Checks if the provided string is Base64 encoded - - >>> isBase64EncodedString('dGVzdA==') - True - >>> isBase64EncodedString('123456') - False - """ - - return re.match(r"\A(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\Z", subject) is not None - def isHexEncodedString(subject): """ Checks if the provided string is hex encoded From bcc907ce099b46c2125650ad1c60fbc962e17f9b Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Fri, 18 Jan 2013 11:00:21 +0100 Subject: [PATCH 3/6] Minor update --- lib/core/common.py | 3 ++- lib/core/settings.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/core/common.py b/lib/core/common.py index c9b3d887b..ed71fe843 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -99,6 +99,7 @@ from lib.core.settings import INVALID_UNICODE_CHAR_FORMAT from lib.core.settings import ISSUES_PAGE from lib.core.settings import IS_WIN from lib.core.settings import LARGE_OUTPUT_THRESHOLD +from lib.core.settings import MIN_ENCODED_LEN_CHECK from lib.core.settings import MIN_TIME_RESPONSES from lib.core.settings import ML from lib.core.settings import NULL @@ -570,7 +571,7 @@ def paramToDict(place, parameters=None): for encoding in ("hex", "base64"): try: decoded = value.decode(encoding) - if all(_ in string.printable for _ in decoded): + if len(decoded) > MIN_ENCODED_LEN_CHECK and all(_ in string.printable for _ in decoded): warnMsg = "provided parameter '%s' " % parameter warnMsg += "seems to be '%s' encoded" % encoding logger.warn(warnMsg) diff --git a/lib/core/settings.py b/lib/core/settings.py index e6c075e6e..a5a8f5d4a 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -506,6 +506,9 @@ MIN_BINARY_DISK_DUMP_SIZE = 100 # Regular expression used for extracting form tags FORM_SEARCH_REGEX = r"(?si)" +# Minimum field entry length needed for encoded content (hex, base64,...) check +MIN_ENCODED_LEN_CHECK = 5 + # CSS style used in HTML dump format HTML_DUMP_CSS_STYLE = """