Information Gathering
Rustscan
SSH, HTTP, and DNS was running on the target. Seeing SSH and HTTP open on Linux machine is pretty normal but not DNS. I decided I should spend some time on domain enumeration later.
Nmap
Nmap didn’t provided anything very useful:
Enumeration
DNS - UDP/TCP 53
nslookup discovered ns1.cronos.htb. From this, I can also assume the base domain name as cronos.htb.
nslookup
I confirmed on cronos.htb through dig
dig @10.10.13 cronos.htb
Zone transfer is always worth a try because even if it fails, because sometimes it still provides bunch of information as such:
dig axfr @10.10.10.13 cronos.htb
I added the below newly discovered domain names to /etc/hosts file:
HTTP - TCP 80
Let’s take a look at each of the discovered domain on browser:
http://10.10.10.248 → Apache Ubuntu Default Page (Nothing interesting)
http://cronos.htb/ → Webpage.
All the sublinks(DOCUMENTATION, LARACASTS, etc) were linked to Laravel related external websites. Maybe I can search for Laravel related exploits?
http://ns1.cronos.htb/ → Again, Apache Ubuntu Default Page (Nothing Interesting)
http://admin.cronos.htb/ → Login Page.
I could try on SQL Injection or try bruteforcing login credentials later.
http://www.cronos.htb/ → Showed the same webpage as http://cronos.htb
So at this point I had three plans in mind.
- Directory Bruteforce on cronos.htb and see if anything interesting is there.
- Laravel exploit on cronos.htb
- SQL Injection on admin.cronos.htb
cronos.htb
Feroxbuster (Nothing)
As plan #1, I tried directory bruteforcing on cronos.htb but nothing interesting was found:
Laravel Exploit (Failed)
I knew cronos.htb is using Laravel and from bit of googling, I knew that Laravel has lot of known public exploits.
Issue was about the Laravel version that I do not know so I tried couple of exploits hoping one of them work but nothing worked out : (
SQLi on admin.cronos.htb
I intercepted the request for login through Burp Suite and used it with sqlmap to see if the login page is vulnerable to SQL Injection.
Sadly, sqlmap decided none of the parameters are injectable:
sqlmap -r admin-cronos-htb-login-req.txt --batch
After jumping around bunch of rabbit holes, I came back to login page thinking “This has to be the entry point”, because nothing else worked out.
After spending good enough time on SQL injection, I found out ' or 1=1-- -
gets me pass the login form.
This taught me a lesson that automated tools aren’t always perfect since sqlmap didn’t find this vulnerable access point.
Shell as www-data
Command Injection
Now with SQLi, I have access to the service running inside of it, which seems to be a Net Tool that allows you to either ping or traceroute to a set IP address:
Pinging 8.8.8.8, I can see that it actually runs the ping command and shows the output on webpage:
I intercepted the request with Burp Suite to tamper command.
What was interesting is that I can choose whatever command I want to using Burp Suite:
I tried listing out home directory of the target and I can see that it works:
Reverse Shell
With netcat listener running locally on my Kali machine, I ran the following payload through Burp Suite:
Now I have shell as www-data:
Before I do anything, I first enhanced the shell:
python3 -c 'import pty; pty.spawn("/bin/bash")'
Privesc www-data to root
Local Enumeration
Before running linpeas, I manually looked around the file system and on /var/www/admin, I saw config.php which seemed interesting:
It had MySQL credentials in it → admin:kEjdbRigfBHUREiNSDs
MySQL Enumeration(Nothing)
I was able to login to MySQL using the credentials found above:
mysql -u admin -p
I was hoping to see more credentials but only thing that I see was password hash for admin which probably is what I already have as plain text:
Laravel Privesc (Failed)
Earlier I was looking for Laravel’s version which I failed to discover, now through composer.json, I found out about it’s version: 5.4.*
I tried searching for Laravel 5.4 related Privilege Escalation but it seemed nothing is doable.
Cronjob Privesc (Success!)
LinPEAs
Now I moved on to Linpeas.
I used python http server and wget to upload Linpeas to /tmp folder and ran it.
One stood out with yellow, which seemed to be my escalation point: /var/www/laravel/artisan
Confirming on /etc/crontab, /var/www/laravel/artisan is being ran every minute:
cat /etc/crontab
I checked whether I can overwrite on file artisan → www-data owns this file! Meaning I can overwrite this file.
With file overwrite permission on cronjob, I can easily escalate privilege by overwriting the file with reverse shell, which will be executed as root, giving attacker escalated privilege.
I used PentestMonkey PHP Reverse Shelland generated reverse shell php script, naming it as artisan and uploaded it to target /tmp folder:
Now I move malicious artisan file to /var/www/laravel which will replace original artisan file with my malicious one:
Now waiting for a bit on netcat listener, I get a reverse shell as a root:
Beyond Root
Above I got a shell as root, but it is always best to have a stable shell connection such as SSH other than reverse shell. Below are several ways of maintaining persistence once gained shell as a root.
SSH as root
This is my most recommended and preferred method of maintaining persistence.
First move to the root directory: cd /root
If there is not already, created .ssh directory: mkdir .ssh
Move in to .ssh directory: cd .ssh
Generate ssh key: ssh-keygen -f mykey
Copy generated public key to authorized_keys: cat mykey.pub > authorized_keys
Now there should be these three files on your target root .ssh directory:
Copy private key to local machine.
Back in your target system, change permission for .ssh directory and authorized_keys file: chmod 700 .ssh
& chmod 600 .ssh/authorized_keys
Now using the copied private key, you sign in to SSH as root: ssh -i mykey root@10.10.10.13
Add user
I can add whatever user I want to root group and this will allow me to escalate my privilege to root directly when I gain access to low privilege user shell.
I add user and set password using the commands below:
Now I can switch to user hacker-jadu using su hacker-jadu
:
Crack /etc/shadow
This method is not very recommended since you don’t know how strict password policy is for your target environment.
Taking a look at /etc/shadow file, I can see hashed password for the previous set user hacker-jadu:
Using hashcat, I can crack this hash which will reveal password:
hashcat -m 1800 hash rockyou.txt