From 5369657cd5b48280c768c43ef9aace981d38974f Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Wed, 25 May 2011 20:54:30 +0000 Subject: [PATCH] fix for cases with retrieved binary files (preventing difflib nagging around comparison) --- lib/request/comparison.py | 10 ++++++++-- lib/techniques/blind/inference.py | 3 --- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/request/comparison.py b/lib/request/comparison.py index 27f5cf895..653a81064 100644 --- a/lib/request/comparison.py +++ b/lib/request/comparison.py @@ -9,8 +9,6 @@ See the file 'doc/COPYING' for copying permission import re -from difflib import SequenceMatcher - from lib.core.common import getFilteredPageContent from lib.core.common import removeDynamicContent from lib.core.common import wasLastRequestDBMSError @@ -19,6 +17,7 @@ from lib.core.data import conf from lib.core.data import kb from lib.core.data import logger from lib.core.exception import sqlmapNoneDataException +from lib.core.settings import DEFAULT_PAGE_ENCODING from lib.core.settings import DIFF_TOLERANCE from lib.core.settings import MIN_RATIO from lib.core.settings import MAX_RATIO @@ -70,6 +69,13 @@ def comparison(page, getRatioValue=False, pageLength=None): if ratio > 1.: ratio = 1. / ratio else: + # Preventing "Unicode equal comparison failed to convert both arguments to Unicode" + # (e.g. if one page is PDF and the other is HTML) + if isinstance(seqMatcher.a, str) and isinstance(page, unicode): + page = page.encode(kb.pageEncoding or DEFAULT_PAGE_ENCODING) + elif isinstance(seqMatcher.a, unicode) and isinstance(page, str): + seqMatcher.a = seqMatcher.a.encode(kb.pageEncoding or DEFAULT_PAGE_ENCODING) + seqMatcher.set_seq1(getFilteredPageContent(seqMatcher.a, True) if conf.textOnly else seqMatcher.a) seqMatcher.set_seq2(getFilteredPageContent(page, True) if conf.textOnly else page) if seqMatcher.a is None or seqMatcher.b is None: diff --git a/lib/techniques/blind/inference.py b/lib/techniques/blind/inference.py index 5077c5586..edf1db3c9 100644 --- a/lib/techniques/blind/inference.py +++ b/lib/techniques/blind/inference.py @@ -530,9 +530,6 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None if len(finalValue) > INFERENCE_BLANK_BREAK and finalValue[-INFERENCE_BLANK_BREAK:].isspace(): break - if finalValue: - finalValue = finalValue.rstrip(INFERENCE_UNKNOWN_CHAR) - if conf.verbose in (1, 2) or showEta: dataToStdout("\n")