{"id":244256,"date":"2022-06-16T10:05:30","date_gmt":"2022-06-16T02:05:30","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=244256"},"modified":"2022-06-04T02:00:52","modified_gmt":"2022-06-03T18:00:52","slug":"selinux-operating-mode","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/selinux-operating-mode.html","title":{"rendered":"\u8bf4\u8bf4SELinux\u5de5\u4f5c\u539f\u5219"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nSELinux\u4f7f\u7528\u6240\u8c13\u7684\u59d4\u4efb\u5f0f\u8bbf\u95ee\u63a7\u5236\uff08Mandatory Access Control,MAC\uff09,\u53ef\u4ee5\u6839\u636e\u7279\u5b9a\u7684\u7a0b\u5e8f\u548c\u7279\u5b9a\u7684\u6587\u4ef6\u8d44\u6e90\u8fdb\u884c\u6743\u9650\u7684\u7ba1\u7406\u3002\u5373\u4f7f\u662froot\u7528\u6237\uff0c\u5728\u4f7f\u7528\u4e0d\u540c\u7684\u7a0b\u5e8f\u65f6\uff0c\u4f60\u6240\u80fd\u83b7\u5f97\u7684\u6743\u9650\u4e0d\u4e00\u5b9a\u662froot\uff0c\u9700\u8981\u6839\u636e\u7a0b\u5e8f\u7684\u8bbe\u5b9a\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u4e00\u3001SELinux\u7684\u5de5\u4f5c\u6a21\u5f0f<\/strong><\/div>\n

1\u3001\u4e3b\u4f53\uff08Subject\uff09
\n SELinux\u4e3b\u8981\u7ba1\u7406\u7684\u5c31\u662f\u7a0b\u5e8f\u3002\u53ef\u4ee5\u76f8\u6bd4\u4e8eprocess\u3002
\n2\u3001\u76ee\u6807\uff08Object\uff09
\n \u4e3b\u4f53\u7a0b\u5e8f\u8bbf\u95ee\u7684\u76ee\u6807\u8d44\u6e90\u4e00\u822c\u5c31\u662f\u6587\u4ef6\u7cfb\u7edf\u3002
\n3\u3001\u7b56\u7565\uff08Policy\uff09
\n \u8bbf\u95ee\u5b89\u5168\u6027\u7b56\u7565\uff0c\u89c4\u5219\u7b49\u3002CentOS6.x\u63d0\u4f9btargeted\u548cmls\u4e24\u4e2a\u4e3b\u8981\u7684\u7b56\u7565\u3002
\n targeted\uff1a\u9488\u5bf9\u7f51\u7edc\u670d\u52a1\u9650\u5236\u8f83\u591a\uff0c\u9488\u5bf9\u672c\u673a\u9650\u5236\u8f83\u5c11\uff0c\u662f\u9ed8\u8ba4\u7684\u7b56\u7565\u3002
\n mls\uff1a\u5b8c\u6574\u7684SELinux\u9650\u5236\uff0c\u9650\u5236\u65b9\u9762\u8f83\u4e3a\u4e25\u683c\u3002
\n4\u3001\u5b89\u5168\u6027\u73af\u5883\uff08Security Context\uff09
\n \u7c7b\u4f3c\u4e8e\u6587\u4ef6\u7cfb\u7edf\u7684rwx\u3002<\/p>\n

\"\"<\/p>\n

\u67e5\u770b\/root\u4e0b\u9762\u6587\u4ef6\u7684\u5b89\u5168\u6027\u73af\u5883<\/p>\n

# ls -Z\r\n-rw-------. root root system_u:object_r:admin_home_t:s0 anaconda-ks.cfg\r\n-rw-r--r--. root root system_u:object_r:admin_home_t:s0 install.log\r\n-rw-r--r--. root root system_u:object_r:admin_home_t:s0 install.log.syslog<\/pre>\n

Identify:role:type
\n\u8eab\u4efd\u8bc6\u522b:\u89d2\u8272:\u7c7b\u578b<\/p>\n

\u8eab\u4efd\u8bc6\u522b\uff08Identify\uff09\uff1a\u76f8\u5f53\u4e8e\u8d26\u53f7\u65b9\u9762\u7684\u8eab\u4efd\u8bc6\u522b\u3002\u4e3b\u8981\u7684\u8eab\u4efd\u8bc6\u522b\u6709\uff1a
\n1\u3001root\uff1a\u8868\u793aroot\u7684\u8d26\u53f7\u8eab\u4efd
\n2\u3001system_u\uff1a\u8868\u793a\u7cfb\u7edf\u7a0b\u5e8f\u65b9\u9762\u7684\u8bc6\u522b\uff0c\u901a\u5e38\u5c31\u662f\u7a0b\u5e8f
\n3\u3001user_u\uff1a\u4ee3\u8868\u7684\u662f\u4e00\u822c\u7528\u6237\u8d26\u53f7\u76f8\u5173\u7684\u8eab\u4efd<\/p>\n

\u89d2\u8272\uff08Rule\uff09\uff1a\u901a\u8fc7\u89d2\u8272\u5b57\u6bb5\uff0c\u6211\u4eec\u53ef\u4ee5\u77e5\u9053\u8fd9\u4e2a\u6570\u636e\u662f\u4ee3\u8868\u7a0b\u5e8f\u3001\u6587\u4ef6\u8d44\u6e90\u8fd8\u662f\u7528\u6237\u3002
\n1\u3001object_r\uff1a\u4ee3\u8868\u7684\u662f\u6587\u4ef6\u6216\u76ee\u5f55\u7b49\u8d44\u6e90\uff0c\u8fd9\u662f\u6700\u5e38\u89c1\u7684\u3002
\n2\u3001system_r\uff1a\u4ee3\u8868\u7684\u5c31\u662f\u7a0b\u5e8f\u4e86\u3002\u4e0d\u8fc7\u4e00\u822c\u7528\u6237\u4e5f\u4f1a\u88ab\u6307\u5b9a\u6210\u4e3asystem_r<\/p>\n

\u7c7b\u578b\uff08Type\uff09\uff1a\u4e00\u4e2a\u4e3b\u4f53\u7a0b\u5e8f\u80fd\u5426\u8bfb\u53d6\u5230\u8fd9\u4e2a\u6587\u4ef6\u8d44\u6e90\uff0c\u4e0e\u7c7b\u578b\u5b57\u6bb5\u6709\u5173
\n1\u3001Type\uff1a\u5728\u6587\u4ef6\u8d44\u6e90\u4e2d\u88ab\u79f0\u4e3a\u7c7b\u578b
\n2\u3001Domain\uff1a\u5728\u4e3b\u4f53\u7a0b\u5e8f\u4e2d\u88ab\u79f0\u4e3a\u57df<\/p>\n

\u4e8c\u3001SELinux\u7684\u542f\u52a8\u3001\u5173\u95ed\u4e0e\u67e5\u770b<\/strong><\/div>\n

\u4e09\u79cd\u6a21\u5f0f\uff1a<\/p>\n

# SELINUX= can take one of these three values:\r\n#    enforcing - SELinux security policy is enforced.\r\n#    permissive - SELinux prints warnings instead of enforcing.\r\n#    disabled - No SELinux policy is loaded.<\/pre>\n

\u67e5\u770b\uff1agetenforce
\n\u4e34\u65f6\u8bbe\u7f6e\uff1asetenforce \u30100 | 1\u3011
\n\u6c38\u4e45\u4fee\u6539\uff1avim \/etc\/selinux\/config\uff0c\u518d\u91cd\u65b0\u542f\u52a8<\/p>\n

\u6ce8\u610f\uff1asetenforce\u65e0\u6cd5\u5728disabled\u7684\u6a21\u5f0f\u4e0b\u8fdb\u884c\u5207\u6362<\/p>\n

\u4e09\u3001SELinux\u7684Type\u5b57\u6bb5\u4fee\u6539<\/strong><\/div>\n

\u590d\u5236\u6587\u4ef6\u7684Type\u5b57\u6bb5\u4f1a\u7ee7\u627f\u81ea\u76ee\u6807\u76ee\u5f55\uff0c\u800c\u79fb\u52a8\u6587\u4ef6\u4fdd\u6301\u4e0d\u53d8\u3002
\n1\u3001chcon<\/p>\n

chcon [-R] [-t type] [-u user] [-r role] \u6587\u4ef6
\nchcon [-R] --reference=\u8303\u4f8b\u6587\u4ef6 \u6587\u4ef6
\n-R\uff1a\u8fde\u540c\u8be5\u76ee\u5f55\u4e0b\u7684\u5b50\u76ee\u5f55\u4e5f\u8fdb\u884c\u4fee\u6539
\n-t\uff1a\u540e\u9762\u63a5\u5b89\u5168\u6027\u73af\u5883\u7684\u7c7b\u578b\u5b57\u6bb5
\n-u\uff1a\u540e\u9762\u63a5\u8eab\u4efd\u8bc6\u522b
\n-r\uff1a\u540e\u9762\u63a5\u89d2\u8272
\n--reference\uff1a\u53c2\u8003\u8303\u4f8b\u6587\u4ef6<\/p>\n

2\u3001restorecon<\/p>\n

restorecon [-Rv] \u6587\u4ef6\u6216\u76ee\u5f55
\n-R\uff1a\u8fde\u540c\u5b50\u76ee\u5f55\u4fee\u6539
\n-v\uff1a\u8fc7\u7a0b\u663e\u793a\u5230\u5c4f\u5e55<\/p>\n

3\u3001semanage<\/p>\n

semanage {login|user|port|interface|fcontext|translation} -l
\nsemanage fcontext -{a|d|m} [-frst] file_spec<\/p>\n

fcontext\uff1a\u4e3b\u8981\u7528\u4f5c\u5b89\u5168\u6027\u73af\u5883\u65b9\u9762\uff0c-l\u4e3a\u67e5\u8be2
\n-a\uff1a\u589e\u52a0
\n-m\uff1a\u4fee\u6539
\n-d\uff1a\u5220\u9664<\/p>\n

\u56db\u3001SELinux\u7b56\u7565\u5185\u7684\u89c4\u5219\u5e03\u5c14\u503c\u4fee\u8ba2<\/strong><\/div>\n

1\u3001\u7b56\u7565\u67e5\u9605<\/p>\n

seinfo [-Atrub]
\n-A\uff1a\u5217\u51faSELinux\u7684\u72b6\u6001
\n-t\uff1a\u6240\u6709\u7c7b\u522b
\n-r\uff1a\u6240\u6709\u89d2\u8272\u79cd\u7c7b
\n-u\uff1a\u6240\u6709\u8eab\u4efd\u8bc6\u522b\u79cd\u7c7b
\n-b\uff1a\u6240\u6709\u89c4\u5219\u7684\u79cd\u7c7b\uff08\u5e03\u5c14\u503c\uff09<\/p>\n

\u8be6\u7ec6\u7684\u89c4\u5219\uff1a
\nsesearch [--all] [-s \u4e3b\u4f53\u7c7b\u522b] [-t \u76ee\u6807\u7c7b\u522b] [-b \u5e03\u5c14\u503c]<\/p>\n

2\u3001\u5e03\u5c14\u503c\u7684\u67e5\u8be2\u4e0e\u4fee\u6539<\/p>\n

\u67e5\u9605\uff1a
\ngetsebool [-a] [\u5e03\u5c14\u503c\u6761\u6b3e]
\n\u4fee\u6539\uff1a
\ngetsebool [-P] \u5e03\u5c14\u503c=[0|1]<\/p>\n

\u4e94\u3001SELinux\u65e5\u5fd7\u6587\u4ef6\u8bb0\u5f55\u6240\u9700\u7684\u670d\u52a1<\/strong><\/div>\n

\u4f7f\u7528setsebool\u3001chcon\u3001restorecon\u7b49\u90fd\u662f\u4e3a\u4e86\u5f53\u67d0\u4e9b\u7f51\u7edc\u670d\u52a1\u65e0\u6cd5\u6b63\u5e38\u63d0\u4f9b\u76f8\u5173\u529f\u80fd\u65f6\u624d\u9700\u8981\u8fdb\u884c\u4fee\u6539\u7684\u4e00\u4e9b\u547d\u4ee4\u52a8\u4f5c\u3002CentOS\u63d0\u4f9b\u4e86\u51e0\u4e2a\u68c0\u6d4b\u7684\u670d\u52a1\u6765\u68c0\u6d4b\u5904\u7406\u5728\u767b\u5f55SELinux\u65f6\u4ea7\u751f\u7684\u9519\u8bef\uff0c\u90a3\u5c31\u662fauditd\u3001setroubleshoot\u3002<\/p>\n

1\u3001setroubleshoot\uff1a\u5c06\u9519\u8bef\u4fe1\u606f\u5199\u5165\/var\/log\/message\u4e0e\/var\/log\/setroubleshoot\/*<\/p>\n

\u5b89\u88c5\u5e76\u542f\u52a8\u8be5\u670d\u52a1<\/p>\n

yum install setroubleshoot setroubleshoot-server\r\nservice auditd restart<\/pre>\n

\u8fd0\u4f5c\u65b9\u5f0f\uff1a
\n1\u3001\u5148\u7531auditd\u53bb\u547c\u53ebaudispd\u670d\u52a1
\n2\u3001\u7136\u540eaudispd\u670d\u52a1\u53bb\u542f\u52a8sedispatch\u7a0b\u5e8f
\n3\u3001sedispatch\u518d\u5c06\u539f\u672c\u7684auditd\u4fe1\u606f\u8f6c\u6210setroubleshoot\u7684\u4fe1\u606f\uff0c\u8fdb\u4e00\u6b65\u50a8\u5b58\u4e0b\u6765\u3002
\n\u4ee5httpd\u7a0b\u5e8f\u4ea7\u751f\u7684\u9519\u8bef\u4e3a\u4f8b
\n2\u3001\u4f7f\u7528E-mail\u6216\u5728\u547d\u4ee4\u5217\u4e0a\u9762\u76f4\u63a5\u63d0\u4f9bsetroubleshoot\u9519\u8bef\u4fe1\u606f
\n3\u3001SELinux\u9519\u8bef\u514b\u670d\u7684\u603b\u7ed3
\n\u7f51\u7edc\u8fde\u63a5\u8981\u901a\u8fc7SELinux\u7684\u6743\u9650\u5224\u5b9a\u540e\u624d\u80fd\u591f\u7ee7\u7eedrwx\u7684\u6743\u9650\u5bf9\u6bd4\uff0c\u800cSELinux\u7684\u5bf9\u6bd4\u9700\u8981\u901a\u8fc7\u7b56\u7565\u7684\u5404\u9879\u89c4\u5219\u5bf9\u6bd4\u540e\u624d\u80fd\u591f\u8fdb\u884cSELinux Type\u5b89\u5168\u6027\u73af\u5883\u7684\u5bf9\u6bd4\u3002\u800c\u540e\u7eed\u7684SELinux\u7684\u4fee\u6539\u901a\u8fc7chcon\u3001restorecon\u3001setsebool\u7b49\u547d\u4ee4\u6765\u5904\u7406\u3002\u901a\u8fc7\u5206\u6790\/var\/log\/messsage\u5185\u63d0\u4f9b\u7684setroubleshoot\u7684\u4fe1\u606f\u3002
\na\u3011\u5728\u670d\u52a1\u548crwx\u6743\u9650\u90fd\u6ca1\u6709\u95ee\u9898\uff0c\u5374\u65e0\u6cd5\u6210\u529f\u7684\u4f7f\u7528\u7f51\u7edc\u670d\u52a1\u65f6\uff0c\u5148\u4f7f\u7528setenforce 0 \u8bbe\u7f6e\u4e3a\u5bbd\u5bb9\u6a21\u5f0f
\nb\u3011\u518d\u6b21\u4f7f\u7528\u8be5\u7f51\u7edc\u670d\u52a1\uff0c\u5982\u679c\u8fd9\u6837\u5c31\u80fd\u4f7f\u7528\uff0c\u5219\u95ee\u9898\u51fa\u73b0\u5728SELinux\u4e0a\u9762\uff0c\u82e5\u4ecd\u65e0\u6cd5\u4f7f\u7528\u5219\u5e94\u4ece\u5176\u4ed6\u65b9\u9762\u8003\u8651\u6392\u9519\u3002
\nc\u3011\u5206\u6790\/var\/log\/message\u4e2d\u7684\u4fe1\u606f\uff0c\u627e\u5230sealert -l\u76f8\u5173\u7684\u4fe1\u606f\u5e76\u4e14\u6267\u884c
\nd\u3011\u627e\u5230Allow Access\u7684\u5173\u952e\u8bcd\uff0c\u6309\u7167\u91cc\u9762\u7684\u52a8\u4f5c\u6765\u8fdb\u884cSELinux\u7684\u9519\u8bef\u514b\u670d\u3002
\ne\u3011\u5904\u7406\u5b8c\u6bd5\u91cd\u65b0setenforce 1\uff0c\u518d\u6b21\u6d4b\u8bd5\u7f51\u7edc\u670d\u52a1<\/p>\n","protected":false},"excerpt":{"rendered":"

1\u3001\u4e3b\u4f53\uff08Subject\uff09 SELinux\u4e3b\u8981\u7ba1\u7406\u7684\u5c31\u662f\u7a0b\u5e8f\u3002\u53ef\u4ee5\u76f8\u6bd4\u4e8eprocess\u3002 2\u3001\u76ee\u6807\uff08Objec […]<\/p>\n","protected":false},"author":310,"featured_media":244275,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-244256","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/244256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/310"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=244256"}],"version-history":[{"count":10,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/244256\/revisions"}],"predecessor-version":[{"id":244425,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/244256\/revisions\/244425"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/244275"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=244256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=244256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=244256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}