The hell it does!
Perhaps you might think that at first glance but stop and think about things for a few
moments and you might realize something you overlooked.
Actually, there is really nothing wrong with the script and you are quite incorrect.
The code is in fact logically sound and as a side note doesn't make use of any TEMP files
deliberately to avoid any potential possibility of injection prior to script completion and
explicitly prohibits "root" permission settings and even if it didn't, you would only accomplish
rendering the account inaccessible instead of elevating any privileges anywhere.
And then you say "but you could replace the commands" before they execute!
Actually, no you couldn't --- well not easily or without the aide of root in the first place and
I'll explain a bit more specifically some of this further on down below.
However, to your credit a few enhancement revisions could be made such as prefixing the
full path name to all commands to make 100% absolutely sure the correct system commands
are indeed called. However because of the way this script is already configured and that it is
also called as a non-user root cron process with an execution point also outside user access, and
further the way Linux executes path searches by default, it really wouldn't matter much either
way other than just being completely and entirely anal to the nth degree since users would
already have to have both root and detailed knowledge of what is running to make any kind of
exploit against anything as you describe but that by definition, would utterly defeat the
point entirely wouldn't it? The only other way to do this is to change the manner in which
Linux performs command path and force location ahead of system paths in searches but that
would again require root and anyone who is stupid enough to set up their servers that way
has much bigger worries to consider anyway. ROFL
Just for you ...
The following is an enhanced extra extreme paranoid version with log feedback:
Code:
#!/bin/bash
IFS="$"
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
PATH="/bin:/usr/bin"
CPLOG="/var/log/messages"
cd /home
/bin/ls /var/cpanel/users | /bin/grep -v "root\|nobody\|mysql" | while read CPUSER; do
CPHOME=$(/bin/grep "${CPUSER}:" /etc/passwd | /usr/bin/head -1 | /bin/cut -d':' -f6)
CPUBLIC="${CPHOME}/public_html"
if [ -d ${CPUBLIC} ]; then
CONFIRM="$(echo ${CPUBLIC} | /bin/cut -d'/' -f3)"
if [ ${CONFIRM} = ${CPUSER} ]; then
/bin/chown ${CPUSER}:nobody ${CPUBLIC} > /dev/null 2>&1
/bin/chmod 0750 ${CPUBLIC} > /dev/null 2>&1
else
echo "$(/bin/date) ${CONFIRM} does not match ${CPUSER} in permission update check ..." >> ${CPLOG}
fi
else
echo "$(/bin/date) ${CPUBLIC} folder for ${CPUSER} appears to be missing ..." >> ${CPLOG}
fi
unset CONFIRM CPUBLIC CPUSER CPHOME
done