在web浏览器中调用exec()php函数


call the exec() php function in the web browser

我有一个名为getServerAddres()的php函数,我正在尝试从web浏览器执行exec()。我知道这不是使用该函数的正确方式,我的任务只是使用远程代码注入来利用web服务器。关于如何通过web浏览器使用exec()进行远程代码注入的任何帮助都将不胜感激。

假设登录屏幕是:https://www.10.10.20.161/test/

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 > 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];
}
}

}

php脚本来自login.php文件。

您似乎不了解exec函数。。。。

首先,请阅读此处的文档。

此函数在服务器端执行,因此无法在客户端执行。

如果你想要的是主机的信息,那么你可以在那里运行命令,并输出结果。

创建这个文件:example.php,并输入这个代码:

<?php
   echo exec('whoami');
?>

现在,将此文件上传到主机,并发出请求:

www.YOURHOST.smg/example.php

并读取结果