TMAegis
Mais regras para linux

TMA-ROCKY8-7.1.11

Ensure world writable files and directories are secured

MédiaNível 1Automatizadalinux

Descrição

World writable files are the least secure. Data in world-writable files can be modified and compromised by any user on the system. World writable files may also indicate an incorrectly written script or program that could potentially be the cause of a larger compromise to the system's integrity. See the chmod(2) man page for more information. Setting the sticky bit on world writable directories prevents users from deleting or renaming files in that directory that are not owned by them.

Como é verificado

Método de auditoria: Comando shell

shell
alt0() { o=$(bash -c '#!/usr/bin/env bash

{
   a_output=() a_output2=() a_file=() a_dir=()
   l_smask='"'"'01000'"'"' l_limit="50"
   a_path=(-path "*/containers/storage/*" -o -path "*/containerd/*" -o -path "*/kubelet/*" -o -path "/sys/*" -o -path "/snap/*" -o -path "/boot/efi/*")
   while IFS= read -r l_mount; do
      while IFS= read -r -d $'"'"'\0'"'"' l_file; do
         if [ -e "$l_file" ]; then
            [ -f "$l_file" ] && a_file+=("$l_file")
            if [ -d "$l_file" ]; then
               l_mode="$(stat -Lc '"'"'%#a'"'"' "$l_file")"
               [ ! $(( $l_mode & $l_smask )) -gt 0 ] && a_dir+=("$l_file")
            fi
         fi
      done < <(find "$l_mount" -mount -xdev \( "${a_path[@]}" \) -prune -o \( -type f -o -type d \) -perm -0002 -print0 2> /dev/null)
   done < <(findmnt -Dkerno fstype,target | awk '"'"'($1 !~ /^\s*(nfs|proc|cifs|smb|vfat|iso9660|efivarfs|selinuxfs|ncpfs)/ && $2 !~ /^(\/run|\/tmp|\/var\/tmp)(\/|$)/){print $2}'"'"')
   if [ "${#a_file[@]}" -le 0 ]; then
      a_output+=("  - No world writable files exist on the local filesystem.")
   else
      a_output2+=("" " - There are \"${#a_file[@]}\" World writable files on the system." \
      "   - The following is a list of World writable files:" \
      "${a_file[@]:0:$l_limit}" "   - end of list")
   fi
   if [ "${#a_dir[@]}" -le 0 ]; then
      a_output+=("  - Sticky bit is set on world writable directories on the local filesystem.")
   else
      a_output2+=("" " - There are \"${#a_dir[@]}\" World writable directories without the sticky bit on the system." \
      "   - The following is a list of World writable directories without the sticky bit:" \
      "${a_dir[@]:0:$l_limit}" "   - end of list")
   fi
   if [ "${#a_output2[@]}" -le 0 ]; then
      printf '"'"'%s\n'"'"' "" "- Audit Result:" "  ** PASS **" "${a_output[@]}"
   else
      printf '"'"'%s\n'"'"' "" "- Audit Result:" "  ** FAIL **" "  * Reasons for audit failure *" "${a_output2[@]}" ""
      [ "${#a_output[@]}" -gt 0 ] && printf '"'"'%s\n'"'"' "- Correctly set:" "${a_output[@]}"
   fi
}' 2>&1); printf '%s\n' "$o" | grep -q '\*\* PASS \*\*' || { echo "step1: script did not report PASS"; return 1; }; }; if alt0; then echo compliant; fi
Saída esperada
compliant

Como é corrigido

Método de correção: Orientação ou patch de infraestrutura

• World Writable Files: o It is recommended that write access is removed from other with the command ( chmod o-w <filename> ), but always consult relevant vendor documentation to avoid breaking any application dependencies on a given file. • World Writable Directories: o Set the sticky bit on all world writable directories with the command ( chmod a+t <directory_name> ) Run the following script to: • Remove other write permission from any world writable files • Add the sticky bit to all world writable directories #!/usr/bin/env bash { l_smask='01000' a_file=() a_dir=() a_path=(-path "*/containers/storage/*" -o -path "*/containerd/*" -o -path "*/kubelet/*" -o -path "/sys/*" -o -path "/snap/*"…

Propriedades

Sistemas operacionais
rocky-8
Tags
cis-convertedlinux
Referência
CIS Rocky Linux 8 Benchmark v3.0.0 - 7.1.11

Verificar este host

Execute isto em uma máquina que você tenha permissão para auditar. A varredura é somente leitura.

shell
tmaegis scan --target linux