메뉴 건너뛰기

리눅스 관련 모음

본문시작

2012.06.07 15:24

selinux 관련 명령모음.

조회 수 36271 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

국산 통나무 수공예 남원제기, 남원목기

자료가 도움이 되셨다면
혼수용품제수용품 필요시
남원제기 공식 홈페이지 http://남원제기.kr
남원목기 공식 홈페이지 http://otchil.kr
에서 구매 해 주세요
정성껏 모시겠습니다.
 

1. getsebool -a 하면 SELinux 의 모든 boolean 값에 대한 상태를 출력해준다.

 allow_polyinstantiation --> off
allow_postfix_local_write_mail_spool --> off
allow_ptrace --> off
allow_rsync_anon_write --> off
allow_saslauthd_read_shadow --> off
..............
..................
 
2. setsebool  -P allow_rsync_anon_write 1
    allow_rsync_anon_write --> on
 
3. SELinux 상태 변경을 요할 경우

1.     /etc/sysconfig/selinux 파일 수정

#vi /etc/sysconfig/selinux 에서 다음 파일 수정
           SELINUX=enforcing 을 disabled 나 permissive 로 수정

           기본 설정 값은 enforcing 로 되어 있다.
SELINUX=enforcing (사용함)
SELINUX=perimssive (보안경고만 사용)
SELINUX=disabled (사용안함)
           위 값 설정 후 시스템 재부팅

 

4. 현재 상태에서만 보안 설정에 대한 활성화 및 비활성화를 설정 할 수 있다.시스템 재부팅 후 원래 상태로 돌아 온다. (휘발성)

           

    #  setenforce 0     (비활성화 disabled)

    #  setenforce 1     (활성화 enforcing

 
5. SELinux 상태 상태 확인

           #sestatus –v

[root@selinux proc]# sestatus

 

SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing  <------ 보안모드
Mode from config file:          enforcing
Policy version:                 21
Policy from config file:        targeted

 

6. # ls -lZ 또는 ll -Z /etc/selinux

-rw-r--r--  root    root   system_u:object_r:selinux_config_t config

drwxr-xr-x  root    root   system_u:object_r:selinux_config_t targeted


           _u : 신분(identify)필드 , _r : 역할(role)필드 , _t :유형(type) 필드

 

7.  SELinux 문맥 변경

       문맥 변경 명령 chcon 을 이용한다.

       하위 디렉토리에 똑 같은 유형을 넣을 때 –R 옵션을 이용한다.


Centos -role file 위치: /etc/selinux/target/contexts/files/file_contexts

 

-t : 해당 파일에 대한 role 설정

-R : 하위 디렉토리 내 모든 파일에 대한 같은 role 설정


           # chcon –t httpd_user_content_t /home/www/index.htm


위 명령 chcon 명령을 이용하여 해당 /home/www/index.htm 파일에 httpd_user_content_t 유형을 설정

 


8. SELinux 문맥 복구

       변경된 문맥 복구를 위해서는 restorecon 명령을 이용 한다.


# restorecon –Rv /home/www/index.htm


[root@selinux data]# ls -lZ

-rw-r--r--  root     root     root:object_r:httpd_user_content_t index.htm

[root@selinux data]# restorecon -Rv index.htm

restorecon reset context /data/index.htm:root:object_r:httpd_user_content_t->system_u:object_r:default_t

[root@selinux data]# ls -lZ

-rw-r--r--  root     root     system_u:object_r:default_t      index.htm

 

9. SELinux 로그 파일

 

    SELinux log  ---> /var/log/audit/audit.log

 

           audit(timestamp) : SELinux 검사 메세지이며 타임 스탬프 형식으로 기록한다.
           avc : SELinux 벡터 캐시 액세스를 나타나며 거의모든 기록은 이 캐시이다.
           denied | accepted : 해당 액션이 허가되었는지 거부되었는지를 나타낸다.
           { read | write | unlink | .....} 이 필드는 파일을 읽기,쓰기, unlink 등 정책을 로딩등의 액션 종류을 출력'
           for pid=<PID> : 접근하는 액션의 프로세스 ID를 나타낸다.
           exe=<executable> : 실행되는 프로세스의 경로를 나타낸다.
           name=<name> : 액션을 시도하는 타켓의 이름을 나타낸다.
           dev=<device> : 타켓 파일이 위치한 디바이스를 나타낸다.
           ino=<inode-number> : 액션 타켓의 inode를 나타낸다.
           scontext=<security context> : 프로세스의 보안상태(문맥)을 나타낸다. 사용자,규칙,타입을 가지고 있다.
           tcontext=<target context> : 액션 타켓(파일이나 디렉토리등에 사용되는)의 보안상태(문맥)을 나타낸다.
           tclass=<target class> : 타켓 오브젝트(디렉토리,파일,디바이스,노드같은)의 클래스를 나타낸다.

 

▣로그를 분석해 보면..

SELinux 로그는 프로세스가 거부 되었을때 기록을 한다.(허거되었을때도 기록이 가능하지만)

기본정책이 거부를 허가로 변경해서도 로그를 기록할수도 있다.

아래는 SELinux의 로그 기록이다.(기본적으로 /var/log/messages에 기록된다.)


kernel: audit(1114070701.193:0): avc:  denied  { read } for  pid=24216 exe=/usr/libexec/mysqld

name=mysql dev=cciss/c0d0p6 ino=16408 scontext=user_u:system_r:mysqld_t

tcontext=root:object_r:var_lib_t tclass=dir


우선 읽기 요구를 거부하고 있다. (denied {read})

읽기 요구를 하는 프로셋의 ID는 24216이다. (for pid=24216)

프로세스 이름은 /usr/libexec/mysqld 이고, (exe=/usr/libexec/mysql name=mysql)

액션의 타켓은 /dev/cciss/c0d0p6 장치에서 실행되고 있다.)

액션 타켓의 inode는 16408이고, (ino=16408)

프로세스의 SELinux context는 user이고, mysqld 타입이다.(scontext=user_u:system_r:mysqld_t)

읽으려고 하는 파일은 var_lib_t 타  입의 루트 소유의 파일이다. (tcontext=root:object_r:var_lib_t)


해당 log 파일은 SELinux 활성화 및 /etc/rc.d/init.d/auditd 데몬이 활성화 되어 있어야 한다.


-       /etc/rc.d/init.d/auditd 는 chkconfig –list 및 setup 에서 확인 가능 ps –ef | grep auditd 데몬 확인

-       Auditd log 파일은 /var/log/audit/audit.log 에서 확인 가능

-       Avc 포함 된 log 는 SELinux 에 대한 권한 설정 및 보안 문제로 발생 한다. Messages 나 auditd 에.

 

!!SELinux 활성화시 auditd 와 같이 활성화 시켜 준다.

/etc/rc.d/init.d/auditd start


 ▣ SELinux yum 패키지 업데이트


           [root@selinux proc]# yum update selinux*


           selinux-policy-targeted-sources

           selinux-policy-targeted-sources.noarch 0:1.17.30-2.150.el4

          selinux-policy-targeted.noarch 0:1.17.30-2.150.el4

 


▣ SELinux 관리툴
           Semanage / setsebool / audit2allow


           #audit2allow –l –i /var/log/messages

           #audit2allow –d

           #audit2alllow –a

 

 

audit2allow -M 모듈명 < /var/log/audit/audit.log && semodule -i 모듈명.pp

 

=================

 

 

SELinux 관련 소프트웨어(툴)

policycoreutils

policycoreutils-gui

 

# sestatus -v
Once you have found your problem you can reset to the default mode by executing 
당신의
문제를 발견하시면 기본 모드로 실행하여 재설정 할 수 있습니다
# semodule -b /usr/share/selinux/targeted/base.pp
 
 
   

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
50 SELinux Lockdown Part One: SELinux Users 햇빛소년 2012.06.07 35101
» selinux 관련 명령모음. 햇빛소년 2012.06.07 36271
48 DCC관련 명령어 모음 햇빛소년 2012.06.02 43924
47 - FQDN - 올바른 Hostname 설정하기. 햇빛소년 2012.06.02 32825
46 설치관련 DCC+razor2+pyzor how to ---[ spamassassin -D <test 2>debug ] file 햇빛소년 2012.05.31 31628
45 Red Hat / CentOS IPv6 Network Configuration 햇빛소년 2012.05.30 28092
44 cdcc 문서 햇빛소년 2012.05.30 32758
43 chmod 파일 퍼미션의 다양한 조건들.... 햇빛소년 2012.05.16 28499
42 iptables 삭제명령 햇빛소년 2012.05.15 71451
41 설치관련 스팸어쎄신(spamassassin)은 설치 후 service등록과 업데이트를 한번 더 해 줘야 한다. 햇빛소년 2012.05.10 29482
40 cpan 으로 설치힌 perl 모듈의 검색과 삭제... 햇빛소년 2012.05.10 30036
39 Starting spamd: Apr 29 16:41:34.934 [14162] warn: server socket setup failed, retry 1: spamd: could not chown 에러해결 햇빛소년 2012.04.29 32110
38 ClamAV 0.97.4 버전으로 새로 컴파일 하여 업데이트 한후 에러발생 해결... 햇빛소년 2012.04.29 28719
37 Apache 2.4.1 소스설치시 에러에 대한 해결 햇빛소년 2012.02.26 58178
36 specifies multiple packages 대처법 햇빛소년 2012.02.22 27959
35 convert: error while loading shared libraries: libMagick.so.10: cannot open file 햇빛소년 2012.02.20 29870
34 segmentation fault가 발생할 때 디버깅 방법 햇빛소년 2012.01.05 38160
33 chattr, lsattr 햇빛소년 2011.10.05 41615
32 su 명령의 문제점 햇빛소년 2011.10.04 54648
31 윈도우에서 내 컴퓨터 ip주소 확인하기 햇빛소년 2011.06.20 38099
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 Next
/ 10