Last active
April 1, 2024 06:17
-
-
Save rallisf1/b8c78ce8bc465c39cbccfe5c0a27d429 to your computer and use it in GitHub Desktop.
get all emails and their password hashes from a cPanel server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set the path to the cPanel user file | |
USERS_FILE="/etc/trueuserdomains" | |
# Loop through each cPanel user | |
while read DOMAIN USER; do | |
# Remove the colon from the end of the DOMAIN variable | |
DOMAIN=$(echo "$DOMAIN" | sed 's/:$//') | |
# Get the user's email accounts | |
EMAIL_ACCOUNTS=$(whmapi1 list_pops_for user=$USER | grep ' - ' | cut -d "-" -f 2-99 | tr -d ' ') | |
for EMAIL_ACCOUNT in $EMAIL_ACCOUNTS; do | |
# Extract the user part from the email address | |
POP=$(echo $EMAIL_ACCOUNT | cut -d@ -f1) | |
# Get the password hash from the shadow file & remove any leading exclamation marks | |
PASSWORD=$(grep "^$POP:" /home/$USER/etc/$DOMAIN/shadow | cut -d: -f2 | sed 's/^!*\([^!].*\)/\1/') | |
echo "$EMAIL_ACCOUNT,{CRYPT}$PASSWORD" | |
done | |
done < "$USERS_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thats a problem when you have hundreds of mail accounts :-(