finish change logger format(time to datetime)

This commit is contained in:
Name 2023-12-23 00:39:15 +08:00
parent bf125be101
commit 737e648862
19 changed files with 49 additions and 48 deletions

3
.gitignore vendored
View File

@ -5,4 +5,5 @@ __pycache__/
traffic.txt
*~
req*.txt
.idea/
.idea/
.vscode/

View File

@ -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

View File

@ -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)

View File

@ -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:

View File

@ -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'<a class="result__url" href="(htt[^"]+)'

View File

@ -174,7 +174,7 @@ def vulnTest():
for options, checks in TESTS:
status = '%d/%d (%d%%) ' % (count, len(TESTS), round(100.0 * count / len(TESTS)))
dataToStdout("\r[%s] [INFO] complete: %s" % (time.strftime("%X"), status))
dataToStdout("\r[%s] [INFO] complete: %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), status))
if IS_WIN and "uraj" in options:
options = options.replace(u"\u0161u\u0107uraj", "sucuraj")
@ -265,7 +265,7 @@ def smokeTest():
count += 1
status = '%d/%d (%d%%) ' % (count, length, round(100.0 * count / length))
dataToStdout("\r[%s] [INFO] complete: %s" % (time.strftime("%X"), status))
dataToStdout("\r[%s] [INFO] complete: %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), status))
def _(node):
for __ in dir(node):

View File

@ -46,7 +46,7 @@ def update():
debugMsg = "sqlmap will try to update itself using 'pip' command"
logger.debug(debugMsg)
dataToStdout("\r[%s] [INFO] update in progress" % time.strftime("%X"))
dataToStdout("\r[%s] [INFO] update in progress" % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
output = ""
try:
@ -133,7 +133,7 @@ def update():
debugMsg = "sqlmap will try to update itself using 'git' command"
logger.debug(debugMsg)
dataToStdout("\r[%s] [INFO] update in progress" % time.strftime("%X"))
dataToStdout("\r[%s] [INFO] update in progress" % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
output = ""
try:

View File

@ -331,7 +331,7 @@ class Connect(object):
if conf.liveCookies:
with kb.locks.liveCookies:
if not checkFile(conf.liveCookies, raiseOnError=False) or os.path.getsize(conf.liveCookies) == 0:
warnMsg = "[%s] [WARNING] live cookies file '%s' is empty or non-existent. Waiting for timeout (%d seconds)" % (time.strftime("%X"), conf.liveCookies, LIVE_COOKIES_TIMEOUT)
warnMsg = "[%s] [WARNING] live cookies file '%s' is empty or non-existent. Waiting for timeout (%d seconds)" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), conf.liveCookies, LIVE_COOKIES_TIMEOUT)
dataToStdout(warnMsg)
valid = False
@ -1478,7 +1478,7 @@ class Connect(object):
warnMsg += "time-based injections because of inherent high latency time"
singleTimeWarnMessage(warnMsg)
warnMsg = "[%s] [WARNING] %stime-based comparison requires " % (time.strftime("%X"), "(case) " if kb.responseTimeMode else "")
warnMsg = "[%s] [WARNING] %stime-based comparison requires " % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), "(case) " if kb.responseTimeMode else "")
warnMsg += "%s statistical model, please wait" % ("larger" if len(kb.responseTimes) == 1 else "reset of")
dataToStdout(warnMsg)

View File

@ -594,7 +594,7 @@ class Metasploit(object):
logger.debug("executing local command: %s" % self._payloadCmd)
process = execute(self._payloadCmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False)
dataToStdout("\r[%s] [INFO] creation in progress " % time.strftime("%X"))
dataToStdout("\r[%s] [INFO] creation in progress " % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
pollProcess(process)
payloadStderr = process.communicate()[1]

View File

@ -203,10 +203,10 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
if conf.verbose in (1, 2) and not any((showEta, conf.api, kb.bruteMode)):
if isinstance(length, int) and numThreads > 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)):

View File

@ -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)

View File

@ -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]

View File

@ -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]

View File

@ -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})

View File

@ -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()

View File

@ -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])

View File

@ -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

View File

@ -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)

View File

@ -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