2026-05-18 12:14:53 -05:00
|
|
|
// Phase 13 (Track L.11) — Koa CMDI vuln fixture.
|
|
|
|
|
//
|
|
|
|
|
// The `/run` route forwards a `cmd` query parameter straight into
|
|
|
|
|
// `child_process.exec`. Adapter binding: `router.get('/run', runCmd)`
|
|
|
|
|
// with `cmd` flowing through `ctx.query.cmd`.
|
|
|
|
|
|
|
|
|
|
const Koa = require('koa');
|
|
|
|
|
const Router = require('@koa/router');
|
|
|
|
|
const { exec } = require('child_process');
|
|
|
|
|
|
|
|
|
|
const app = new Koa();
|
|
|
|
|
const router = new Router();
|
|
|
|
|
|
|
|
|
|
async function runCmd(ctx) {
|
|
|
|
|
const cmd = ctx.query.cmd || '';
|
|
|
|
|
await new Promise((resolve) => {
|
2026-05-23 09:17:02 -05:00
|
|
|
exec('ls ' + cmd, (err, stdout) => {
|
2026-05-18 12:14:53 -05:00
|
|
|
ctx.body = err ? String(err) : stdout;
|
|
|
|
|
resolve();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
router.get('/run', runCmd);
|
|
|
|
|
app.use(router.routes());
|
|
|
|
|
|
|
|
|
|
module.exports = { app, runCmd };
|