macOS MACF - Mandatory Access Control Framework
Basic Information
MACF का मतलब है अनिवार्य पहुँच नियंत्रण ढांचा, जो एक सुरक्षा प्रणाली है जो ऑपरेटिंग सिस्टम में निर्मित है ताकि आपके कंप्यूटर की सुरक्षा में मदद मिल सके। यह कठोर नियम निर्धारित करके काम करता है कि कौन या क्या सिस्टम के कुछ हिस्सों, जैसे फ़ाइलें, अनुप्रयोग और सिस्टम संसाधन, तक पहुँच सकता है। इन नियमों को स्वचालित रूप से लागू करके, MACF सुनिश्चित करता है कि केवल अधिकृत उपयोगकर्ता और प्रक्रियाएँ विशिष्ट क्रियाएँ कर सकें, जिससे अनधिकृत पहुँच या दुर्भावनापूर्ण गतिविधियों का जोखिम कम हो जाता है।
ध्यान दें कि MACF वास्तव में कोई निर्णय नहीं लेता क्योंकि यह केवल क्रियाओं को अवरुद्ध करता है, यह निर्णय नीति मॉड्यूल (कर्नेल एक्सटेंशन) पर छोड़ देता है जिसे यह कॉल करता है जैसे AppleMobileFileIntegrity.kext
, Quarantine.kext
, Sandbox.kext
, TMSafetyNet.kext
और mcxalr.kext
।
Flow
प्रक्रिया एक syscall/mach ट्रैप करती है
संबंधित फ़ंक्शन कर्नेल के अंदर कॉल किया जाता है
फ़ंक्शन MACF को कॉल करता है
MACF उन नीति मॉड्यूलों की जाँच करता है जिन्होंने अपनी नीति में उस फ़ंक्शन को हुक करने के लिए अनुरोध किया
MACF संबंधित नीतियों को कॉल करता है
नीतियाँ संकेत करती हैं कि वे क्रिया की अनुमति देती हैं या अस्वीकार करती हैं
Apple एकमात्र है जो MAC Framework KPI का उपयोग कर सकता है।
Labels
MACF लेबल का उपयोग करता है जिन्हें फिर नीतियों द्वारा जाँच की जाएगी कि क्या उन्हें कुछ पहुँच प्रदान करनी चाहिए या नहीं। लेबल संरचना की घोषणा का कोड यहाँ पाया जा सकता है, जिसे फिर struct ucred
के अंदर यहाँ cr_label
भाग में उपयोग किया जाता है। लेबल में फ्लैग और MACF नीतियों द्वारा पॉइंटर्स आवंटित करने के लिए उपयोग किए जा सकने वाले स्लॉट की संख्या होती है। उदाहरण के लिए, Sandbox कंटेनर प्रोफ़ाइल की ओर इशारा करेगा।
MACF Policies
एक MACF नीति कुछ कर्नेल संचालन में लागू करने के लिए नियम और शर्तें परिभाषित करती है।
एक कर्नेल एक्सटेंशन एक mac_policy_conf
संरचना को कॉन्फ़िगर कर सकता है और फिर इसे mac_policy_register
को कॉल करके पंजीकृत कर सकता है। यहाँ से:
यह नीतियों को कॉन्फ़िगर करने वाले कर्नेल एक्सटेंशन की पहचान करना आसान है, mac_policy_register
कॉल की जांच करके। इसके अलावा, एक्सटेंशन के डिस्सेम्बल की जांच करने पर mac_policy_conf
स्ट्रक्चर भी पाया जा सकता है।
ध्यान दें कि MACF नीतियों को डायनामिकली भी पंजीकृत और अपंजीकृत किया जा सकता है।
mac_policy_conf
के मुख्य क्षेत्रों में से एक है mpc_ops
। यह क्षेत्र निर्दिष्ट करता है कि नीति किन ऑपरेशनों में रुचि रखती है। ध्यान दें कि इनमें सैकड़ों हैं, इसलिए सभी को शून्य करना संभव है और फिर केवल उन पर ध्यान केंद्रित करना जो नीति में रुचि रखते हैं। यहां से:
Almost all the hooks will be called back by MACF when one of those operations are intercepted. However, mpo_policy_*
hooks are an exception because mpo_hook_policy_init()
एक कॉलबैक है जो पंजीकरण के समय (तो mac_policy_register()
के बाद) कॉल किया जाता है और mpo_hook_policy_initbsd()
को लेट पंजीकरण के दौरान कॉल किया जाता है जब BSD उपप्रणाली सही तरीके से प्रारंभ हो चुकी होती है।
Moreover, the mpo_policy_syscall
hook can be registered by any kext to expose a private ioctl style call interface. Then, a user client will be able to call mac_syscall
(#381) specifying as parameters the policy name with an integer code and optional arguments.
For example, the Sandbox.kext
uses this a lot.
Checking the kext's __DATA.__const*
is possible to identify the mac_policy_ops
structure used when registering the policy. It's possible to find it because its pointer is at an offset inside mpo_policy_conf
and also because the amount of NULL pointers that will be in that area.
Moreover, it's also possible to get the list of kexts that have configured a policy by dumping from memory the struct _mac_policy_list
which is updated with every policy that is registered.
MACF Initialization
MACF को बहुत जल्दी प्रारंभ किया जाता है। इसे XNU के bootstrap_thread
में सेट किया जाता है: ipc_bootstrap
के बाद mac_policy_init()
को कॉल किया जाता है जो mac_policy_list
को प्रारंभ करता है और कुछ ही क्षणों बाद mac_policy_initmach()
को कॉल किया जाता है। अन्य चीजों के बीच, यह फ़ंक्शन सभी Apple kexts को प्राप्त करेगा जिनके Info.plist में AppleSecurityExtension
कुंजी है जैसे ALF.kext
, AppleMobileFileIntegrity.kext
, Quarantine.kext
, Sandbox.kext
और TMSafetyNet.kext
और उन्हें लोड करता है।
MACF Callouts
यह MACF के लिए कॉलआउट्स को कोड में ढूंढना सामान्य है जैसे: #if CONFIG_MAC
कंडीशनल ब्लॉक्स। इसके अलावा, इन ब्लॉक्स के अंदर mac_proc_check*
को कॉल करने के लिए MACF को अनुमतियों की जांच करने के लिए कॉल किया जाता है। इसके अलावा, MACF कॉलआउट्स का प्रारूप है: mac_<object>_<opType>_opName
।
The object is one of the following: bpfdesc
, cred
, file
, proc
, vnode
, mount
, devfs
, ifnet
, inpcb
, mbuf
, ipq
, pipe
, sysv[msg/msq/shm/sem]
, posix[shm/sem]
, socket
, kext
.
The opType
is usually check which will be used to allow or deny the action. However, it's also possible to find notify
, which will allow the kext to react to the given action.
You can find an example in https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/bsd/kern/kern_mman.c#L621:
Then, it's possible to find the code of mac_file_check_mmap
in https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/security/mac_file.c#L174
जो MAC_CHECK
मैक्रो को कॉल कर रहा है, जिसका कोड यहां पाया जा सकता है।
जो सभी पंजीकृत मैक नीतियों को उनके कार्यों को कॉल करते हुए और आउटपुट को त्रुटि चर में संग्रहीत करते हुए जाएगा, जिसे केवल mac_error_select
द्वारा सफलता कोड के द्वारा ओवरराइड किया जा सकेगा, इसलिए यदि कोई जांच विफल होती है तो पूरी जांच विफल हो जाएगी और क्रिया की अनुमति नहीं दी जाएगी।
हालांकि, याद रखें कि सभी MACF कॉलआउट केवल क्रियाओं को अस्वीकार करने के लिए उपयोग नहीं किए जाते हैं। उदाहरण के लिए, mac_priv_grant
मैक्रो MAC_GRANT को कॉल करता है, जो यदि कोई नीति 0 के साथ उत्तर देती है तो अनुरोधित विशेषाधिकार को प्रदान करेगा:
priv_check & priv_grant
ये कॉल्स उन (दर्जनों) privileges की जांच और प्रदान करने के लिए हैं जो bsd/sys/priv.h में परिभाषित हैं।
कुछ कर्नेल कोड priv_check_cred()
को bsd/kern/kern_priv.c से प्रक्रिया के KAuth क्रेडेंशियल्स के साथ और एक प्रिविलेज कोड के साथ कॉल करेगा जो mac_priv_check
को कॉल करेगा यह देखने के लिए कि क्या कोई नीति denies प्रिविलेज देने से रोकती है और फिर यह mac_priv_grant
को कॉल करेगा यह देखने के लिए कि क्या कोई नीति privilege
को प्रदान करती है।
proc_check_syscall_unix
यह हुक सभी सिस्टम कॉल्स को इंटरसेप्ट करने की अनुमति देता है। bsd/dev/[i386|arm]/systemcalls.c
में घोषित फ़ंक्शन unix_syscall
को देखना संभव है, जिसमें यह कोड है:
जो कॉलिंग प्रक्रिया bitmask में जांच करेगा कि क्या वर्तमान syscall को mac_proc_check_syscall_unix
को कॉल करना चाहिए। इसका कारण यह है कि syscalls इतनी बार कॉल किए जाते हैं कि हर बार mac_proc_check_syscall_unix
को कॉल करने से बचना दिलचस्प है।
ध्यान दें कि फ़ंक्शन proc_set_syscall_filter_mask()
जो एक प्रक्रिया में bitmask syscalls सेट करता है, Sandbox द्वारा सैंडबॉक्स किए गए प्रक्रियाओं पर मास्क सेट करने के लिए कॉल किया जाता है।
एक्सपोज़ MACF syscalls
MACF के साथ इंटरैक्ट करना संभव है कुछ syscalls के माध्यम से जो security/mac.h में परिभाषित हैं:
संदर्भ
Last updated