Hack Forums
Hacking cPanel With ~/.contactemail - Resetting Passwords - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Hacks, Exploits, and Various Discussions (https://hackforums.net/forumdisplay.php?fid=45)
+--- Forum: Grayhat • Purple Team • Hybrid Security (https://hackforums.net/forumdisplay.php?fid=449)
+---- Forum: Beginner Hacking (https://hackforums.net/forumdisplay.php?fid=4)
+----- Forum: Hacking Tutorials (https://hackforums.net/forumdisplay.php?fid=47)
+----- Thread: Hacking cPanel With ~/.contactemail - Resetting Passwords (/showthread.php?tid=6260440)



Hacking cPanel With ~/.contactemail - Resetting Passwords - Hackers - Jan 7, 2024

This tutorial is based on how one of my old servers was compromised. It took nearly 2 years to figure out how the hacker was repeatedly re-gaining access to a cPanel account. This is something that may even be patched in the newest cPanel licenses, but there are reports going all the way into 2022 and 1 report in 2023 of the hack still around. Older versions are obviously much more vulnerable.

The whole hack is centered around cPanel's method of storing contact emails for users in plaintext in a file:
Code
~/.contactemail

TLDR Version:
- update .contactemail to have any email address
- using cPanel reset password will now send the password reset link to the new email address, instead of original email on file
- because .contactemail has not always been secure, many servers are vulnerable
- any vulnerability that allows a hacker to edit files, even if the hack is 100% unrelated to cPanel, can be used to edit .contactemail for this method

Although the emails of users are tracked elsewhere as well, this file can be manipulated to take control. For example, WHCMS has a list of users with a variable in each file for CONTACTEMAIL, but when updates roll out this just replaces the value inside the individual .contactemail file, per user. However, if you change the value in .contactemail, parts of cPanel use that without doublechecking other values in the master list. What this means is that if you can write to .contactemail, you can get full control of the cPanel.

The reason this is is bad is because contactemail was not readonly / secured by default. For example, we brought on a new client that had an infected Wordpress. because the hacker was already in there, they were already targeting the email file. Any time we locked them back out, they were still able to get back in. This is because we would change password, even change the email ourselves, and also alter permissions for files on the system, and remove their PHP shells... but we didn't know about contactemail.

You see, once you have access to the system and have found the .contactemail file, you have a few options, and this is what the hacker did to us:
Spoiler (Click to View)



Again - this is much more of a hack for older versions of cPanel, but I do see some recent notes on it that suggest it's either not fully patched, can be manipulated depending on server settings, or there simply are a lot of people still using older cPanel versions. Either way, this was the worst any of my servers ever got hacked and I am happy to share this info if it helps you complete your own pentesting or to otherwise secure your server.


RE: Hacking cPanel With ~/.contactemail - Resetting Passwords - Scofield112 - Jan 12, 2024

so fucking goooooooooooooodddddddddddddddddddd [warn]


RE: Hacking cPanel With ~/.contactemail - Resetting Passwords - xanutree - Jan 19, 2024

there are any way to secure cPanel? how to disable or restrict contactemail file?


RE: Hacking cPanel With ~/.contactemail - Resetting Passwords - Hackers - Jan 19, 2024

(Jan 19, 2024 05:48 PM)xanutree Wrote:  there are any way to secure cPanel? how to disable or restrict contactemail file?

Chmod, chown, protect against directory traversal code, don't let your server get infected


RE: Hacking cPanel With ~/.contactemail - Resetting Passwords - MarkGold - Jan 20, 2024

thank you for this useful tut hope to see more content fro myou


RE: Hacking cPanel With ~/.contactemail - Resetting Passwords - Hackers - Jan 31, 2024

(Jan 20, 2024 05:20 AM)MarkGold Wrote:  thank you for this useful tut hope to see more content fro myou

Thanks Mark, I plan on releasing more tutorials over time. Glad you found this useful!