From 57be1856a6abdcdea6bdd289e0f0f6a8121046bc Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Thu, 5 Jul 2018 14:01:43 +0200 Subject: [PATCH] Where things could go kaboom (changing terminal coloring) --- lib/core/common.py | 6 +----- lib/core/settings.py | 2 +- thirdparty/ansistrm/ansistrm.py | 35 +++++++++++++++++++++++++++------ txt/checksum.md5 | 6 +++--- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index d747a42ef..f060039e6 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -884,11 +884,7 @@ def setColor(message, bold=False): retVal = colored(message, color=None, on_color=None, attrs=("bold",)) elif level: level = getattr(logging, level, None) if isinstance(level, basestring) else level - _ = LOGGER_HANDLER.level_map.get(level) - if _: - background, foreground, bold = _ - retVal = colored(message, color=foreground, on_color="on_%s" % background if background else None, attrs=("bold",) if bold else None) - + retVal = LOGGER_HANDLER.colorize(message, level) kb.stickyLevel = level if message and message[-1] != "\n" else None return retVal diff --git a/lib/core/settings.py b/lib/core/settings.py index de16dd5f4..873a5efc8 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import DBMS_DIRECTORY_NAME from lib.core.enums import OS # sqlmap version (...) -VERSION = "1.2.7.4" +VERSION = "1.2.7.5" 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/thirdparty/ansistrm/ansistrm.py b/thirdparty/ansistrm/ansistrm.py index 9f3a6c5ec..5ecc05961 100644 --- a/thirdparty/ansistrm/ansistrm.py +++ b/thirdparty/ansistrm/ansistrm.py @@ -1,6 +1,8 @@ # # Copyright (C) 2010-2012 Vinay Sajip. All rights reserved. Licensed under the new BSD license. +# (Note: 2018 modifications by @stamparm) # + import logging import os import re @@ -127,9 +129,9 @@ class ColorizingStreamHandler(logging.StreamHandler): ctypes.windll.kernel32.SetConsoleTextAttribute(h, color) - def colorize(self, message, record): - if record.levelno in self.level_map and self.is_tty: - bg, fg, bold = self.level_map[record.levelno] + def colorize(self, message, levelno): + if levelno in self.level_map and self.is_tty: + bg, fg, bold = self.level_map[levelno] params = [] if bg in self.color_map: @@ -148,11 +150,32 @@ class ColorizingStreamHandler(logging.StreamHandler): else: prefix = "" - message = "%s%s" % (prefix, ''.join((self.csi, ';'.join(params), - 'm', message, self.reset))) + match = re.search(r"\[([A-Z]+)\]", message) + if match: + level = match.group(1) + if message.startswith("\x1b[1m"): + message = message.replace("\x1b[1m", "") + reset = self.reset + "\x1b[1m" + params.append('1') + else: + reset = self.reset + message = message.replace(level, ''.join((self.csi, ';'.join(params), 'm', level, reset)), 1) + else: + message = "%s%s" % (prefix, ''.join((self.csi, ';'.join(params), 'm', message, self.reset))) + + match = re.search(r"\A\s*\[([\d:]+)\]", message) + if match: + time = match.group(1) + if not message.endswith(self.reset): + reset = self.reset + elif message.startswith("\x1b[1m"): # bold + reset = self.reset + "\x1b[1m" + else: + reset = self.reset + message = message.replace(time, ''.join((self.csi, str(self.color_map["cyan"] + 30), 'm', time, reset)), 1) return message def format(self, record): message = logging.StreamHandler.format(self, record) - return self.colorize(message, record) + return self.colorize(message, record.levelno) diff --git a/txt/checksum.md5 b/txt/checksum.md5 index b5a0c6d58..467d7de28 100644 --- a/txt/checksum.md5 +++ b/txt/checksum.md5 @@ -28,7 +28,7 @@ c7443613a0a2505b1faec931cee2a6ef lib/controller/handler.py 1e5532ede194ac9c083891c2f02bca93 lib/controller/__init__.py 0adf547455a76dc71e6a599e52da1ed9 lib/core/agent.py fd8f239e259afaf5f24bcf34a0ad187f lib/core/bigarray.py -6c3ba41569f9403aef6cd9312fe9b96e lib/core/common.py +ab2f7ecb7d3dff9afd05675031942e8e lib/core/common.py 0d082da16c388b3445e656e0760fb582 lib/core/convert.py 9f87391b6a3395f7f50830b391264f27 lib/core/data.py 72016ea5c994a711a262fd64572a0fcd lib/core/datatype.py @@ -48,7 +48,7 @@ c8c386d644d57c659d74542f5f57f632 lib/core/patch.py 0c3eef46bdbf87e29a3f95f90240d192 lib/core/replication.py a7db43859b61569b601b97f187dd31c5 lib/core/revision.py fcb74fcc9577523524659ec49e2e964b lib/core/session.py -af78e555614c7e1bf89c37271831b486 lib/core/settings.py +9f27c2f2abae2c21eb623f16abfeccf9 lib/core/settings.py dd68a9d02fccb4fa1428b20e15b0db5d lib/core/shell.py a7edc9250d13af36ac0108f259859c19 lib/core/subprocessng.py 95f04c1c1d8c3998d86e1bdf0e12771c lib/core/target.py @@ -285,7 +285,7 @@ fd1bff6caefe5007444f7a0fabbc8ce9 tamper/space2mysqlblank.py 929a2586dbb7b758a454eb09e13e5a73 tamper/versionedkeywords.py 3aff4d344ebd4f38e033e73b63f84447 tamper/versionedmorekeywords.py ed1acafbac707bfa71c72f76b81c1bdd tamper/xforwardedfor.py -368165b45dadcdff4422bc010700832a thirdparty/ansistrm/ansistrm.py +b743632abd4eee8654f98dcfdb753246 thirdparty/ansistrm/ansistrm.py d41d8cd98f00b204e9800998ecf8427e thirdparty/ansistrm/__init__.py 8e775c25bc9e84891ad6fcb4f0005c23 thirdparty/beautifulsoup/beautifulsoup.py cb2e1fe7c404dff41a2ae9132828f532 thirdparty/beautifulsoup/__init__.py