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.md

268 lines
20 KiB
Markdown
Raw Normal View History

2024-08-10 00:27:39 -04:00
---
2024-08-10 01:39:55 -04:00
title: "macOS Security Overview"
2024-08-10 00:27:39 -04:00
date: 2024-08-09
tags: ['macOS', 'Security']
author: kimg45
---
2024-08-11 02:12:52 -04:00
macOS comes equipped with many security features to keep you safe. Check out the [Apple Platform Security](https://support.apple.com/guide/security/welcome/web) page for more detail about the security features in a Mac. This guide assumes you're running on official Apple hardware that's officially supported by the latest stable version of macOS.
2024-08-08 13:57:56 -04:00
## FileVault
2024-08-08 14:27:03 -04:00
By default, your macOS install is encrypted, but it will automatically unlock on boot. Turning on [FileVault](https://support.apple.com/guide/mac-help/protect-data-on-your-mac-with-filevault-mh11785/mac) 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.
2024-08-15 04:47:03 -04:00
All encryption keys are handled by the Secure Enclave and are never exposed to the CPU.
2024-08-15 05:04:32 -04:00
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.
2024-08-08 14:27:03 -04:00
## App Sandbox
The [App Sandbox](https://developer.apple.com/documentation/security/app_sandbox/protecting_user_data_with_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, so it's not possible for you to enable it or modify the entitlements since they are defined in the signature.
The App Sandbox is designed to limit the damage to your system in the event an app is exploited, however it can't protect against malicious developers since they can just disable or weaken the sandbox in a future update if they want. For protection against malicious developers, you'll need to install apps from the App Store where the sandbox 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"
2024-09-24 13:38:50 -04:00
![Activity Monitor](/images/activity-monitor.png)
2024-08-08 14:27:03 -04:00
2024-09-03 20:12:03 -04:00
You can check whether an app is sandboxed and what entitlements it has *before* running it by running the command
2024-08-08 14:27:03 -04:00
``` zsh
2024-09-29 03:46:54 -04:00
codesign -dvvv --entitlements - <path to your app>
2024-08-08 14:27:03 -04:00
```
If the app is sandboxed, you will see
``` zsh
[Key] com.apple.security.app-sandbox
[Value]
[Bool] true
2024-08-08 14:38:21 -04:00
```
2024-08-10 23:58:38 -04:00
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](https://pewpewthespells.com/blog/blocking_code_injection_on_ios_and_os_x.html). Ideally, this should say "Yes."
2024-08-10 23:58:20 -04:00
2024-08-08 14:38:21 -04:00
## Hardened Runtime
2024-08-13 07:56:45 -04:00
The [Hardened Runtime](https://developer.apple.com/documentation/security/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 a flag 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.
2024-08-08 14:38:21 -04:00
Unlike the App Sandbox, the Hardened Runtime is required in order for an app to be notarized and so you'll be warned by Gatekeeper if an app doesn't use it. While this warning is bypassable, you should be cautious and investigate a bit more before running it.
Check if an app is using the Hardened Runtime before running it with the command
``` zsh
2024-09-29 03:46:54 -04:00
codesign --display --verbose <path to your app>
2024-08-08 14:38:21 -04:00
```
2024-08-08 15:06:38 -04:00
You will see `flags=0x10000(runtime)` if it's enabled.
## Gatekeeper
2024-08-10 21:20:53 -04:00
[Gatekeeper](https://support.apple.com/guide/security/gatekeeper-and-runtime-protection-sec5599b66df/web) stops you from running apps that aren't notarized. 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.
2024-08-08 15:06:38 -04:00
2024-09-19 17:34:12 -04:00
While the Gatekeeper warning can be easily bypassed by going to **Privacy & Security** in the settings and clicking open, it's useful since it presents an unavoidable warning when you try to run an app for the first time that's not downloaded from the App Store.
2024-08-08 16:21:55 -04:00
2024-08-14 23:33:36 -04:00
You can change [Gatekeeper settings](https://support.apple.com/en-us/102445) to only allow apps downloaded from the App Store if you choose. It will still be bypassable but it will stop apps from being run that aren't from the app store without you explicitly allowing it.
2024-08-14 15:39:41 -04:00
## Apps vs Other Executables
Gatekeeper, the App Sandbox, and the Hardened Runtime only apply to apps and not other types of executable files, so when installing non-apps, you should be extremely careful. If possible, avoid installing non-app software altogether or install it in a virtual machine.
2024-08-14 23:29:10 -04:00
## Systemwide Permissions
2024-09-17 13:49:38 -04:00
macOS has permissions that apply to all software across the system, called Transparency, Consent and Control (TCC). These can be found under [Privacy & Security](https://support.apple.com/guide/mac-help/change-privacy-security-settings-on-mac-mchl211c911f/mac) in the Settings.
2024-08-14 23:29:10 -04:00
2024-09-03 18:22:50 -04:00
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.
2024-08-08 16:21:55 -04:00
## 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.
2024-08-10 21:21:59 -04:00
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.
2024-08-08 16:21:55 -04:00
2024-08-11 23:08:21 -04:00
Apple also issues revocations for notarization tickets, which are detected with encrypted online OCSP checks. Blocking these checks will make you more vulnerable to malicious apps.
2024-08-10 00:02:29 -04:00
## System Integrity Protection
2024-08-10 21:32:01 -04:00
[SIP](https://support.apple.com/guide/security/system-integrity-protection-secb7ea06b49/web) protects [system files](https://support.apple.com/en-us/102149) from being changed, even by the root user. Since it's protecting your base system files, you should **never** disable it even temporarily if you want the best security.
On Apple Silicon Macs, it's combined with [Kernel Integrity Protection](https://support.apple.com/guide/security/operating-system-integrity-sec8b776536b/web#sec41bf3cd61) to protect kernel memory from being exploited.
2024-08-10 00:02:29 -04:00
## Secure Boot
2024-08-26 06:00:13 -04:00
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](https://support.apple.com/guide/security/boot-process-secac71d5623/web) that starts with the Boot ROM burned into the Secure Enclave at the factory as the first step.
2024-08-10 00:02:29 -04:00
2024-08-16 07:31:46 -04:00
Macs let you reduce your boot security by setting a [security policy](https://support.apple.com/guide/security/startup-disk-security-policy-control-sec7d92dc49f/web). It's best to leave it set to Full Security.
2024-08-13 07:42:02 -04:00
A unique feature of Mac computers is that you can set a different [security policy](https://support.apple.com/guide/security/startup-disk-security-policy-control-sec7d92dc49f/web) 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.
2024-08-10 00:05:00 -04:00
## DMA Protection
2024-08-10 00:10:26 -04:00
Mac computers have an [IOMMU](https://support.apple.com/guide/security/direct-memory-access-protections-seca4960c2b5/1/web/1) so that each DMA agent, including PCIe and Thunderbolt ports, can only access memory explicitly mapped for their use.
## Lockdown Mode
2024-09-27 22:26:50 -04:00
[Lockdown Mode](https://support.apple.com/en-us/105120) 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.
2024-08-10 00:14:39 -04:00
## Custom umask
2024-08-10 21:35:25 -04:00
macOS is a Unix-like, so certain security practices carry over from other systems. Consider setting a [stricter umask](https://support.apple.com/en-us/101914).
2024-08-10 00:17:12 -04:00
## Terminal Security
2024-08-10 00:17:12 -04:00
2024-08-10 00:25:37 -04:00
To prevent other apps from detecting what you type in Terminal, enable [Secure Keyboard Entry](https://support.apple.com/guide/terminal/use-secure-keyboard-entry-trml109/mac).
Avoid giving the Terminal full disk access so that unsandboxed apps can't abuse it to gain unauthorized access.
2024-08-10 00:25:37 -04:00
## Standard User Account
2024-08-10 21:24:24 -04:00
When you first set up your Mac, you will create an Administrator account that has powerful access to the OS. [Apple recommends](https://support.apple.com/guide/mac-help/set-up-your-mac-to-be-secure-flvlt003/mac) limiting the number of Administrator accounts on your machine and using a Standard user account when Aministrator privileges aren't needed.
2024-08-10 00:37:40 -04:00
You can [hide an administrator account](https://support.apple.com/en-us/102099) 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](https://support.apple.com/guide/mac-help/set-your-mac-to-log-out-when-not-in-use-mchlp2443/14.0/mac/14.0).
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:
``` zsh
for user in $(ls /Users | grep -v 'Shared'); do
sudo chmod 700 /Users/"$user"
done
```
2024-08-10 01:07:59 -04:00
## Lock Screen Security
Make sure you [require users to login](https://support.apple.com/guide/mac-help/set-up-your-mac-to-be-secure-flvlt003/mac#mchlpf5777a4) and set your Mac to [require a password](https://support.apple.com/guide/mac-help/require-a-password-after-waking-your-mac-mchlp2270/14.0/mac/14.0) after waking up.
2024-08-10 01:12:14 -04:00
Use the Control + Command + Q keyboard shortcut to lock your screen any time you leave your computer.
2024-08-10 00:51:45 -04:00
## Automatically Empty Trash
You can set the trash to [automatically empty](https://support.apple.com/en-ca/guide/mac-help/mchlp1093/14.0/mac/14.0#mchl0deca7f1) every 30 days to prevent old unwanted files from sticking around.
## Show File Extensions
2024-08-10 01:00:45 -04:00
You should set Finder to always [show all file extensions](https://support.apple.com/en-ca/guide/mac-help/mchlp2304/mac) to help you see when a file is masquerading as another filetype.
## System Extensions
2024-08-10 21:17:44 -04:00
There are two types of [system extensions](https://support.apple.com/en-us/120363) 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.
2024-08-10 01:00:45 -04:00
2024-08-10 21:27:06 -04:00
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**.
2024-08-10 01:26:11 -04:00
## Apps Requiring Admin
Be careful installing apps that require Administrator privileges to run, you're giving them a lot of power in your system.
2024-08-10 10:24:31 -04:00
**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.
2024-08-29 11:44:22 -04:00
.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.
2024-08-11 20:01:18 -04:00
2024-08-10 10:24:31 -04:00
## Firewall
2024-08-10 23:52:08 -04:00
macOS comes with a built-in [firewall](https://support.apple.com/guide/mac-help/change-firewall-settings-on-mac-mh11783/mac). 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.
2024-09-29 03:43:24 -04:00
To block an app from the Terminal, run the command
```zsh
/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.
2024-08-10 23:52:08 -04:00
## Disable AirDrop and Handoff
2024-08-10 23:53:12 -04:00
You can disable [AirDrop and Handoff](https://support.apple.com/guide/mac-help/change-airdrop-handoff-settings-mchl6a407f99/mac) to better protect yourself against nearby threats. 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."
2024-08-14 23:48:53 -04:00
## Bluetooth
2024-08-10 23:53:12 -04:00
2024-08-10 23:56:19 -04:00
Bluetooth adds extra attack surface for nearby adversaries, so if that fits your threat model then you should [disable it](https://support.apple.com/guide/mac-help/turn-bluetooth-on-or-off-blth1008/mac).
2024-08-14 23:48:19 -04:00
Note that Macs support [BLE Privacy](https://support.apple.com/guide/security/bluetooth-security-sec82597d97e/web#sec18ee64d9d) 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.
2024-08-14 23:47:28 -04:00
2024-08-19 01:10:42 -04:00
Apple Bluetooth accessories update their firmware automatically without the need for third party software.
2024-08-10 23:56:19 -04:00
## Hardware Microphone Disconnect
2024-08-14 17:32:21 -04:00
Macs feature a [hardware disconnect](https://support.apple.com/en-gb/guide/security/secbbd20b00b/1/web/1) 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.
2024-08-22 04:43:26 -04:00
## Camera
The built-in camera in Macs uses an indicator light that shows when the camera is on. According to [Apple](https://support.apple.com/en-us/102177):
>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.
2024-08-14 17:32:21 -04:00
## 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](https://support.apple.com/en-ca/guide/mac-help/mchlpx1065/mac).
2024-08-14 23:36:34 -04:00
Apps installed through the App Store can be set to [automatically update](https://support.apple.com/en-ca/guide/app-store/fir9b01adda3/mac) themselves as well.
2024-08-15 00:08:19 -04:00
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.
2024-08-14 23:36:34 -04:00
## Encrypted Backups
2024-08-14 23:39:12 -04:00
If you choose to backup your Mac, you should do so with [Time Machine](https://support.apple.com/en-us/104984) and not a third party program. You should [encrypt your backups](https://support.apple.com/guide/mac-help/keep-your-time-machine-backup-disk-secure-mh21241/mac) for added security.
## Encrypted Disk Image
2024-08-14 23:42:37 -04:00
In macOS, if you want to encrypt some files you should create an [encrypted disk image](https://support.apple.com/guide/disk-utility/create-a-disk-image-dskutl11888/mac#dsku7bb3d28c) to store them in using Disk Utility.
2024-08-14 23:51:52 -04:00
You can also [add a checksum](https://support.apple.com/guide/disk-utility/add-a-checksum-to-a-disk-image-dskutl1019/22..6/mac/14.0) and [verify it later](https://support.apple.com/guide/disk-utility/verify-a-disk-images-data-corrupted-utility-dskutl15186/22..6/mac/14.0) to ensure data integrity.
## iCloud Security
If you use iCloud, you should enable [Advanced Data Protection](https://support.apple.com/en-us/108756) so that your files are E2EE.
2024-09-24 13:29:03 -04:00
You can also add a [security key](https://support.apple.com/en-us/102637) to your Apple Account for extra protection.
2024-08-14 23:55:56 -04:00
## Touch ID
2024-08-15 00:21:03 -04:00
Macs support [Touch ID](https://support.apple.com/guide/mac-help/use-touch-id-mchl16fbf90a/mac) 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.
## Network Security
Prefer networks that support [WPA3](https://support.apple.com/en-us/102766#security) and avoid networks that use deprecated protocols.
2024-08-15 04:53:59 -04:00
Avoid connecting to [hidden networks](https://support.apple.com/en-us/102766#hiddennetwork) as they require your device to broadcast the network SSID which could be used to fingerprint you and identify the networks you connect to.
2024-09-17 03:16:27 -04:00
You can [randomize your MAC address](https://support.apple.com/en-gb/guide/mac-help/mh11935/15.0/mac/15.0#mchldb2b7302) in Network settings. Set it to rotating and you'll periodically get a new one.
2024-08-15 04:53:59 -04:00
## Securely Erase Your Mac
2024-09-24 13:29:03 -04:00
To completely wipe your Mac securely, use the [Erase All Content and Settings](https://support.apple.com/en-us/102664) 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.
2024-08-15 05:08:06 -04:00
## Rosetta 2
2024-08-15 10:51:26 -04:00
Apple silicon Macs offer [Rosetta 2](https://support.apple.com/en-us/102527), a translation layer that lets you run Intel apps on an ARM Mac. Since it allows you to run more software than you could otherwise run, installing Rosetta 2 increases your attack surface and should be avoided unless you absolutely need it.
## Keychain
2024-08-15 10:59:50 -04:00
[Keychain](https://support.apple.com/guide/security/keychain-data-protection-secb0694df1a/1/web/1) is the secure keystore in macOS. There's also a built-in [password manager](https://support.apple.com/en-us/105115) that can securely keep track of your passwords and generate new secure passwords.
## iCloud Private Relay
2024-08-24 08:39:00 -04:00
With an iCloud+ subscription, you will have access to [Private Relay](https://developer.apple.com/icloud/prepare-your-network-for-icloud-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.
## 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.
2024-09-03 18:25:28 -04:00
This adds a lot of attack surface to your machine, so it's best to avoid installing developer tools unless you absolutely need them.
## Accessibility
2024-09-29 03:33:14 -04:00
Never give software [accessibility permissions](https://support.apple.com/en-my/guide/mac-help/mh43185/mac) 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
2024-09-29 03:35:55 -04:00
If you don't need ssh, [turn it off](https://support.apple.com/en-gb/guide/mac-help/mchlp1066/15.0/mac/15.0). The same goes for [remote desktop](https://support.apple.com/en-gb/guide/mac-help/mh11851/15.0/mac/15.0) and [remote application scripting](https://support.apple.com/en-mide/guide/mac-help/mchlp1398/mac).