code-injection-codegen
Skill2 starsChanged 2 months agoMITView on GitHub
Detect code injection vulnerabilities in packages that dynamically generate or evaluate code via new Function(), eval(), vm.run*, or template literal interpolation.
In this repository255 other files it gives its agents.
- ad-acl-abuseSkill
- ad-adcs-access-and-relaySkill
- ad-adcs-persistenceSkill
- ad-adcs-template-abuseSkill
- ad-ad-discoverySkill
- ad-ad-persistenceSkill
- ad-auth-coercion-relaySkill
- ad-credential-dumpingSkill
- ad-gpo-abuseSkill
- ad-kerberos-delegationSkill
- ad-kerberos-roastingSkill
- ad-kerberos-ticket-forgingSkill
- ad-pass-the-hashSkill
- ad-sccm-exploitationSkill
- ad-trust-attacksSkill
- hunt-ntlm-infoSkill
- offensive-active-directorySkill
- hunt-llm-aiSkill
- hunt-rag-vectorSkill
- offensive-ai-securitySkill
- cloud-iam-deepSkill
- hunt-cloud-misconfigSkill
- hunt-k8sSkill
- m365-entra-attackSkill
- network-container-escapesSkill
- offensive-cloudSkill
- offensive-container-escapeSkill
- offensive-k8s-attacksSkill
- okta-attackSkill
- vmware-vcenter-attackSkill
- credential-password-sprayingSkill
- hunt-brute-forceSkill
- hunt-forgot-passwordSkill
- post-exploit-credential-recoverySkill
- meme-coin-auditSkill
- offensive-crypto-attacksSkill
- web3-auditSkill
- ctfSkill
- advisory-miningSkill
- auth-bypassSkill
- command-injectionSkill
- cross-pollinationSkill
- cve-hunting-methodologySkill
- decompression-bombSkill
- entity-expansionSkill
- fp-checkSkill
- method-clobberingSkill
- path-traversalSkill
- prototype-pollutionSkill
- recursion-dosSkill
- redosSkill
- sandbox-escapeSkill
- target-reconSkill
- web2-vuln-classesSkill
- evasion-av-edr-evasionSkill
- offensive-anti-forensicsSkill
- offensive-edr-evasionSkill
- offensive-keylogger-archSkill
- offensive-mitigationsSkill
- offensive-waf-bypassSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 31
Search for all dynamic code execution:
- Very specific: line 67
Check for template literals:
new Function(return ${userInput}) - Very specific: line 68
Check for string concatenation: new Function("return " + userInput)
- Distinctive: line 69
Check for variable interpolation in generated code
- Distinctive: line 82
Search for this pattern:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Code Injection via Code Generation
When to Use
Audit any package that dynamically generates or evaluates code — schema validators, template engines, expression evaluators, serializers with code generation, JIT compilers, query builders that emit JavaScript.
This is the highest-yield vulnerability class for CVE hunting. ~90% acceptance rate when confirmed.
Key Insight
Code generation packages often interpolate user-controlled values directly into generated code strings. Unlike template injection (where user input goes INTO a template), here user input becomes PART of the generated code itself.
Process
Step 1: Find Code Evaluation Sinks
Search for all dynamic code execution:
# JavaScript/TypeScript
grep -rn "new Function\(" .
grep -rn "eval(" .
grep -rn "vm\.run" .
grep -rn "vm\.compileFunction" .
grep -rn "setTimeout(" . | grep -v "setTimeout(function"
grep -rn "setInterval(" . | grep -v "setInterval(function"
grep -rn "new AsyncFunction" .
grep -rn "script\.runIn" .
# Python
grep -rn "eval(" .
grep -rn "exec(" .
grep -rn "compile(" . | grep -v "re.compile"
# Ruby
grep -rn "\.eval\b" .
grep -rn "instance_eval" .
grep -rn "class_eval" .
# PHP
grep -rn "eval(" .
grep -rn "assert(" .
grep -rn "create_function" .
grep -rn "preg_replace.*\/e" .Step 2: Trace Data Flow to Sink
For each sink found:
- Identify what string is being evaluated
- Trace backwards — is any part of that string derived from user input?
- Check for template literals:
new Function(`return ${userInput}`) - Check for string concatenation:
new Function("return " + userInput) - Check for variable interpolation in generated code
Step 3: Check for Block Comment Escape
JSON.stringify does NOT escape */. If generated code wraps values in block comments:
// VULNERABLE PATTERN:
let code = `/* ${JSON.stringify(userValue)} */ actual_code_here`;
// Attacker input: */ malicious_code /*
// Result: /* */ malicious_code /* */ actual_code_hereSearch for this pattern:
grep -rn "\/\*.*JSON\.stringify" .
grep -rn "\/\*.*\$\{" .Step 4: Check for Incomplete Escaping
Common mistakes:
- Escaping single quotes but not backticks (template literals)
- Escaping backslash but not newlines (line injection)
- Using JSON.stringify but not escaping
</script>in HTML context - Escaping in the value but not in the key (object property names)
Step 5: Verify Exploitability
- Can the attacker control the interpolated value?
- Does the generated code get executed (not just constructed)?
- What is the execution context? (Node.js process = RCE, browser = XSS)
- Is there any sandboxing? (node:vm is NOT security — see sandbox-escape skill)
Vulnerable Patterns
Pattern 1: Template Literal in new Function()
// Schema validator generating validation function
function createValidator(schema) {
const code = `return function(value) {
if (typeof value !== "${schema.type}") throw new Error("invalid");
}`;
return new Function(code)();
}
// Exploit: schema.type = '"; }); process.mainModule.require("child_process").execSync("id"); //'Pattern 2: String Concatenation in eval()
// Expression evaluator
function evaluate(expr) {
return eval("(" + expr + ")");
}Pattern 3: Code Generation with Object Keys
// Serializer generating accessor code
function createGetter(path) {
return new Function("obj", `return obj.${path}`);
}
// Exploit: path = "x; process.mainModule.require('child_process').execSync('id'); //"Pattern 4: Block Comment Escape
// Code generator with "safe" comments
function generateModule(config) {
return `
/* Config: ${JSON.stringify(config.name)} */
module.exports = { value: ${JSON.stringify(config.value)} };
`;
}
// Exploit: config.name = "*/ require('child_process').execSync('id'); /*"Pattern 5: sourceURL Injection
// Debug source mapping
const code = `${generatedCode}\n//# sourceURL=${filename}`;
new Function(code)();
// Exploit: filename contains newline + malicious codeCVSS Guidance
- Server-side code execution (Node.js): CRITICAL 9.8 (AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)
- With authentication required: HIGH 8.8 (PR:L)
- Client-side only (browser): HIGH 7.5 (XSS equivalent)
- Requires specific configuration: reduce AC to H
References
- Sinks — Code execution sinks by language
- False Positive Indicators — When this isn't a real bug
- PoC Skeleton — Proof of concept template
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

