JSON Write Up (THM)
JSON Write Up (THM)
by exploiting the web found a cookie encoded in base64 and when decoding it results to :
{”email”=”<theinput>”} , also the web was using a nodejs
Exploiting Node.js deserialization bug for Remote Code Execution
Exploiting Node.js deserialization bug for Remote Code Execution
Untrusted data passed into unserialize() function in node-serialize module can be exploited to
achieve arbitrary code execution by passing a serialized JavaScript Object with an Immediately
invoked function expression (IIFE).
The Bug
During a Node.js code review, I happen to see a serialization/deserialization module named node-
serialize. A cookie value that comes from the request was passed into the unserialize() function
provided by the module. Here is a sample node.js application to imitate the code:
Java, PHP, Ruby and Python have a fair share of Deserialization bugs. Some
resources explaining these issues:
The vulnerability in the web application is that it reads a cookie named profile from the HTTP request,
perform base64 decode of the cookie value and pass it to unserialize() function. As cookie is an
untrusted input, an attacker can craft malicious cookie value to exploit this vulnerability.I used
nodejsshell.py for generating a reverse shell payload.
2) $ nc -lvnp <port>
3) Now let’s generate the serialized payload and add IIFE brackets () after the function body.
{"rce":"_$$ND_FUNC$$_function (){
<code generated by nodejsshell.py>
}()"}