1
0
mirror of https://github.com/PrivSec-dev/privsec.dev synced 2024-12-23 13:21:34 -05:00
privsec.dev/content/posts/macos/macOS Security Overview/index.md
Tommy 4f30fcc529
Update post
Signed-off-by: Tommy <contact@tommytran.io>
2024-11-27 07:15:23 -07:00

24 KiB
Raw Blame History

title date tags author
macOS Security Overview 2024-08-09
macOS
Security
kimg45, Tommy

macOS comes equipped with many security features to keep you safe. Check out the Apple Platform Security page for more detail about the security features in a Mac. This post assumes you're running on official Apple hardware that's officially supported by the latest stable version of macOS.

Encryption

By default, your macOS install is encrypted, but it will automatically unlock on boot. Turning on FileVault will require a user password to unlock the volume. It also makes it so that you need to enter a user password to enter recovery mode.

FileVault works with two encryption keys: the volume key and the class key. The volume key encrypts the data in your drive and with FileVualt turned on, the class key encrypts the volume key. The class key is protected by a combination of the users password and the hardware UID when FileVault is turned on, meaning that the user password is required and the key is tied to the device and can't be decrypted outside the actual hardware.

All encryption keys are handled by the Secure Enclave and are never exposed to the CPU. Swap space is also encrypted.

Your Mac is at its most secure when it's fully off and the data is at rest. Depending on your threat model, it might behoove you to turn your Mac off completely whenever you're not using it, especially since Macs do not have memory encryption.

App Sandbox

The App Sandbox is a feature that limits the access an app has to the rest of your system. Developers enable it when they sign their app.

Sandboxed apps are given their own directories in ~/Library/Containers that they have exclusive read/write access to. Unsandboxed apps can't access them unless they have root privileges.

The App Sandbox is designed to limit the damage to your system in the event an app is exploited, however it cannot protect against malicious developers since they can just disable the sandbox in a future update. For protection against malicious developers, you'll need to install apps from the App Store where having the sandbox enabled is enforced.

There are a few ways to check whether an app is sandboxed:

You can check whether running processes are sandboxed in the Activity Monitor. Right click on the columns and check "Sandbox"

Activity Monitor

You can check whether an app is sandboxed and what entitlements it has before running it by running the command

codesign -dvvv --entitlements - <path to your app>

If the app is sandboxed, you will see

    [Key] com.apple.security.app-sandbox
    [Value]
        [Bool] true

You can enable a column in Activity Monitor called "Restricted" which is a flag that prevents programs from injecting code via macOS's dynamic linker. Ideally, this should say "Yes."

Hardened Runtime

The Hardened Runtime is an optional security feature that developers can enable that makes an app more resistant to exploitation. Like the App Sandbox, it's enabled through an entitlement when the developers sign it so you aren't able to control it for apps you run. It prevents certain classes of exploits, like code injection, dynamically linked library (DLL) hijacking, and process memory space tampering.

Unlike the App Sandbox, the Hardened Runtime is required in order for an app to be notarized and so you will be warned by Gatekeeper if an app doesn't use it. While this warning is dismissable, you should be cautious and investigate a bit more before running the app.

Check if an app is using the Hardened Runtime before running it with the command

codesign --display --verbose <path to your app>

You will see flags=0x10000(runtime) if it's enabled.

Gatekeeper

Gatekeeper is a security protection which serves two purposes:

  • To warn the user about apps that aren't notarized.
  • To notify the user that you are running an app downloaded outside of the App Store the first time you run it.

Notarization is a process by which app developers submit their app to Apple to scan for malware and ensure it meets certain requirements. Among these are that it is signed with a key provided by Apple to the developer and that the Hardened Runtime is enabled. Gatekeeper also prevents the loading of unwanted plugins with benign apps by opening apps from randomized, read-only locations. Warnings about notarization can be dismissed by going to Privacy & Security in the settings and clicking open.

To prompt the user that they are running an app downloaded outside of the app store for the first time, Gatekeeper checks for the quarantine extended attribute. This attribute, however, requires filesystem support and the tool used to download the application to set it. As such, it is trivially bypassable and should not be relied upon. For example, Gatekeeper will not prompt a user if they try to run an app for the first time on a FAT32 flash drive.

Another thing to note is that when changed to only allow apps downloaded from the App Store, Gatekeeper will not warn you about apps that have been previously launched on the system and is still bypassable.

Other Executables

Gatekeeper, the App Sandbox, and the Hardened Runtime only apply to apps (packaged with the .app extension) and not other types of executables. They also do not apply to CLI utils shipped inside an app if you invoke them directly using the terminal.

Command Line Tools

If you need developer tools like Python and git, you can install Xcode and get them with automatic updates without having to install any third-party software. Alternatively, you can use the command xcode-select --install to install the tools without Xcode.

This adds a lot of attack surface to your machine, so it's best to avoid installing developer tools unless you absolutely need them.

TCC

macOS has permissions that apply to all software across the system, called Transparency, Consent and Control (TCC). These can be found under Privacy & Security in the Settings.

The Downloads, Desktop, Documents, Movies, Music, and Pictures folders for each user in particular are protected by permissions and thus are more secure than other places you might save your files. Consider using these folders for particularly sensitive data.

TCC doesn't have temporary permissions, so it can be useful to reset all premissions for an app at once. To do this, first find the app's bundle ID by running the command:

osascript -e 'id of app "[name of app]"'

Reset the permissions with the command:

sudo tccutil reset All [app.bundle.id]

It is important to note that TCC is not a panacea, especially with unsandboxed app. TCC only protects a very limited number of directories, and unsandboxed apps can abuse their file system access to attack each other. For example, TCC does not protect ~/.zshrc, allowing unsandboxed apps to inject their own commands to the file, which the Terminal app will execute at launch. If the user grants the terminal to all files on the system, then a malicious unsandboxed app can also gain access to all files on the system through the Terminal app. As such, it is crucial that you only give the minimum amount of privileges to apps, including ones written by Apple.

XProtect

XProtect is the built-in antivirus software in macOS. Like all AV, it's a last line of defense after all others have been bypassed.

XProtect uses YARA signatures and is updated frequently, independent of OS updates. This is one of the many reasons you should be cautious about blocking connections to Apple servers; many of them serve a security purpose, so make sure you know what you're blocking. It can also detect unknown malware using heuristics. When it detects unkown malware, it will send information about that software to Apple so that they can update the signatures in XProtect.

Apple also issues revocations for notarization tickets, which are detected with OCSP checks over https. While OCSP checks may reveal to Apple which type of apps a user on an IP address is using, it is not recommended that you this check as it will break a very important security feature. Instead, you are better off using a commercial VPN to blend in with other Mac users.

Verified Boot

Mac computers ensure that only Apple-signed code runs from the lowest levels of the firmware to macOS itself (assuming Full Security is enabled). It accomplishes this with a chain of trust that starts with the Boot ROM burned into the Secure Enclave at the factory as the first step.

Macs let you reduce your boot security by setting a security policy. It's best to leave it set to Full Security.

A unique feature of Mac computers is that you can set a different security policy for different installs, so you could have your main macOS with Full Security set and also an Asahi Linux install set to Permissive Security and it won't affect the security of your macOS. Avoid lowering the security policy below Full Security for any operating system you require to be secure, even temporarily.

System Integrity Protection

SIP protects certain system files from being changed, even by the root user. This protection goes beyond what is provided by verified boot.

On Apple Silicon Macs, SIP is combined with Kernel Integrity Protection to protect kernel memory from being exploited.

System Extensions

There are two types of system extensions on macOS: legacy system extensions (also known as kernel extensions) and system extensions. Kernel extensions modify the actual kernel, giving the software extremely low-level access to your system. These are very dangerous and in fact you need to lower your security policy to even load them. They're being phased out more and more with every version of macOS.

Newer system extensions don't directly modify the kernel, but they use APIs that give them lower level access to your system than regular apps. You should be very cautious with these as well and only allow them when absolutely necessary.

Removing an app doesn't automatically remove the system extensions associated with it. You can use the systemextensionctl command to list and manage extensions. You may need to disable SIP before you can remove extensions.

DMA Protection

Mac computers have an IOMMU so that each DMA agent, including PCIe and Thunderbolt ports, can only access memory explicitly mapped for their use.

Lockdown Mode

Lockdown Mode is an optional security feature that disables lots of attack surface in your Mac. It may break certain things like websites or apps, but you can disable it for individual websites if you need to.

Custom umask

macOS is a Unix-like, so certain security practices carry over from other systems. Consider setting a stricter umask.

Terminal Security

To prevent other apps from detecting what you type in Terminal, enable Secure Keyboard Entry.

Avoid giving the Terminal full disk access so that unsandboxed apps can't abuse it to gain unauthorized access.

Standard User Account

When you first set up your Mac, you will create an Administrator account that has powerful access to the OS. Apple recommends limiting the number of Administrator accounts on your machine and using a Standard user account when Aministrator privileges aren't needed.

You can hide an administrator account so you don't accidentally log into it.

Also make sure to set a strong password for any accounts you make and set a time after which a user will automatically be logged out.

By default, users can read folders and files in other users' home directories, other than the Desktop, Downloads, Movies, Music, and Pictures folders. To fix this, run this in the Terminal:

for user in $(ls /Users | grep -v 'Shared'); do
sudo chmod 700 /Users/"$user"
done

Lock Screen Security

Make sure you require users to login and set your Mac to require a password after waking up.

Use the Control + Command + Q keyboard shortcut to lock your screen any time you leave your computer.

Automatically Empty Trash

You can set the trash to automatically empty every 30 days to prevent old unwanted files from sticking around.

Show File Extensions

You should set Finder to always show all file extensions to help you see when a file is masquerading as another filetype.

Apps Requiring Admin

Be careful installing apps that require Administrator privileges to run, you're giving them a lot of power in your system.

Note: When mounting a .dmg file, usually a graphic will come up asking you to move the app to your Applications folder, which will trigger an Administrator popup. The app isn't actually running, you're just moving it to the systemwide Applications folder so that all users on the system can run it. If you're not comfortable with this, you can simply drag the app anywhere else and run it.

.dmg files are just a disk image that you're mounting, similar to a virtual flash drive. These won't run any scripts on your machine, they simply allow you to copy the app to wherever you want on your machine and then run it.

.pkg files are a bit different in that they will typically run some kind of install script, which most of the time requires Administrator privileges. You should avoid .pkg files and favor apps that just give you the .app file itself.

Firewall

macOS comes with a built-in firewall. Make sure it's enabled at the very least, but you can block all incoming connections for the best security/privacy.

Avoid third-party firewalls like LittleSnitch or LuLu that require you to install a system extension. They don't cover DNS so data exfiltration is still possible.

To block an app from the Terminal, run the command

/usr/libexec/ApplicationFirewall/socketfilterfw --blockapp <path to your app>

Some software might not allow you to block it in the UI, you can use this command to bypass it.

Disable AirDrop and Handoff

You can disable AirDrop and Handoff to better protect yourself against nearby threats. Go to General > AirDrop and Handoff. Turn off "Allow Handoff between this Mac and your iCloud devices," change "Airdrop" to "No one," turn off "AirPlay Receiver," and turn on "Require password."

Bluetooth

Bluetooth adds extra attack surface for nearby adversaries, so if that fits your threat model then you should disable it.

Note that Macs support BLE Privacy to protect you against bluetooth hardware address tracking. You'll need to check with the OEM of the bluetooth accessory you're using to see if it supports this feature as well. Apple bluetooth accessories support it.

Apple Bluetooth accessories update their firmware automatically without the need for third party software.

Hardware Microphone Disconnect

Macs feature a hardware disconnect for the microphone when you close the lid. There is no such feature for the camera as it's blocked when the lid is closed anyway.

Camera

The built-in camera in Macs uses an indicator light that shows when the camera is on. According to Apple:

The camera is engineered so that it cant activate without the camera indicator light also turning on. This is how you can tell if your camera is on.

Make sure not to use a camera cover on your Mac or it might damage the screen. Only use something no thicker than a standard piece of printer paper, such as part of a sticky note, to cover the camera.

Automatic Updates

One of the most important things you can do to secure your Mac is keep it up-to-date. On macOS it's especially important since most preinstalled software like Safari updates along with the OS itself. Enable automatic updates.

Apps installed through the App Store can be set to automatically update themselves as well.

Apple makes beta updates available, however you should avoid installing them in your main system as they add extra telemetry, can be unstable, and can potentially have undiscovered security vulnerabilities.

Encrypted Backups

If you choose to backup your Mac, you should do so with Time Machine and not a third party program. You should encrypt your backups.

Encrypted Disk Image

In macOS, if you want to encrypt some files you should create an encrypted disk image to store them in using Disk Utility.

You can also add a checksum and verify it later to ensure data integrity.

iCloud Security

If you use iCloud, you should enable Advanced Data Protection so that your files are E2EE.

Note that your calendar, email, and contacts are not E2EE due to protocol limitations.

Third party apps can use E2EE, but they must explicitly opt-in to it.

If you want to be able to install apps from the App Store without enabling iCloud, you can sign in to your Apple Account from the App Store instead of System Settings.

You can also add a security key to your Apple Account for extra protection.

Touch ID

Macs support Touch ID for secure authentication without having to enter your password. This can protect against shoulder surfing or someone recording your keystrokes. The fingerprint data never leaves the device.

You can enable sudo with Touch ID by adding the following above lines with "required" in /etc/pam.d/sudo:

auth       sufficient     pam_tid.so

Network Security

Prefer networks that support WPA3 and avoid networks that use deprecated protocols.

Avoid connecting to hidden networks as they require your device to broadcast the network SSID which could be used to fingerprint you and identify the networks you connect to.

By default, macOS uses a random MAC address for each SSID. However, it also defaults to using the "Fixed" randomization mode, re-using the same MAC address for SSID instead of changing it on every connection. Essentially, this allows network operators to recognize that you are the same user that has previously connected to the network. Consider changing the randomization mode to "Rotating" depending on your threat model.

Securely Erase Your Mac

To completely wipe your Mac securely, use the Erase All Content and Settings option. This will ensure all data is securely wiped and no traces of your ownership are left on the Mac. This is important so that the next owner is able to set it up without running into issues with verification. You'll need to know an Administrator password and Apple Account password to turn off Find My if you've enabled it previously.

Keychain

Keychain is the secure keystore in macOS. Unlike the org.freedesktop.Secrets dbus implementation found in most Linux distributions, macOS's Keychain supports scoped access, allowing secrets to only be accessible by applications associated with it.

On macOS Sequoia, the Keychain Access app is hidden from launchpad. However, it still exists on the system. You can access it by running the following in the Terminal:

open /System/Library/CoreServices/Applications/Keychain Access.app

There's also a built-in password manager that can securely keep track of your passwords and generate new secure passwords.

iCloud Private Relay

With an iCloud+ subscription, you will have access to Private Relay. Private Relay uses the QUIC protocol and routes your traffic through two nodes: one run by Apple and one run by a third party so that your real IP address and your destination can't be easily correlated. Private Relay covers Safari traffic, DNS queries, and insecure http app traffic leaving your device.

Accessibility

Never give software accessibility permissions unless you absolutely need them for genuine accessibility reasons. It's not uncommon for apps to ask for these permissions for eroneous things.

Remote Management

If you don't need ssh, turn it off. The same goes for remote desktop and remote application scripting.

Configuration Profiles and Shortcuts

Configuration Profiles and Shortcuts are very powerful, so you should avoid installing or running ones made by other people. Make sure you understand everything it's doing before you install a profile or run a Shortcut.