refactor: 合并 fileinfo 和 dcinfo 到 systeminfo

- fileinfo 的敏感文件扫描合并到 systeminfo
- dcinfo 的域控信息收集合并到 systeminfo,通过 build tag 隔离平台差异
- 检测到域环境时自动触发域信息收集,WORKGROUP 环境自动跳过
- 新增 systeminfo_dc_windows.go 和 systeminfo_dc_other.go 处理跨平台编译
This commit is contained in:
ZacharyZcR
2026-05-15 23:16:35 +08:00
parent 76a4331fae
commit 150e48ba85
7 changed files with 371 additions and 1038 deletions
+74 -3
View File
@@ -11,6 +11,7 @@ import (
"os"
"os/exec"
"os/user"
"path/filepath"
"runtime"
"strings"
@@ -58,7 +59,9 @@ func (p *SystemInfoPlugin) Scan(ctx context.Context, info *common.HostInfo, sess
p.collectPrivilegeInfo()
p.collectPlatformInfo()
p.collectAVInfo()
p.collectSensitiveFiles()
p.collectSensitiveEnvVars()
p.collectDomainInfo()
return &plugins.Result{
Success: true,
@@ -237,15 +240,13 @@ func (p *SystemInfoPlugin) collectAVInfo() {
return
}
// 建立进程名索引,O(1) 查找
processIndex := make(map[string][]string)
for _, proc := range processes {
name := proc
if idx := strings.Index(proc, " (PID: "); idx != -1 {
name = proc[:idx]
}
key := strings.ToLower(name)
processIndex[key] = append(processIndex[key], proc)
processIndex[strings.ToLower(name)] = append(processIndex[strings.ToLower(name)], proc)
}
for avName, av := range avProducts {
@@ -312,6 +313,76 @@ func (p *SystemInfoPlugin) getUnixProcesses() []string {
return processes
}
func (p *SystemInfoPlugin) collectSensitiveFiles() {
var sensitiveFiles []string
switch runtime.GOOS {
case "windows":
sensitiveFiles = []string{
`C:\Windows\System32\config\SAM`,
`C:\Windows\repair\sam`,
}
case "linux", "darwin":
sensitiveFiles = []string{
"/etc/shadow",
"/root/.ssh/id_rsa",
"/root/.ssh/authorized_keys",
"/root/.bash_history",
}
}
homeDir, _ := os.UserHomeDir()
if homeDir != "" {
sensitiveFiles = append(sensitiveFiles,
filepath.Join(homeDir, ".ssh", "id_rsa"),
filepath.Join(homeDir, ".ssh", "id_ed25519"),
filepath.Join(homeDir, ".aws", "credentials"),
filepath.Join(homeDir, ".azure", "accessTokens.json"),
filepath.Join(homeDir, ".kube", "config"),
)
}
for _, f := range sensitiveFiles {
if _, err := os.Stat(f); err == nil {
p.logSuccess("systeminfo_sensitive_file", f)
}
}
if homeDir != "" {
p.searchSensitiveInDirs(homeDir)
}
}
func (p *SystemInfoPlugin) searchSensitiveInDirs(homeDir string) {
searchDirs := []string{
filepath.Join(homeDir, "Desktop"),
filepath.Join(homeDir, "Documents"),
filepath.Join(homeDir, ".ssh"),
filepath.Join(homeDir, ".aws"),
}
keywords := []string{"password", "key", "secret", "token", "credential", "passwd"}
for _, dir := range searchDirs {
info, err := os.Stat(dir)
if err != nil || !info.IsDir() {
continue
}
_ = filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error {
if err != nil || fi.IsDir() || fi.Size() > 1024*1024 {
return nil
}
name := strings.ToLower(filepath.Base(path))
for _, kw := range keywords {
if strings.Contains(name, kw) {
p.logSuccess("systeminfo_sensitive_file", path)
break
}
}
return nil
})
}
}
func (p *SystemInfoPlugin) collectSensitiveEnvVars() {
keywords := []string{
"password", "passwd", "secret", "key", "token",