SlideShare a Scribd company logo
SELinux
Stop Disabling SELinux
2021.06.23.
최용범
Contents
SELinux란
01
작동 방식
02
시연
03
당장 사용하기 위해 필요한 지식
04
SELinux?
CHAPTER 01
SELinux?
SELinux란 Security-Enhanced Linux 약자
미국 국가안보국(NSA) 에서 개발 2003년부터 커널에 통합됨
DAC(Discretionary Access Control) 가 아닌 MAC(Mandatory Access Control)을 사용하는 보안 모듈
Enforcing, Permissive, Disabled 모드가 있음
얼마나 사용하고 있나?
전세계적으로 disabled 하여 사용하고 있음
stopdisablingselinux.com 라는 사이트를 만들어 홍보할 정도
많은 블로그에서 selinux를 한번 써보라고 권장하나 그 누구도…
왜 사용하지 않는가?
Selinux는 어렵다
Selinux는 귀찮다
OS관리자의 역할이 늘어난다
Application이 SELinux의 보안사양을 따르지 않는다 = app 작동 불가
물리 방화벽이 있으니 OS방화벽을 끄는것과 같은 이치
사용해야 하는 이유?
Zero-Day 공격을 막을 거의 유일한 수단
Selinux는 어렵지 않다
보안은 강화될수록 귀찮은 것이 당연하다
OS관리자의 임무는 보안을 강화하는 부분도 있다
보안사양을 따르지 않는 Application이라도 여러가지 정책들을 적용하여 작동하게 할 수 있다
안드로이드처럼 이미 Selinux를 사용하면서 구동중인 어플리케이션이 있다
당장은 힘들겠지만 우리 제품 Playce RoRo & Playce Cloud 등이 selinux를 지원한다면??
물리 방화벽이 있어도 OS방화벽을 같이 사용하면 좋다 = 보안은 다다익선 = 다만 귀찮을뿐
거기다가 공짜!!
https://source.android.com/security/selinux?hl=ko
작동 방식
CHAPTER 02
작동방식
[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
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 프로세스가 사용 할 수 있는 포트 목록
부울
semanage boolean -l |grep httpd_unified
httpd_unified (off , off) Allow httpd to unified
해당 boolean의 설명(redhat.com)
활성화되면이 부울은 httpd_t가 모든 httpd 유형 (즉 sys_content_t를 실행, 읽기 또는 쓰기)에 대한 완전한 액세스를
허용합니다. 비활성화되면 읽기 전용, 쓰기 가능 또는 실행 가능한 웹 콘텐츠가 분리됩니다. 이 부울을 비활성화하면 추가
보안 수준이 보장되지만 스크립트 및 기타 웹 콘텐츠에 각각 있어야하는 파일 액세스를 기반으로 개별적으로 레이블을
지정해야하는 관리 오버 헤드가 추가됩니다
정리
SELinux 작동의 핵심 개념
SELinux에서 사용하는 레이블
각 객체에 레이블링을 함
컨텍스트 별 사용 할 수 있는 포트가 있음
컨텍스트 별 읽거나 쓸 수 있는 컨텍스트가 있음
정책이 존재하지 않으면 기본적으로 차단 됨
컨텍스트 부울
사전 정의된 정책으로 간단하게 on/off하여 사용 할 수
있음
현재 기본값으로 약 300여개의 부울이 있음
모든 SELinux의 정책이 부울로 있는 것은 아니다
시연
CHAPTER 03
시연 시나리오
a.com(192.168.7.155)
b.com(192.168.7.150)
시연 시나리오
운영중인 웹서버에 해커의 침입이 발생
Webshell 공격에 노출되어 웹서버상에 Webshell 이 구동됨
또한 이 해커는 nginx의 취약점을 이용하여 root권한 탈취에도 성공함
b.com의 웹서버에는 Selinux가 Disabled 상태이며
a.com의 웹서버에는 Selinux 가 Enforcing 상태임
이 두개의 서버에 똑같은 명령어를 직접 내려 과연 SELinux가 어떻게 OS를 보호하는지 살펴보자
시연
Webshell을 이용하여 pwd명령어를 내리면
양쪽 모두 잘 작동하고 있다
시연
Id명령어를 내리면 두 사이트 모두 root계정이 확인됨
그러나 a.com에는 context가 보인다
시연
아래 명령어를 수행하여 양쪽 비교
Touch hack
Cat /etc/passwd
Cat 1.txt
Cat /root/2.txt
echo "hello" >test
Cat test
Cat /etc/shadow
Cat /root/.ssh/id_rsa
시연 마무리
Reboot
rm -rf / --no-preserve-root rm –rf /
당장 사용하기 위해 필요한 지식들
CHAPTER 04
당장 사용하기 위해 알아야 하는 지식들
Context 관리법
Port 수정
Boolean on/off
Sealert 사용법
context
[root@a ~]# mkdir /data
[root@a ~]# touch /data/123.html
[root@a ~]# ls -lZ /data/123.html
-rw-r--r--. root root unconfined_u:object_r:default_t:s0 /data/123.html
[root@ybsvr lightkube]# semanage fcontext -l |grep httpd_sys_content_t
/srv/([^/]*/)?www(/.*)? all files system_u:object_r:httpd_sys_content_t:s0
/var/www(/.*)? all files system_u:object_r:httpd_sys_content_t:s0
/usr/share/nginx/html(/.*)? all files system_u:object_r:httpd_sys_content_t:s0
[root@a ~]# semanage fcontext -a -t httpd_sys_content_t '/data(/.*)?'
[root@a ~]# semanage fcontext -l |grep /data
//data(/.*)? all files system_u:object_r:httpd_sys_content_t:s0
[root@a ~]# ls -lZ /data/123.html
-rw-r--r--. root root unconfined_u:object_r:default_t:s0 /data/123.html
[root@a ~]# restorecon -RFvv /data
restorecon reset /data context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0
restorecon reset /data/123.html context unconfined_u:object_r:default_t:s0-
>system_u:object_r:httpd_sys_content_t:s0
[root@a ~]# ls -lZ /data/123.html
-rw-r--r--. root root system_u:object_r:httpd_sys_content_t:s0 /data/123.html
port
[root@a ~]# semanage port -l |grep http_port_t
http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000
[root@a ~]# semanage port --add -t http_port_t -p tcp 6443
[root@a ~]# semanage port -l |grep http_port_t
http_port_t tcp 6443, 80, 81, 443, 488, 8008, 8009, 8443, 9000
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 할 수 있음
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
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
정리
일반적으로 많이 사용하는 APP이라면 별다른 조치가 없어도 바로 적용하여 사용이 가능
일반적인 사용이 아닌 경우 = 정책을 수정하여 적용
Cloud & Collaboration
T. 02-516-0711 E. sales@osci.kr
서울시강남구테헤란로83길32,5층(삼성동,나라키움삼성동A빌딩)
www.osci.kr
감사합니다
THANK YOU

More Related Content

PDF
[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교 및 구축 방법
PDF
Open source APM Scouter로 모니터링 잘 하기
PDF
Faster packet processing in Linux: XDP
PDF
[OpenInfra Days Korea 2018] (Track 2) Neutron LBaaS 어디까지 왔니? - Octavia 소개
PDF
DevOpsに求められる様々な技術とその連携の学習方法
PPTX
Introduction to the Container Network Interface (CNI)
PDF
[오픈소스컨설팅]Scouter 설치 및 사용가이드(JBoss)
PDF
Kubernetes & helm 활용
[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교 및 구축 방법
Open source APM Scouter로 모니터링 잘 하기
Faster packet processing in Linux: XDP
[OpenInfra Days Korea 2018] (Track 2) Neutron LBaaS 어디까지 왔니? - Octavia 소개
DevOpsに求められる様々な技術とその連携の学習方法
Introduction to the Container Network Interface (CNI)
[오픈소스컨설팅]Scouter 설치 및 사용가이드(JBoss)
Kubernetes & helm 활용

What's hot (20)

PDF
いまさらながらの Windows Workflow 入門
PDF
Elastic Stack & Data pipeline (1장)
PPTX
[NDC17] Kubernetes로 개발서버 간단히 찍어내기
PDF
Building Event Streaming Architectures on Scylla and Kafka
PDF
Automation with ansible
PPTX
Pushing Packets - How do the ML2 Mechanism Drivers Stack Up
PDF
PostgreSQL 15の新機能を徹底解説
PDF
以 eBPF 構建一個更為堅韌的 Kubernetes 叢集
PDF
Rancher/Kubernetes入門ハンズオン資料~第2回さくらとコンテナの夕べ #さくらの夕べ 番外編
PDF
分散システム読書会 06章-同期(前編)
PDF
Kubernetes Architecture - beyond a black box - Part 1
PDF
PostgreSQLをKubernetes上で活用するためのOperator紹介!(Cloud Native Database Meetup #3 発表資料)
PPTX
Kafka monitoring using Prometheus and Grafana
PDF
[오픈소스컨설팅]오픈스택에 대하여
PPTX
[오픈소스컨설팅]Ansible overview
PPTX
Introduction to CNI (Container Network Interface)
PDF
[OpenInfra Days Korea 2018] (Track 1) TACO (SKT All Container OpenStack): Clo...
PDF
ITサービスマネジメントとSRE
PDF
SSHパケットの復号ツールを作ろう_v1(Decrypt SSH .pcap File)
PDF
[OpenStack Days Korea 2016] Track3 - 오픈스택 환경에서 공유 파일 시스템 구현하기: 마닐라(Manila) 프로젝트
いまさらながらの Windows Workflow 入門
Elastic Stack & Data pipeline (1장)
[NDC17] Kubernetes로 개발서버 간단히 찍어내기
Building Event Streaming Architectures on Scylla and Kafka
Automation with ansible
Pushing Packets - How do the ML2 Mechanism Drivers Stack Up
PostgreSQL 15の新機能を徹底解説
以 eBPF 構建一個更為堅韌的 Kubernetes 叢集
Rancher/Kubernetes入門ハンズオン資料~第2回さくらとコンテナの夕べ #さくらの夕べ 番外編
分散システム読書会 06章-同期(前編)
Kubernetes Architecture - beyond a black box - Part 1
PostgreSQLをKubernetes上で活用するためのOperator紹介!(Cloud Native Database Meetup #3 発表資料)
Kafka monitoring using Prometheus and Grafana
[오픈소스컨설팅]오픈스택에 대하여
[오픈소스컨설팅]Ansible overview
Introduction to CNI (Container Network Interface)
[OpenInfra Days Korea 2018] (Track 1) TACO (SKT All Container OpenStack): Clo...
ITサービスマネジメントとSRE
SSHパケットの復号ツールを作ろう_v1(Decrypt SSH .pcap File)
[OpenStack Days Korea 2016] Track3 - 오픈스택 환경에서 공유 파일 시스템 구현하기: 마닐라(Manila) 프로젝트
Ad

Similar to [오픈소스컨설팅] SELinux : Stop Disabling SELinux (20)

PDF
Nginx basic configurations
PDF
[오픈소스컨설팅]Nginx 1.2.7 설치가이드__v1
PDF
Zinst 패키지 기반의-리눅스_중앙관리시스템_20140415
PDF
Fluentd with MySQL
PPTX
리눅스서버세팅-김태호
PDF
[오픈소스컨설팅]Nginx jboss 연동가이드__v1
PDF
CoreOS를 이용한 Docker 관리툴 소개
PDF
Udamp3 django apache-my_sql_python3_ubuntu14.04-v11
PDF
[Ansible] Solution Guide V0.4_20181204.pdf
PDF
[231]나는서버를썰터이니너는개발만하여라 양지욱
PDF
제2회 난공불락 오픈소스 인프라 세미나 zinst 관리툴 소개
PDF
Enterprise Linux 7 new feature_network configuration
PDF
Puppet과 자동화된 시스템 관리
PDF
2node cluster
PDF
2node cluster
PDF
시큐어디스크 ECM
PDF
[2022]Flutter_IO_Extended_Korea_멀티모듈을활용한플러터클린아키텍처_...
PDF
Laravel로 스타트업 기술 스택 구성하기
PDF
Openstack security(2018)
PPTX
리눅스 드라이버 실습 #1
Nginx basic configurations
[오픈소스컨설팅]Nginx 1.2.7 설치가이드__v1
Zinst 패키지 기반의-리눅스_중앙관리시스템_20140415
Fluentd with MySQL
리눅스서버세팅-김태호
[오픈소스컨설팅]Nginx jboss 연동가이드__v1
CoreOS를 이용한 Docker 관리툴 소개
Udamp3 django apache-my_sql_python3_ubuntu14.04-v11
[Ansible] Solution Guide V0.4_20181204.pdf
[231]나는서버를썰터이니너는개발만하여라 양지욱
제2회 난공불락 오픈소스 인프라 세미나 zinst 관리툴 소개
Enterprise Linux 7 new feature_network configuration
Puppet과 자동화된 시스템 관리
2node cluster
2node cluster
시큐어디스크 ECM
[2022]Flutter_IO_Extended_Korea_멀티모듈을활용한플러터클린아키텍처_...
Laravel로 스타트업 기술 스택 구성하기
Openstack security(2018)
리눅스 드라이버 실습 #1
Ad

More from Open Source Consulting (20)

PDF
[Atlassian System of Work] 모든 협업을 연결하는 아틀라시안의 프레임워크
PDF
[Team on Tour 2025] Atlassian의 System of Work
PDF
Playce WASup | Apache/Tomcat은 그대로, 운영은 더 강력하게
PDF
Playce Cloud 소개자료 | 글로벌 표준과 로컬라이제이션을 위한 오픈소스 패키지
PDF
Good-bye Digital Transformation, Hello AI-first Transformation
PDF
[Recap] Atlassian Team25 - Progress is impossible alone
PDF
[오픈소스컨설팅] 오픈소스로 확장하는 NKP 기반 Kubernetes 환경
PDF
[오픈소스컨설팅] 먼데이닷컴 소개서
PDF
[Next-Gen ITSM | Atlassian이 제시하는 ITSM 혁신] 04. Rovo가 적용된 ITSM 시스템 ᄃ...
PDF
[Next-Gen ITSM | Atlassian이 제시하는 ITSM 혁신] 03. ITSM 구현과 고객 사례_신철ᄆ...
PDF
[Next-Gen ITSM | Atlassian이 제시하는 ITSM 혁신] 02. 클라우드 기반 ITSM 최적화를...
PDF
[Next-Gen ITSM | Atlassian이 제시하는 ITSM 혁신] 01. Gen Next ITSM_김윤희.pdf
PDF
[발표 자료] 시각화로 전략을 실현하는 스마트 워크플로우 with 먼데이닷컴.pdf
PDF
[The Future of IT] 1. AI 시대의 일하는 방법_김대일 고문
PDF
[The Future of IT] 2. 조직 목표 Align 및 전사 협업 확장_한진규 부사장
PDF
[The Future of IT] 3. AI 시대의 인프라_오픈소스를 활용한 인프라 구축 및 GPU as a Service 구현사례_김호진 상무
PDF
[발표자료] 오픈소스 기반 클라우드 네이티브 애플리케이션 구축 방안 (feat. Kubernetes)
PDF
[202412 SAFe Meetup] SAFe Transfomration Journey
PDF
[워크숍] Get to know AI, Meet your new teammate!
PDF
[웨비나 발표자료] VMware 정책 변화 대응 - 왜 오픈소스 기반 클라우드 네이티브 인프라로 가야하는가?
[Atlassian System of Work] 모든 협업을 연결하는 아틀라시안의 프레임워크
[Team on Tour 2025] Atlassian의 System of Work
Playce WASup | Apache/Tomcat은 그대로, 운영은 더 강력하게
Playce Cloud 소개자료 | 글로벌 표준과 로컬라이제이션을 위한 오픈소스 패키지
Good-bye Digital Transformation, Hello AI-first Transformation
[Recap] Atlassian Team25 - Progress is impossible alone
[오픈소스컨설팅] 오픈소스로 확장하는 NKP 기반 Kubernetes 환경
[오픈소스컨설팅] 먼데이닷컴 소개서
[Next-Gen ITSM | Atlassian이 제시하는 ITSM 혁신] 04. Rovo가 적용된 ITSM 시스템 ᄃ...
[Next-Gen ITSM | Atlassian이 제시하는 ITSM 혁신] 03. ITSM 구현과 고객 사례_신철ᄆ...
[Next-Gen ITSM | Atlassian이 제시하는 ITSM 혁신] 02. 클라우드 기반 ITSM 최적화를...
[Next-Gen ITSM | Atlassian이 제시하는 ITSM 혁신] 01. Gen Next ITSM_김윤희.pdf
[발표 자료] 시각화로 전략을 실현하는 스마트 워크플로우 with 먼데이닷컴.pdf
[The Future of IT] 1. AI 시대의 일하는 방법_김대일 고문
[The Future of IT] 2. 조직 목표 Align 및 전사 협업 확장_한진규 부사장
[The Future of IT] 3. AI 시대의 인프라_오픈소스를 활용한 인프라 구축 및 GPU as a Service 구현사례_김호진 상무
[발표자료] 오픈소스 기반 클라우드 네이티브 애플리케이션 구축 방안 (feat. Kubernetes)
[202412 SAFe Meetup] SAFe Transfomration Journey
[워크숍] Get to know AI, Meet your new teammate!
[웨비나 발표자료] VMware 정책 변화 대응 - 왜 오픈소스 기반 클라우드 네이티브 인프라로 가야하는가?

[오픈소스컨설팅] SELinux : Stop Disabling 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를 보호하는지 살펴보자
  • 16. 시연 Webshell을 이용하여 pwd명령어를 내리면 양쪽 모두 잘 작동하고 있다
  • 17. 시연 Id명령어를 내리면 두 사이트 모두 root계정이 확인됨 그러나 a.com에는 context가 보인다
  • 18. 시연 아래 명령어를 수행하여 양쪽 비교 Touch hack Cat /etc/passwd Cat 1.txt Cat /root/2.txt echo "hello" >test Cat test Cat /etc/shadow Cat /root/.ssh/id_rsa
  • 19. 시연 마무리 Reboot rm -rf / --no-preserve-root rm –rf /
  • 20. 당장 사용하기 위해 필요한 지식들 CHAPTER 04
  • 21. 당장 사용하기 위해 알아야 하는 지식들 Context 관리법 Port 수정 Boolean on/off Sealert 사용법
  • 22. context [root@a ~]# mkdir /data [root@a ~]# touch /data/123.html [root@a ~]# ls -lZ /data/123.html -rw-r--r--. root root unconfined_u:object_r:default_t:s0 /data/123.html [root@ybsvr lightkube]# semanage fcontext -l |grep httpd_sys_content_t /srv/([^/]*/)?www(/.*)? all files system_u:object_r:httpd_sys_content_t:s0 /var/www(/.*)? all files system_u:object_r:httpd_sys_content_t:s0 /usr/share/nginx/html(/.*)? all files system_u:object_r:httpd_sys_content_t:s0 [root@a ~]# semanage fcontext -a -t httpd_sys_content_t '/data(/.*)?' [root@a ~]# semanage fcontext -l |grep /data //data(/.*)? all files system_u:object_r:httpd_sys_content_t:s0 [root@a ~]# ls -lZ /data/123.html -rw-r--r--. root root unconfined_u:object_r:default_t:s0 /data/123.html [root@a ~]# restorecon -RFvv /data restorecon reset /data context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0 restorecon reset /data/123.html context unconfined_u:object_r:default_t:s0- >system_u:object_r:httpd_sys_content_t:s0 [root@a ~]# ls -lZ /data/123.html -rw-r--r--. root root system_u:object_r:httpd_sys_content_t:s0 /data/123.html
  • 23. port [root@a ~]# semanage port -l |grep http_port_t http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000 [root@a ~]# semanage port --add -t http_port_t -p tcp 6443 [root@a ~]# semanage port -l |grep http_port_t http_port_t tcp 6443, 80, 81, 443, 488, 8008, 8009, 8443, 9000
  • 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