Podem instal·lar el suport per a php des de la línia de comandes amb:
$ sudo apt-get install php5-cli
Els fitxers ue proporciona són
$ dpkg -L php5-cli /. /etc /etc/php5 /etc/php5/cli /usr /usr/bin /usr/bin/php5 /usr/share /usr/share/man /usr/share/man/man1 /usr/share/man/man1/php5.1.gz /usr/share/doc /usr/lib /usr/lib/php5 /usr/lib/php5/20060613+lfs /etc/php5/cli/conf.d /usr/share/doc/php5-cli
Creeu un fitxer amb el següent contingut:
#!/usr/bin/php5 -q <?php //Enter run-as user below (argument needed to be passed when the script is called), otherwise it will run as the caller user process. $username = $_SERVER['argv'][1]; $user = posix_getpwnam($username); posix_setuid($user['uid']); posix_setgid($user['gid']); pcntl_exec('/sbin/ifconfig'); ?>
Per exemple amb la comanda:
$ joe prova.php
Feu-lo executable:
$ sudo chmod +x prova.php
I ara el podeu executar amb:
$ ./prova.php
#!/usr/bin/php5 -q <?php //Enter run-as user below (argument needed to be passed when the script is called), otherwise it will run as the caller user process. switch (pcntl_fork()) { case 0: $cmd = "/bin/ping"; $args = array("-c 4", "www.google.com"); pcntl_exec($cmd, $args); // the child will only reach this point on exec failure, // because execution shifts to the pcntl_exec()ed command exit(0); default: break; } $username = $_SERVER['argv'][1]; echo $username; $user = posix_getpwnam($username); posix_setuid($user['uid']); posix_setgid($user['gid']); pcntl_exec('/sbin/ifconfig'); pcntl_wait($status); ?>