HTB - ScriptKiddie
NMAP
We will start with NMAP -
Enumeration
Since SSH is secure service and not much attack surface, we will start with port 5000.
Port 5000
We see Python Web framework - Werkzeug/0.16.1 Python/3.8.5
Looking at the functionality, we can generate Shell, perform NMAP scan and look for exploits via Searchsploit. This looks like "frontend" of the Metasploit framework.
We also see that the web page is accepting template
file while generating payloads
Quick google search on MSFVenom and Template, we come across CVE-2020-7384 Reference - https://www.exploit-db.com/exploits/49491
We can inject our own payload and when MSFvenom generates payload, the payload is executed.
Exploitation
Initial Foothold
Exploiting CVE-2020-7384
We will download the exploit code and input attacker ip and port on the prompt -
Install jarsigner
if it is not installed -
sudo apt-get install default-jdk
The exploit.apk
is generated and we start the netcat listener -
Upload apk to work
-
Once uploaded exploit.apk
and click generate
Reverse Shell -
Make shell stabilize by inserting our SSH public key in /home/kid/.ssh/authorized_keys
SSH to target as user kid
with SSH key -
Privilege Escalation
Exploiting intended functionality -
We see another user pwn
in the system and we can access their home directory. Browsing to the /home/pwn/
we see scanlosers.sh
script.
Looking at the script, we see it is calling /home/kid/logs/hackers
which own'd by our current user kid
-
Let's dissect the scanlosers.sh script line by line and see if we can own user pwn
--
Looking at permissions, we can read/write /home/kid/logs/hackers
. This is the one we can control.
The core of the scanlosers.sh
script is the nmap
command which is ran using shell script sh. So if we overwrite that using the $log file we control, we can use bash magic and append our payload.
Also, looking at the "cut" command in the script, it is grabbing text from log file after second white space
So we can stuff our payload as -
Finally, at last line in the scanlosers.sh
script, we see a if condition in the last line that if the line count is more than 0, then the file is overwritten with nothing by script itself.
To overcome this, we can use "echo -n" so there is no "new line" or "line break" inserted.
We get shell as pwn
-
Looking at sudo -l
output for pwn
, we see they can /opt/metasploit-framework-6.0.9/msfconsole
as SUDO
without password -
Proof
Last updated