liveBook · Manning

Remote code execution

As explained in Grokking Web Application Security

Remote code execution is an attack in which an attacker causes arbitrary code to run on a remote system.

Remote code execution (RCE) occurs when an attacker causes arbitrary code to run on a remote system. In a web application, that can expose files, compromise the server, or enable a complete system takeover. The common root problem is treating untrusted request data as executable code. section 12.1 section 11.2

Recognize the main paths to RCE and the corresponding defensive action:

  • Dynamic evaluation: passing request data to JavaScript eval() lets an attacker execute code inside the Node.js server runtime; never evaluate untrusted input. section 11.2 section 12.1
  • Unsafe JSON handling: parse request bodies with JSON.parse() instead of eval(), so non-JSON code is rejected. section 11.2
  • Remote server-side includes: a PHP include whose URL comes from an HTTP request can load and execute attacker-controlled code; avoid URL-based includes or disable them with allow_url_include(false). section 12.3
  • Dependency exposure: track newly disclosed vulnerabilities and apply security patches quickly, especially when a major remote code execution flaw becomes public. section 1.5
const express = require('express')
const app     = express()

app.post('/api/profile', (request, response) => {
  let data = ''

  request.on('data', chunk => {
    data += chunk.toString()
  })

  request.on('end', () => {
    const edits = eval(data)

    saveProfileChanges(edits)

    response.json({ 
      success: true, message: 'Profile updated.' 
    })
  })
})

Inspect the deliberately unsafe Express handler to see how eval() turns request data into executable server-side JavaScript; compare it with the JSON.parse() alternative. section 11.2

A race after disclosure

Log4Shell illustrates why RCE warnings demand operational urgency: once a remote code execution vulnerability becomes public, attackers may move quickly, so teams must follow security alerts and apply the available patch. section 1.5

How Grokking Web Application Security covers it

How deep it goes
Explains dynamic evaluation, JSON deserialization, remote includes, and patch urgency, but stops short of exploit-development detail.
Examples
Uses Express handlers with eval() and JSON.parse(), a PHP remote include, and the Log4Shell disclosure.
What it assumes
Assumes basic web-request and programming knowledge while explaining dynamic evaluation and unsafe input handling directly.
What you can do after
Apply JSON.parse(), avoid eval(), disable remote PHP includes, and prioritize patches for newly disclosed RCE vulnerabilities.
How it connects
Connects RCE to injection vulnerabilities, dynamic evaluation, JSON handling, server-side includes, and security patching.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Web Application Security. The section links point to the parts of the book it draws on.