카테고리 없음

[LINUX] 2026년도 보안 취약점 조치

PeamS 2026. 5. 7. 11:35

다음 문서를 참조하여 만듭니다.

https://www.kisa.or.kr/2060204/form?postSeq=22&page=1#fnPostAttachDownload

U-01 root 계정 원격 접속 제한

기준 : root 직접 접속을 허용하고 원격 서비스를 사용하는 경우 "취약"

 

Rocky 8 / 9, Ubuntu 24.04

# PermitRootLogin yes : 취약
egrep -ne "^[^#]*PermitRootLogin" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/* 2>/dev/null
# PermitRootLogin yes 가 한줄만 나올 시 자동 조치
p_cmd=$(egrep -ne "^[^#]*PermitRootLogin" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*)
p_file="$(echo ${p_cmd} | cut -d: -f1)"
p_line="$(echo ${p_cmd} | cut -d: -f2)"

sed -i "${p_line}s/PermitRootLogin yes/PermitRootLogin no/" "${p_file}"

systemctl restart sshd

# ubuntu 24.04
systemctl restat ssh

 

U-02 비밀번호 관리정책 설정

비밀번호 관리 정책이 설정되지 않은 경우

 

CentOS 6

# 최소길이, 암호 조건, 암호 기억
vi /etc/pam.d/system-auth & vi /etc/pam.d/password-auth
#password    requisite     pam_cracklib.so try_first_pass retry=3 type=
password    requisite     pam_cracklib.so try_first_pass retry=3 type= minlen=8 dcredit=-1 ucredit=-1 lcredit=-1 ocredit=-1

#password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=4

# max min
sed -i 's:PASS_MAX_DAYS\t99999:PASS_MAX_DAYS\t90:g' /etc/login.defs
sed -i 's:PASS_MIN_DAYS\t0:PASS_MIN_DAYS\t1:g' /etc/login.defs

 

CentOS 7

vi /etc/pam.d/password-auth
# 맨 뒤에 enforce_for_root 추가
password    requisite     pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type= enforce_for_root

vi /etc/pam.d/system-auth
# 맨 뒤에 enforce_for_root 추가
password    requisite     pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type= enforce_for_root

#pwquality
sed -i 's:# minlen = 9:minlen = 8:g' /etc/security/pwquality.conf
sed -i 's:# dcredit = 1:dcredit = -1:g' /etc/security/pwquality.conf
sed -i 's:# ucredit = 1:ucredit = -1:g' /etc/security/pwquality.conf
sed -i 's:# lcredit = 1:lcredit = -1:g' /etc/security/pwquality.conf
sed -i 's:# ocredit = 1:ocredit = -1:g' /etc/security/pwquality.conf

# login.defs
sed -i 's:PASS_MAX_DAYS\t99999:PASS_MAX_DAYS\t90:g' /etc/login.defs
sed -i 's:PASS_MIN_DAYS\t0:PASS_MIN_DAYS\t1:g' /etc/login.defs

Rocky 8 / 9, Ubuntu 24.04

# pwquality 모듈 로드 확인 (password/requisite 에 pam_pwquality.so 존재 필요)
grep -ie pam_pwquality.so /etc/pam.d/*

# pwquality 설정 확인 (minlen = 8, d u l o = -1, retry = 3, enforce_for_root 정상)
cat /etc/security/pwquality.conf /etc/security/pwquality.conf.d/*.conf 2>/dev/null | grep -v "^#"

# pwhistory 설정 확인 (enforce_for_root, remember = 4, file = /etc/security/opassword 정상)
cat /etc/security/pwhistory.conf | grep -v "^#"

# login.defs 설정 확인 (MAX = 90, MIN = 1 정상
cat /etc/login.defs | egrep "PASS_MAX_DAYS|PASS_MIN_DAYS" | grep -v "^#"
# pwquality
sed -i 's:# minlen = 8:minlen = 8:g' /etc/security/pwquality.conf
sed -i 's:# dcredit = 0:dcredit = -1:g' /etc/security/pwquality.conf
sed -i 's:# ucredit = 0:ucredit = -1:g' /etc/security/pwquality.conf
sed -i 's:# lcredit = 0:lcredit = -1:g' /etc/security/pwquality.conf
sed -i 's:# ocredit = 0:ocredit = -1:g' /etc/security/pwquality.conf
sed -i 's:# enforce_for_root:enforce_for_root:g' /etc/security/pwquality.conf

# pwhistory
sed -i 's:# enforce_for_root:enforce_for_root:' /etc/security/pwhistory.conf
sed -i 's:# remember =.*:remember = 4:' /etc/security/pwhistory.conf
sed -i 's:# file = /etc/security/opasswd:file = /etc/security/opasswd:' /etc/security/pwhistory.conf

# login.defs
sed -i 's:PASS_MAX_DAYS\t99999:PASS_MAX_DAYS\t90:g' /etc/login.defs
sed -i 's:PASS_MIN_DAYS\t0:PASS_MIN_DAYS\t1:g' /etc/login.defs

 

U-03 계정 잠금 임계값 설정

 계정 잠금 임계값이 설정되어 있지 않거나, 10회 이하의 값으로 설정되지 않은 경우

 

CentOS 6

vi /etc/pam.d/system-auth * vi /etc/pam.d/password-auth
auth        required      pam_env.so # 밑에 추가
auth        required      pam_tally2.so deny=10 unlock_time=120 onerr=fail audit

account     required      pam_tally2.so
account     required      pam_unix.so # 위에 추가

 

CentOS 7

authconfig --enablefaillock \
           --faillockargs="deny=5 unlock_time=120 fail_interval=300" \
           --update

Rocky 8 / 9

# 모듈 확인 (auth 에 preauth, authfail 존재 / account 에 존재 시 정상)
grep -e faillock /etc/pam.d/*

# faillock 설정 확인 (silent, deny = 10, unlock_time = 120 정상)
cat /etc/security/faillock.conf | grep -v "^#"

 

authselect sssd 프로파일 적용 및 failock 기능 추가

 - 아래 명령어 입력 시 /etc/pam.d/ 가 authselect sssd 기본 프로파일로 덮어 씌워집니다. 수동으로 pam.d 관리 시 주의!(날라가요)

# authselect sssd 사용 여부 확인
authselect current

# authselect sssd 사용하기 (sssd 를 쓰고 있으면 무시)
authselect select sssd --force

# authselect faillock 기능 추가
authselect enable-feature with-faillock
sed -i 's:# silent:silent:g' /etc/security/faillock.conf
sed -i 's:# deny = 3:deny = 10:g' /etc/security/faillock.conf
sed -i 's:# unlock_time = 600:unlock_time = 120:g' /etc/security/faillock.conf

 

Ubuntu 24.04

# 사용여부 보기
cat /etc/pam.d/common-auth |grep faillock

# 정책 보기
cat /etc/security/faillock.conf | grep -v "^#"
vi /etc/pam.d/common-auth
# 다음과 같이 추가
auth    required                        pam_faillock.so preauth
auth    [success=1 default=ignore]      pam_unix.so nullok
auth    [default=die]                   pam_faillock.so authfail
auth    sufficient                      pam_faillock.so authsucc
# here's the fallback if no module succeeds
auth    requisite                       pam_deny.so
sed -i 's:# silent:silent:g' /etc/security/faillock.conf
sed -i 's:# deny = 3:deny = 10:g' /etc/security/faillock.conf
sed -i 's:# unlock_time = 600:unlock_time = 120:g' /etc/security/faillock.conf

 

U-06 사용자 계정 su 기능 제한

su 명령어를 모든 사용자가 사용하도록 설정된 경우

 

Rocky 8 / 9

ll /usr/bin/su
cat /etc/group | grep wheel
# 사용자 추가
su_user=creeper
useradd ${su_user}
usermod ${su_user} -G wheel
passwd ${su_user}

# su 파일 수정
chown root.wheel /bin/su
chmod 4750 /usr/bin/su

 

U-12 세션 종료 시간 설정

Session Timeout이 600초(10분) 이하로 설정되지 않은 경우

 

echo $TMOUT
cat <<EOF>> /etc/profile

# timeout
TMOUT=600
export TMOUT
EOF

 

U-21 /etc/(r)syslog.conf 파일 소유자 및 권한 설정

/etc/(r)syslog.conf 파일의 소유자가 root(또는 bin, sys)가 아니거나, 권한이 640 이하가 아닌
경우

 

ll /etc/rsyslog.conf
chmod 640 /etc/rsyslog.conf

 

U-30 UMASK 설정 관리

UMASK 값이 022 미만으로 설정된 경우

 

확인

echo $TMOUT

 

# profile 에 umask 022 추가
cat <<EOF>> /etc/profile

# umask
umask 022
export umask
EOF

# login.defs 에 umask 077 -> 022 로 수정
sed -i 's/UMASK           077/UMASK           022/g' /etc/login.defs

 

U-37 crontab 설정파일 권한 설정 미흡

crontab 및 at 명령어에 일반 사용자 실행 권한이 부여되어 있으며, cron 및 at 관련 파일 권한이
640 이상인 경우

 

Rocky 8 / 9

ll /usr/bin/crontab
ll /etc/cron*/*
ll /var/spool/cron/*
ll /var/sppol/cron/crontabs/*
ls -alF /etc/ | grep cron

# user 별 cron 검사
awk -F: '{print $1}' /etc/passwd | while read u; do o=$(crontab -u "$u" -l 2>/dev/null); [ $? -eq 0 ] && [ -n "$o" ] && { echo "===== $u ====="; echo "$o"; echo; }; done
# 사용하는 유저가 있으면 /usr/bin/crontab setuid 제거로 인해 장애 발생 가능성 있음.
# 다음 기준으로 조치 
[root@rocky9 ~]# ls -alF /etc/ | grep cron
-rw-r--r--.  1 root root      541  8월  6  2025 anacrontab
drwxr-xr-x.  2 root root       21  8월  6  2025 cron.d/
drwxr-xr-x.  2 root root        6  5월 11  2022 cron.daily/
-rw-r--r--.  1 root root        0  8월  6  2025 cron.deny
drwxr-xr-x.  2 root root       22 11월 25 12:11 cron.hourly/
drwxr-xr-x.  2 root root        6  5월 11  2022 cron.monthly/
drwxr-xr-x.  2 root root        6  5월 11  2022 cron.weekly/
-rw-r--r--.  1 root root      451  5월 11  2022 crontab

# other 의 read, write, excute 제거
chmod o-rwx /etc/cron*

# cron 파일 other 의 read, write, excute 제거
chmod o-rx /etc/cron.d/0hourly
chmod o-rwx /etc/cron.hourly/0anacron

# rocky 8 추가
chmod o-rx /etc/cron.daily/logrotate
chmod o-r /etc/cron.d/raid-check
chmod o-r /etc/cron.d/opa-cablehealth

# crontab 일반사용자 사용중이면 장애 발생
chmod 0750 /usr/bin/crontab

 

U-41 불필요한 automountd 제거

automountd 서비스가 활성화된 경우

 

CentOS 6

# 확인
chkconfig | grep autofs

# 조치
chkconfig --level 345 autofs off

 

U-62 로그인 시 경고 메시지 설정

서버 및 Telnet, FTP, SMTP, DNS 서비스에 로그온 시 경고 메시지가 설정되어 있지 않은 경우

 

Rocky 8 / 9

# /etc/motd, Banner 사용 여부 확인
cat /etc/motd
cat /etc/ssh/sshd_config | grep Banner
cat <<EOF> /etc/motd
*************************************************************
*                   AUTHORIZED ACCESS ONLY                  *
*************************************************************

This system is for authorized users only.
All activities on this system are monitored and recorded.
Unauthorized access or use of this system is strictly
prohibited and may be subject to criminal prosecution
under applicable laws.

If you are not an authorized user, disconnect immediately.

*************************************************************
EOF
sed -i 's:#Banner none:Banner /etc/motd:g' /etc/ssh/sshd_config

systemctl restart sshd

 

U-67 로그 디렉터리 소유자 및 권한 설정

디렉터리 내 로그 파일의 소유자가 root가 아니거나, 권한이 644를 초과하는 경우

 

Rocky 8 / 9

find /var/log -perm /o=rwx
# dnf 내 log rotate 비활성화
sed -i '/^\[main\]/a log_rotate=0' /etc/dnf/dnf.conf

# rocky 9 기준
# logrotate dnf 내 dnf 관련 로그 관리 추가 및 600 추가
cat <<EOF> /etc/logrotate.d/dnf
/var/log/dnf.librepo.log /var/log/dnf.rpm.log /var/log/hawkey.log /var/log/dnf.log {
    missingok
    notifempty
    rotate 4
    weekly
    create 0600 root root
}
EOF

# 기존 dnf 관련 파일 권한 변경
chmod 600 /var/log/dnf.*
chmod 600 /var/log/hawkey.log*

# anaconda (설치 시 정보 담는 디렉터리)
chmod -R 600 /var/log/anaconda/

chmod 660 /var/log/lastlog
chmod 660 /var/log/wtmp

# sysstat 사용시
sed -i 's/UMASK=.*/UMASK=0027/' /etc/sysconfig/sysstat
chmod -R o-rx /var/log/sa

# 레드헷 8
# vi /etc/logrotate.d/subscription-manager
/var/log/rhsm/*.log {
    missingok
    notifempty
    sharedscripts
    copytruncate
    create 0640 root root # 추가
}

chmod -R o-rwx /var/log/rhsm/

# tuned 디렉터리
chmod -R o-rx /var/log/tuned/

# cups
chmod o-rx /var/log/cups/

https://access.redhat.com/solutions/4923771