title: call the exec() php function in the web browser
body: <p>I have a php function called getServerAddres() and I am trying to execute the exec() from the web browser. I understand this is not the proper way of using the function, I was just a task to exploit a web server using remote code injection. Any help on how to do remote code injection using the exec() through the web browser would be greatly appreciated.</p>
  
  <p>Lets say the login in screen is: <a href="https://www.10.10.20.161/test/" rel="nofollow">https://www.10.10.20.161/test/</a>  </p>
  
  <pre><code>function getServerAddress() {
  if(isset($_SERVER["SERVER_ADDR"]))
  return $_SERVER["SERVER_ADDR"];
  else {
  // Running CLI
  if(stristr(PHP_OS, 'WIN')) {
      //  Rather hacky way to handle windows servers
      exec('ipconfig /all', $catch);
      foreach($catch as $line) {
      if(eregi('IP Address', $line)) {
          // Have seen exec return "multi-line" content, so another hack.
          if(count($lineCount = split(':', $line)) == 1) {
          list($t, $ip) = split(':', $line);
          $ip = trim($ip);
          } else {
          $parts = explode('IP Address', $line);
          $parts = explode('Subnet Mask', $parts[1]);
          $parts = explode(': ', $parts[0]);
          $ip = trim($parts[1]);
          }
          if(ip2long($ip &gt; 0)) {
          echo 'IP is '.$ip."\n";
          return $ip;
          } else
          ; // to-do: Handle this failure condition.
      }
      }
  } else {
      $ifconfig = shell_exec('/sbin/ifconfig eth0');
      preg_match('/addr:([\d\.]+)/', $ifconfig, $match);
      return $match[1];
  }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The php script came from the login.php file. </p>