{"record":{"id":"8c325527b621578c","repo":"shadow1ng/fscan","slug":"keylogging-failed-w","errorCode":null,"errorMessage":"Keylogging failed: %w","messagePattern":"Keylogging failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/local/keylogger.go","lineNumber":116,"sourceCode":"\n// startKeylogging 启动键盘记录\nfunc (p *KeyloggerPlugin) startKeylogging(ctx context.Context, outputFile string, session *common.ScanSession) error {\n\n\t// 根据平台启动相应的键盘记录\n\tvar err error\n\tswitch runtime.GOOS {\n\tcase \"windows\":\n\t\terr = p.startWindowsKeylogging(ctx)\n\tcase \"linux\":\n\t\terr = p.startLinuxKeylogging(ctx)\n\tcase \"darwin\":\n\t\terr = p.startDarwinKeylogging(ctx)\n\tdefault:\n\t\terr = fmt.Errorf(\"%s\", i18n.Tr(\"unsupported_platform\", runtime.GOOS))\n\t}\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%s: %w\", i18n.GetText(\"keylogger_failed_plain\"), err)\n\t}\n\n\t// 保存到文件\n\tif err := p.saveKeysToFile(outputFile, session); err != nil {\n\t\tsession.LogError(i18n.Tr(\"keylogger_save_failed\", err))\n\t}\n\n\treturn nil\n}\n\n// checkOutputFilePermissions 检查输出文件权限\nfunc (p *KeyloggerPlugin) checkOutputFilePermissions(outputFile string) error {\n\tfile, err := os.OpenFile(outputFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%s: %w\", i18n.Tr(\"output_file_create_failed\", outputFile), err)\n\t}\n\t_ = file.Close()\n\treturn nil","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/plugins/local/keylogger.go#L98-L134","documentation":"After the platform dispatch, startKeylogging wraps any error from the platform-specific keylogging goroutine with the localized keylogger_failed_plain prefix (\"Keylogging failed\"). It is a generic wrapper: the wrapped %w cause carries the real reason (device access denied, missing input devices, X11/wayland restrictions, unsupported platform, etc.).","triggerScenarios":"startWindowsKeylogging/startLinuxKeylogging/startDarwinKeylogging returned an error — e.g. Linux lacking /dev/input access or running without an X session, macOS lacking accessibility permissions, or the unsupported-platform error itself.","commonSituations":"Linux agent not run as root so /dev/input/event* is unreadable; macOS process lacking Accessibility/Input Monitoring permission; headless servers with no display to capture; Wayland sessions where X11 hooks do not work.","solutions":["Inspect the wrapped cause (%w) in the error chain — fix that underlying issue, not this message.","On Linux, run with read access to /dev/input (root or input group membership).","On macOS, grant the process Accessibility and Input Monitoring permissions.","On headless/Wayland environments, use a supported capture path or skip keylogging."],"exampleFix":"// before\n$ ./agent --plugin keylogger            # as unprivileged user -> permission denied\n// after\n$ sudo ./agent --plugin keylogger       # or: sudo usermod -aG input $USER","handlingStrategy":"try-catch","validationCode":"if runtime.GOOS == \"linux\" {\n    if f, err := os.OpenFile(\"/dev/input/event0\", os.O_RDONLY, 0); err != nil {\n        return fmt.Errorf(\"no input device access: %w\", err)\n    } else { f.Close() }\n}","typeGuard":null,"tryCatchPattern":"res := plugin.Scan(ctx, cfg)\nif !res.Success && strings.Contains(res.Error.Error(), \"Keylogging failed\") {\n    log.Printf(\"keylogger underlying cause: %v\", errors.Unwrap(res.Error))\n}","preventionTips":["Always inspect the wrapped cause via errors.Unwrap / %w chain.","Provision OS permissions in advance (input group on Linux, Accessibility on macOS).","Skip keylogging on headless/Wayland-only machines.","Pre-flight device/display availability checks before invoking the plugin."],"tags":["keylogger","error-wrapping","platform"],"backgroundTag":"unsupported-platform","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}