✍️
Writeups and Walkthroughs
HomeGitHubPortfolio Twitter/X Medium Cont@ct
  • ✍️Writeups and Walkthroughs
  • THM
    • Simple CTF
    • RootMe
    • Eternal Blue
    • Vulnversity
    • Pickle Rick
    • Brooklyn Nine Nine
    • Kenobi
    • Bounty Hacker
    • Overpass
    • LazyAdmin
    • Ignite
    • Bolt
    • Agent Sudo
    • Anonymous
    • Startup
    • Wgel
    • Lian_Yu
    • Blog
    • ColdBox
    • H4cked
    • Smag Grotto
    • Ice
    • Blaster
    • The Sticker Shop
    • 🔟OWASP
      • 1️⃣Injection
    • Active Directory Basics
    • Attacktive Directory
    • Post-Exploitation Basics
  • HackTheBox
    • Active
    • Devel
    • Delivery
    • Analytics
    • Bashed
    • Valentine
    • Sau
    • Sunday
    • Cap
    • Bizness
    • Chemistry %
  • Vulnhub
    • Brainpain (BoF)
  • DockerLabs
    • Trust
    • Upload
    • Vacaciones
  • DVWA
    • Install and configure DVWA
    • Command Injection
    • CSRF
    • File Inclusion
    • SQL Injection
    • SQLi Blind
  • Mutillidae II
    • Install & configure OWASP Mutillidae II
    • SQLi
      • SQLi Login Bypass
      • Extracting Data
      • Finding Number of Columns
      • Pivoting with SQL injection
    • Command Injection
      • Extracting User Accounts
      • Web Shell
    • IDOR & File Inclusion
      • Edit Another User's Profile
      • Extracting User Accounts
      • Extracting User Accounts with Local File Inclusion
      • Web Shell with Remote File Inclusion (RFI)
    • XSS
      • XSS Reflected
      • XSS Stored
      • XSS DOM-Based
  • Secure Bank
    • Install & configure Secure Bank
    • -----
      • SQLi Login Bypass
      • Extracting Data
      • Finding Number of Columns
      • Pivoting with SQL injection
    • -----
      • Extracting User Accounts
      • Web Shell
  • PortSwigger - Web Security Academy
    • Burp Suite Config
    • Information Disclosure
      • Information disclosure vulnerabilities
      • Common sources of information disclosure
        • Information disclosure in error messages
        • Information disclosure on debug page
        • Source code disclosure via backup files
        • Authentication bypass via information disclosure
        • Information disclosure in version control history
    • Essential skills
      • Obfuscating attacks using encodings
        • SQL injection with filter bypass via XML encoding
      • Using Burp Scanner
      • Identifying unknown vulnerabilities
    • Server-side vulnerabilities
      • Path traversal
        • File path traversal, simple case
      • Access control
        • Unprotected admin functionality
        • Unprotected admin functionality with unpredictable URL
        • User role controlled by request parameter
        • User ID controlled by request parameter, with unpredictable user IDs
        • User ID controlled by request parameter with password disclosure
      • Authentication
        • Username enumeration via different responses
        • 2FA simple bypass
      • Server-side request forgery (SSRF)
        • Basic SSRF against the local server
        • Basic SSRF against another back-end system
      • File upload vulnerabilities
        • Remote code execution via web shell upload
        • Web shell upload via Content-Type restriction bypass
      • OS Command Injection
        • OS command injection, simple case
      • SQL injection
        • SQL injection vulnerability in WHERE clause allowing retrieval of hidden data
        • SQL injection vulnerability allowing login bypass
    • JWT Attacks
      • Json Web Tokens (JWT)
      • Exploiting JWT
        • JWT authentication bypass via unverified signature
        • JWT authentication bypass via flawed signature verification
        • JWT authentication bypass via weak signing key
        • To-Do
          • JWT authentication bypass via jwk header injection - %
          • JWT authentication bypass via jku header injection - %
          • JWT authentication bypass via kid header path traversal - %
    • API Testing
      • API Testing
        • Exploiting an API endpoint using documentation
        • Finding and exploiting an unused API endpoint
        • Exploiting a mass assignment vulnerability
      • Server-side parameter pollution
        • Exploiting server-side parameter pollution in a query string
    • Deserialization Insecure
      • Serialization vs Deserialization
        • Lab
        • Lab
      • Java Insecure Deserialization
        • Lab
        • Lab
      • PHP Insecure Deserialization
        • Lab
        • Lab
  • HomeMade Labs
    • Active Directory
      • AD Lab Setup
      • AD Enumeration
      • SMB Common Attacks
    • Pivoting
      • Pivoting Theory
      • Pivoting Guidelines
      • Lab (3 Targets)
    • Buffer Overflow (BoF)
      • BoF Theory
      • Brainpain (BoF Lab)
Powered by GitBook
On this page
  • Java Insecure Deserialization
  • Exploitation and Attack Vectors
  • Mitigation Strategies
  • Labs 🔬
  1. PortSwigger - Web Security Academy
  2. Deserialization Insecure

Java Insecure Deserialization

https://portswigger.net/web-security/deserialization/exploiting#java-serialization-format

Java Insecure Deserialization

Insecure deserialization in Java occurs when an application deserializes untrusted data without proper validation, allowing an attacker to manipulate the serialized object and achieve remote code execution (RCE), privilege escalation, or other malicious activities.

Key Concepts

Gadgets and Gadget Libraries

  • Gadget: A property or method inside an object that can be leveraged for exploitation when deserialized.

  • Gadget Library: Some Java libraries contain pre-existing gadgets that attackers can use to construct an exploit. Examples include:

    • Apache CommonsCollections (versions 1-6)

    • Spring Framework

    • JDK classes (e.g., java.rmi.server.UnicastRemoteObject)

    • Jackson, Fastjson, and XStream

Even though these libraries are not inherently vulnerable, if an application deserializes untrusted input while these libraries are present in the classpath, an attacker can exploit them to create a gadget chain, leading to successful exploitation.

How Java Deserialization Works

Serialization in Java is the process of converting an object into a byte stream that can be stored or transmitted.

  • ObjectOutputStream.writeObject(obj): Serializes an object.

  • ObjectInputStream.readObject(): Deserializes the byte stream into an object.

If the input passed to readObject() is attacker-controlled, it can be exploited to execute arbitrary code.

Exploitation and Attack Vectors

Exploiting Java Insecure Deserialization

An attacker can exploit insecure deserialization by sending a crafted malicious serialized object to a vulnerable application. Common attack vectors include:

  • Cookies → Sending serialized payloads via HTTP cookies.

  • Web Requests → Injecting payloads through POST/GET parameters.

  • Files → Uploading serialized payloads as files.

  • Inter-Process Communication (IPC) → Sending malicious objects through network sockets, RMI, or JNDI.

Ysoserial Tool

bashCopiaModificajava -jar ysoserial.jar CommonsCollections1 "whoami" > payload.ser
  • This generates a payload that executes whoami upon deserialization.

  • The payload is then sent to the vulnerable application, which executes the system command when deserialized.

Exploit Example

If an application deserializes objects from an untrusted source, an attacker can craft a malicious object like:

javaCopiaModificaimport java.io.*;

public class MaliciousPayload implements Serializable {
    private void readObject(ObjectInputStream in) throws Exception {
        Runtime.getRuntime().exec("calc.exe");  // Arbitrary code execution
    }
}

When deserialized, this object spawns a calculator on Windows or executes a system command.

Mitigation Strategies

  • Avoid deserialization of untrusted data.

  • Use ObjectInputFilter (Java 9+) to allowlist safe classes:

    javaCopiaModificaObjectInputFilter filter = info -> info.serialClass().getName().startsWith("trusted.package") 
        ? ObjectInputFilter.Status.ALLOWED 
        : ObjectInputFilter.Status.REJECTED;
  • Use safer data formats like JSON or protobuf instead of Java serialization.

  • Keep dependencies updated to avoid known gadget chains.

  • Restrict available classes in the classpath to prevent gadget chains.


Labs 🔬

  • aaa

  • bbb

PreviousLabNextLab

Last updated 1 month ago

is a popular tool for generating exploit payloads using known gadget libraries. Example command:

ysoserial