Sc rce

From ersinkoc/security-check · View interactive version

Sc rce is an AI agent skill from the GitHub repository ersinkoc/security-check. Remote Code Execution detection via eval, exec, dynamic code loading, and code injection vectors

How to use this skill

Skill file

SC: Remote Code Execution (RCE)

Purpose

Detects remote code execution vulnerabilities where user-controlled input reaches functions that evaluate or execute code dynamically. Covers eval-based injection, dynamic function construction, script engine execution, template code execution, and code loading from untrusted sources. This skill focuses on code evaluation mechanisms beyond command injection (covered by sc-cmdi) and deserialization (covered by sc-deserialization).

Activation

Called by sc-orchestrator during Phase 2. Runs against all detected languages.

Phase 1: Discovery

Keyword Patterns to Search

# Python
"eval(", "exec(", "compile(", "__import__(", "importlib.import_module(",
"builtins.__import__", "code.InteractiveInterpreter", "ast.literal_eval"

# JavaScript/Node.js
"eval(", "Function(", "setTimeout(.*string", "setInterval(.*string",
"vm.runInNewContext(", "vm.runInThisContext(", "vm.createContext(",
"require(.*variable", "import(.*variable", "new Function("

# PHP
"eval(", "assert(", "create_function(", "preg_replace(.*/e",
"call_user_func(", "call_user_func_array(", "array_map(",
"usort(.*\\$", "include(.*\\$", "require(.*\\$"

# Java
"ScriptEngine", "ScriptEngineManager", "Nashorn", "GraalVM",
"GroovyShell", "GroovyClassLoader", "javax.script",
"MethodHandle", "ClassLoader.loadClass"

# C#
"CSharpCodeProvider", "Roslyn", "Microsoft.CodeAnalysis",
"Assembly.Load(", "Activator.CreateInstance(",
"Type.GetType(.*variable", "DynamicMethod"

# Go
"plugin.Open(", "yaegi", "go/ast"

# Ruby
"eval(", "instance_eval(", "class_eval(", "module_eval(",
"send(.*variable", "public_send(", "method("

Data Flow Tracing

Trace user input to any dynamic code evaluation function. Key patterns:

Phase 2: Verification

Python Examples

# VULNERABLE: eval with user input
result = eval(request.GET['expression'])

# VULNERABLE: exec with user input
exec(request.POST['code'])

# SAFE: ast.literal_eval for safe subset
import ast
result = ast.literal_eval(request.GET['data'])  # Only parses literals

# SAFE: Restricted evaluation with custom namespace
allowed_names = {"abs": abs, "min": min, "max": max}
result = eval(expression, {"__builtins__": {}}, allowed_names)
# Note: Still risky — sandbox escapes are possible

JavaScript Examples

// VULNERABLE: eval with user input
const result = eval(req.body.expression);

// VULNERABLE: Function constructor
const fn = new Function('return ' + req.body.code);

// VULNERABLE: vm module (escapable sandbox)
const vm = require('vm');
vm.runInNewContext(req.body.code, sandbox);

// SAFE: Use a math parser library instead
const mathjs = require('mathjs');
const result = mathjs.evaluate(req.body.expression);

PHP Examples

// VULNERABLE: eval
eval($_POST['code']);

// VULNERABLE: Dynamic function call
$func = $_GET['action'];
$func(); // Calls arbitrary function

// SAFE: Allowlist of functions
$allowed = ['view', 'edit', 'delete'];
if (in_array($_GET['action'], $allowed)) {
    $func = $_GET['action'];
    $func();
}

Severity Classification

Output Format

Finding: RCE-{NNN}

Common False Positives

  1. eval with constants — eval("1+2") with no user input is not exploitable
  2. ast.literal_eval — Python's literal_eval only parses literal values (safe for simple data)
  3. Template engine rendering — template engines are covered by sc-ssti, not this skill
  4. Build/dev tooling — webpack, babel, jest using eval internally for build purposes
  5. REPL/debug tools — eval in development REPL tools not deployed to production
  6. Math expression parsers — libraries like mathjs safely evaluate mathematical expressions
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.