news 2026/7/22 10:58:41

Linux命令-seinfo(SELinux 策略信息查询 —— 查看安全上下文与策略规则)

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Linux命令-seinfo(SELinux 策略信息查询 —— 查看安全上下文与策略规则)

Linux命令-seinfo(SELinux 策略信息查询 —— 查看安全上下文与策略规则)

    • 🔰 简介
      • 安装位置
    • 📖 语法
    • ⚙️ 选项
    • 💡 示例
      • 示例 1:查看 SELinux 策略统计
      • 示例 2:列出与 Web 服务相关的 SELinux 类型
      • 示例 3:列出 SELinux 用户和角色
      • 示例 4:列出所有布尔值及其当前状态
      • 示例 5:列出 SELinux 类别和属性
      • 示例 6:查看网络端口上下文
      • 示例 7:完整查看所有策略信息
    • ⚠️ 注意
      • SELinux 相关工具集
      • seinfo vs sesearch 使用场景
      • 发行版差异
      • SELinux 状态检查
    • 📝 总结
    • 📚 相关命令

快速参考seinfo是 SELinux 策略分析工具集(setools-console)中的一员,用于从二进制 SELinux 策略文件中查询和提取类型(type)、角色(role)、用户(user)、布尔值(boolean)、类别(class)等安全策略信息。它是理解 SELinux 策略结构问题排查的重要工具。需要安装setools-console包。


🔰 简介

SELinux(Security-Enhanced Linux)是 Linux 内核中的强制访问控制(MAC)系统。策略文件(policy.33或类似)以二进制格式存储,seinfo可以解析并展示这些策略的构成要素,帮助管理员了解当前系统中定义了哪些安全类型、哪些角色、哪些访问控制类别。

安装位置

# seinfo 命令路径whichseinfo# 输出:/usr/bin/seinfo# 查看所属软件包rpm-qf/usr/bin/seinfo2>/dev/null# 输出:setools-console-3.3.8-4.el7.x86_64dpkg-S/usr/bin/seinfo2>/dev/null# 输出:setools: /usr/bin/seinfo# 安装# CentOS/RHEL 7sudoyuminstallsetools-console# CentOS/RHEL 8+sudodnfinstallsetools-console# Debian/Ubuntusudoaptinstallsetools# SELinux 策略文件位置ls/etc/selinux/targeted/policy/# 输出:policy.33 (或其他版本号)# 路径模式:/etc/selinux/{策略名}/policy/policy.{版本号}

📖 语法

seinfo [选项] [策略文件]

如果不指定策略文件,默认使用当前活动的 SELinux 策略。


⚙️ 选项

选项说明
-a, --all显示所有信息(类型、角色、用户、布尔值、类别等)
-t, --type列出所有 SELinux 类型(最常用
-r, --role列出所有 SELinux 角色
-u, --user列出所有 SELinux 用户
-b, --bool列出所有 SELinux 布尔值及其状态
-c, --class列出所有对象类别(文件、进程、套接字等)
--attribute列出类型属性
--sens列出敏感度级别
--cat列出类别(MLS/MCS 使用)
-x, --expand展开显示(属性成员详细列表)
--stats显示策略统计信息
-A, --avtab显示访问向量表(规则数较多)
--polcap显示策略能力
--genfscon显示 genfscon 语句
--netifcon显示网络接口上下文
--nodecon显示节点上下文
--portcon显示端口上下文

💡 示例

示例 1:查看 SELinux 策略统计

# 查看策略整体统计信息seinfo--stats# 输出示例:# Statistics for policy file: /etc/selinux/targeted/policy/policy.33# Policy Version & Type: v.33 (binary, MLS)## Classes: 134 Permissions: 436# Sensitivities: 1 Categories: 1024# Types: 4875 Attributes: 252# Users: 9 Roles: 14# Booleans: 316 Cond. Expr.: 361# Allow: 113267 Neverallow: 0# Auditallow: 16 Dontaudit: 2017# Type_trans: 20039 Type_change: 74# Type_member: 0 Role allow: 36# Role_trans: 389 Range_trans: 682# Constraints: 106 Validatetrans: 0# Initial SIDs: 27 Fs_use: 34# Genfscon: 109 Portcon: 587# Netifcon: 0 Nodecon: 0# Permissives: 78 Polcap: 5# Ibpkeycon: 0 Ibendportcon: 0

示例 2:列出与 Web 服务相关的 SELinux 类型

# 列出所有类型并过滤 http 相关项seinfo-t|grephttp# 输出示例:# httpd_t# httpd_sys_content_t# httpd_sys_script_t# httpd_sys_script_exec_t# httpd_sys_rw_content_t# httpd_sys_content_rw_t# httpd_user_content_t# httpd_user_script_t# httpd_user_script_exec_t# httpd_cache_t# httpd_tmp_t# httpd_log_t# httpd_config_t# httpd_exec_t# httpd_unit_file_t# ...# 统计 http 相关类型数量seinfo-t|grephttp|wc-l# 输出:47

示例 3:列出 SELinux 用户和角色

# 列出所有 SELinux 用户seinfo-u# 输出:# Users: 9# guest_u# root# staff_u# sysadm_u# system_u# unconfined_u# user_u# xguest_u# *# 列出所有 SELinux 角色seinfo-r# 输出:# Roles: 14# auditadm_r# dbadm_r# guest_r# logadm_r# nx_server_r# object_r# secadm_r# staff_r# sysadm_r# system_r# unconfined_r# user_r# webadm_r# xguest_r# 查看特定角色的详细信息seinfo-ruser_r-x# 输出:# user_r# Dominated Roles:# user_r# Types:# virt_content_t# httpd_user_content_t# ...

示例 4:列出所有布尔值及其当前状态

# 列出所有布尔值seinfo-b|head-20# 输出:# Boolean: 316# abrt_handle_event# abrt_upload_watch_anon_write# antivirus_can_scan_system# antivirus_use_jit# auditadm_exec_content# authlogin_nsswitch_use_ldap# authlogin_radius# authlogin_yubikey# awstats_purge_apache_log_files# boinc_execmem# ...# 查看 httpd 相关布尔值seinfo-b|grephttpd# 输出:# httpd_anon_write# httpd_builtin_scripting# httpd_can_check_spam# httpd_can_connect_ftp# httpd_can_connect_ldap# httpd_can_connect_mythtv# httpd_can_connect_zabbix# httpd_can_network_connect# httpd_can_network_connect_cobbler# httpd_can_network_connect_db# httpd_can_network_memcache# httpd_can_network_relay# httpd_can_sendmail# httpd_dbus_avahi# httpd_dbus_sssd# httpd_dontaudit_search_dirs# httpd_enable_cgi# httpd_enable_ftp_server# httpd_enable_homedirs# httpd_execmem# httpd_graceful_shutdown# httpd_manage_ipa# httpd_mod_auth_ntlm_winbind# httpd_mod_auth_pam# httpd_read_user_content# httpd_run_ipa# httpd_run_preupgrade# httpd_run_stickydir# httpd_serve_cobbler_files# httpd_setrlimit# httpd_ssi_exec# httpd_sys_script_anon_write# httpd_tmp_exec# httpd_tty_comm# httpd_unified# httpd_use_cifs# httpd_use_fusefs# httpd_use_gpg# httpd_use_nfs# httpd_use_opencryptoki# httpd_use_sasl# httpd_verify_dns

示例 5:列出 SELinux 类别和属性

# 列出所有对象类别seinfo-c# 输出:# Classes: 134# appletalk_socket# association# atmpvc_socket# atm_svc_socket# ax25_socket# blk_file# bridge_socket# can_socket# cap_userns# cap2_userns# chr_file# context# db_blob# db_buffer# db_column# ...# 展开查看类型属性(查看哪些类型属于某个属性域)seinfo-adomain-x|head-30# 输出:# domain# abrt_dump_oops_t# abrt_handle_event_t# abrt_helper_t# abrt_retrace_worker_t# abrt_t# abrt_watch_log_t# abrt_upload_watch_t# accountsd_t# ...

示例 6:查看网络端口上下文

# 查看所有端口安全上下文定义seinfo--portcon|head-20# 输出示例:# Portcon: 587# portcon tcp 0-511 system_u:object_r:reserved_port_t:s0# portcon tcp 80 system_u:object_r:http_port_t:s0# portcon tcp 443 system_u:object_r:http_port_t:s0# portcon tcp 22 system_u:object_r:ssh_port_t:s0# portcon tcp 25 system_u:object_r:smtp_port_t:s0# portcon tcp 3306 system_u:object_r:mysqld_port_t:s0# portcon tcp 5432 system_u:object_r:postgresql_port_t:s0# portcon udp 53 system_u:object_r:dns_port_t:s0# portcon udp 123 system_u:object_r:ntp_port_t:s0# ...# 查看与 http 相关的端口定义seinfo--portcon|grephttp# 输出:# portcon tcp 80 system_u:object_r:http_port_t:s0# portcon tcp 443 system_u:object_r:http_port_t:s0# portcon tcp 488 system_u:object_r:http_port_t:s0# ...

示例 7:完整查看所有策略信息

# 查看所有策略信息(输出非常多)seinfo-a2>/dev/null|head-50# 输出(前50行):# ...# 包含类型、角色、用户、布尔值、类别的完整列表## 建议重定向到文件查看:seinfo-a>/tmp/selinux_policy_full.txt2>&1wc-l/tmp/selinux_policy_full.txt# 输出:15234 /tmp/selinux_policy_full.txt

⚠️ 注意

SELinux 相关工具集

# setools-console 包含的常用工具rpm-qlsetools-console|grep/usr/bin/# 输出:# /usr/bin/seinfo # 策略信息查询# /usr/bin/sesearch # 策略规则搜索(查找 allow/auditallow 等规则)# /usr/bin/seinfo # 策略信息查询# /usr/bin/sediff # 策略比较(版本差异)# /usr/bin/sechecker # 策略安全检查# 这些工具的关系:# seinfo → 告诉你有多少类型、多少角色、多少类别# sesearch → 查找特定的 allow 规则(如 httpd_t 能访问哪些文件)# sediff → 比较两个策略版本之间的差异

seinfo vs sesearch 使用场景

# seinfo:宏观了解策略结构seinfo-t|grephttpd# httpd 有哪些类型?seinfo-b|grephttpd# httpd 有哪些布尔值开关?# sesearch:微观查询具体规则sesearch-A-shttpd_t-thttpd_sys_content_t# 查询 httpd_t 类型对 httpd_sys_content_t 类型的访问规则sesearch-A-shttpd_t|grep"read"# 查询 httpd_t 类型的读权限

发行版差异

# CentOS/RHEL 7# SELinux 默认 enforcing,策略版本 v.28 ~ v.33# setools-console 包名# CentOS/RHEL 8/9# SELinux 默认 enforcing,策略版本 v.33# setools-console 包名不变sudodnfinstallsetools-console# Fedora# 包管理相同,但 Selinux 策略更激进sudodnfinstallsetools-console# Debian/Ubuntu# SELinux 默认不安装(使用 AppArmor 替代)sudoaptinstallselinux-basics selinux-policy-defaultsudoaptinstallsetools# 注意:Ubuntu 中 seinfo 输出通常为空(SELinux 未启用)

SELinux 状态检查

# 检查 SELinux 是否启用getenforce# 输出:Enforcing / Permissive / Disabledsestatus# 输出:# SELinux status: enabled# SELinuxfs mount: /sys/fs/selinux# SELinux root directory: /etc/selinux# Loaded policy name: targeted# Current mode: enforcing# Mode from config file: enforcing# Policy MLS status: enabled# Policy deny_unknown status: allowed# Max kernel policy version: 33# 如果 SELinux 为 Disabled,seinfo 无法读取策略sudoseinfo--stats# 输出:error: cannot open policy file: /etc/selinux/targeted/policy/policy.33

📝 总结

seinfo是 SELinux 策略分析工具链中的"宏观查看器":

  • 核心功能:解析二进制 SELinux 策略文件,展示类型、角色、用户、布尔值、类别等元数据
  • 最常用选项-t(类型)、-b(布尔值)、--stats(统计摘要)
  • 与 sesearch 的关系seinfo告诉你"有什么",sesearch告诉你"怎么运作"
  • 前提条件:SELinux 必须处于 Enforcing 或 Permissive 模式,且安装了setools-console
  • 实用价值:排查 SELinux 引起的服务异常时,先用seinfo -t | grep 服务名了解相关安全类型

📚 相关命令

命令说明
sesearch查询 SELinux 策略中的具体访问规则
semanageSELinux 策略管理(端口/文件上下文/布尔值配置)
restorecon恢复文件默认 SELinux 上下文
chcon修改文件 SELinux 上下文
getenforce查看 SELinux 当前模式
setenforce切换 SELinux 运行模式
setsebool设置 SELinux 布尔值
audit2why将 AVC 拒绝日志翻译为人类可读的解释
audit2allow根据拒绝日志生成允许规则
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/22 10:57:51

ESP32-S3 屏幕显示图片格式对显示速度的影响 png rgb565

ESP32-S3 屏幕显示图片格式对显示速度的影响 png rgb565针对 Cardputer(ESP32-S3 SPI RGB565 屏)固件中的图标绘制。 相对耗时为经验量级,非精确 benchmark;同尺寸对比以 RGB565 已在 RAM、pushImage 为 1。1. 结论先看 同尺寸下…

作者头像 李华
网站建设 2026/7/22 10:56:10

DAY 11 机器学习建模与评估

浙大疏锦行 一、知识点 1.1 数据预处理 1.1.1 导入所需要的包 (边写代码边添加包) import pandas as pd #用于数据处理和分析,可处理表格数据 import numpy as np #用于数值计算,提供高效数组操作 import matplotlib.pyplot as plt #用于绘制各类图表…

作者头像 李华
网站建设 2026/7/22 10:54:49

CUDA进阶学习与深入

什么需要错误处理? CUDA API 调用可能失败,常见原因: 内存不足 设备不存在 内核启动失败 驱动程序错误 不检查错误会导致: 程序崩溃 结果错误 难以调试 CUDA 错误类型 typedef enum cudaError { cudaSuccess 0, …

作者头像 李华
网站建设 2026/7/22 10:54:35

知识的边界:从Anthropic与阿里风波看大模型安全攻防战

知识的边界:从Anthropic与阿里风波看大模型安全攻防战 在人工智能飞速迭代的今天,我们往往沉迷于模型参数的规模、推理速度的快慢以及多模态能力的炫酷,却容易忽视一个隐藏在冰山之下的核心议题——模型知识产权的保护与数据边界的界定。近期…

作者头像 李华