From 737e64886243866a25b175797738d6e999862688 Mon Sep 17 00:00:00 2001 From: Name Date: Sat, 23 Dec 2023 00:39:15 +0800 Subject: [PATCH] finish change logger format(time to datetime) --- .gitignore | 3 ++- lib/controller/controller.py | 2 +- lib/core/log.py | 2 +- lib/core/option.py | 2 +- lib/core/settings.py | 2 +- lib/core/testing.py | 4 ++-- lib/core/update.py | 4 ++-- lib/request/connect.py | 4 ++-- lib/takeover/metasploit.py | 2 +- lib/techniques/blind/inference.py | 14 +++++++------- lib/techniques/dns/use.py | 2 +- lib/techniques/error/use.py | 2 +- lib/techniques/union/use.py | 2 +- lib/utils/api.py | 20 ++++++++++---------- lib/utils/brute.py | 12 ++++++------ lib/utils/crawler.py | 2 +- lib/utils/hash.py | 8 ++++---- lib/utils/versioncheck.py | 4 ++-- sqlmap.py | 6 +++--- 19 files changed, 49 insertions(+), 48 deletions(-) diff --git a/.gitignore b/.gitignore index 1f7f94a3b..9bfa00d63 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ __pycache__/ traffic.txt *~ req*.txt -.idea/ \ No newline at end of file +.idea/ +.vscode/ \ No newline at end of file diff --git a/lib/controller/controller.py b/lib/controller/controller.py index 0c06b5153..40f65b83d 100644 --- a/lib/controller/controller.py +++ b/lib/controller/controller.py @@ -306,7 +306,7 @@ def start(): logger.info(infoMsg) if not checkInternet(): - warnMsg = "[%s] [WARNING] no connection detected" % time.strftime("%X") + warnMsg = "[%s] [WARNING] no connection detected" % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) dataToStdout(warnMsg) valid = False diff --git a/lib/core/log.py b/lib/core/log.py index 64e4f1b71..aa2b0f2d5 100644 --- a/lib/core/log.py +++ b/lib/core/log.py @@ -109,7 +109,7 @@ try: except ImportError: LOGGER_HANDLER = logging.StreamHandler(sys.stdout) -FORMATTER = logging.Formatter("\r[%(asctime)s] [%(levelname)s] %(message)s", "%H:%M:%S") +FORMATTER = logging.Formatter("\r[%(asctime)s] [%(levelname)s] [%(module)s] [%(filename)s] [Line: %(lineno)d] %(message)s", "%Y-%m-%d %H:%M:%S") LOGGER_HANDLER.setFormatter(FORMATTER) LOGGER.addHandler(LOGGER_HANDLER) diff --git a/lib/core/option.py b/lib/core/option.py index 612b855c8..f08f8deab 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -517,7 +517,7 @@ def _findPageForms(): if conf.verbose in (1, 2): status = '%d/%d links visited (%d%%)' % (i + 1, len(targets), round(100.0 * (i + 1) / len(targets))) - dataToStdout("\r[%s] [INFO] %s" % (time.strftime("%X"), status), True) + dataToStdout("\r[%s] [INFO] %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), status), True) except KeyboardInterrupt: break except Exception as ex: diff --git a/lib/core/settings.py b/lib/core/settings.py index 5fec2e407..14b5d0149 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -128,7 +128,7 @@ MAX_MURPHY_SLEEP_TIME = 3 GOOGLE_REGEX = r"webcache\.googleusercontent\.com/search\?q=cache:[^:]+:([^+]+)\+&cd=|url\?\w+=((?![^>]+webcache\.googleusercontent\.com)http[^>]+)&(sa=U|rct=j)" # Google Search consent cookie -GOOGLE_CONSENT_COOKIE = "CONSENT=YES+shp.gws-%s-0-RC1.%s+FX+740" % (time.strftime("%Y%m%d"), "".join(random.sample(string.ascii_lowercase, 2))) +GOOGLE_CONSENT_COOKIE = "CONSENT=YES+shp.gws-%s-0-RC1.%s+FX+740" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), "".join(random.sample(string.ascii_lowercase, 2))) # Regular expression used for extracting results from DuckDuckGo search DUCKDUCKGO_REGEX = r' 1: - dataToStdout("[%s] [INFO] retrieved: %s" % (time.strftime("%X"), "_" * min(length, conf.progressWidth))) - dataToStdout("\r[%s] [INFO] retrieved: " % time.strftime("%X")) + dataToStdout("[%s] [INFO] retrieved: %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), "_" * min(length, conf.progressWidth))) + dataToStdout("\r[%s] [INFO] retrieved: " % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) else: - dataToStdout("\r[%s] [INFO] retrieved: " % time.strftime("%X")) + dataToStdout("\r[%s] [INFO] retrieved: " % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) def tryHint(idx): with kb.locks.hint: @@ -561,7 +561,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None status = ' %d/%d (%d%%)' % (_, length, int(100.0 * _ / length)) output += status if _ != length else " " * len(status) - dataToStdout("\r[%s] [INFO] retrieved: %s" % (time.strftime("%X"), output)) + dataToStdout("\r[%s] [INFO] retrieved: %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), output)) runThreads(numThreads, blindThread, startThreadMsg=False) @@ -580,10 +580,10 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None partialValue = "".join(value[:value.index(None)]) if partialValue: - infoMsg = "\r[%s] [INFO] partially retrieved: %s" % (time.strftime("%X"), filterControlChars(partialValue)) + infoMsg = "\r[%s] [INFO] partially retrieved: %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), filterControlChars(partialValue)) else: finalValue = "".join(value) - infoMsg = "\r[%s] [INFO] retrieved: %s" % (time.strftime("%X"), filterControlChars(finalValue)) + infoMsg = "\r[%s] [INFO] retrieved: %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), filterControlChars(finalValue)) if conf.verbose in (1, 2) and infoMsg and not any((showEta, conf.api, kb.bruteMode)): dataToStdout(infoMsg) @@ -700,7 +700,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None hashDBWrite(expression, "%s%s" % (PARTIAL_VALUE_MARKER if not conf.hexConvert else PARTIAL_HEX_VALUE_MARKER, partialValue)) if conf.hexConvert and not any((abortedFlag, conf.api, kb.bruteMode)): - infoMsg = "\r[%s] [INFO] retrieved: %s %s\n" % (time.strftime("%X"), filterControlChars(finalValue), " " * retrievedLength) + infoMsg = "\r[%s] [INFO] retrieved: %s %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), filterControlChars(finalValue), " " * retrievedLength) dataToStdout(infoMsg) else: if conf.verbose in (1, 2) and not any((showEta, conf.api, kb.bruteMode)): diff --git a/lib/techniques/dns/use.py b/lib/techniques/dns/use.py index d2c474fdc..9991b59af 100644 --- a/lib/techniques/dns/use.py +++ b/lib/techniques/dns/use.py @@ -102,7 +102,7 @@ def dnsUse(payload, expression): retVal = output if kb.dnsTest is not None: - dataToStdout("[%s] [INFO] %s: %s\n" % (time.strftime("%X"), "retrieved" if count > 0 else "resumed", safecharencode(output))) + dataToStdout("[%s] [INFO] %s: %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), "retrieved" if count > 0 else "resumed", safecharencode(output))) if count > 0: hashDBWrite(expression, output) diff --git a/lib/techniques/error/use.py b/lib/techniques/error/use.py index 749cef5d8..4edd906d2 100644 --- a/lib/techniques/error/use.py +++ b/lib/techniques/error/use.py @@ -255,7 +255,7 @@ def _errorFields(expression, expressionFields, expressionFieldsList, num=None, e if kb.fileReadMode and output and output.strip(): print() elif output is not None and not (threadData.resumed and kb.suppressResumeInfo) and not (emptyFields and field in emptyFields): - status = "[%s] [INFO] %s: '%s'" % (time.strftime("%X"), "resumed" if threadData.resumed else "retrieved", output if kb.safeCharEncode else safecharencode(output)) + status = "[%s] [INFO] %s: '%s'" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), "resumed" if threadData.resumed else "retrieved", output if kb.safeCharEncode else safecharencode(output)) if len(status) > width: status = "%s..." % status[:width - 3] diff --git a/lib/techniques/union/use.py b/lib/techniques/union/use.py index 1ad4ff813..8552a6070 100644 --- a/lib/techniques/union/use.py +++ b/lib/techniques/union/use.py @@ -412,7 +412,7 @@ def unionUse(expression, unpack=True, dump=False): if conf.verbose == 1 and not (threadData.resumed and kb.suppressResumeInfo) and not threadData.shared.showEta and not kb.bruteMode: _ = ','.join("'%s'" % _ for _ in (flattenValue(arrayizeValue(items)) if not isinstance(items, six.string_types) else [items])) - status = "[%s] [INFO] %s: %s" % (time.strftime("%X"), "resumed" if threadData.resumed else "retrieved", _ if kb.safeCharEncode else safecharencode(_)) + status = "[%s] [INFO] %s: %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), "resumed" if threadData.resumed else "retrieved", _ if kb.safeCharEncode else safecharencode(_)) if len(status) > width: status = "%s..." % status[:width - 3] diff --git a/lib/utils/api.py b/lib/utils/api.py index eef6d5a2d..5e08435d0 100644 --- a/lib/utils/api.py +++ b/lib/utils/api.py @@ -154,7 +154,7 @@ class Database(object): def init(self): self.execute( - "CREATE TABLE logs(id INTEGER PRIMARY KEY AUTOINCREMENT, taskid INTEGER, time TEXT, level TEXT, message TEXT)") + "CREATE TABLE logs(id INTEGER PRIMARY KEY AUTOINCREMENT, taskid INTEGER, datetime TEXT, level TEXT, message TEXT)") self.execute( "CREATE TABLE data(id INTEGER PRIMARY KEY AUTOINCREMENT, taskid INTEGER, status INTEGER, content_type INTEGER, value TEXT)") self.execute( @@ -327,8 +327,8 @@ class LogRecorder(logging.StreamHandler): Record emitted events to IPC database for asynchronous I/O communication with the parent process """ - conf.databaseCursor.execute("INSERT INTO logs VALUES(NULL, ?, ?, ?, ?)", (conf.taskid, time.strftime( - "%X"), record.levelname, record.msg % record.args if record.args else record.msg)) + conf.databaseCursor.execute("INSERT INTO logs VALUES(NULL, ?, ?, ?, ?)", (conf.taskid, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), + record.levelname, record.msg % record.args if record.args else record.msg)) def setRestAPILog(): @@ -962,9 +962,9 @@ def scan_log_limited(taskid, start, end): end = max(1, int(end)) # Read a subset of log messages from the IPC database - for time_, level, message in DataStore.current_db.execute("SELECT time, level, message FROM logs WHERE taskid = ? AND id >= ? AND id <= ? ORDER BY id ASC", (taskid, start, end)): + for datetime_, level, message in DataStore.current_db.execute("SELECT datetime, level, message FROM logs WHERE taskid = ? AND id >= ? AND id <= ? ORDER BY id ASC", (taskid, start, end)): json_log_messages.append( - {"time": time_, "level": level, "message": message}) + {"datetime": datetime_, "level": level, "message": message}) logger.debug("(%s) Retrieved scan log messages subset" % taskid) return jsonize({"success": True, "log": json_log_messages}) @@ -987,13 +987,13 @@ def scan_log_details(taskid): # Read all log messages from the IPC database logs = [] result_cursor = DataStore.current_db.only_execute( - "SELECT time, level, message FROM logs WHERE taskid = ? ORDER BY id ASC", (taskid,)) + "SELECT datetime, level, message FROM logs WHERE taskid = ? ORDER BY id ASC", (taskid,)) query_result = result_cursor.fetchall() index = 0 - for time_, level, message in query_result: + for datetime_, level, message in query_result: index += 1 - logs.append({"index": index, "time": time_, + logs.append({"index": index, "datetime": datetime_, "level": level, "message": message}) logger.debug("(%s) Retrieved scan log messages" % taskid) @@ -1013,9 +1013,9 @@ def scan_log(taskid): return jsonize({"success": False, "message": "Invalid task ID"}) # Read all log messages from the IPC database - for time_, level, message in DataStore.current_db.execute("SELECT time, level, message FROM logs WHERE taskid = ? ORDER BY id ASC", (taskid,)): + for datetime_, level, message in DataStore.current_db.execute("SELECT datetime, level, message FROM logs WHERE taskid = ? ORDER BY id ASC", (taskid,)): json_log_messages.append( - {"time": time_, "level": level, "message": message}) + {"datetime": datetime_, "level": level, "message": message}) logger.debug("(%s) Retrieved scan log messages" % taskid) return jsonize({"success": True, "log": json_log_messages}) diff --git a/lib/utils/brute.py b/lib/utils/brute.py index d927ed6a5..f55207da4 100644 --- a/lib/utils/brute.py +++ b/lib/utils/brute.py @@ -145,12 +145,12 @@ def tableExists(tableFile, regex=None): if conf.verbose in (1, 2) and not conf.api: clearConsoleLine(True) - infoMsg = "[%s] [INFO] retrieved: %s\n" % (time.strftime("%X"), unsafeSQLIdentificatorNaming(table)) + infoMsg = "[%s] [INFO] retrieved: %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), unsafeSQLIdentificatorNaming(table)) dataToStdout(infoMsg, True) if conf.verbose in (1, 2): status = '%d/%d items (%d%%)' % (threadData.shared.count, threadData.shared.limit, round(100.0 * threadData.shared.count / threadData.shared.limit)) - dataToStdout("\r[%s] [INFO] tried %s" % (time.strftime("%X"), status), True) + dataToStdout("\r[%s] [INFO] tried %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), status), True) kb.locks.io.release() @@ -266,12 +266,12 @@ def columnExists(columnFile, regex=None): if conf.verbose in (1, 2) and not conf.api: clearConsoleLine(True) - infoMsg = "[%s] [INFO] retrieved: %s\n" % (time.strftime("%X"), unsafeSQLIdentificatorNaming(column)) + infoMsg = "[%s] [INFO] retrieved: %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), unsafeSQLIdentificatorNaming(column)) dataToStdout(infoMsg, True) if conf.verbose in (1, 2): status = "%d/%d items (%d%%)" % (threadData.shared.count, threadData.shared.limit, round(100.0 * threadData.shared.count / threadData.shared.limit)) - dataToStdout("\r[%s] [INFO] tried %s" % (time.strftime("%X"), status), True) + dataToStdout("\r[%s] [INFO] tried %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), status), True) kb.locks.io.release() @@ -376,12 +376,12 @@ def fileExists(pathFile): if not conf.api: clearConsoleLine(True) - infoMsg = "[%s] [INFO] retrieved: '%s'\n" % (time.strftime("%X"), path) + infoMsg = "[%s] [INFO] retrieved: '%s'\n" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), path) dataToStdout(infoMsg, True) if conf.verbose in (1, 2): status = '%d/%d items (%d%%)' % (threadData.shared.count, threadData.shared.limit, round(100.0 * threadData.shared.count / threadData.shared.limit)) - dataToStdout("\r[%s] [INFO] tried %s" % (time.strftime("%X"), status), True) + dataToStdout("\r[%s] [INFO] tried %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), status), True) kb.locks.io.release() diff --git a/lib/utils/crawler.py b/lib/utils/crawler.py index 2d9070713..a2cd388d0 100644 --- a/lib/utils/crawler.py +++ b/lib/utils/crawler.py @@ -135,7 +135,7 @@ def crawl(target, post=None, cookie=None): if conf.verbose in (1, 2): threadData.shared.count += 1 status = '%d/%d links visited (%d%%)' % (threadData.shared.count, threadData.shared.length, round(100.0 * threadData.shared.count / threadData.shared.length)) - dataToStdout("\r[%s] [INFO] %s" % (time.strftime("%X"), status), True) + dataToStdout("\r[%s] [INFO] %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), status), True) threadData.shared.deeper = set() threadData.shared.unprocessed = set([target]) diff --git a/lib/utils/hash.py b/lib/utils/hash.py index 4a013338b..e09a6b043 100644 --- a/lib/utils/hash.py +++ b/lib/utils/hash.py @@ -848,7 +848,7 @@ def _bruteProcessVariantA(attack_info, hash_regex, suffix, retVal, proc_id, proc clearConsoleLine() - infoMsg = "\r[%s] [INFO] cracked password '%s'" % (time.strftime("%X"), word) + infoMsg = "\r[%s] [INFO] cracked password '%s'" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), word) if user and not user.startswith(DUMMY_USER_PREFIX): infoMsg += " for user '%s'\n" % user @@ -868,7 +868,7 @@ def _bruteProcessVariantA(attack_info, hash_regex, suffix, retVal, proc_id, proc status = "current status: %s... %s" % (word.ljust(5)[:5], ROTATING_CHARS[rotator]) if not api: - dataToStdout("\r[%s] [INFO] %s" % (time.strftime("%X"), status)) + dataToStdout("\r[%s] [INFO] %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), status)) except KeyboardInterrupt: raise @@ -924,7 +924,7 @@ def _bruteProcessVariantB(user, hash_, kwargs, hash_regex, suffix, retVal, found clearConsoleLine() - infoMsg = "\r[%s] [INFO] cracked password '%s'" % (time.strftime("%X"), word) + infoMsg = "\r[%s] [INFO] cracked password '%s'" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), word) if user and not user.startswith(DUMMY_USER_PREFIX): infoMsg += " for user '%s'\n" % user @@ -947,7 +947,7 @@ def _bruteProcessVariantB(user, hash_, kwargs, hash_regex, suffix, retVal, found status += " (user: %s)" % user if not api: - dataToStdout("\r[%s] [INFO] %s" % (time.strftime("%X"), status)) + dataToStdout("\r[%s] [INFO] %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), status)) except KeyboardInterrupt: raise diff --git a/lib/utils/versioncheck.py b/lib/utils/versioncheck.py index 7dd85e1b3..5fcf9295d 100644 --- a/lib/utils/versioncheck.py +++ b/lib/utils/versioncheck.py @@ -11,7 +11,7 @@ import time PYVERSION = sys.version.split()[0] if PYVERSION < "2.6": - sys.exit("[%s] [CRITICAL] incompatible Python version detected ('%s'). To successfully run sqlmap you'll have to use version 2.6, 2.7 or 3.x (visit 'https://www.python.org/downloads/')" % (time.strftime("%X"), PYVERSION)) + sys.exit("[%s] [CRITICAL] incompatible Python version detected ('%s'). To successfully run sqlmap you'll have to use version 2.6, 2.7 or 3.x (visit 'https://www.python.org/downloads/')" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), PYVERSION)) errors = [] extensions = ("bz2", "gzip", "pyexpat", "ssl", "sqlite3", "zlib") @@ -22,7 +22,7 @@ for _ in extensions: errors.append(_) if errors: - errMsg = "[%s] [CRITICAL] missing one or more core extensions (%s) " % (time.strftime("%X"), ", ".join("'%s'" % _ for _ in errors)) + errMsg = "[%s] [CRITICAL] missing one or more core extensions (%s) " % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), ", ".join("'%s'" % _ for _ in errors)) errMsg += "most likely because current version of Python has been " errMsg += "built without appropriate dev packages" sys.exit(errMsg) diff --git a/sqlmap.py b/sqlmap.py index f35db5504..87cd07fd2 100755 --- a/sqlmap.py +++ b/sqlmap.py @@ -98,7 +98,7 @@ except KeyboardInterrupt: raise SystemExit else: import time - sys.exit("\r[%s] [CRITICAL] %s" % (time.strftime("%X"), errMsg)) + sys.exit("\r[%s] [CRITICAL] %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), errMsg)) def modulePath(): """ @@ -172,7 +172,7 @@ def main(): conf.showTime = True dataToStdout("[!] legal disclaimer: %s\n\n" % LEGAL_DISCLAIMER, forceOutput=True) - dataToStdout("[*] starting @ %s\n\n" % time.strftime("%X /%Y-%m-%d/"), forceOutput=True) + dataToStdout("[*] starting @ %s\n\n" % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), forceOutput=True) init() @@ -558,7 +558,7 @@ def main(): logger.warning(warnMsg) if conf.get("showTime"): - dataToStdout("\n[*] ending @ %s\n\n" % time.strftime("%X /%Y-%m-%d/"), forceOutput=True) + dataToStdout("\n[*] ending @ %s\n\n" % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), forceOutput=True) kb.threadException = True