Information
While norhosts files are shipped by default, users can easily create them.
This action is only meaningful ifrhosts support is permitted in the file /etc/pam.conf Even though therhosts files are ineffective if support is disabled in /etc/pam.conf they may have been brought over from other systems and could contain information useful to an attacker for those other systems.
Solution
Making global modifications to users' files without alerting the user community can result in unexpected outages and unhappy users. Therefore, it is recommended that a monitoring policy be established to report userrhosts files and determine the action to be taken in accordance with site policy.
The following script will removerhosts files from interactive users' home directories
#!/usr/bin/env bash
{
perm_mask='0177'
valid_shells="^($( sed -rn '/^//{s,/,\\/,g;p}' /etc/shells | paste -s -d '|' - ))$"
awk -v pat="$valid_shells" -F: '$(NF) ~ pat { print $1 " " $(NF-1) }' /etc/passwd | while read -r user home; do
if [ -f "$home/.rhosts" ]; then
echo -e "
- User \"$user\" file: \"$home/.rhosts\" exists
- removing file: \"$home/.rhosts\"
"
rm -f "$home/.rhosts"
fi
done
}