SELinux(Security-Enhanced Linux)는 미국 국가 안보국(NSA)에서 개발한 것으로,
관리자가 시스템 엑세스 권한을 효과적으로 제어할 수 있게 하는 Linux 시스템용 보안 아키텍처입니다.
특정 서비스의 구동이 원활하지 않거나 혹은 관리의 번거로움 등으로 인해 SELinux를 Disable 하는 경우가 많은데요,
SELinux를 사용해야 하는 이유와 작동 방식에 대해 설명합니다,
4. SELinux?
SELinux란 Security-Enhanced Linux 약자
미국 국가안보국(NSA) 에서 개발 2003년부터 커널에 통합됨
DAC(Discretionary Access Control) 가 아닌 MAC(Mandatory Access Control)을 사용하는 보안 모듈
Enforcing, Permissive, Disabled 모드가 있음
5. 얼마나 사용하고 있나?
전세계적으로 disabled 하여 사용하고 있음
stopdisablingselinux.com 라는 사이트를 만들어 홍보할 정도
많은 블로그에서 selinux를 한번 써보라고 권장하나 그 누구도…
6. 왜 사용하지 않는가?
Selinux는 어렵다
Selinux는 귀찮다
OS관리자의 역할이 늘어난다
Application이 SELinux의 보안사양을 따르지 않는다 = app 작동 불가
물리 방화벽이 있으니 OS방화벽을 끄는것과 같은 이치
7. 사용해야 하는 이유?
Zero-Day 공격을 막을 거의 유일한 수단
Selinux는 어렵지 않다
보안은 강화될수록 귀찮은 것이 당연하다
OS관리자의 임무는 보안을 강화하는 부분도 있다
보안사양을 따르지 않는 Application이라도 여러가지 정책들을 적용하여 작동하게 할 수 있다
안드로이드처럼 이미 Selinux를 사용하면서 구동중인 어플리케이션이 있다
당장은 힘들겠지만 우리 제품 Playce RoRo & Playce Cloud 등이 selinux를 지원한다면??
물리 방화벽이 있어도 OS방화벽을 같이 사용하면 좋다 = 보안은 다다익선 = 다만 귀찮을뿐
거기다가 공짜!!
https://source.android.com/security/selinux?hl=ko
9. 작동방식
[root@ybsvr ~]# ls -ld /tmp
drwxrwxrwt. 19 root root 4096 Jun 16 17:11 /tmp
[root@ybsvr ~]# ls -ld /var/tmp
drwxrwxrwt. 9 root root 4096 Jun 16 06:17 /var/tmp
[root@ybsvr ~]# ls -ldZ /root
dr-xr-x---. root root system_u:object_r:admin_home_t:s0 /root
이미지출처:redhat rh124
10. Context
[root@seon ~]# semanage port -l |grep http_port_t
http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000
[root@seon ~]# ps -eZ |grep nginx
system_u:system_r:httpd_t:s0 996 ? 00:00:00 nginx
system_u:system_r:httpd_t:s0 997 ? 00:00:00 nginx
Nginx 프로세스의 context
[root@seon ~]# ls -ldZ /var/www/html
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html
[root@seon ~]# ls -lZ /var/www/html
-rw-------. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html
-rw-r--rwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.php
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 test.php
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 web.php
웹서버 홈폴더와 파일들의 context
http 프로세스가 사용 할 수 있는 포트 목록
11. 부울
semanage boolean -l |grep httpd_unified
httpd_unified (off , off) Allow httpd to unified
해당 boolean의 설명(redhat.com)
활성화되면이 부울은 httpd_t가 모든 httpd 유형 (즉 sys_content_t를 실행, 읽기 또는 쓰기)에 대한 완전한 액세스를
허용합니다. 비활성화되면 읽기 전용, 쓰기 가능 또는 실행 가능한 웹 콘텐츠가 분리됩니다. 이 부울을 비활성화하면 추가
보안 수준이 보장되지만 스크립트 및 기타 웹 콘텐츠에 각각 있어야하는 파일 액세스를 기반으로 개별적으로 레이블을
지정해야하는 관리 오버 헤드가 추가됩니다
12. 정리
SELinux 작동의 핵심 개념
SELinux에서 사용하는 레이블
각 객체에 레이블링을 함
컨텍스트 별 사용 할 수 있는 포트가 있음
컨텍스트 별 읽거나 쓸 수 있는 컨텍스트가 있음
정책이 존재하지 않으면 기본적으로 차단 됨
컨텍스트 부울
사전 정의된 정책으로 간단하게 on/off하여 사용 할 수
있음
현재 기본값으로 약 300여개의 부울이 있음
모든 SELinux의 정책이 부울로 있는 것은 아니다
15. 시연 시나리오
운영중인 웹서버에 해커의 침입이 발생
Webshell 공격에 노출되어 웹서버상에 Webshell 이 구동됨
또한 이 해커는 nginx의 취약점을 이용하여 root권한 탈취에도 성공함
b.com의 웹서버에는 Selinux가 Disabled 상태이며
a.com의 웹서버에는 Selinux 가 Enforcing 상태임
이 두개의 서버에 똑같은 명령어를 직접 내려 과연 SELinux가 어떻게 OS를 보호하는지 살펴보자
24. boolean
[root@a ~]# semanage boolean -l |grep httpd_uni
httpd_unified (off , off) Allow httpd to unified
[root@a ~]# semanage boolean --modify --on httpd_unified
[root@a ~]# semanage boolean -l |grep httpd_uni
httpd_unified (on , on) Allow httpd to unified
Httpd_unified 부울은 http_content_t 들에 대해 r/w 를 통합하여 관리 할 것인지에 대한 부울
해당 부울이 off상태이면 http_content_t 컨텍스트를 가진 파일 및 디렉토리에 httpd_t 프로세스가 wirte할 수 없음
별도의 http_content_rw_t 컨텍스트를 줘야함
On상태이면 http_content_t 컨텍스트를 가진 파일 및 디렉토리에 write 할 수 있음
25. sealert
Jun 16 20:46:10 seon setroubleshoot: SELinux is preventing sh from write access on the directory html. For complete SELinux messages run: sealert -l
3821baef-ad7e-4c57-a76a-e8433dd03f0a
Jun 16 20:46:10 seon python: SELinux is preventing sh from write access on the directory html.#012#012***** Plugin httpd_write_content (92.2 confidence)
suggests ***************#012#012If you want to allow sh to have write access on the html directory#012Then you need to change the label on
'html'#012Do#012# semanage fcontext -a -t httpd_sys_rw_content_t 'html'#012# restorecon -v 'html'#012#012***** Plugin catchall_boolean (7.83
confidence) suggests ******************#012#012If you want to allow httpd to unified#012Then you must tell SELinux about this by enabling the
'httpd_unified' boolean.#012#012Do#012setsebool -P httpd_unified 1#012#012***** Plugin catchall (1.41 confidence) suggests
**************************#012#012If you believe that sh should be allowed write access on the html directory by default.#012Then you should report
this as a bug.#012You can generate a local policy module to allow this access.#012Do#012allow this access for now by executing:#012# ausearch -c 'sh' --
raw | audit2allow -M my-sh#012# semodule -i my-sh.pp#012
# sealert -l 3821baef-ad7e-4c57-a76a-e8433dd03f0a
26. sealert
# semanage fcontext -a -t httpd_sys_rw_content_t 'html'
# restorecon -v 'html'
***** Plugin catchall_boolean (7.83 confidence) suggests ******************
If you want to allow httpd to unified
Then you must tell SELinux about this by enabling the 'httpd_unified' boolean.
setsebool -P httpd_unified 1
***** Plugin catchall (1.41 confidence) suggests **************************
If you believe that sh should be allowed write access on the html directory by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# ausearch -c 'sh' --raw | audit2allow -M my-sh
# semodule -i my-sh.pp
Additional Information:
Source Context system_u:system_r:httpd_t:s0
Target Context system_u:object_r:httpd_sys_content_t:s0
Target Objects html [ dir ]
Source sh
Source Path sh
Port <Unknown>
Host seon
Source RPM Packages coreutils-8.22-24.el7.x86_64
Target RPM Packages
Policy RPM selinux-policy-3.13.1-268.el7.noarch
Selinux Enabled True
Policy Type targeted
Enforcing Mode Enforcing
Host Name a.com
Platform Linux a.com 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct
19 16:18:59 UTC 2020 x86_64 x86_64
Alert Count 7
First Seen 2021-05-03 10:50:52 KST
Last Seen 2021-06-16 20:46:09 KST
Local ID 3821baef-ad7e-4c57-a76a-e8433dd03f0a
27. 정리
일반적으로 많이 사용하는 APP이라면 별다른 조치가 없어도 바로 적용하여 사용이 가능
일반적인 사용이 아닌 경우 = 정책을 수정하여 적용
28. Cloud & Collaboration
T. 02-516-0711 E. sales@osci.kr
서울시강남구테헤란로83길32,5층(삼성동,나라키움삼성동A빌딩)
www.osci.kr
감사합니다
THANK YOU