今天网站中木马了,写了个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