mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 14:06:44 +08:00

- 删除整个legacy插件系统(7794行代码) - 完成所有插件向单文件架构迁移 - 移除19个插件的虚假Exploit功能,只保留真实利用: * Redis: 文件写入、SSH密钥注入、计划任务 * SSH: 命令执行 * MS17010: EternalBlue漏洞利用 - 统一插件接口,简化架构复杂度 - 清理临时文件和备份文件 重构效果: - 代码行数: -7794行 - 插件文件数: 从3文件架构→单文件架构 - 真实利用插件: 从22个→3个 - 架构复杂度: 大幅简化
75 lines
2.3 KiB
Python
75 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
||
import re
|
||
import os
|
||
|
||
# 需要清理的文件(保留ssh.go redis.go ms17010.go)
|
||
FILES_TO_CLEAN = [
|
||
'elasticsearch.go', 'findnet.go', 'ftp.go', 'kafka.go',
|
||
'ldap.go', 'netbios.go', 'rabbitmq.go', 'rdp.go',
|
||
'rsync.go', 'smb.go', 'smb2.go', 'smbghost.go',
|
||
'smbinfo.go', 'smtp.go', 'snmp.go', 'telnet.go',
|
||
'vnc.go', 'webpoc.go', 'webtitle.go'
|
||
]
|
||
|
||
def clean_exploit_function(file_path):
|
||
"""清理单个文件的Exploit函数"""
|
||
with open(file_path, 'r', encoding='utf-8') as f:
|
||
content = f.read()
|
||
|
||
# 使用正则表达式匹配并删除Exploit函数
|
||
# 匹配从 "// Exploit" 注释开始到函数结束的整个块
|
||
pattern = r'\/\/\s*Exploit.*?利用操作.*?\nfunc\s+\([^)]*\)\s+Exploit\([^{]*\{[^}]*(?:\{[^}]*\}[^}]*)*\}\n'
|
||
|
||
# 简化方法:按行处理
|
||
lines = content.split('\n')
|
||
output_lines = []
|
||
skip_mode = False
|
||
brace_count = 0
|
||
|
||
i = 0
|
||
while i < len(lines):
|
||
line = lines[i]
|
||
|
||
# 检测Exploit函数开始
|
||
if ('// Exploit' in line and '利用操作' in line) or ('func ' in line and 'Exploit(' in line):
|
||
skip_mode = True
|
||
brace_count = 0
|
||
if 'func ' in line and '{' in line:
|
||
brace_count = line.count('{') - line.count('}')
|
||
i += 1
|
||
continue
|
||
|
||
if skip_mode:
|
||
# 计算花括号
|
||
brace_count += line.count('{')
|
||
brace_count -= line.count('}')
|
||
|
||
# 如果花括号归零,函数结束
|
||
if brace_count <= 0:
|
||
skip_mode = False
|
||
i += 1
|
||
continue
|
||
|
||
output_lines.append(line)
|
||
i += 1
|
||
|
||
# 写回文件
|
||
with open(file_path, 'w', encoding='utf-8') as f:
|
||
f.write('\n'.join(output_lines))
|
||
|
||
def main():
|
||
os.chdir('plugins/services')
|
||
|
||
for filename in FILES_TO_CLEAN:
|
||
if os.path.exists(filename):
|
||
print(f"Cleaning {filename}...")
|
||
try:
|
||
clean_exploit_function(filename)
|
||
print(f"✅ {filename}")
|
||
except Exception as e:
|
||
print(f"❌ {filename}: {e}")
|
||
else:
|
||
print(f"⚠️ {filename} not found")
|
||
|
||
if __name__ == "__main__":
|
||
main() |