메뉴 건너뛰기

리눅스 관련 모음

본문시작

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 에러해결 error: wrong mysql library version or lib not found. 햇빛소년 2014.03.16 16582
49 에러해결 error on line at column Input is not proper UTF-8, indicate encoding ! 햇빛소년 2013.12.26 4628
48 에러해결 eaccelerator.c:66:23: error: php_logos.h: 그런 파일이나 디렉터리가 없습니다. 햇빛소년 2014.02.28 9608
47 에러해결 dovecot 설치 후 squirrelmail 가동하면 /.imap/INBOX, group=12(mail)) failed: Operation not permitted 햇빛소년 2013.06.30 19280
46 설치관련 dnssec-keygen 사용법 및 구축과 검증 햇빛소년 2013.06.07 24035
45 DCC로 안티스팸 기능 확장하기 햇빛소년 2011.03.18 51328
44 DCC관련 명령어 모음 햇빛소년 2012.06.02 43924
43 설치관련 DCC+razor2+pyzor how to ---[ spamassassin -D <test 2>debug ] file 햇빛소년 2012.05.31 31628
42 crontab 설정 햇빛소년 2011.05.12 45046
41 cpanm 햇빛소년 2011.04.04 47599
40 cpan 으로 설치힌 perl 모듈의 검색과 삭제... 햇빛소년 2012.05.10 30038
39 convert: error while loading shared libraries: libMagick.so.10: cannot open file 햇빛소년 2012.02.20 29870
38 에러해결 configure: error: Unable to find libgd.(a|so) >= 2.1.0 anywhere under 햇빛소년 2014.03.02 4546
37 에러해결 configure: error: snmp.h not found. Check your SNMP installation. 햇빛소년 2015.12.01 907
36 설치관련 clamav.cf --> Clamav Multiple Score 햇빛소년 2013.07.07 18141
35 ClamAV 0.97.4 버전으로 새로 컴파일 하여 업데이트 한후 에러발생 해결... 햇빛소년 2012.04.29 28719
34 chmod 파일 퍼미션의 다양한 조건들.... 햇빛소년 2012.05.16 28504
33 chattr, lsattr 햇빛소년 2011.10.05 41615
32 에러해결 CentOS7 firewall 사용시 spamd: could not create INET socket on 127.0.0.1:783: 햇빛소년 2014.11.04 3748
31 에러해결 CentOS-7 Network 설정에 관하여.... 햇빛소년 2014.10.27 7707
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 Next
/ 10