全面分析RHCE(红帽认证工程师)考试题目之 ----SELinux篇

Linux 安全保护模式

DAC,自主访问控制

MAC,强制访问控制

SELinux 

一套强化Linux安全的MAC扩展模块

美国国家安全局主导开发

SELinux的运作机制

集成Linux内核(2.6及以上)

操作系统提供可定制的策略,管理工具

[[email protected] ~]# cat /etc/redhat-release

Red Hat Enterprise Linux Server release 7.2 (Maipo)

[[email protected] ~]# uname -r

3.10.0-327.el7.x86_64

[[email protected] ~]# rpm -qa | grep -i selinux

selinux-policy-3.13.1-60.el7.noarch

libselinux-2.2.2-6.el7.x86_64

selinux-policy-targeted-3.13.1-60.el7.noarch

libselinux-utils-2.2.2-6.el7.x86_64

libselinux-python-2.2.2-6.el7.x86_64

查看当前SELinux的状态

[[email protected] ~]# sestatus

SELinux status:                 enabled

SELinuxfs mount:                /sys/fs/selinux

SELinux root directory:         /etc/selinux

Loaded policy name:             targeted

Current mode:                   permissive

Mode from config file:          enforcing

Policy MLS status:              enabled

Policy deny_unknown status:     allowed

Max kernel policy version:      28

[[email protected] ~]# ls /etc/selinux/

[[email protected] ~]# ls /sys/fs/selinux/

[[email protected] ~]# setenforce 0|1  #0:permissive 1:enforcing

[[email protected] ~]# getenforce  #查看当前SELinux状态

[[email protected] ~]# vim /etc/selinux/config #配置文件

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#     enforcing - SELinux security policy is enforced. #强制启动

#     permissive - SELinux prints warnings instead of enforcing. #宽松/允许模式

#     disabled - No SELinux policy is loaded. #禁用

SELINUX=enforcing

# SELINUXTYPE= can take one of three two values:

#     targeted - Targeted processes are protected,

#     minimum - Modification of targeted policy. Only selected processes are protected.

#     mls - Multi Level Security protection.  #提供多层次,全面的安全防护策略

SELINUXTYPE=targeted #推荐,仅保护最常见/关键的网络服务,其他不限制

SELinux策略设置

一,安全上下文

进程  ps aux -Z

目录  ls -dZ 目录名

文件  ls -lZ 文件名

[[email protected] ~]# ls -lZ /etc/passwd

-rw-r--r--. root root system_u:object_r:passwd_file_t:s0 /etc/passwd

[[email protected] ~]# ls -dZ /var/www/html/

drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html/

[[email protected] ~]# ls -dZ /var/lib/mysql/

drwxr-x--x. mysql mysql system_u:object_r:mysqld_db_t:s0 /var/lib/mysql/

[[email protected] ~]# ps aux -Z | grep httpd

system_u:system_r:httpd_t:s0    root      5965  0.1  0.4 226128  5052 ?        Ss   22:33   0:00 /usr/sbin/httpd -DFOREGROUND

system_u:system_r:httpd_t:s0    apache    5966  0.0  0.3 228212  3144 ?        S    22:33   0:00 /usr/sbin/httpd -DFOREGROUND

安全上下文的组成

用户:角色:访问类型:选项

常见访问类型

bin_t #二进制执行文件

etc_t #系统配置文件

fsadm_exec_t #文件系统管理

admin_home_t #管理员账户的宿主目录

user_home_t #普通用户的宿主目录

httpd_sys_content_t #httpd网站内容

SELinux启用后一般的操作规律

新建文件或新建目录 会继承父目录的安全上下文

[[email protected] ~]# touch /root/1.txt

[[email protected] ~]# ls -dZ /root/

dr-xr-x---. root root system_u:object_r:admin_home_t:s0 /root/

[[email protected] ~]# ls -lZ /root/1.txt

-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 /root/1.txt

拷贝时继承目标目录的安全上下文

[[email protected] ~]# cp /root/1.txt  /var/www/html/

[[email protected] ~]# ls -lZ /var/www/html/1.txt

-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/1.txt

移动时保留源文件的安全上下文

[[email protected] ~]# rm -rf /var/www/html/1.txt

[[email protected] ~]# mv /root/1.txt  /var/www/html/

[[email protected] ~]# ls -lZ /var/www/html/1.txt

-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 /var/www/html/1.txt

修改安全上下文

chcon  修改安全上下文

选项: -t:指定访问类型

-u,-r:分别用来指定用户,角色

-R:递归修改

[[email protected] ~]# ls -lZ /var/www/html/1.txt

-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 /var/www/html/1.txt

[[email protected] ~]# chcon -t httpd_sys_content_t /var/www/html/1.txt

[[email protected] ~]# ls -lZ /var/www/html/1.txt

-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/1.txt

restorecon  重置安全上下文

— 恢复为所在位置的默认上下文属性

-R:递归恢复

[[email protected] ~]# touch /root/2.txt

[[email protected] ~]# mv /root/2.txt  /var/www/html/

[[email protected] ~]# ls -lZ /var/www/html/2.txt

-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 /var/www/html/2.txt

[[email protected] ~]# restorecon /var/www/html/2.txt

[[email protected] ~]# ls -lZ /var/www/html/2.txt

-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/2.txt

二.SELinux布尔值:(功能开关)

getsebool 查看

-a 可列出所有布尔值

setsebool 设置

-P 永久更改,重启仍然有效

启用SELinux日志程序

[[email protected] ~]# rpm -qa | grep shoot

setroubleshoot-plugins-3.0.59-1.el7.noarch

setroubleshoot-3.2.24-1.1.el7.x86_64

setroubleshoot-server-3.2.24-1.1.el7.x86_64

练习:启用SELinux,允许本机的ftp服务,允许匿名用户上传和下在文件

[[email protected] ~]# yum -y install vsftpd

[[email protected] ~]# mkdir /var/ftp/sharedir

[[email protected] ~]# chmod o+w /var/ftp/sharedir/

[[email protected] ~]# cp /etc/hosts /var/ftp/sharedir/

[[email protected] ~]# vim /etc/vsftpd/vsftpd.conf

29 anon_upload_enable=YES

[[email protected] ~]# systemctl restart vsftpd

[[email protected] ~]# getsebool -a | grep ftp

[[email protected] ~]# setsebool -P ftpd_full_access=on

[[email protected] ~]# setsebool -P ftpd_anon_write=on

[[email protected] ~]# yum -y install ftp.x86_64

[[email protected] ~]# ftp 192.168.4.12

Connected to 192.168.4.12 (192.168.4.12).

220 (vsFTPd 3.0.2)

Name (192.168.4.12:root): ftp

Password:

ftp> cd sharedir

ftp> lcd /root #设定本地接受目录位置

ftp> put test.txt #上传本地文件

ftp> get hosts #下在文件

练习 启用SELinux,修改本机网站服务监听的端口8090

[[email protected] ~]# sed -i '42s/80/8090/' /etc/httpd/conf/httpd.conf

[[email protected] ~]# grep -n 8090 /etc/httpd/conf/httpd.conf

42:Listen 8090

[[email protected] ~]# systemctl restart httpd

Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

[[email protected] ~]# grep -i "setroubleshoot" /var/log/messages | tail -1

Jan  3 01:43:44 test setroubleshoot: SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket port 8090. For complete SELinux messages. run sealert -l b044047d-64e3-425b-aa88-50ffb248f814

[[email protected] ~]# sealert -l b044047d-64e3-425b-aa88-50ffb248f814 #运行日志文件提供的解决方案 在其中寻找解决办法

...

If you want to allow /usr/sbin/httpd to bind to network port 8090

Then you need to modify the port type.

Do

# semanage port -a -t PORT_TYPE -p tcp 8090

其中 PORT_TYPE 是以下之一:http_cache_port_t, http_port_t, jboss_management_port_t, jboss_messaging_port_t, ntop_port_t, puppet_port_t。

...

[[email protected] ~]# semanage port -a -t http_port_t  -p tcp 8090

[[email protected] ~]# systemctl restart httpd

[[email protected] ~]# netstat -pantu | grep httpd

tcp6       0      0 :::8090                 :::*                    LISTEN      9668/httpd

RHCE 的考试中有一道题目是:

配置SELinux

    确保您的两个虚拟机的SELinux处于强制启用模式 

    我们需要做的是在两台虚拟机器上执行如下操作:

# setenforce 1                            #配置当前SELinux状态为  enforcing (强制启动)

# getenforce                               #查看当前SELinux状态

Enforcing

# vim /etc/selinux/config         #修改配置文件 配置为 enforcing (强制启动)

# sed -n "7p" /etc/selinux/config

SELINUX=enforcing

原文地址:http://blog.51cto.com/13558754/2058355

时间: 2024-08-02 09:20:15

全面分析RHCE(红帽认证工程师)考试题目之 ----SELinux篇的相关文章

全面分析RHCE7(红帽认证工程师)考试题目之 ----配置IPv6地址,配置聚合连接篇

配置聚合连接(网卡绑定) team ,聚合连接(也称为链路聚合) 由多块网卡一起组建而成的虚拟网卡 作用1:轮询式(roundrobin)的流量负载均衡 作用2:热备份(activebackup)连接冗余 热备份配置: {"runner": {"name": "activebackup"}} man帮助辅助记忆 /example    #全文查找example #按n 跳转到下一个匹配 找到热备份配置 粘贴 一.添加team团队设备 [[emai

全面分析RHCE(红帽认证工程师)考试题目之 ----alias(自定义别名)篇

自定义命令 alias 别名设置 alias [别名名称] #查看已设计的别名 alias 别名名称 = '实际执行命令行' #定义新的别名 unalias [别名名称] #取消以设置的别名 配置文件 用户个性化配置文件 影响指定用户的bash解释环境 -/.bashrc(用户的家目录下) ,每次开启bash终端时生效 vim /root/.bashrc(root用户配置文件) 全局环境配置 影响所有用户的bash解释环境 /etc/bashrc,每次开启bash终端时生效 vim /etc/b

全面分析RHCE7(红帽认证工程师)考试题目之 ----WEB 服务器 篇

HTTP服务基础 独立Web服务 Web通信基本概念 基于B/S 服务端提供网页 浏览器下载并显示网页 Hyper Text Markup Language (HTML)超文本标记语言 Hyper Text Transfer Protocol(http)超文本传输协议 RHEL7中的Web服务 软件包:httpd 系统服务:httpd 提供的默认配置 Listen:监听地址:端口(80) ServerName:本站点注册的DNS名称 DcocumentRoot:网页根目录(/var/www/ht

全面分析RHCE7(红帽认证工程师)考试题目之 ----NFS文件共享 篇

配置NFS共享(Linux与Linux之间) Network Flie System 网络文件系统 协议:NFS(TCP/UDP 2049),RPC(TCP/UDP 111) 所需软件包:nfs-utils (默认会装) 系统服务:nfs-server 搭建基本只读NFS服务 1.检测是否装包 [[email protected] ~]# rpm -q nfs-utils nfs-utils-1.3.0-0.el7.x86_64 2.修改配置文件 /etc/exports [[email pro

CJE-Jenkins认证工程师考试预约报名流程

先决条件 考试费用150美元,需要由master/visr信用卡支付 考试全英文  哈哈哈 考试目的 通过各种渠道能够找到Jenkins的学习资料,并能够完成jenkins的配置管理,还是想全面的系统的去学习 . 证书不是目标,重要的是考试的流程. Let's 重新认识Jenkins! 预约考试(cloudbees官网) https://www.cloudbees.com/jenkins/jenkins-certification  可在此链接中下载学习指南. 预约考试 选择一个合适距离的考场

红帽认证最详细,最权威的总结大全

RHEL6 的RHCE考试分为RHCSA(RHCT)和RHCE两部分 考试时间: RHCSA 2个半小时总分300分,210分pass RHCE 2个小时 总分300分,210分pass 考试环境:考试为上机考试,在一台真实机系统中,已经预安装好虚拟机,要求所有的考试题必须在虚拟机中完成. 网络必须配置好,如果从网络不能被访问到,则考试也不能通过. 在iptables配置中如需要拒绝访问,请使用REJECT (考试过程中iptables默认策略均为ACCEPT) 考试过程中,可以选择语言环境为繁

RHCE-红帽认证工程师 腾科

RHCE-红帽认证工程师 对应证书 红帽认证工程师-RHCE(Red Hat Certified Engineer) 认证前提 同时通过RHCSA与RHCE认证 适合人群 在学习Linux系统和网络管理知识之前想掌握用户级技能的人士: 对红帽企业Linux有基本了解,并希望通过进一步的技术培训成为系统管理员的UNIX系统管理员和Linux用户: 接触Linux较少的或者没有系统学习过Linux的希望进入互联网系统运维.Linux开发.UNIX平台数据库.ERP等行业的人群. 就业方向 Linux

关于红帽认证

介绍 编辑 Redhat认证是由服务器系统领域著名的厂商--Redhat公司推出的.红帽认证分为三个层次,初级的RHCT(红帽官方在2011年1月1号,取消RHCT的考试,改为RHCSA),中级的RHCE,高级的RHCA.另外在2005年,红帽又推出了一个新的安全领域的高级认证:RHCSS. RHCSA,是红帽认证系统管理员的简称.它是Red Hat的入门级认证,通过此项认证表明你可以独立完成Red Hat Linux 本地客户的配置,包括安装调配Linux的本地使用.本地网络客户端和本地系统的

2019年上半年网络工程师考试上午试题分析

2019年上半年网络工程师考试上午试题结构分析 1.整体难度偏难:出现部分超纲题目.如位示图,有限自动机等与软件设计师的题目完全一样,对于网络工程师考试来说,确实比较难,不太可能网工的学员去学这些知识点.而且这些知识点在网工考试中的出现频度是非常低,可能就考这一次,以后都不会去考了.因此,考生也不要太担心.这类题分值整体不高,也就是2-3分.如:●某文件系统采用位示图( bitmap)记录磁盘的使用情况.若计算机系统的字长为64位,磁盘的容量为1024GB,物理块的大小为4MB,那么位示图的大小