Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

3.2. 제한되지 않은 프로세스

제한되지 않은 프로세스는 제한되지 않은 도메인에서 실행됩니다. 예를 들어 init 에서 실행한 제한되지 않은 서비스는 결국 unconfined_service_t 도메인, 커널에서 실행되는 제한되지 않은 서비스는 kernel_t 도메인에서 실행되고, unconfined Linux 사용자가 실행한 제한되지 않은 서비스는 결국 unconfined_t 도메인에서 실행됩니다. 제한되지 않은 프로세스의 경우 SELinux 정책 규칙이 적용되지만 제한되지 않은 도메인에서 실행되는 프로세스가 거의 모든 액세스를 허용하는 정책 규칙이 있습니다. 제한되지 않은 도메인에서 실행되는 프로세스는 DAC 규칙을 독점적으로 사용하는 것으로 대체됩니다. 제한되지 않은 프로세스가 손상되면 SELinux를 통해 공격자가 시스템 리소스 및 데이터에 대한 액세스 권한을 얻지 못하지만 물론 DAC 규칙이 계속 사용됩니다. SELinux는 DAC 규칙의 보안 개선 사항이므로 대체되지 않습니다.
SELinux가 활성화되고 시스템이 다음 예제를 수행할 준비가 되었는지 확인하려면 3.1절. “제한된 프로세스” 에 설명된 절차 3.1. “SELinux 상태를 확인하는 방법” 을(를) 완료합니다.
다음 예제에서는 제한 없이 실행할 때 Apache HTTP Server(httpd)가 Samba에서 사용하도록 의도한 데이터에 액세스하는 방법을 보여줍니다. Red Hat Enterprise Linux에서 httpd 프로세스는 기본적으로 제한된 httpd_t 도메인에서 실행됩니다. 이는 예제이며 프로덕션에서 사용해서는 안 됩니다. httpd,wget,dbusaudit 패키지가 설치되어 있고, SELinux 대상 지정 정책이 사용되며 SELinux가 강제 모드로 실행 중이라고 가정합니다.

절차 3.3. 제한되지 않은 프로세스의 예

  1. chcon 명령은 파일의 레이블을 다시 지정합니다. 그러나 파일 시스템에 레이블을 다시 지정하면 이러한 레이블 변경 사항이 유지되지 않습니다. 파일 시스템의 레이블 변경 후에도 유지되는 영구 변경의 경우 semanage 유틸리티를 사용합니다. 이 유틸리티는 나중에 설명합니다. root 사용자로 다음 명령을 입력하여 유형을 Samba에서 사용하는 유형으로 변경합니다.
    ~]# chcon -t samba_share_t /var/www/html/testfile
    변경 사항을 확인합니다.
    ~]$ ls -Z /var/www/html/testfile
    -rw-r--r--  root root unconfined_u:object_r:samba_share_t:s0 /var/www/html/testfile
  2. 다음 명령을 입력하여 httpd 프로세스가 실행 중이 아닌지 확인합니다.
    ~]$ systemctl status httpd.service
    httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
       Active: inactive (dead)
    출력이 다르면 root로 다음 명령을 입력하여 httpd 프로세스를 중지합니다.
    ~]# systemctl stop httpd.service
  3. httpd 프로세스를 제한 없이 실행하려면 root로 다음 명령을 입력하여 /usr/sbin/httpd 파일의 유형을 제한된 도메인으로 전환하지 않는 유형으로 변경합니다.
    ~]# chcon -t bin_t /usr/sbin/httpd
  4. /usr/sbin/httpdbin_t 유형으로 레이블이 지정되어 있는지 확인합니다.
    ~]$ ls -Z /usr/sbin/httpd
    -rwxr-xr-x. root root system_u:object_r:bin_t:s0       /usr/sbin/httpd
    
  5. root로 httpd 프로세스를 시작하고 성공적으로 시작되었는지 확인합니다.
    ~]# systemctl start httpd.service
    ~]# systemctl status httpd.service
    httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
       Active: active (running) since Thu 2013-08-15 11:17:01 CEST; 5s ago
    
  6. 다음 명령을 입력하여 unconfined_service_t 도메인에서 실행 중인 httpd 를 확인합니다.
    ~]$ ps -eZ | grep httpd
    system_u:system_r:unconfined_service_t:s0 11884 ? 00:00:00 httpd
    system_u:system_r:unconfined_service_t:s0 11885 ? 00:00:00 httpd
    system_u:system_r:unconfined_service_t:s0 11886 ? 00:00:00 httpd
    system_u:system_r:unconfined_service_t:s0 11887 ? 00:00:00 httpd
    system_u:system_r:unconfined_service_t:s0 11888 ? 00:00:00 httpd
    system_u:system_r:unconfined_service_t:s0 11889 ? 00:00:00 httpd
    
  7. Linux 사용자가 에 대한 쓰기 액세스 권한이 있는 디렉터리로 변경하고 다음 명령을 입력합니다. 기본 구성을 변경하지 않는 한 이 명령은 성공합니다.
    ~]$ wget http://localhost/testfile
    --2009-05-07 01:41:10--  http://localhost/testfile
    Resolving localhost... 127.0.0.1
    Connecting to localhost|127.0.0.1|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 0 [text/plain]
    Saving to: `testfile'
    
    [ <=>                            ]--.-K/s   in 0s
    
    2009-05-07 01:41:10 (0.00 B/s) - `testfile' saved [0/0]
    httpd 프로세스가 samba_share_t 유형으로 레이블이 지정된 파일에 액세스할 수 없지만 httpd 는 제한되지 않은 unconfined_service_t 도메인에서 실행되며 DAC 규칙 사용을 대체합니다. 따라서 wget 명령은 성공합니다. httpd 가 제한된 httpd_t 도메인에서 실행 중이면 wget 명령이 실패했습니다.
  8. restorecon 유틸리티는 파일의 기본 SELinux 컨텍스트를 복원합니다. root로 /usr/sbin/httpd 의 기본 SELinux 컨텍스트를 복원하려면 다음 명령을 입력합니다.
    ~]# restorecon -v /usr/sbin/httpd
    restorecon reset /usr/sbin/httpd context system_u:object_r:unconfined_exec_t:s0->system_u:object_r:httpd_exec_t:s0
    
    /usr/sbin/httpdhttpd_exec_t 유형이 지정되었는지 확인합니다.
    ~]$ ls -Z /usr/sbin/httpd
    -rwxr-xr-x  root root system_u:object_r:httpd_exec_t:s0 /usr/sbin/httpd
  9. root로 다음 명령을 입력하여 httpd 를 다시 시작합니다. 재시작 후 httpd_t 도메인이 제한된 httpd _t 도메인에서 실행 중인지 확인합니다.
    ~]# systemctl restart httpd.service
    ~]$ ps -eZ | grep httpd
    system_u:system_r:httpd_t:s0    8883 ?        00:00:00 httpd
    system_u:system_r:httpd_t:s0    8884 ?        00:00:00 httpd
    system_u:system_r:httpd_t:s0    8885 ?        00:00:00 httpd
    system_u:system_r:httpd_t:s0    8886 ?        00:00:00 httpd
    system_u:system_r:httpd_t:s0    8887 ?        00:00:00 httpd
    system_u:system_r:httpd_t:s0    8888 ?        00:00:00 httpd
    system_u:system_r:httpd_t:s0    8889 ?        00:00:00 httpd
    
  10. root 권한으로 testfile 을 제거합니다.
    ~]# rm -i /var/www/html/testfile
    rm: remove regular empty file `/var/www/html/testfile'? y
    
  11. httpd 를 실행할 필요가 없는 경우 root로 다음 명령을 입력하여 httpd 를 중지합니다.
    ~]# systemctl stop httpd.service
이 섹션의 예제에서는 손상된 제한된 프로세스(SELinux로 보호)로부터 데이터를 보호할 수 있는 방법과 공격자가 손상된 제한 프로세스(SELinux에 의해 보호되지 않음)로부터 데이터를 더 효과적으로 액세스할 수 있는 방법을 보여줍니다.