How can '/e' regex expression be misused on a PHP code snippet running on my server?

Viewed 20

I'm learning about linux systems, and I've read that '/e' is deprecated, but I'm using a machine with PHP 5.3 and I want to learn how this code could be misused to execute different commands. How can I use this code to execute external commands?

#!/usr/bin/php
<?php
        function y($m)
        {
                $m = preg_replace("/\./", " x ", $m);
                $m = preg_replace("/@/", " y", $m);
                return $m;
        }

        function x($y, $z)
        {
                $a = file_get_contents($y);
                $a = preg_replace("/(\[x (.*)\])/e", "y(\"\\2\")", $a);
                $a = preg_replace("/\[/", "(", $a);
                $a = preg_replace("/\]/", ")", $a);
                return $a;
        }
        $r = x($argv[1], $argv[2]);
        print $r;
?>

0 Answers
Related