diff --git a/.pylintrc b/.pylintrc index 39cf72c05..ec855adbc 100644 --- a/.pylintrc +++ b/.pylintrc @@ -70,7 +70,6 @@ enable=import-error, unused-wildcard-import, global-variable-not-assigned, undefined-loop-variable, - global-statement, global-at-module-level, bad-open-mode, redundant-unittest-assert, diff --git a/lib/controller/checks.py b/lib/controller/checks.py index 49a9f3c58..d3e7a0f88 100644 --- a/lib/controller/checks.py +++ b/lib/controller/checks.py @@ -561,7 +561,7 @@ def checkSqlInjection(place, parameter, value): candidates = trueSet - falseSet - errorSet if candidates: - candidates = sorted(candidates, key=lambda _: len(_)) + candidates = sorted(candidates, key=len) for candidate in candidates: if re.match(r"\A[\w.,! ]+\Z", candidate) and ' ' in candidate and candidate.strip() and len(candidate) > CANDIDATE_SENTENCE_MIN_LENGTH: conf.string = candidate @@ -595,7 +595,7 @@ def checkSqlInjection(place, parameter, value): candidates = filterNone(_.strip() if _.strip() in trueRawResponse and _.strip() not in falseRawResponse else None for _ in (trueSet - falseSet - errorSet)) if candidates: - candidates = sorted(candidates, key=lambda _: len(_)) + candidates = sorted(candidates, key=len) for candidate in candidates: if re.match(r"\A\w+\Z", candidate): break @@ -609,7 +609,7 @@ def checkSqlInjection(place, parameter, value): candidates = filterNone(_.strip() if _.strip() in falseRawResponse and _.strip() not in trueRawResponse else None for _ in (falseSet - trueSet)) if candidates: - candidates = sorted(candidates, key=lambda _: len(_)) + candidates = sorted(candidates, key=len) for candidate in candidates: if re.match(r"\A\w+\Z", candidate): break diff --git a/lib/core/bigarray.py b/lib/core/bigarray.py index 95c602711..a6f6ac24d 100644 --- a/lib/core/bigarray.py +++ b/lib/core/bigarray.py @@ -53,7 +53,7 @@ class BigArray(list): List-like class used for storing large amounts of data (disk cached) """ - def __init__(self, items=[]): + def __init__(self, items=None): self.chunks = [[]] self.chunk_length = sys.maxsize self.cache = None @@ -61,7 +61,7 @@ class BigArray(list): self._os_remove = os.remove self._size_counter = 0 - for item in items: + for item in (items or []): self.append(item) def append(self, value): @@ -139,12 +139,6 @@ class BigArray(list): self.__init__() self.chunks, self.filenames = state - def __getslice__(self, i, j): - i = max(0, len(self) + i if i < 0 else i) - j = min(len(self), len(self) + j if j < 0 else j) - - return BigArray(self[_] for _ in xrange(i, j)) - def __getitem__(self, y): if y < 0: y += len(self) diff --git a/lib/core/common.py b/lib/core/common.py index ee753692d..e50c57d60 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -2328,22 +2328,21 @@ def initCommonOutputs(): kb.commonOutputs = {} key = None - with openFile(paths.COMMON_OUTPUTS, 'r') as f: - for line in f: - if line.find('#') != -1: - line = line[:line.find('#')] + for line in openFile(paths.COMMON_OUTPUTS, 'r'): + if line.find('#') != -1: + line = line[:line.find('#')] - line = line.strip() + line = line.strip() - if len(line) > 1: - if line.startswith('[') and line.endswith(']'): - key = line[1:-1] - elif key: - if key not in kb.commonOutputs: - kb.commonOutputs[key] = set() + if len(line) > 1: + if line.startswith('[') and line.endswith(']'): + key = line[1:-1] + elif key: + if key not in kb.commonOutputs: + kb.commonOutputs[key] = set() - if line not in kb.commonOutputs[key]: - kb.commonOutputs[key].add(line) + if line not in kb.commonOutputs[key]: + kb.commonOutputs[key].add(line) def getFileItems(filename, commentPrefix='#', unicoded=True, lowercase=False, unique=False): """ @@ -3921,7 +3920,7 @@ def normalizeUnicode(value, charset=string.printable[:string.printable.find(' ') # Reference: http://www.peterbe.com/plog/unicode-to-ascii - >>> normalizeUnicode(u'\u0161u\u0107uraj') == u'sucuraj' + >>> normalizeUnicode(u'\\u0161u\\u0107uraj') == u'sucuraj' True >>> normalizeUnicode(getUnicode(decodeHex("666f6f00626172"))) == u'foobar' True @@ -4096,7 +4095,7 @@ def expandMnemonics(mnemonics, parser, args): debugMsg = "mnemonic '%s' resolved to %s). " % (name, found) logger.debug(debugMsg) else: - found = sorted(options.keys(), key=lambda x: len(x))[0] + found = sorted(options.keys(), key=len)[0] warnMsg = "detected ambiguity (mnemonic '%s' can be resolved to any of: %s). " % (name, ", ".join("'%s'" % key for key in options)) warnMsg += "Resolved to shortest of those ('%s')" % found logger.warn(warnMsg) @@ -5043,7 +5042,6 @@ def parseRequestFile(reqFile, checkParams=True): def getSafeExString(ex, encoding=None): """ Safe way how to get the proper exception represtation as a string - (Note: errors to be avoided: 1) "%s" % Exception(u'\u0161') and 2) "%s" % str(Exception(u'\u0161')) >>> getSafeExString(SqlmapBaseException('foobar')) == 'foobar' True diff --git a/lib/core/datatype.py b/lib/core/datatype.py index 0fc30d817..860347a49 100644 --- a/lib/core/datatype.py +++ b/lib/core/datatype.py @@ -184,15 +184,15 @@ class OrderedSet(collections.MutableSet): def __contains__(self, key): return key in self.map - def add(self, key): - if key not in self.map: + def add(self, value): + if value not in self.map: end = self.end curr = end[1] - curr[2] = end[1] = self.map[key] = [key, curr, end] + curr[2] = end[1] = self.map[value] = [value, curr, end] - def discard(self, key): - if key in self.map: - key, prev, next = self.map.pop(key) + def discard(self, value): + if value in self.map: + value, prev, next = self.map.pop(value) prev[2] = next next[1] = prev diff --git a/lib/core/dump.py b/lib/core/dump.py index 0a1b3979e..6c6580075 100644 --- a/lib/core/dump.py +++ b/lib/core/dump.py @@ -468,8 +468,7 @@ class Dump(object): shutil.copyfile(dumpFileName, candidate) except IOError: pass - finally: - break + break else: count += 1 diff --git a/lib/core/option.py b/lib/core/option.py index 4b0087a6a..9fef8f3e6 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -838,6 +838,7 @@ def _setPreprocessFunctions(): if conf.preprocess: for script in re.split(PARAMETER_SPLITTING_REGEX, conf.preprocess): found = False + function = None script = safeFilepathEncode(script.strip()) diff --git a/lib/core/replication.py b/lib/core/replication.py index 837839289..e68710618 100644 --- a/lib/core/replication.py +++ b/lib/core/replication.py @@ -79,9 +79,9 @@ class Replication(object): errMsg = "wrong number of columns used in replicating insert" raise SqlmapValueException(errMsg) - def execute(self, sql, parameters=[]): + def execute(self, sql, parameters=None): try: - self.parent.cursor.execute(sql, parameters) + self.parent.cursor.execute(sql, parameters or []) except sqlite3.OperationalError as ex: errMsg = "problem occurred ('%s') while accessing sqlite database " % getSafeExString(ex, UNICODE_ENCODING) errMsg += "located at '%s'. Please make sure that " % self.parent.dbpath diff --git a/lib/core/settings.py b/lib/core/settings.py index 34351bc41..988c37df5 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -18,7 +18,7 @@ from lib.core.enums import OS from thirdparty.six import unichr as _unichr # sqlmap version (...) -VERSION = "1.3.5.154" +VERSION = "1.3.5.155" 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/parse/banner.py b/lib/parse/banner.py index 77ae798f6..6d5a60f29 100644 --- a/lib/parse/banner.py +++ b/lib/parse/banner.py @@ -53,11 +53,11 @@ class MSSQLBannerHandler(ContentHandler): elif name == "servicepack": self._inServicePack = True - def characters(self, data): + def characters(self, content): if self._inVersion: - self._version += sanitizeStr(data) + self._version += sanitizeStr(content) elif self._inServicePack: - self._servicePack += sanitizeStr(data) + self._servicePack += sanitizeStr(content) def endElement(self, name): if name == "signature": diff --git a/lib/utils/getch.py b/lib/utils/getch.py index 733fdf570..f3b16f9e5 100644 --- a/lib/utils/getch.py +++ b/lib/utils/getch.py @@ -57,10 +57,10 @@ class _GetchMacCarbon(object): """ def __init__(self): import Carbon - Carbon.Evt # see if it has this (in Unix, it doesn't) + + _ = Carbon.Evt # see if it has this (in Unix, it doesn't) def __call__(self): - import Carbon if Carbon.Evt.EventAvail(0x0008)[0] == 0: # 0x0008 is the keyDownMask return '' else: diff --git a/lib/utils/hash.py b/lib/utils/hash.py index 508410603..ef521fa40 100644 --- a/lib/utils/hash.py +++ b/lib/utils/hash.py @@ -635,7 +635,7 @@ def attackDumpedTable(): col_passwords = set() attack_dict = {} - for column in sorted(columns, key=lambda _: len(_), reverse=True): + for column in sorted(columns, key=len, reverse=True): if column and column.lower() in COMMON_USER_COLUMNS: col_user = column break diff --git a/lib/utils/timeout.py b/lib/utils/timeout.py index 4f661769f..a08f1f2c3 100644 --- a/lib/utils/timeout.py +++ b/lib/utils/timeout.py @@ -11,7 +11,7 @@ from lib.core.data import logger from lib.core.enums import CUSTOM_LOGGING from lib.core.enums import TIMEOUT_STATE -def timeout(func, args=(), kwargs={}, duration=1, default=None): +def timeout(func, args=None, kwargs=None, duration=1, default=None): class InterruptableThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) @@ -20,7 +20,7 @@ def timeout(func, args=(), kwargs={}, duration=1, default=None): def run(self): try: - self.result = func(*args, **kwargs) + self.result = func(*(args or ()), **(kwargs or {})) self.timeout_state = TIMEOUT_STATE.NORMAL except Exception as ex: logger.log(CUSTOM_LOGGING.TRAFFIC_IN, ex) diff --git a/lib/utils/xrange.py b/lib/utils/xrange.py index 8bdb407b9..962f7f625 100644 --- a/lib/utils/xrange.py +++ b/lib/utils/xrange.py @@ -66,9 +66,6 @@ class xrange(object): def __hash__(self): return hash(self._slice) - def __cmp__(self, other): - return (cmp(type(self), type(other)) or cmp(self._slice, other._slice)) - def __repr__(self): return '%s(%r, %r, %r)' % (type(self).__name__, self.start, self.stop, self.step)