shadow1ng/fscan · error
Unable to create any system cron task
Error message
Unable to create any system cron task
What it means
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.
Source
Thrown at plugins/local/crontask.go:261
modified = append(modified, cronFile)
}
// 在每个cron目录中创建脚本
for _, cronDir := range cronDirs[1:] { // 跳过cron.d
if _, err := os.Stat(cronDir); os.IsNotExist(err) {
continue
}
scriptFile := filepath.Join(cronDir, ".system-check")
scriptContent := fmt.Sprintf("#!/bin/bash\n%s >/dev/null 2>&1 &\n", execPath)
if err := os.WriteFile(scriptFile, []byte(scriptContent), 0755); err == nil {
modified = append(modified, scriptFile)
}
}
if len(modified) == 0 {
return nil, fmt.Errorf("%s", i18n.GetText("crontask_system_create_none"))
}
return modified, nil
}
// addAtJob 添加at延时任务
func (p *CronTaskPlugin) addAtJob(execPath string) error {
// 检查at命令是否可用
if _, err := exec.LookPath("at"); err != nil {
return err
}
// 创建5分钟后执行的任务
atCommand := fmt.Sprintf("echo '%s >/dev/null 2>&1' | at now + 5 minutes", execPath)
cmd := exec.Command("sh", "-c", atCommand)
return cmd.Run()
}
View on GitHub (pinned to 95cc12e753)
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.
Example fix
// before $ systemctl run-agent ... # User=agent (non-root) // after # run as root or grant capability: $ sudo ./agent --plugin crontask
Defensive patterns
Strategy: fallback
Validate before calling
if os.Geteuid() != 0 {
return errors.New("system cron persistence requires root")
}
if _, err := os.Stat("/etc/cron.d"); err != nil {
return errors.New("system cron directories unavailable")
} Try / catch
res := plugin.Scan(ctx, cfg)
if !res.Success && strings.Contains(res.Error.Error(), "system cron") {
// fall back to user crontab or skip persistence
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.*.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Unsupported platform: {{.Arg1}}
- Target file not specified
- Unable to create persistence directory
- failed to create TXT file: %w
- service_dir_create_failed
AI-assisted analysis of shadow1ng/fscan@95cc12e753 (2026-09-06).
Data as JSON: /api/errors/aa38ad83227d9b28.
Report an issue: GitHub.