限时免费试用:欢迎注册 api.bigmodel.org ,快速体验大模型 API 接入服务。
当前位置:首页 >未分类

py的全文搜索小工具

分类:未分类时间:2024-11-27浏览:1021

今天网站中木马了,写了个py小工具用于搜索文件中的关键词

import os def search_string_in_files(directory, search_string): # 遍历目录及其子目录 for foldername, subfolders, filenames in os.walk(directory): for filename in filenames: file_path = os.path.join(foldername, filename) try: with open(file_path, 'rb') as file: # 以二进制模式打开文件 # 读取文件内容 content = file.read() # 将字节数据解码为字符串(可尝试使用 'utf-8' 或 'ISO-8859-1' 等编码) try: decoded_content = content.decode('utf-8', errors='ignore') # 忽略无法解码的字节 except UnicodeDecodeError: decoded_content = content.decode('ISO-8859-1', errors='ignore') # 查找指定字符串 if search_string in decoded_content: print(f"异常文件: {file_path}") except Exception as e: print(f"无法读取文件 {file_path}: {e}") if __name__ == "__main__": # 替换为你想要查询的目录路径 directory_to_search = "/www/wwwroot/aa.com" # 要查询的字符串 search_string = "z.xlqwmw." search_string_in_files(directory_to_search, search_string) 直接使用python3 s.py
本站文章如未注明出处均为原创,转载请注明出处,如有侵权请邮件联系站长。
0/500
Share your thoughts respectfully.