博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
selinux-网络服务安全
阅读量:4320 次
发布时间:2019-06-06

本文共 2461 字,大约阅读时间需要 8 分钟。

一、显示和设置selinux

 [root@localhost ~]# vim /etc/sysconfig/selinux //强制模式 许可模式 禁用模式

[root@localhost ~]# getenforce //查看当前SElinux的状态
[root@localhost ~]# setenforce //可以在强制模式(1) 许可模式(0)之间切换
[root@localhost ~]# sestatus //列出目录SELinux使用的策略(Policy)

 

二、查看安全上下文

进程

ps -ZC sshd

文件

ll -dZ /var/www/html/

端口

[root@localhost ~]# yum provides *bin/semanage

[root@localhost ~]# semanage port -l |egrep '\<80\>'
http_port_t tcp 80, 443, 488, 8008, 8009, 8443

三、修改selinux 上下文

cp 、 mv 对上下文影像

cp:会重新生成安全上下文

 mv:安全上下文则不变

Chcon:

1、  chcon –R httpd_sys_content_t  /webdata

2、  chcon –R –reference /var/www/html   /webdata     //将前一个文件的上下文作为参考,赋给/webdata

 

例:ftp匿名上传

  1. 文件系统的权限
    [root@localhost ~]# mkdir /var/ftp/music
    [root@localhost ~]# setfacl -m u:ftp:rwx /var/ftp/music/
    2. FTP服务器配置
    anonymous_enable=YES
    anon_upload_enable=YES
    anon_mkdir_write_enable=YES

修改上下文

chcon –R  public_content_rw_t  /var/ftp/music/

3.查看

[root@localhost ~]# getsebool -a | grep ftpd

4.设置

[root@localhost ~]# setsebool -P allow_ftpd_anon_write on

5.启动

[root@localhost ~]# systemctl start vsftpd

 

四、监控selinux策略冲突情况

部署selinux日志分析工具

1、安装setroubleshoot-server软件包,才能将SELinux消息发送至/var/log/messages

setroubleshoot-server侦听/var/log/audit/audit.log中的审核信息并将简短摘要发送至/var/log/messages

该摘要包括SELinux冲突的唯一标识符(UUIDs),可用于收集更多信息

 

2、systemctl  restart  rsyslog

Systemctl  restart  auditd

3、测试

[root@localhost ~]# vim /tmp/index.html

[root@localhost ~]# mv /tmp/index.html /var/www/html/

[root@localhost ~]# curl http://localhost

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

<html><head>

<title>403 Forbidden</title>

</head><body>

<h1>Forbidden</h1>

<p>You don't have permission to access /index.html                 //权限拒绝,不能访问

on this server.</p>

</body></html>

4、查看/var/log/messages

 

Nov 16 02:03:35 localhost setroubleshoot: SELinux is preventing httpd from open access on the file /var/www/html/index.html. For complete SELinux messages run: sealert -l f1243e54-7eb7-458b-a260-ca1f8ff61070

……………………………………………………..

If you want to fix the label.

/var/www/html/index.html default label should be httpd_sys_content_t.

Then you can run restorecon.

Do

# /sbin/restorecon -v /var/www/html/index.html

………………..

[root@localhost ~]# /sbin/restorecon -v /var/www/html/index.html

/sbin/restorecon reset /var/www/html/index.html context unconfined_u:object_r:user_tmp_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0

5、访问成功

[root@localhost ~]# curl http://localhost

 

------------------------------

this is a test web !

 

转载于:https://www.cnblogs.com/sxchengchen/p/7840698.html

你可能感兴趣的文章
Selector的2种样式
查看>>
Mac 卸载mysql
查看>>
php-fpm用socket连接
查看>>
.net core跨域传递cookie
查看>>
SpringMVC <mvc:view-controller path=""/>标签
查看>>
adobe flash player升级coredump分析
查看>>
pycharm快捷键、经常使用设置、配置管理
查看>>
element-ui table 最后一行合计,单元格合并
查看>>
.NET 常用加密、解密& 数字签名算法
查看>>
开博声明
查看>>
FileReader读取文件
查看>>
逆向-攻防世界-re2-cpp-is-awesome
查看>>
Oracle分割字符串 REGEXP_SUBSTR用法
查看>>
O/R Mapping实际开发经验之谈(转)
查看>>
今天才知道原来我还没弄清楚js中全局变量和局部变量的定义...
查看>>
用户心理特征
查看>>
【z05】聪明的质检员
查看>>
【5001】n皇后问题
查看>>
【codeforces 796D】Police Stations
查看>>
数据库事务与锁详解
查看>>