1:SELinux概念一:简介SELinux:SecureEnhancedLinux是由美国国家安全局(NSA=TheNationalSecurityAgency)和SCC(SecureComputingCorporation)共同开发的Linux强制访问控制安全模块。2000年在GNUGPL下发布,Linux内核2.6版本后集成到内核中特点:MAC环境下的策略规则决定控制的严格程度MAC环境下可以限制进程的策略用来定义哪些受限进程可以使用的资源(文件和端口)默认情况下,未明确允许的行为将被拒绝2:typeview:cat/etc/selinux/configSELINUXTYPE=targetedminimummls目标进程受到保护:保护本质上是为了阻止进程为所欲为。在一定范围内活动。不在范围内的进程将不被管理3:targetedSELinux:一切皆对象安全上下文五要素:User:表示登录系统的用户类型,如root、user_u、system_u,大部分本地进程是空闲的(unconfined)ProcessRole:定义文件、进程和用户的用途:文件:object_r,进程和用户:system_rType:指定数据类型,规则中定义了哪个进程类型访问哪个文件敏感度:需要限制访问,由组织定义的分级安全级别,如unclassified、secret、top、secret,一个对象只有一个敏感度,分为0-15级,s0最低,Target策略默认使用s0Category:对于一个具体组织,分为无等级类别,如FBISecret,NSAsecret,一个object可以有多个类别,c0-c1023,共1024个类别,Targetpolicy不使用类别,如:system_u:object_r:admin_home_t:s0type:admin_home_t根据文件类型,可以指定策略。多服务public:public_content_tll-Z查看真实类型semanagefcontext-l查看预期的安全上下文2:SELinux策略1:启用/禁用SELinuxstatus:enforcing:mandatory,everyrestrictedprocessmustberestrictedpermissive:allowed,eachrestrictedprocessviolation操作不会被禁止,但会记录在审计日志中disabled:DisableSELinux相关命令:getenforce:获取selinux的当前状态查看:sestatus这个命令比较清楚setenforce0|10:setPermissive1:将此命令设置为强制执行。该命令不能设置为disabledsemanagefcontext-l查看预期的安全上下文:配置文件:/etc/selinux/configSELinux策略转换并生效1:enforcing->permissive使用命令setenforce0permissive--->enforcing使用命令setenforce12:permissive或enforcing转换为disabled。需要在配置文件/etc/selinux/config中将SELINUX=enforing改为SELINUX=disabled,重启电脑才能生效。3Disabled转为permissive或enforcing需要在配置文件/etc/selinux/config中将SELINUX=disabled改为SELINUX=enforcing,重启电脑后生效。2:ManageFileLabels这部分是一道rhce考试题,需要掌握文件标签的变化:chcon–tfilelabelfilechangedirectorylabelchcon–rtfilelabelfile恢复文件标签到正常状态:1)restoreconfile2)参考正常值:semanagefcontext–l修改标签:chcon–tfilelabelfilerestoredirectorylabel:restorecon–RDIRECTORYaddSecuritycontext:相当于在安全上下文库中添加记录,restorecon恢复文件的标签,即就是,从引用库的标签中,然后对semanage做相应的修改fcontext–a–thttpd_sys_content_t'/testdir(/.*)?'三:manageportlabel查看端口标签semanageport–l查看系统默认端口和对应的应用添加端口:semanageport-a-tport_label-ptcp|udpPOR删除端口标签:semanageport-d-tport_label-ptcp|udpPORTsemanageport-d-thttp_port_t-ptcp9527修改端口标签:此端口必须定义,未定义的标签不可更改四:管理SELinux布尔值开关查看:semanageboolean–lchangechangeboolvalue(临时作用):setboolhttpd_enable_homedirson临时作用permanentchangestorage1ison,0isoffsetbool–Phttpd_enable_homedir=1
