You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2019-11-22-insecure_deserialization_java.md
+63-7Lines changed: 63 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,15 +47,15 @@ The process of `re-creating` the actual object in memory from byte stream is cal
47
47
48
48
-[x] Some objects may be required to implement `Serializable` due to inheritance for example `SuperUser`. It inherites the base class `User` that implements `Serializable`.
49
49
50
-
To ensure that such objects (e.g., `SuperUser`) cannot be deserialized, we can override the `readObject()` method and mark it as final to throw an exception during the deserialization process.
50
+
To ensure that such objects (e.g., `SuperUser`) cannot be deserialized, we can override the `readObject()` method and mark it as `final` to throw an exception during the deserialization process.
1. The readObject method of `java.io.ObjectInputStream` is vulnerable.
56
+
1. The `readObject()` method of `java.io.ObjectInputStream` is vulnerable.
57
57
58
-
2. During the Deserialization process, the `readObject()` method is always being called, and it can construct any sort of Serializable object that can be found on the Java classpath before passing it back to the caller for the type_check.
58
+
2. During the Deserialization process, the `readObject()` method is always being called, and it can construct any sort of Serializable object that can be found on the Java classpath before passing it back to the caller for the type check.
59
59
60
60
3. An Exception occurs only when there’s a type mismatch between the returned object and the expected object. If the constructed object performs any harmful actions during its construction, it’s already too late to prevent them by the time type checking.
61
61
@@ -85,17 +85,73 @@ From a Whitebox perspective
85
85
86
86
## How to Exploit
87
87
88
-
### Denial of Service
88
+
### Perform Denial of Service
89
89
90
-
1. Generate a malicious serialized object.
90
+
1. Generate a malicious serialized object using `DoSExploit.java`.
91
91
92
92
2. During deserialization, when the application attempts to reconstruct the object in memory, it consumes 100% of the CPU resources.
-[x] The modern Java Security Manager by default includes protections against unsafe deserialization by blocking blacklisted gadgets. Therefore, `disabling` that feature in code by adding the following line in `DemoDeserilization.java`
107
+
108
+
```java
109
+
// in current Java, by default enableUnsafeSerialization is set to 'false'
> I’ve put together a detailed blog [post](https://greyshell.github.io/posts/demystify_java_gadget_chain/) on how to create the entire RCE gadget chain from scratch.
123
+
{: .prompt-tip }
124
+
125
+
- Set up the exploit dev environment
126
+
- JDK version: `openjdk-23`
127
+
- Add `commons-collectios-3.2.2.jar`, `commons-lang3-3.7.jar` and `mockito-all-1.9.5.jar` into the Java classpath.
- Download the exploit code - [RCE.java](https://github.com/greyshell/java_insecure_deserialization/blob/main/src/RCE.java).
133
+
134
+
> Java’s **strong encapsulation** introduced in **Java 9+**, which restricts reflective access to certain internal Java classes and fields by default. This is especially relevant when using libraries or tools that attempt to access private or internal fields of classes like `HashMap`.
135
+
{: .prompt-danger }
136
+
137
+
-[x] By adding the `--add-opens` option, we can explicitly open the necessary package (`java.util`) for reflection. In IntelliJ IDEA -> Run -> Edit Configurations -> In **VM options** field, add the following
0 commit comments