T06 · System Persistence
- Location
hooks/cron-scripts-loader/handler.ts:64- Finding
Persistent Scheduled Execution of Arbitrary Shell Scripts
- Content
View full analysis
{ if (!filename.endsWith(".sh")) return; const filePath = join(SCRIPTS_DIR, filename); try { await stat(filePath); } catch { return; } let content: string; try { content = await readFile(filePath, "utf8"); } catch (err: any) { console.error(`${LOG_PREFIX} Cannot read ${filename}: ${err.message}`); return; } const meta = parseMeta(content, filePath); if (!meta) return; stopJob(filename); try { const job = new Cron( meta.schedule, { timezone: meta.tz, protect: true }, () => { try { runScript(meta); } catch (err: any) { console.error(`${LOG_PREFIX}[${meta.name}] Unexpected run error: ${err.message}`); } } ); activeJobs.set(filename, job); ``` The directory watcher automatically activates newly created or modified scripts: ```ts function watchDir(): void { con ...[truncated 5189 chars]- Remediation
View remediation
