Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

FORBIDDEN FUNCTIONS: Add eval() #34

Conversation

sjokkateer
Copy link
Contributor

@sjokkateer sjokkateer commented May 23, 2022

This PR forbids the use of a considered non-secure function, eval().

All scripting languages used in web applications have a form of an eval call which receives code at runtime and executes it. If code is crafted using unvalidated and unescaped user input code injection can occur which allows an attacker to subvert application logic and eventually to gain local access.

Take the following PHP script as an example:

<?php

// index.php

declare(strict_types=1);

$x = $_GET['x'];
$y = $_GET['y'];
$z = $_GET['z'];

eval("echo $x * $y / $z;");

Using the following query string:

?x="<pre>", print_r(scandir('./')), "</pre>";//&y=5&z=7

Displays the following in the browser:

Array
(
    [0] => .
    [1] => ..
    [2] => .valet-env.php
    [3] => .vscode
    [4] => composer.json
    [5] => composer.lock
    [6] => index.php
    [7] => phpcs.xml
    [8] => src
    [9] => vendor
)
1

A malicious user has more creative exploits than the example but it demonstrates the risk.

Information taken from OWASP, example taken from SE INFOSEC.

For a real example see: TRUESEC which exploits unserialize() (forbidden in PR 33), which, through a so called gadget chain gets to a class that makes use of eval(), resulting in the establishment of a reverse shell.

With eval() added to the list of forbidden functions, the user would get the following error notification:

------------------------------------------------------------------------------------------------------------------------
9 | ERROR | The use of function eval() is forbidden (Generic.PHP.ForbiddenFunctions.Found)
------------------------------------------------------------------------------------------------------------------------

The PHP documentation also reports a warning/caution about eval() in its documentation.

@jeroennoten jeroennoten merged commit 2bc515a into isaaceindhoven:develop Jun 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants