zoukankan      html  css  js  c++  java
  • 浅触selinux(持续更新)

    ls -lZ 查看selinux权限情况

    chcon命令

      修改对象(文件)的安全上下文,比如:用户、角色、类型、安全级别。也就是将每个文件的安全环境变更至指定环境。使用--reference选项时,把指定文件的安全环境设置为与参考文件相同。chcon命令位于/usr/bin/chcon

    Gammar

    chcon [选项]... 环境 文件...
    chcon [选项]... [-u 用户] [-r 角色] [-l 范围] [-t 类型] 文件...
    chcon [选项]... --reference=参考文件 文件...

    Option

    -h, --no-dereference:影响符号连接而非引用的文件。
        --reference=参考文件:使用指定参考文件的安全环境,而非指定值。
    -R, --recursive:递归处理所有的文件及子目录。
    -v, --verbose:为处理的所有文件显示诊断信息。
    -u, --user=用户:设置指定用户的目标安全环境。
    -r, --role=角色:设置指定角色的目标安全环境。
    -t, --type=类型:设置指定类型的目标安全环境。
    -l, --range=范围:设置指定范围的目标安全环境。

    以下选项是在指定了-R选项时被用于设置如何穿越目录结构体系。如果您指定了多于一个选项,那么只有最后一个会生效。

    -H:如果命令行参数是一个通到目录的符号链接,则遍历符号链接。

    -L:遍历每一个遇到的通到目录的符号链接。-P:不遍历任何符号链接(默认)。--help:显示此帮助信息并退出。

    --version:显示版本信息并退出。

    Example:
    chcon -u system_u
    loki.log # 修改loki.log 文件的安全上下文,角色的值




    restorecon命令
    恢复SELinux文件属性即恢复文件的安全上下文。

    Grammar


    restorecon [-iFnrRv] [-e excludedir ] [-o filename ] [-f filename | pathname...]


    Option


    -i:忽略不存在的文件。
    -f:infilename 文件 infilename 中记录要处理的文件。
    -e:directory 排除目录。
    -R/-r:递归处理目录。
    -n:不改变文件标签。
    -o/outfilename:保存文件列表到 outfilename,在文件不正确情况下。
    -v:将过程显示到屏幕上。
    -F:强制恢复文件安全语境。

    Example:

     restorecon -R /var/www/html/  # 使用restorecon来恢复网页主目录中所有文件的SELinux配置信息(如果目标为一个目录,可以添加-R参数递归)

    sestatus 命令 

    -v Verbose check of process and file contexts.
    -b Display current state of booleans.

     seinfo 命令 

     查询SELinux的策略提供多少相关规则,一个主体进程能否读取到目标文件资源的重点是在于SELinux的策略以及策略内的各项规则,然后再通过该规则的定义去处理各项目标文件的安全上下文,尤其是“类型”部分。

    GRAMMAR:

    seinfo [OPTIONS] [EXPRESSION] [POLICY ...]

    EXPRESSIONS:
    -c[NAME], --class[=NAME] print object classes
    --sensitivity[=NAME] print sensitivities
    --category[=NAME] print categories
    -t[NAME], --type[=NAME] print types (no aliases or attributes)
    -a[NAME], --attribute[=NAME] print type attributes
    -r[NAME], --role[=NAME] print roles
    -u[NAME], --user[=NAME] print users
    -b[NAME], --bool[=NAME] print conditional booleans
    --constrain print constrain statements
    --initialsid[=NAME] print initial SIDs
    --fs_use[=TYPE] print fs_use statements
    --genfscon[=TYPE] print genfscon statements
    --netifcon[=NAME] print netif contexts
    --nodecon[=ADDR] print node contexts
    --permissive print permissive types
    --polcap print policy capabilities
    --portcon[=PORT] print port contexts
    --protocol=PROTO specify a protocol for portcons
    --all print all of the above


    OPTIONS:
    -x, --expand show more info for specified components
    --stats print useful policy statistics
    -l, --line-breaks print line breaks in constrain statements
    -h, --help print this help text and exit
    -V, --version print version information and exit

    For component options, if NAME is provided, then only show info for
    NAME. Specifying a name is most useful when used with the -x option.
    If no option is provided, display useful policy statistics (-s).

    The default source policy, or if that is unavailable the default binary
    policy, will be opened if no policy is provided.

     EXAMPLE:

     seinfo -b  # list all tyep(bool)

    semanage命令

    查询与修改SELinux默认目录的安全上下文。

    GRAMMAR:

    semanage {login|user|port|interface|fcontext|translation} -l
    semanage fcontext -{a|d|m} [-frst] file_spec

    OPTION:

    -l:查询。
    fcontext:主要用在安全上下文方面。
    -a:增加,你可以增加一些目录的默认安全上下文类型设置。
    -m:修改。
    -d:删除。

    getsebool命令

    查询SElinux策略内各项规则的布尔值。

    getsebool [-a] [布尔值条款]

    -a:列出目前系统上面的所有布尔值条款设置为开启或关闭值。

    setsebool命令

    修改SElinux策略内各项规则的布尔值。

    setsebool [-P] 布尔值=[0|1]  # 1 是开启, 0 是关闭

    -P:直接将设置值写入配置文件,该设置数据将来会生效的。

    setsebool -P allow_ftpd_anon_write=1  # 允许vsvtp匿名用户写入权限

    setsebool -P ftp_home_dir 1  # 如果你希望你的ftp用户可以访问自己的家目录的话,需要开启

    sesearch命令

    使用seinfo命令可以查询SELinux的策略提供多少相关规则,如果查到的相关类型或者布尔值,想要知道详细规则时,使用sesearch命令查询。

    sesearch [-a] [-s 主体类型] [-t 目标类型] [-b 布尔值]

    -a:列出该类型或布尔值的所有相关信息
    -t:后面还要接类型,例如 -t httpd_t
    -b:后面还要接布尔值的规则,例如 -b httpd_enable_ftp_server

    sesearch --all |grep "logrotate"

    REFER TO:

    http://man.linuxde.net/

  • 相关阅读:
    CF1539 VP 记录
    CF1529 VP 记录
    CF875C National Property 题解
    CF1545 比赛记录
    CF 1550 比赛记录
    CF1539E Game with Cards 题解
    CF1202F You Are Given Some Letters... 题解
    vmware Linux虚拟机挂载共享文件夹
    利用SOLR搭建企业搜索平台 之九(solr的查询语法)
    利用SOLR搭建企业搜索平台 之四(MultiCore)
  • 原文地址:https://www.cnblogs.com/Cong0ks/p/9440757.html
Copyright © 2011-2022 走看看