源码阅读

yangzhisheng_branch
XU 2 months ago
parent 0dc81c2219
commit 041f4fb8cc

Binary file not shown.

@ -610,41 +610,43 @@ def main():
# 如果临时目录中没有其他文件,则删除临时目录 # 如果临时目录中没有其他文件,则删除临时目录
if not filterNone(filepath for filepath in glob.glob(os.path.join(kb.tempDir, '*')) if not any(filepath.endswith(_) for _ in (".lock", ".exe", ".so", '_'))): # 检查临时目录是否为空 if not filterNone(filepath for filepath in glob.glob(os.path.join(kb.tempDir, '*')) if not any(filepath.endswith(_) for _ in (".lock", ".exe", ".so", '_'))): # 检查临时目录是否为空
# 使用glob模块获取临时目录中的所有文件路径并过滤掉以.lock、.exe、.so或_结尾的文件
try: try:
shutil.rmtree(kb.tempDir, ignore_errors=True) # 删除临时目录 shutil.rmtree(kb.tempDir, ignore_errors=True) # 删除临时目录ignore_errors=True表示忽略删除过程中可能出现的错误
except OSError: # 捕获目录删除错误 except OSError: # 捕获目录删除错误
pass # 忽略错误 pass # 忽略错误,继续执行后续代码
if conf.get("hashDB"): if conf.get("hashDB"): # 检查配置中是否存在hashDB
conf.hashDB.flush(True) conf.hashDB.flush(True) # 将hashDB中的数据刷新到磁盘
conf.hashDB.close() # NOTE: because of PyPy conf.hashDB.close() # 关闭hashDB连接NOTE: 由于PyPy的原因需要显式关闭
if conf.get("harFile"): if conf.get("harFile"): # 检查配置中是否存在harFile
try: try:
with openFile(conf.harFile, "w+b") as f: with openFile(conf.harFile, "w+b") as f: # 以二进制写模式打开harFile
json.dump(conf.httpCollector.obtain(), fp=f, indent=4, separators=(',', ': ')) json.dump(conf.httpCollector.obtain(), fp=f, indent=4, separators=(',', ': ')) # 将HTTP收集器中的数据以JSON格式写入文件
except SqlmapBaseException as ex: except SqlmapBaseException as ex: # 捕获sqlmap基础异常
errMsg = getSafeExString(ex) errMsg = getSafeExString(ex) # 获取异常的安全字符串表示
logger.critical(errMsg) logger.critical(errMsg) # 记录严重错误日志
if conf.get("api"): if conf.get("api"): # 检查配置中是否存在api
conf.databaseCursor.disconnect() conf.databaseCursor.disconnect() # 断开数据库游标连接
if conf.get("dumper"): if conf.get("dumper"): # 检查配置中是否存在dumper
conf.dumper.flush() conf.dumper.flush() # 刷新dumper中的数据
# short delay for thread finalization # short delay for thread finalization
_ = time.time() _ = time.time() # 获取当前时间
while threading.active_count() > 1 and (time.time() - _) > THREAD_FINALIZATION_TIMEOUT: while threading.active_count() > 1 and (time.time() - _) > THREAD_FINALIZATION_TIMEOUT: # 检查当前活跃线程数是否大于1并且等待时间是否超过线程最终化超时时间
time.sleep(0.01) time.sleep(0.01) # 等待0.01秒避免CPU占用过高
if cmdLineOptions.get("sqlmapShell"): if cmdLineOptions.get("sqlmapShell"): # 检查命令行选项中是否存在sqlmapShell
cmdLineOptions.clear() cmdLineOptions.clear() # 清空命令行选项
conf.clear() conf.clear() # 清空配置
kb.clear() kb.clear() # 清空知识库
conf.disableBanner = True conf.disableBanner = True # 禁用启动横幅
main() main() # 调用主函数重新启动sqlmap
# 检查是否是作为主模块运行,如果是,则执行以下代码 # 检查是否是作为主模块运行,如果是,则执行以下代码
if __name__ == "__main__": if __name__ == "__main__":

Loading…
Cancel
Save