
Originally Posted by
santrix
I appreciate your proof of concept, but my understanding of the script is that the context in which the line
Code:
/bin/chown -R ${CPUSER}:${CPUSER} -- ${CPHOME}
appears, means that $CPUSER and $CPHOME can't ever be "root" or "/root" because it is encased within a while loop that starts:
Code:
/bin/ls -- /var/cpanel/users | /bin/grep -v "\`\|\.\|cpanel\|root\|mysql\|nobody" | while read CPUSER; do
So, I can't see how it is possible for this script to expose this exploit. However, it's late on Friday and I have been wrong before... often...

Because
Code:
/bin/chown -R ${CPUSER}:${CPUSER} -- ${CPHOME}
is the same as
Code:
chown -R homer:homer /home/homer/public_html/*
in my proof of concept. Notice that the command is not relying upon sending root:root or operating on /root, the flaw is in blindly chowning files as root.
All that this line:
Code:
/bin/ls -- /var/cpanel/users | /bin/grep -v "\`\|\.\|cpanel\|root\|mysql\|nobody" | while read CPUSER; do
does is ensure the chown step doesn't do this:
Code:
chown -R root:root /home/homer/public_html/*
which would be harmful in another manner.
So, let's do a step-by-step commentary on a few lines from this script:
Code:
/bin/ls -- /var/cpanel/users | /bin/grep -v "\`\|\.\|system\|cpanel\|root\|mysql\|nobody" | while read CPUSER; do
Get a list of cPanel users, filtering out root, system, cpanel, mysql, nobody, ` and . Iterate over this list.
Code:
CPHOME="$(/bin/grep "^${CPUSER}:" /etc/passwd | cut -d':' -f6)/public_html"
Grab the location of the home directory for the user. Set the bash variable to /home/user/public_html
Code:
dialog --keep-window --title "Checking ${CPHOME}" --infobox "\n\n Updating ${CPUSER}'s account ..." 10 50
sleep ${DELAY} # Slow things down so you can see dialog message
echo "Checking ${CPHOME} ... "
Provide some feedback
Code:
if [ -d "${CPHOME}" ]; then
Ensure /home/user/public_html is directory
Code:
echo "Setting global ownership in ${CPHOME} to ${CPUSER} ..."
Feedback
Code:
/bin/chown -R ${CPUSER}:${CPUSER} -- ${CPHOME}/*
Blindly change ownership of everything in /home/user/public_html to user:user. This is the problem line illustrated in my proof of concept.
If you doubt it, you are free to perform your own analysis and tests. I'm simply providing a warning and information on the danger of executing this script without performing due diligence.