Page cover

Week 2. Backfire

SUMMARY

This is a Debian 12 machine running as a C2 teamserver for a red team. There computer hosts two vulnerable versions of C2 frameworks Havoc and Hardhat, that we have to exploit to get root (therefore the C2 teamserver "backfires" on the red team). The Havoc C2 is based on websockets and is vulnerable to SSRF (CVE-2024-41570) and authenticated command injection. Chaining both vulnerabilities we can get initial shell in the host.

Regarding escalation, it turns out Hardhat is vulnerable to authentication bypass. This can be leveraged to move laterally to another user who in turn is a sudoer, which allows us to gain root.

KEYWORDS

C2, websockets, Havoc, CVE-2024-41570, Hardhat, authentication bypass, sudo escalation.

ENUMERATION

Port scan.

> for ports in $(nmap $target -p- --min-rate=5000 -Pn --open --reason | grep open | awk -F "/" '{print $1}' | tr '\n' ',' | sed s/,$//); do nmap $target -p$ports -sV -sC -Pn -vv -n && echo "\nList of open ports: $ports";done

Nmap scan report for 10.10.11.49
Host is up, received user-set (0.037s latency).
Scanned at 2025-01-23 18:49:15 GMT for 15s
PORT     STATE SERVICE  REASON  VERSION
22/tcp   open  ssh      syn-ack OpenSSH 9.2p1 Debian 2+deb12u4 (protocol 2.0)
| ssh-hostkey: 
|   256 7d6bbab6254877ac3aa2efaef51d98c4 (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJuxaL9aCVxiQGLRxQPezW3dkgouskvb/BcBJR16VYjHElq7F8C2ByzUTNr0OMeiwft8X5vJaD9GBqoEul4D1QE=
|   256 bef3279ec6d629277b9818914e972599 (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA2oT7Hn4aUiSdg4vO9rJIbVSVKcOVKozd838ZStpwj8
443/tcp  open  ssl/http syn-ack nginx 1.22.1
|_http-server-header: nginx/1.22.1
|_ssl-date: TLS randomness does not represent time
|_http-title: 404 Not Found
| tls-alpn: 
|   http/1.1
|   http/1.0
|_  http/0.9
| ssl-cert: Subject: commonName=127.0.0.1/organizationName=debug llc/stateOrProvinceName=Florida/countryName=US/streetAddress=/localityName=Jacksonville/postalCode=3121
| Subject Alternative Name: IP Address:127.0.0.1
| Issuer: commonName=127.0.0.1/organizationName=debug llc/stateOrProvinceName=Florida/countryName=US/streetAddress=/localityName=Jacksonville/postalCode=3121
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2024-02-29T22:39:45
| Not valid after:  2027-02-28T22:39:45
| MD5:   fbe4c3b6830a87f428ef78d77347c012
| SHA-1: 88e6ac1bda871324f618a7f120ca2d2d1799e962
| -----BEGIN CERTIFICATE-----
| MIID7DCCAtSgAwIBAgIQHZYBJzhQJyghNoxZIjfvaTANBgkqhkiG9w0BAQsFADB4
| MQswCQYDVQQGEwJVUzEQMA4GA1UECBMHRmxvcmlkYTEVMBMGA1UEBxMMSmFja3Nv
| bnZpbGxlMQkwBwYDVQQJEwAxDTALBgNVBBETBDMxMjExEjAQBgNVBAoTCWRlYnVn
| IGxsYzESMBAGA1UEAxMJMTI3LjAuMC4xMB4XDTI0MDIyOTIyMzk0NVoXDTI3MDIy
| ODIyMzk0NVoweDELMAkGA1UEBhMCVVMxEDAOBgNVBAgTB0Zsb3JpZGExFTATBgNV
| BAcTDEphY2tzb252aWxsZTEJMAcGA1UECRMAMQ0wCwYDVQQREwQzMTIxMRIwEAYD
| VQQKEwlkZWJ1ZyBsbGMxEjAQBgNVBAMTCTEyNy4wLjAuMTCCASIwDQYJKoZIhvcN
| AQEBBQADggEPADCCAQoCggEBAM1udMchH92dKimVKU3TbW4FclnoYCF0cCy++3YB
| nmP47VFmUn0NmLXAb8q9ntb+CgMIJ8v3UNnRuAgAHtqokdFY5U7CV/u+FgwUog77
| 3AYW6fEQLJH8juSWSl4HcyHyAhhzI8yNVKDbmFfQ+/LNh6VdWtEVzmU4GiapwEJs
| is4Mra1m04LeEp83LyTfq+sNNWkklt78/p5ITMIPb4ih+iTOa2C2d/zHfen0uSuY
| ePo4enVA7fWSQUuGJ6t18hL4mOgAjjBp5oy1BrQ6UdigjZgwHCzAt8fRFHj5mgO/
| n4Ne6QqKddtuH7fvD5xZslovHZcPC/qF842H4gSFE6TpvRUCAwEAAaNyMHAwDgYD
| VR0PAQH/BAQDAgKkMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAPBgNV
| HRMBAf8EBTADAQH/MB0GA1UdDgQWBBRkO8lMEXGIzZskEokOL1DmlYeKEzAPBgNV
| HREECDAGhwR/AAABMA0GCSqGSIb3DQEBCwUAA4IBAQCp1/flWB7d8JQyS6IS811v
| LTxcgVxWDCXFlgcn7HE1wFs+0f50RomKToqJ10wSzM4xonayyFojAGhZ1elEPZ9y
| 9xT7+mEe+9wPnqa2Fg9UCV4OZLxoV6zDt9GHME5r4+t0PwsB8jGKGD9RrGtEG4tk
| 7ZrkW2D7WqAcBfd0ySHXtcS71CpRgbx9rRK9fNARRvf9X15Cw8UHyyFcTIF8B/6I
| IwiE1U3joYVzEhsWY5yNN7uzinK7r+UQkvcv3ljRozB36HV8ZDBrKr+oOkA2afEk
| Jm1RTQSFpxb7FptMnJzW+lcHCfYuvBxbdjgqvBXAZCoKyLAtrN3gdf5oU/FLy8uI
|_-----END CERTIFICATE-----
8000/tcp open  http     syn-ack nginx 1.22.1
| http-methods: 
|_  Supported Methods: GET HEAD POST
| http-ls: Volume /
| SIZE  TIME               FILENAME
| 1559  17-Dec-2024 11:31  disable_tls.patch
| 875   17-Dec-2024 11:34  havoc.yaotl
|_
|_http-open-proxy: Proxy might be redirecting requests
|_http-title: Index of /
|_http-server-header: nginx/1.22.1
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Nmap done: 1 IP address (1 host up) scanned in 16.43 seconds

List of open ports: 22,443,8000

There are 2 files exposed on port 8000.

The file havoc.yaotl suggests a Havoc C2 framework teamserver is running on the host. This file contains configuration in Yaotl language, including credentials for 2 operators: sergej and ilya

The other file is a note where they say they have disabled TLS, and they use websocket management port 40056.

In summary, it seems someone has installed and set up a C2 Havoc teamserver. According to documentation: "the teamserver handles connected operators, tasking agents and parsing the callback, listeners, and downloaded files and screenshots from the agents."

USER

Looking for C2 vulnerabilities, I came across this SSRF related to Havoc C2 (PoC here), that once exploited enables opening a TCP socket on the teamserver and read/write data from it (CVE-2024-41570). Thinking about what to send to the socket the answer is of course an RCE payload, since the stuff is also vulnerable to authenticated (and we have credentials) command injection.

I found a PoC that basically chains both exploits. The first one has been modified to upgrade the socket to a websocket, adding functions to create the websocket requests manually. Then, the second one is used to exploit the command injection to get RCE.

Note that you have to add your Kali IP in the command injection line (search for "Kali IP here").

Prepare the shell.sh script and launch the exploit.

Stabilize your shell adding your pub key to authorized_keys

Open an SSH shell with your private key.

And collect the user flag.

ROOT

Start from the low-priv shell and take the opportunity to enumerate the user and the system.

There is a text file in the home directory.

So it seems there is another C2 called Hardhat installed in the host.

There is something listening on ports 7076 and 5000.

Forward both ports to Kali and run this authentication bypass PoC.

A JWT is dumped and a new user is created.

Login with credentials sth_pentest:sth_pentest on https://127.0.0.1:7096

In the operator's dashboard, navigate to Implants → Terminal, check you are running as user sergej

Use the terminal to add your pub key into Sergej's authorized keys.

Now you can SSH in as sergej

Now check sudoers configuration.

Seems he can run iptables as root, no password will be prompted. The comment function is used to overwrite other files and to escalate privileges.

Back in the victim shell.

You are root.

REFERENCES

https://havocframework.com/docs/profiles

https://redfoxsec.com/blog/havoc-c2-framework/

https://havocframework.com/docs/welcome

https://blog.includesecurity.com/2024/09/vulnerabilities-in-open-source-c2-frameworks/

https://blog.chebuya.com/posts/server-side-request-forgery-on-havoc-c2/

https://github.com/chebuya/Havoc-C2-SSRF-poc

https://www.cvedetails.com/cve/CVE-2024-41570

https://github.com/IncludeSecurity/c2-vulnerabilities/tree/main/havoc_auth_rce

https://blog.sth.sh/hardhatc2-0-days-rce-authn-bypass-96ba683d9dd7

https://www.shielder.com/blog/2024/09/a-journey-from-sudo-iptables-to-local-privilege-escalation/

Last updated