23.12.24 삭제예정/Unix 서버 취약점 점검

■ 리눅스 서버 점검 가이드 2-9 SUID, SGID, Sticky bit 설정 파일 점검

몽블86 2017. 6. 30. 13:21

■ 점검 분류항목: 파일 및 디렉터리 관리

■ 세부점검항목: 파일 및 디렉터리 소유자 설정

■ 대상: 리눅스

■ 위험도: 상

■ 과련코드: U-24


1. 취약점 개요

SUID(Set User-ID)와 * SGID((Set Group-ID)가 설정된 파일은(특히, root 소유의 파일인 경우) 특정 명령어를 실행하여 root 권한 획득 및 정상 서비스 장애를 발생시킬수 있으며, 로컬 공격에 많이 이용되므로 보안상 철저한 관리가 필요함

root소유의 SUID 파일의 경우에는 꼭 필요한 파일을 제외하고는 SUIDSGID 속성을 제거해주고, 잘못 설정되어 보안위협이 되고 있는지 주기적인 진단 및 관리가 요구됨

SUID(Set-User-ID) 설정된 파일 실행 시, 특정 작업 수행을 위하여 일시적으로 파일 소유자의 권한을 얻게 됨

SUID(Set Group-ID) 설정된 파일 실행 시, 특정 작업 수행을 위하여 일시적으로 파일 소유 그룹의 권한을 얻게 됨


2. 판단기준

양호: 주요 파일의 권한에 SUID와 SGID에 대한 설정이 부여되어 있지 않는 경우

취약: 주요 파일의 권한에 SUID와 SGID에 대한 설정이 부여되어 있는 경우


3. 조치방법

ⓐ 불필요한 SUID, SGID 파일제거

ⓑ 아래의 목록 이외에 애플리케이션에서 생성한 파일이나 사용자가 임의로 생성한 파일 등 의심스럽거나 특이한 파일의 발견시 SUID 제거 필요


4. 보안 설정방법

■ 점검방법

OS별 주요 파일에 대한 SUID/SGID 설정 여부확인

#ls -alL [check_file] |awk ' {print $1 }' | grep -i 's'


■ 설정 방법


1. 제거 방법

#chmod -s <file_name>


2. 주기적인 감사 방법

#find / -user root -type f \( -perm -4000 -o -perm -2000 \) -xdev -exec ls -al { } \;


3. 반드시 사용이 필요한 경우 특정 그룹에서만 사용하도록 제한하는 방법

일반 사용자의 Setuid 사용을 제한함 (임의의 그룹만 가능)


#/usr/bin/chgrp <group_name> <setuid_file_name>


#/usr/bin/chmod 4750 <setuid_file_name>


SetUID/SetGID 비트를 제거하는 파일 종류


/sbin/dump 


/usr/bin/lpq-lpd 


/usr/bin/newgrp


/sbin/restore 


/usr/bin/lpr 


/usr/sbin/lpc


/sbin/unix_chkpwd 


/usr/bin/lpr-lpd 


/usr/sbin/lpc-lpd


/usr/bin/at 


/usr/bin/lprm 


/usr/sbin/traceroute


/usr/bin/lpq 


/usr/bin/lprm-lpd


(5) 조치시 영향

SUID 제거 시 OS 및 응용 프로그램 등 서비스 정상작동 유무 확인 필요


(고객에게 설명)


SetUID, SetGID 프로그램의 개수가 변경되었다면 거의 70 ~ 80%가 해킹을 당한것일 가능성이 높다. 일부 프로그램 설치시 SetUID 비트 설정이 될수 있지만 이런 경우는 극히 드문 경우이다.





SetUID 프로그램에 의해 공격 당할 가능성


  


  


[실습] SetUID 프로그램의 위험성


[실습] SetUID 프로그램을 목록화하고 비교하는 프로그램 작성


-> 개인적으로 작성


  


/test/SetUID.list


A


| compare


V


/test/SetUID.current


  


# vi check_SetUID.sh 


-----------------------------------------------


#!/bin/bash


  


#


# # crontab -l 


# 분 시 일 월 요일 CMD


# 0 1 * * * /test/check_SetUID.sh


#


  


if [ ! -f /test/SetUID.list ] ; then


find / -perm -4000 -type f 2>/dev/null | egrep -v '(/test|/tmp)' > /test/SetUID.list


echo "First excution"


exit 0


fi


  


find / -perm -4000 -type f 2>/dev/null | egrep -v '(/test|/tmp)' > /test/SetUID.current


if [ $? -eq 0 ] ; then


diff /test/SetUID.list /test/SetUID.current > /test/.file1


if [ -s /test/.file1 ] ; then


mailx -s "[ WARN ]: check setuid" root < /test/.file1


else


echo `date` | mailx -s "[ OK ]: all clear" root 


fi


else


echo "Error 1: Can't excute a find command"


exit 1


fi


-----------------------------------------------


  


  


  


[실습] 중요한 파일들의 변경 사항(수정 사항)을 점검하는 프로그램 작성


# cat /test/important_file.txt 


/etc/passwd


/etc/shadow


/etc/group


/etc/hosts


.......




/test/important_file.txt


A


| compare


V


/test/important_file.current


  


/test/report.txt


-------------------------------------


[ OK ] : /etc/passwd


[ OK ] : /etc/shadow


[ WARN ] : /etc/hosts


......


-------------------------------------


  


# vi check_important_file.sh


-----------------------------------------------


#!/bin/bash



# # crontab -l


# 0 1 * * * /test/check_important_file.sh



# # cat /test/important_file.txt


# /etc/passwd


# /etc/hosts


# ......


#


# 이 프로그램이 처음 동작 할 때


if [ ! -d /check ] ; then


mkdir -p /check


cat /test/important_file.txt | while read FILE1


do


cp -p $FILE1 /check # cp -p /etc/passwd /check


echo "First excution"


exit 0


 done


fi


> /test/report.txt


cat /test/important_file.txt | while read FILE2


do


FILE1=$(basename $FILE2)  # basename /etc/passwd


cmp -s /check/$FILE1 $FILE2


if [ $? -eq 0 ] ; then


echo "[ OK ] : $FILE2" >> /test/report.txt


else


echo "[ WARN ] : $FILE2" >> /test/report.txt


fi


done


if grep WARN /test/report.txt 2>/dev/null ; then


mailx -s "[ WARN ] : check important file" root < /test/report.txt


else


mailx -s "[ OK ] : all clear" root < /test/report.txt


fi