메뉴 건너뛰기

리눅스 관련 모음

본문시작

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
번호 분류 제목 글쓴이 날짜 조회 수
190 Mail Server 구축(postfix, dovecot, amavisd-new, spamassassin, clamav) file 햇빛소년 2011.05.02 96540
189 에러해결 pcre최신버전 소스설치 후 modsecurity-apache 컴파일시 에러 햇빛소년 2013.01.19 76615
188 Spam Assassin + ClamAV 바이러스 필터 연동하기 file 햇빛소년 2011.03.29 74186
187 Amavisd 에서 spam filtering 수준 조절 햇빛소년 2011.04.09 72543
186 iptables 삭제명령 햇빛소년 2012.05.15 71452
185 Iptables 간략 사용하기 햇빛소년 2011.05.12 65475
184 Install amavisd-new, SpamAssassin 햇빛소년 2011.04.09 62648
183 리눅스 관리자가 알아두어야 할 50가지 햇빛소년 2011.05.12 60805
182 에러해결 phpmyadmin 4.0 로그인시 에러.. 햇빛소년 2013.06.18 59735
181 Apache 2.4.1 소스설치시 에러에 대한 해결 햇빛소년 2012.02.26 58420
180 rndc: connection to remote host closed 네임서버오류 햇빛소년 2011.04.10 55309
179 su 명령의 문제점 햇빛소년 2011.10.04 54653
178 httpd 스크립트 - /etc/rc.d 햇빛소년 2011.05.01 51811
177 ModSecurity-Apache 설치, Lua, readline 햇빛소년 2013.01.07 51532
176 [1원짜리 팁] hosts.deny 햇빛소년 2011.05.11 51435
175 [Mysql] password설정 및 변경, root 비번 잃어버렸을 경우 변경법 햇빛소년 2011.03.20 51422
174 DCC로 안티스팸 기능 확장하기 햇빛소년 2011.03.18 51328
173 MySQL에러[Warning] IP address '211.154.154.171' could not be resolved: no reverse address mapping. 햇빛소년 2011.05.09 51323
172 SURBL을 이용해 스팸 정확도 극대화하기 file 햇빛소년 2011.04.14 50988
171 MYSQL / 필드내 특정 문자열 치환하는 mysql 명령문 햇빛소년 2011.03.26 50687
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 Next
/ 10