diff --git a/lib/core/common.py b/lib/core/common.py index 9ca883b06..c6da1478d 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -133,6 +133,7 @@ from lib.core.settings import IGNORE_SAVE_OPTIONS from lib.core.settings import INFERENCE_UNKNOWN_CHAR from lib.core.settings import IP_ADDRESS_REGEX from lib.core.settings import ISSUES_PAGE +from lib.core.settings import IS_TTY from lib.core.settings import IS_WIN from lib.core.settings import LARGE_OUTPUT_THRESHOLD from lib.core.settings import LOCALHOST @@ -928,7 +929,7 @@ def setColor(message, color=None, bold=False, level=None, istty=None): retVal = message level = level or extractRegexResult(r"\[(?P%s)\]" % '|'.join(_[0] for _ in getPublicTypeMembers(LOGGING_LEVELS)), message) - if message and getattr(LOGGER_HANDLER, "is_tty", False) or istty: # colorizing handler + if message and IS_TTY or istty: # colorizing handler if bold or color: retVal = colored(message, color=color, on_color=None, attrs=("bold",) if bold else None) elif level: @@ -1064,7 +1065,7 @@ def readInput(message, default=None, checkBatch=True, boolean=False): elif answer is None and retVal: retVal = "%s,%s" % (retVal, getUnicode(item, UNICODE_ENCODING)) - if message and getattr(LOGGER_HANDLER, "is_tty", False): + if message and IS_TTY: message = "\r%s" % message if retVal: @@ -1256,7 +1257,7 @@ def banner(): if not any(_ in sys.argv for _ in ("--version", "--api")) and not conf.get("disableBanner"): _ = BANNER - if not getattr(LOGGER_HANDLER, "is_tty", False) or "--disable-coloring" in sys.argv: + if not IS_TTY or "--disable-coloring" in sys.argv: _ = clearColors(_) elif IS_WIN: coloramainit() @@ -2168,7 +2169,7 @@ def clearConsoleLine(forceOutput=False): Clears current console line """ - if getattr(LOGGER_HANDLER, "is_tty", False): + if IS_TTY: dataToStdout("\r%s\r" % (" " * (getConsoleWidth() - 1)), forceOutput) kb.prependFlag = False diff --git a/lib/core/convert.py b/lib/core/convert.py index 7ea5baf02..54aa42471 100644 --- a/lib/core/convert.py +++ b/lib/core/convert.py @@ -20,6 +20,7 @@ import sys from lib.core.data import conf from lib.core.data import kb from lib.core.settings import INVALID_UNICODE_PRIVATE_AREA +from lib.core.settings import IS_TTY from lib.core.settings import IS_WIN from lib.core.settings import NULL from lib.core.settings import PICKLE_PROTOCOL @@ -107,7 +108,7 @@ def shellExec(cmd): # Cross-referenced function def stdoutEncode(value): value = value or "" - if IS_WIN and kb.get("codePage", -1) is None: + if IS_WIN and IS_TTY and kb.get("codePage", -1) is None: output = shellExec("chcp") match = re.search(r": (\d{3,})", output or "") diff --git a/lib/core/settings.py b/lib/core/settings.py index e80e6bfa7..6dfadd00e 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.124" +VERSION = "1.3.5.125" 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) @@ -233,6 +233,9 @@ PLATFORM = os.name PYVERSION = sys.version.split()[0] IS_WIN = PLATFORM == "nt" +# Check if running in terminal +IS_TTY = os.isatty(sys.stdout.fileno()) + # DBMS system databases MSSQL_SYSTEM_DBS = ("Northwind", "master", "model", "msdb", "pubs", "tempdb") MYSQL_SYSTEM_DBS = ("information_schema", "mysql", "performance_schema", "sys")