System call injection

With the follow commands you can execute an external program on the system (server).

  • shell_exec
  • proc_open
  • system
  • exec
  • passthru
  • popen
  • “ (back tick operator)

This form sends a domain name and prints the result back from the linux program whois.

<form>
<input type=”text” name=”domain” value=”" />
<input type=”submit” value=”whois” />
</form>

<pre>
<?
    if ($_GET['domain']) {
        system(“whois “.$_GET['domain']);
    }
?>
</pre>

send example.com to the whois program

whois output

The problem of this script is that the user input touches directly the system without any validation. An attacker can end the whois command with a semicolon (;) and add any command he wants.

send “;uname -a” to the system and print system informations

whois injected

Using system calls which can be manipulate could be very dangerous. Never trust the user, always Filter Input.
If you must use system calls, use “escapeshellarg” and “escapeshellcmd” to escape strings.

1 comment so far

  1. animal facts on

    The main thing i’m enjoying while reading your blog is the way you write, you are a really charismatic person and your posts are wonderful, keep it up!


Leave a reply