├── .github └── FUNDING.yml ├── LICENSE └── README.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [drduh] 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This guide is a collection of techniques for improving the security and privacy of [Apple silicon](https://support.apple.com/116943) Mac computers running a [currently supported](https://support.apple.com/HT201222) version of macOS. **Using Macs with Intel CPUs leaves you open to [security vulnerabilities](https://github.com/axi0mX/ipwndfu?tab%253Dreadme-ov-file#checkm8) on the hardware level that Apple can't patch**. Apple silicon Macs are the minimum recommendation but as a general rule, newer chips are always more secure. 2 | 3 | This guide is targeted to power users who wish to adopt enterprise-standard security, but is also suitable for novice users with an interest in improving their privacy and security on a Mac. 4 | 5 | If you're securing computers for an organization, use the [official NIST guidelines for macOS](https://github.com/usnistgov/macos_security). 6 | 7 | A system is only as secure as its administrator is capable of making it. There is no one single technology, software, nor technique to guarantee perfect computer security; a modern operating system and computer is very complex, and requires numerous incremental changes to meaningfully improve one's security and privacy posture. 8 | 9 | This guide is provided on an 'as is' basis without any warranties of any kind. Only **you** are responsible if you break anything or get in any sort of trouble by following this guide. 10 | 11 | To suggest an improvement, send a pull request or [open an issue](https://github.com/drduh/macOS-Security-and-Privacy-Guide/issues). 12 | 13 | - [Basics](#basics) 14 | - [Threat modeling](#threat-modeling) 15 | * [Identify assets](#identify-assets) 16 | * [Identify adversaries](#identify-adversaries) 17 | * [Identify capabilities](#identify-capabilities) 18 | * [Identify mitigations](#identify-mitigations) 19 | - [Hardware](#hardware) 20 | - [Installing macOS](#installing-macos) 21 | * [System activation](#system-activation) 22 | * [Apple Account](#apple-account) 23 | * [App Store](#app-store) 24 | * [Virtualization](#virtualization) 25 | - [First boot](#first-boot) 26 | - [Admin and user accounts](#admin-and-user-accounts) 27 | * [Caveats](#caveats) 28 | * [Setup](#setup) 29 | - [Firmware](#firmware) 30 | - [FileVault](#filevault) 31 | - [Lockdown Mode](#lockdown-mode) 32 | - [Firewall](#firewall) 33 | * [Application layer firewall](#application-layer-firewall) 34 | * [Third party firewalls](#third-party-firewalls) 35 | * [Kernel level packet filtering](#kernel-level-packet-filtering) 36 | - [Services](#services) 37 | - [Siri Suggestions and Spotlight](#siri-suggestions-and-spotlight) 38 | - [Homebrew](#homebrew) 39 | - [DNS](#dns) 40 | * [DNS profiles](#dns-profiles) 41 | * [Hosts file](#hosts-file) 42 | * [DNSCrypt](#dnscrypt) 43 | * [Dnsmasq](#dnsmasq) 44 | - [Certificate authorities](#certificate-authorities) 45 | - [Privoxy](#privoxy) 46 | - [Browser](#browser) 47 | * [Firefox](#firefox) 48 | * [Chrome](#chrome) 49 | * [Safari](#safari) 50 | * [Other browsers](#other-browsers) 51 | * [Web browser privacy](#web-browser-privacy) 52 | - [Tor](#tor) 53 | - [VPN](#vpn) 54 | - [PGP/GPG](#pgpgpg) 55 | - [Messengers](#messengers) 56 | * [XMPP](#xmpp) 57 | * [Signal](#signal) 58 | * [iMessage](#imessage) 59 | - [Viruses and malware](#viruses-and-malware) 60 | * [Downloading Software](#downloading-software) 61 | * [App Sandbox](#app-sandbox) 62 | * [Hardened Runtime](#hardened-runtime) 63 | * [Antivirus](#antivirus) 64 | * [Gatekeeper](#gatekeeper) 65 | - [System Integrity Protection](#system-integrity-protection) 66 | - [Metadata and artifacts](#metadata-and-artifacts) 67 | - [Passwords](#passwords) 68 | - [Backup](#backup) 69 | - [Wi-Fi](#wi-fi) 70 | - [SSH](#ssh) 71 | - [Physical access](#physical-access) 72 | - [System monitoring](#system-monitoring) 73 | * [OpenBSM audit](#openbsm-audit) 74 | * [DTrace](#dtrace) 75 | * [Execution](#execution) 76 | * [Network](#network) 77 | - [Miscellaneous](#miscellaneous) 78 | - [Related software](#related-software) 79 | - [Additional resources](#additional-resources) 80 | 81 | # Basics 82 | 83 | General security best practices apply: 84 | 85 | - Create a [threat model](#threat-modeling) 86 | * What are you trying to protect and from whom? Is the adversary a three letter agency, a nosy eavesdropper on the network, or a determined [APT](https://en.wikipedia.org/wiki/Advanced_persistent_threat) orchestrating a campaign against you? 87 | * Recognize threats and how to reduce attack surface against them. 88 | 89 | - Keep the system and software up to date 90 | * Patch the operating system and all installed software regularly. 91 | * macOS system updates can be completed in the [settings](https://support.apple.com/guide/mac-help/keep-your-mac-up-to-date-mchlpx1065) and set to automatically install. You can also use the `softwareupdate` command-line utility - neither requires registering an Apple account. 92 | * Subscribe to announcement mailing lists like [Apple security-announce](https://lists.apple.com/mailman/listinfo/security-announce). 93 | 94 | - Encrypt sensitive data 95 | * In addition to [FileVault](https://support.apple.com/guide/mac-help/protect-data-on-your-mac-with-filevault-mh11785) volume encryption, consider using the [built-in password manager](https://support.apple.com/105115) to protect passwords and other sensitive data. 96 | 97 | - Assure data availability 98 | * Create [regular backups](https://support.apple.com/104984) of critical data and be ready to [restore from a backup](https://support.apple.com/102551) in case of compromise. 99 | * [Encrypt locally](https://support.apple.com/guide/mac-help/keep-your-time-machine-backup-disk-secure-mh21241) before copying backups to unencrypted external media or the "cloud"; alternatively, enable [end-to-end encryption](https://support.apple.com/guide/security/advanced-data-protection-for-icloud-sec973254c5f). 100 | * Verify backups by accessing them regularly. 101 | 102 | - Click carefully 103 | * Ultimately, the security of a system depends on the capabilities of its administrator. 104 | * Care should be taken when installing new software; only install from official sources that the developers indicate on their official website/github/etc. 105 | 106 | # Threat modeling 107 | 108 | The first and most important step for security and privacy is to create a [threat model](https://owasp.org/www-community/Threat_Modeling). You need to understand your adversaries in order to defend against them. Each person will have their own needs so everyone's threat model will be different. Threat models tend to evolve over time as our situation changes, so be sure to periodically reassess your threat model. 109 | 110 | ## Identify assets 111 | 112 | This is probably a lot of things: phone, laptop, passwords stored on various devices, internet browsing history, etc. Make a list starting with the most important assets to protect. You can put them in categories based on how important they are: public, sensitive, or secret. 113 | 114 | ## Identify adversaries 115 | 116 | Define whom you are defending against. Start by defining the motivation they might have to attack assets. [Financial gain](https://www.verizon.com/business/resources/reports/dbir/) is a big motivator for many attackers, for example. 117 | 118 | ## Identify capabilities 119 | 120 | In order to counter adversaries, you'll need to understand what they're capable of and what they're not capable of. Rank adversaries from totally unsophisticated to very advanced. For example, a common thief is not very sophisticated; they will likely be stopped by basic things like simply having a password and drive encryption on devices. A very advanced adversary like a state actor might require fully turning off devices when not in use to clear the keys from RAM and a long diceware password. 121 | 122 | ## Identify mitigations 123 | 124 | Now is when you decide the best way to counter each threat. You might avoid writing passwords down on paper so your roommate can't find them or you might encrypt the drive on your computer so a thief can't get data from it. It's important to balance security and usability; every mitigation should counter some capability of your adversaries, otherwise you might be making your life inconvenient for little to no gain. If you can't think of any more capabilities your adversaries might have and you've implemented mitigations for them all, your work is done. 125 | 126 | Here's an example of the type of table you should make for each asset you want to protect: 127 | 128 | Adversary | Motivation | Capabilities | Mitigation 129 | -|-|-|- 130 | Roommate | See private chats or browsing history | Close proximity; can see screen or watch type in password | Use biometrics, use privacy screen, keep phone locked when not using it 131 | Thief | Unlock phone and steal personal info and drain bank accounts, sell phone for money | Shoulder surf to see password, steal device when not looking while it's logged in | Keep phone in sight or on person at all times, keep locked when not in use, use biometrics to avoid typing password in public, use Find My or similar service to track/remotely disable stolen device 132 | Criminal | Financial | Social engineering, readily-available malware, password reuse, exploiting vulnerabilities | Use sandboxing, enable security features in OS, keep OS and all software updated and turn on automatic updates 133 | Corporation | User data marketing | Telemetry and behavioral data collection | Block network connections, reset unique identifiers, avoid adding payment data 134 | Nation State/APT | Targeted surveillance | Passive surveillance of internet infrastructure, advanced computers for cracking encryption/analysis of packets | Use open source e2ee, use strong diceware passwords for devices, use hardware with secure element for secure encryption, shut down devices when not using them, software tripwire/honeypot/[canary tokens](https://canarytokens.org/) 135 | 136 | Read more about threat modeling [here](https://www.netmeister.org/blog/threat-model-101.html). 137 | 138 | # Hardware 139 | 140 | macOS is most secure running on [Apple hardware](https://support.apple.com/guide/security/hardware-security-overview-secf020d1074/1/web/1) with Apple silicon. The newer the Mac, the better. Avoid hackintoshes and Macs that don't support the latest macOS, as Apple doesn't [patch all vulnerabilities](https://support.apple.com/guide/deployment/about-software-updates-depc4c80847a) in versions that aren't the most recent one. 141 | 142 | When you purchase your Mac, you might want to avoid it being linked back to you. Depending on your threat model, you should pay for it in cash in person rather than ordering online or purchasing with a credit/debit card, that way no identifying information can be linked back to your purchase. 143 | 144 | If you want to use a wireless keyboard, mouse, headphones or other accessory, the most secure option is Apple ones since they will automatically be updated by your system. They also support the latest [Bluetooth features](https://support.apple.com/guide/security/bluetooth-security-sec82597d97e/web) like BLE Privacy which randomizes your Bluetooth hardware address to prevent tracking. With third party accessories, this isn't a guarantee. 145 | 146 | # Installing macOS 147 | 148 | There are several ways to [install macOS](https://support.apple.com/102662). Choose your preferred method from the available options. 149 | 150 | **You should install the latest version of macOS that is compatible with your Mac**. More recent versions have security patches and other improvements that older versions lack. 151 | 152 | ## System activation 153 | 154 | As part of Apple's [theft prevention system](https://support.apple.com/102541), Apple silicon Macs will need to activate with Apple's servers every time you reinstall macOS to check against the database of stolen or activation-locked Macs. 155 | 156 | You can read about exactly how this process works [here](https://support.apple.com/guide/security/localpolicy-signing-key-creation-management-sec1f90fbad1). 157 | 158 | ## Apple Account 159 | 160 | Creating an Apple Account is not required to use macOS. Making an Apple Account requires a phone number and it will by default sync a [lot of data](https://www.apple.com/legal/privacy/data/en/apple-id/) to iCloud, Apple's cloud storage service. You can [disable](https://support.apple.com/102651) the syncing later if you want or enable [end-to-end encryption](https://support.apple.com/guide/security/advanced-data-protection-for-icloud-sec973254c5f/web) for your iCloud data. 161 | 162 | You can [control the data](https://support.apple.com/102283) associated with your Apple Account or completely delete it. 163 | 164 | An Apple Account is required in order to access the App Store and use most Apple services like iCloud, Apple Music, etc. 165 | 166 | ## App Store 167 | 168 | The Mac App Store is a [curated](https://developer.apple.com/app-store/review/guidelines) repository of software that is required to utilize the [App Sandbox](https://developer.apple.com/documentation/security/app_sandbox/protecting_user_data_with_app_sandbox) and [Hardened Runtime](https://developer.apple.com/documentation/security/hardened_runtime), as well as offering automatic updates that integrate with your system. 169 | 170 | The App Store offers the greatest security guarantees for software on macOS, but it requires you to log in with an Apple Account and Apple will be able to link your Apple Account to your downloaded applications. 171 | 172 | ## Virtualization 173 | 174 | You can easily run macOS natively in a virtual machine using [UTM](https://mac.getutm.app). It's free from their site but if you buy it from the App Store, you'll get automatic updates. 175 | 176 | Follow their [documentation](https://docs.getutm.app/guest-support/macos) to install a macOS VM with just a few clicks. 177 | 178 | Another option is [VMware Fusion](https://www.vmware.com/products/fusion.html). You can read their [documentation](https://docs.vmware.com/en/VMware-Fusion/13/com.vmware.fusion.using.doc/GUID-474FC78E-4E77-42B7-A1C6-12C2F378C5B9.html) to see how to install a macOS VM. 179 | 180 | # First boot 181 | 182 | When macOS first starts, you'll be greeted by **Setup Assistant**. 183 | 184 | When creating the first account, use a [strong password](https://www.eff.org/dice) without a hint. 185 | 186 | If you enter your real name at the account setup process, be aware that your computer's name and local hostname will comprise that name (e.g., *John Appleseed's MacBook*) and thus will appear on local networks and in various preference files. 187 | 188 | Both should be verified and updated as needed in **System Settings > About** or with the following commands after installation: 189 | 190 | ```console 191 | sudo scutil --set ComputerName MacBook 192 | sudo scutil --set LocalHostName MacBook 193 | ``` 194 | 195 | # Admin and user accounts 196 | 197 | The first user account is always an admin account. Admin accounts are members of the admin group and have access to `sudo`, which allows them to usurp other accounts, in particular root, and gives them effective control over the system. Any program that the admin executes can potentially obtain the same access, making this a security risk. 198 | 199 | Utilities like `sudo` have [weaknesses that can be exploited](https://bogner.sh/2014/03/another-mac-os-x-sudo-password-bypass/) by concurrently running programs. 200 | 201 | It is considered a best practice by [Apple](https://help.apple.com/machelp/mac/10.12/index.html#/mh11389) to use a separate standard account for day-to-day work and use the admin account for installations and system configuration. 202 | 203 | It is not strictly required to ever log into the admin account via the macOS login screen. When a Terminal command requires administrator privileges, the system will prompt for authentication and Terminal then continues using those privileges. To that end, Apple provides some [recommendations](https://support.apple.com/HT203998) for hiding the admin account and its home directory. This can be an elegant solution to avoid having a visible 'ghost' account. 204 | 205 | ## Caveats 206 | 207 | * Only administrators can install applications in `/Applications` (local directory). Finder and Installer will prompt a standard user with an authentication dialog. Many applications can be installed in `~/Applications` instead (the directory can be created). As a rule of thumb: applications that do not require admin access – or do not complain about not being installed in `/Applications` – should be installed in the user directory, the rest in the local directory. Mac App Store applications are still installed in `/Applications` and require no additional authentication. 208 | * `sudo` is not available in shells of the standard user, which requires using `su` or `login` to enter a shell of the admin account. This can make some maneuvers trickier and requires some basic experience with command-line interfaces. 209 | * System Preferences and several system utilities (e.g. Wi-Fi Diagnostics) will require root privileges for full functionality. Many panels in System Preferences are locked and need to be unlocked separately by clicking on the lock icon. Some applications will simply prompt for authentication upon opening, others must be opened by an admin account directly to get access to all functions (e.g. Console). 210 | * There are third-party applications that will not work correctly because they assume that the user account is an admin. These programs may have to be executed by logging into the admin account, or by using the `open` utility. 211 | * See additional discussion in [issue 167](https://github.com/drduh/macOS-Security-and-Privacy-Guide/issues/167). 212 | 213 | ## Setup 214 | 215 | Accounts can be created and managed in System Preferences. On settled systems, it is generally easier to create a second admin account and then demote the first account. This avoids data migration. Newly installed systems can also just add a standard account. 216 | 217 | Demoting an account can be done either from the the new admin account in System Preferences – the other account must be logged out – or by executing these commands (it may not be necessary to execute both, see [issue 179](https://github.com/drduh/macOS-Security-and-Privacy-Guide/issues/179)): 218 | 219 | ```console 220 | sudo dscl . -delete /Groups/admin GroupMembership 221 | sudo dscl . -delete /Groups/admin GroupMembers 222 | ``` 223 | 224 | To find the **GeneratedUID** of an account: 225 | 226 | ```console 227 | dscl . -read /Users/ GeneratedUID 228 | ``` 229 | 230 | See also [this post](https://superuser.com/a/395738) for more information about how macOS determines group membership. 231 | 232 | # Firmware 233 | 234 | You should check that firmware security settings are set to [Full Security](https://support.apple.com/guide/mac-help/mchl768f7291/mac) to prevent tampering with your OS. This is the default setting. 235 | 236 | # FileVault 237 | 238 | All Mac models with Apple silicon are encrypted by default. Enabling [FileVault](https://support.apple.com/guide/mac-help/mh11785/mac) makes it so that you need to enter a password in order to access the data on your drive. The EFF has a guide on generating [strong but memorable passwords](https://www.eff.org/dice). 239 | 240 | Your FileVault password also acts as a [firmware password](https://support.apple.com/en-us/102384) that will prevent people that don't know it from booting from anything other than the designated startup disk, accessing [Recovery](https://support.apple.com/guide/mac-help/macos-recovery-a-mac-apple-silicon-mchl82829c17/15.0/mac/15.0#mchl5abfbb29), and [reviving](https://support.apple.com/en-us/108900) it with DFU mode. 241 | 242 | FileVault will ask you to set a recovery key in case you forget your password. Keep this key stored somewhere safe. You'll have the option use your iCloud account to unlock your disk; however, anyone with access to your iCloud account will be able to unlock it as well. 243 | 244 | # Lockdown Mode 245 | 246 | macOS offers [Lockdown Mode](https://support.apple.com/105120), a security feature that disables several features across the OS, significantly reducing attack surface for attackers while keeping the OS usable. You can read about exactly what is disabled and decide for yourself if it is acceptable to you. 247 | 248 | When Lockdown Mode is on, you can disable it per site in Safari on trusted sites. 249 | 250 | # Firewall 251 | 252 | There are several types of firewalls available for macOS. 253 | 254 | ## Application layer firewall 255 | 256 | Built-in, basic firewall which blocks **incoming** connections only. This firewall does not have the ability to monitor, nor block **outgoing** connections. 257 | 258 | It can be controlled by the **Firewall** tab of **Network** in **System Settings**, or with the following commands. 259 | 260 | Enable the firewall and stealth mode: 261 | 262 | ```console 263 | sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on 264 | 265 | sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode on 266 | ``` 267 | 268 | Computer hackers scan networks so they can attempt to identify computers to attack. You can prevent your computer from responding to some of these scans by using **stealth mode**. When stealth mode is enabled, your computer does not respond to ICMP ping requests, and does not answer to connection attempts from a closed TCP or UDP port. This makes it more difficult for attackers to find your computer. 269 | 270 | To prevent *built-in software* as well as *code-signed, downloaded software from being whitelisted automatically*: 271 | 272 | ```console 273 | sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setallowsigned off 274 | 275 | sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setallowsignedapp off 276 | ``` 277 | 278 | Applications that are signed by a valid certificate authority are automatically added to the list of allowed apps, rather than prompting the user to authorize them. Apps included in macOS are signed by Apple and are allowed to receive incoming connections when this setting is enabled. For example, since iTunes is already signed by Apple, it is automatically allowed to receive incoming connections through the firewall. 279 | 280 | If you run an unsigned app that is not listed in the firewall list, a dialog appears with options to Allow or Deny connections for the app. If you choose "Allow", macOS signs the application and automatically adds it to the firewall list. If you choose "Deny", macOS adds it to the list but denies incoming connections intended for this app. 281 | 282 | After interacting with `socketfilterfw`, restart the process by sending a line hangup signal: 283 | 284 | ```console 285 | sudo pkill -HUP socketfilterfw 286 | ``` 287 | 288 | ## Third party firewalls 289 | 290 | Programs such as [Little Snitch](https://www.obdev.at/products/littlesnitch/index.html), [Radio Silence](https://radiosilenceapp.com/), and [LuLu](https://objective-see.com/products/lulu.html) provide a good balance of usability and security. 291 | 292 | These programs are capable of monitoring and blocking **incoming** and **outgoing** network connections. However, they may require the use of a closed source [system extension](https://support.apple.com/HT210999). 293 | 294 | If the number of choices of allowing/blocking network connections is overwhelming, use **Silent Mode** with connections allowed, then periodically check the configuration to gain understanding of applications and what they are doing. 295 | 296 | It is worth noting that these firewalls can be bypassed by programs running as **root** or through [OS vulnerabilities](https://www.blackhat.com/docs/us-15/materials/us-15-Wardle-Writing-Bad-A-Malware-For-OS-X.pdf) (pdf), but they are still worth having - just don't expect absolute protection. However, some malware actually [deletes itself](https://www.cnet.com/how-to/how-to-remove-the-flashback-malware-from-os-x/) and doesn't execute if Little Snitch, or other security software, is installed. 297 | 298 | ## Kernel level packet filtering 299 | 300 | A highly customizable, powerful, but also most complicated firewall exists in the kernel. It can be controlled with `pfctl` and various configuration files. 301 | 302 | pf can also be controlled with a GUI application such as [Murus](https://www.murusfirewall.com/). 303 | 304 | There are many books and articles on the subject of pf firewall. Here's is just one example of blocking traffic by IP address. 305 | 306 | Add the following into a file called `pf.rules`: 307 | 308 | ``` 309 | wifi = "en0" 310 | ether = "en7" 311 | set block-policy drop 312 | set fingerprints "/etc/pf.os" 313 | set ruleset-optimization basic 314 | set skip on lo0 315 | scrub in all no-df 316 | table persist 317 | block in log 318 | block in log quick from no-route to any 319 | block log on $wifi from { } to any 320 | block log on $wifi from any to { } 321 | antispoof quick for { $wifi $ether } 322 | pass out proto tcp from { $wifi $ether } to any keep state 323 | pass out proto udp from { $wifi $ether } to any keep state 324 | pass out proto icmp from $wifi to any keep state 325 | ``` 326 | 327 | Then use the following commands to manipulate the firewall: 328 | 329 | * `sudo pfctl -e -f pf.rules` to enable the firewall and load the configuration 330 | * `sudo pfctl -d` to disable the firewall 331 | * `sudo pfctl -t blocklist -T add 1.2.3.4` to add an IP address to the blocklist 332 | * `sudo pfctl -t blocklist -T show` to view the blocklist 333 | * `sudo ifconfig pflog0 create` to create an interface for logging 334 | * `sudo tcpdump -ni pflog0` to view filtered packets 335 | 336 | Unless you're already familiar with packet filtering, spending too much time configuring pf is not recommended. It is also probably unnecessary if the system is behind a [NAT](https://www.grc.com/nat/nat.htm) on a private home network. 337 | 338 | It is possible to use the pf firewall to block network access to entire ranges of network addresses, for example to a whole organization: 339 | 340 | Query [Merit RADb](https://www.radb.net/) for the list of networks in use by an autonomous system, like [Facebook](https://ipinfo.io/AS32934): 341 | 342 | ```console 343 | whois -h whois.radb.net '!gAS32934' 344 | ``` 345 | 346 | Copy and paste the list of networks returned into the blocklist command: 347 | 348 | ```console 349 | sudo pfctl -t blocklist -T add 31.13.24.0/21 31.13.64.0/24 157.240.0.0/16 350 | ``` 351 | 352 | Confirm the addresses were added: 353 | 354 | ```console 355 | $ sudo pfctl -t blocklist -T show 356 | No ALTQ support in kernel 357 | ALTQ related functions disabled 358 | 31.13.24.0/21 359 | 31.13.64.0/24 360 | 157.240.0.0/16 361 | ``` 362 | 363 | Confirm network traffic is blocked to those addresses (DNS requests will still work): 364 | 365 | ```console 366 | $ dig a +short facebook.com 367 | 157.240.2.35 368 | 369 | $ curl --connect-timeout 5 -I http://facebook.com/ 370 | * Trying 157.240.2.35... 371 | * TCP_NODELAY set 372 | * Connection timed out after 5002 milliseconds 373 | * Closing connection 0 374 | curl: (28) Connection timed out after 5002 milliseconds 375 | 376 | $ sudo tcpdump -tqni pflog0 'host 157.240.2.35' 377 | IP 192.168.1.1.62771 > 157.240.2.35.80: tcp 0 378 | IP 192.168.1.1.62771 > 157.240.2.35.80: tcp 0 379 | IP 192.168.1.1.62771 > 157.240.2.35.80: tcp 0 380 | IP 192.168.1.1.62771 > 157.240.2.35.80: tcp 0 381 | IP 192.168.1.1.162771 > 157.240.2.35.80: tcp 0 382 | ``` 383 | 384 | Outgoing TCP SYN packets are blocked, so a TCP connection is not established and thus a Web site is effectively blocked at the IP layer. 385 | 386 | See [drduh/config/scripts/pf-blocklist.sh](https://github.com/drduh/config/blob/main/scripts/pf-blocklist.sh) for more inspiration. 387 | 388 | # Services 389 | 390 | Services on macOS are managed by **launchd**. See [launchd.info](https://launchd.info). 391 | 392 | You can manage and see more information about software that runs at login in [System Settings](https://support.apple.com/guide/mac-help/change-login-items-settings-mtusr003). You can see installed System, Quick Look, Finder, and other extensions in [System Settings](https://support.apple.com/guide/mac-help/change-extensions-settings-mchl8baf92fe) as well. 393 | 394 | * Use `launchctl list` to view running user agents 395 | * Use `sudo launchctl list` to view running system daemons 396 | * Specify the service name to examine it, e.g. `launchctl list com.apple.Maps.mapspushd` 397 | * Use `defaults read` to examine job plists in `/System/Library/LaunchDaemons` and `/System/Library/LaunchAgents` 398 | * Use `man` and `strings` to find out more about what an agent/daemon does 399 | 400 | For example, to learn what a system launch daemon or agent does, start with: 401 | 402 | ```console 403 | defaults read /System/Library/LaunchDaemons/com.apple.apsd.plist 404 | ``` 405 | 406 | Look at the `Program` or `ProgramArguments` section to see which binary is run, in this case `apsd`. To find more information about that, look at the man page with `man apsd` 407 | 408 | > [!IMPORTANT] 409 | > System services are protected by SIP; don't disable SIP just to tinker with system services as SIP is an integral part of macOS security. Disabling system services may cause system instability. 410 | 411 | To view the status of services: 412 | 413 | ```console 414 | find /var/db/com.apple.xpc.launchd/ -type f -print -exec defaults read {} \; 2>/dev/null 415 | ``` 416 | 417 | Annotated lists of launch daemons and agents, the respective program executed, and the programs' hash sums are included in this repository. 418 | 419 | Read more about launchd and where login items can be found on [Apple's website](https://support.apple.com/guide/terminal/script-management-with-launchd-apdc6c1077b-5d5d-4d35-9c19-60f2397b2369). 420 | 421 | # Siri Suggestions and Spotlight 422 | 423 | Apple is moving to on-device processing for a lot of Siri functions, but some info is still sent to Apple when you use Siri Suggestions or Spotlight. You can read Apple's [Privacy Policy](https://www.apple.com/legal/privacy/data/en/siri-suggestions-search/) to see exactly what is sent and how to disable it. 424 | 425 | # Homebrew 426 | 427 | If a program isn't available through the App Store, consider using [Homebrew](https://brew.sh/). 428 | 429 | > [!WARNING] 430 | > Homebrew requiests "App Management" (or "Full Disk Access") permission to the terminal. 431 | > This is a bad idea, as it would make you vulnerable to these attacks again: any non-sandboxed application can execute code with the TCC permissions of the terminal by adding a malicious command to zshrc, for example. 432 | > Granting "App Management" or "Full Disk Access" entitlements should be considered the same as disabling TCC entirely. 433 | 434 | Remember to periodically run `brew upgrade` on trusted and secure networks to download and install software updates. To get information on a package before installation, run `brew info ` and check its formula online. You may also wish to enable [additional security options](https://github.com/drduh/macOS-Security-and-Privacy-Guide/issues/138), such as `HOMEBREW_NO_INSECURE_REDIRECT=1` 435 | 436 | According to [Homebrew's Anonymous Analytics](https://docs.brew.sh/Analytics), Homebrew gathers anonymous analytics and reports these to a self-hosted InfluxDB instance. 437 | 438 | To opt out of Homebrew's analytics, set `export HOMEBREW_NO_ANALYTICS=1` in the environment or shell rc file, or use `brew analytics off` 439 | 440 | 441 | # DNS 442 | 443 | ## DNS profiles 444 | 445 | macOS 11 introduced "DNS configuration profiles" to configure encrypted DNS, filter domains and use DNSSEC. 446 | 447 | DNS profiles [can be created](https://dns.notjakob.com/) or obtained from providers such as [Quad9](https://docs.quad9.net/Setup_Guides/MacOS/Big_Sur_and_later_(Encrypted)/#download-profile), [AdGuard](https://adguard-dns.io/en/public-dns.html) and [NextDNS](https://nextdns.io/). 448 | 449 | ## Hosts file 450 | 451 | Use the [hosts file](https://en.wikipedia.org/wiki/Hosts_(file)) to block known malware, advertising or otherwise unwanted domains. 452 | 453 | Edit the hosts file as root, for example with `sudo vi /etc/hosts` 454 | 455 | To block a domain by `A` record, append any one of the following lines to `/etc/hosts`: 456 | 457 | ``` 458 | 0 example.com 459 | 0.0.0.0 example.com 460 | 127.0.0.1 example.com 461 | ``` 462 | 463 | > [!NOTE] 464 | > IPv6 uses the `AAAA` DNS record type, rather than `A` record type, so you may also want to block those connections by *also* including `::1 example.com` entries, like shown [here](https://someonewhocares.org/hosts/ipv6/). 465 | 466 | There are many lists of domains available online which you can paste in, just make sure each line starts with `0`, `0.0.0.0`, `127.0.0.1`, and the line `127.0.0.1 localhost` is included. 467 | 468 | Here are some popular and useful hosts lists: 469 | 470 | * [Sinfonietta/hostfiles](https://github.com/Sinfonietta/hostfiles) 471 | * [StevenBlack/hosts](https://github.com/StevenBlack/hosts) 472 | * [someonewhocares.org](https://someonewhocares.org/hosts/zero/hosts) 473 | 474 | Append a list of hosts with `tee`: 475 | 476 | ```console 477 | curl https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts | sudo tee -a /etc/hosts 478 | ``` 479 | 480 | If you're using a firewall like [Little Snitch](#third-party-firewalls), you could add the [StevenBlack/hosts](https://github.com/StevenBlack/hosts) [blocklist](https://help.obdev.at/littlesnitch6/lsc-blocklists). Make sure to use this URL: [https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts](https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts) 481 | 482 | ## DNSCrypt 483 | 484 | To encrypt DNS traffic, consider using [DNSCrypt/dnscrypt-proxy](https://github.com/DNSCrypt/dnscrypt-proxy). Used in combination with dnsmasq and DNSSEC, the integrity of DNS traffic can be significantly improved. 485 | 486 | Install DNSCrypt from Homebrew and follow the instructions to configure and start `dnscrypt-proxy`: 487 | 488 | ```console 489 | brew install dnscrypt-proxy 490 | ``` 491 | 492 | If using in combination with Dnsmasq, find the file `homebrew.mxcl.dnscrypt-proxy.plist` by running 493 | 494 | ```console 495 | brew info dnscrypt-proxy 496 | ``` 497 | 498 | which will show a location like `/usr/local/etc/dnscrypt-proxy.toml` 499 | 500 | Open it in a text editor, find the line starting with `listen_addresses =` and edit that line to use DNScrypt on a port other than 53, like 5355: 501 | 502 | ``` 503 | listen_addresses = ['127.0.0.1:5355', '[::1]:5355'] 504 | ``` 505 | 506 | Start DNSCrypt: 507 | 508 | ```console 509 | sudo brew services restart dnscrypt-proxy 510 | ``` 511 | 512 | Confirm DNSCrypt is running: 513 | 514 | ```console 515 | $ sudo lsof +c 15 -Pni UDP:5355 516 | COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME 517 | dnscrypt-proxy 15244 nobody 7u IPv4 0x1337f85ff9f8beef 0t0 UDP 127.0.0.1:5355 518 | dnscrypt-proxy 15244 nobody 10u IPv6 0x1337f85ff9f8beef 0t0 UDP [::1]:5355 519 | dnscrypt-proxy 15244 nobody 12u IPv4 0x1337f85ff9f8beef 0t0 UDP 127.0.0.1:5355 520 | dnscrypt-proxy 15244 nobody 14u IPv6 0x1337f85ff9f8beef 0t0 UDP [::1]:5355 521 | ``` 522 | 523 | > By default, dnscrypt-proxy runs on localhost (127.0.0.1), port 53, balancing traffic across a set of resolvers. If you would like to change these settings, you will have to edit the configuration file: $HOMEBREW_PREFIX/etc/dnscrypt-proxy.toml 524 | 525 | > [!NOTE] 526 | > Applications may resolve DNS using their own provided servers. If dnscrypt-proxy is used, it is possible to disable all other, non-dnscrypt DNS traffic with the following pf rules: 527 | 528 | ```shell 529 | block drop quick on !lo0 proto udp from any to any port = 53 530 | block drop quick on !lo0 proto tcp from any to any port = 53 531 | ``` 532 | 533 | See also [What is a DNS leak](https://dnsleaktest.com/what-is-a-dns-leak.html) and [ipv6-test.com](http://ipv6-test.com/) 534 | 535 | ## Dnsmasq 536 | 537 | Among other features, [dnsmasq](https://www.thekelleys.org.uk/dnsmasq/doc.html) is able to cache replies, prevent upstream queries for unqualified names, and block entire top-level domains. 538 | 539 | Use in combination with DNSCrypt to additionally encrypt DNS traffic. 540 | 541 | If you don't wish to use DNSCrypt, you should at least use DNS [not provided](https://bcn.boulder.co.us/~neal/ietf/verisign-abuse.html) [by your ISP](https://hackercodex.com/guide/how-to-stop-isp-dns-server-hijacking/). Two popular alternatives are [Google DNS](https://developers.google.com/speed/public-dns/) and [OpenDNS](https://www.opendns.com/home-internet-security/). 542 | 543 | **Optional** [DNSSEC](https://en.wikipedia.org/wiki/Domain_Name_System_Security_Extensions) is a set of extensions to DNS which provide to DNS clients (resolvers) origin authentication of DNS data, authenticated denial of existence, and data integrity. All answers from DNSSEC protected zones are digitally signed. The signed records are authenticated via a chain of trust, starting with a set of verified public keys for the DNS root-zone. The current root-zone trust anchors may be downloaded [from IANA website](https://www.iana.org/dnssec/files). There are a number of resources on DNSSEC, but probably the best one is [dnssec.net website](https://www.dnssec.net). 544 | 545 | Install Dnsmasq: 546 | 547 | ```console 548 | brew install dnsmasq --with-dnssec 549 | ``` 550 | 551 | Download and edit [drduh/config/dnsmasq.conf](https://github.com/drduh/config/blob/main/dnsmasq.conf) or the default configuration file. 552 | 553 | See [drduh/config/domains](https://github.com/drduh/config/tree/main/domains) for appendable examples on blocking services by domains. 554 | 555 | Install and start the program (sudo is required to bind to [privileged port](https://unix.stackexchange.com/questions/16564/why-are-the-first-1024-ports-restricted-to-the-root-user-only) 53): 556 | 557 | ```console 558 | sudo brew services start dnsmasq 559 | ``` 560 | 561 | To set dnsmasq as the local DNS server, open **System Preferences** > **Network** and select the active interface, then the **DNS** tab, select **+** and add `127.0.0.1`, or use: 562 | 563 | ```console 564 | sudo networksetup -setdnsservers "Wi-Fi" 127.0.0.1 565 | ``` 566 | 567 | Confirm Dnsmasq is configured: 568 | 569 | ```console 570 | $ scutil --dns | head 571 | DNS configuration 572 | 573 | resolver #1 574 | search domain[0] : whatever 575 | nameserver[0] : 127.0.0.1 576 | flags : Request A records, Request AAAA records 577 | reach : 0x00030002 (Reachable,Local Address,Directly Reachable Address) 578 | 579 | $ networksetup -getdnsservers "Wi-Fi" 580 | 127.0.0.1 581 | ``` 582 | 583 | > [!NOTE] 584 | > Some VPN applications override DNS settings on connect. See [issue 24](https://github.com/drduh/macOS-Security-and-Privacy-Guide/issues/24) and [drduh/config/scripts/macos-dns.sh](https://github.com/drduh/config/blob/main/scripts/macos-dns.sh). 585 | 586 | **Optional** Test DNSSEC validation for signed zones - the reply should have `NOERROR` status and contain `ad` flag: 587 | 588 | ```console 589 | $ dig +dnssec icann.org | head 590 | ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47039 591 | ;; flags: qr rd ra ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1 592 | ``` 593 | 594 | Test DNSSEC validation fails for zones that are signed improperly - the reply should have `SERVFAIL` status: 595 | 596 | ```console 597 | $ dig www.dnssec-failed.org | head 598 | ;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 15190 599 | ;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1 600 | ``` 601 | 602 | # Certificate authorities 603 | 604 | macOS comes with [over 100](https://support.apple.com/103723) root authority certificates installed from corporations like Apple, Verisign, Thawte, Digicert and government agencies from China, Japan, Netherlands, U.S., and more! These Certificate Authorities (CAs) are capable of issuing TLS certificates for any domain, code signing certificates, etc. Apple [blocks these certificates](https://support.apple.com/103247#blocked) when a CA proves to be untrustworthy. They also have [strict requirements](https://www.apple.com/certificateauthority/ca_program.html) that trusted CAs have to meet. 605 | 606 | For more information, see the [CA/Browser Forum's website](https://cabforum.org/resources/browser-os-info/). 607 | 608 | Inspect system root certificates in **Keychain Access**, under the **System Roots** tab or by using the `security` command line tool and `/System/Library/Keychains/SystemRootCertificates.keychain` file. 609 | 610 | You can manually disable certificate authorities through Keychain Access by marking them as **Never Trust** and closing the window: 611 | 612 | A certificate authority certificate 613 | 614 | The risk of a [man in the middle](https://wikipedia.org/wiki/Man-in-the-middle_attack) attack, in which a coerced or compromised certificate authority trusted by a system root store issues a fake/rogue TLS certificate, is relatively low, but [possible](https://wikipedia.org/wiki/DigiNotar#Issuance_of_fraudulent_certificates). 615 | 616 | # Privoxy 617 | 618 | Consider using [Privoxy](https://www.privoxy.org/) as a local proxy to filter Web traffic. 619 | 620 | Install and start privoxy using Homebrew: 621 | 622 | ```console 623 | brew install privoxy 624 | 625 | brew services start privoxy 626 | ``` 627 | 628 | Alternatively, a signed installation package for Privoxy is available from [their website](https://www.privoxy.org/sf-download-mirror/Macintosh%20%28OS%20X%29/) or [Sourceforge](https://sourceforge.net/projects/ijbswa/files/Macintosh%20%28OS%20X%29/). The signed package is [more secure](https://github.com/drduh/macOS-Security-and-Privacy-Guide/issues/65) than the Homebrew version and receives support from the Privoxy project. 629 | 630 | By default, Privoxy listens on local TCP port 8118. 631 | 632 | Set the system **HTTP** proxy for the active network interface `127.0.0.1` and `8118`: 633 | 634 | ```console 635 | sudo networksetup -setwebproxy "Wi-Fi" 127.0.0.1 8118 636 | ``` 637 | 638 | Set the system **HTTPS** proxy: 639 | 640 | ```console 641 | sudo networksetup -setsecurewebproxy "Wi-Fi" 127.0.0.1 8118 642 | ``` 643 | 644 | This can also be done through **System Preferences > Network > Advanced > Proxies** 645 | 646 | Confirm the proxy is set: 647 | 648 | ```console 649 | $ scutil --proxy 650 | { 651 | ExceptionsList : { 652 | 0 : *.local 653 | 1 : 169.254/16 654 | } 655 | FTPPassive : 1 656 | HTTPEnable : 1 657 | HTTPPort : 8118 658 | HTTPProxy : 127.0.0.1 659 | } 660 | ``` 661 | 662 | Although most Web traffic today is encrypted, Privoxy is still useful for filtering by domain name patterns, and for upgrading insecure HTTP requests. 663 | 664 | For example, the following rules block all traffic, except to `.net` and `github.com` and all `apple` domains: 665 | 666 | ```console 667 | { +block{all} } 668 | . 669 | 670 | { -block } 671 | .apple. 672 | .github.com 673 | .net 674 | ``` 675 | 676 | Or to just block Facebook domains, for example: 677 | 678 | ```console 679 | { +block{facebook} } 680 | .facebook*. 681 | .fb. 682 | .fbcdn*. 683 | .fbinfra. 684 | .fbsbx. 685 | .fbsv. 686 | .fburl. 687 | .tfbnw. 688 | .thefacebook. 689 | fb*.akamaihd.net 690 | ``` 691 | 692 | Wildcards are also supported. 693 | 694 | See [drduh/config/privoxy/config](https://github.com/drduh/config/blob/main/privoxy/config) and [drduh/config/privoxy/user.action](https://github.com/drduh/config/blob/main/privoxy/user.action) for additional Privoxy examples. Privoxy does **not** need to be restarted after editing `user.action` filter rules. 695 | 696 | To verify traffic is blocked or redirected, use curl or the Privoxy interface available at in the browser: 697 | 698 | ```console 699 | ALL_PROXY=127.0.0.1:8118 curl example.com -IL | head 700 | 701 | HTTP/1.1 403 Request blocked by Privoxy 702 | Content-Length: 9001 703 | Content-Type: text/html 704 | Cache-Control: no-cache 705 | Pragma: no-cache 706 | 707 | ALL_PROXY=127.0.0.1:8118 curl github.com -IL | head 708 | HTTP/1.1 302 Local Redirect from Privoxy 709 | Location: https://github.com/ 710 | Content-Length: 0 711 | 712 | HTTP/1.1 200 Connection established 713 | 714 | HTTP/2 200 715 | server: GitHub.com 716 | ``` 717 | 718 | > [!NOTE] 719 | > Proxy settings are not universal; applications and services may bypass system proxy settings. Ensure the application to proxy is correctly configured and verify connections don't leak. Additionally, *pf* can be configured to transparently proxy traffic on certain ports. 720 | 721 | # Browser 722 | 723 | The Web browser likely poses the largest security and privacy risk, as its fundamental job is to download and execute untrusted code from the Internet. 724 | 725 | An important property of modern browsers is the Same Origin Policy ([SOP](https://en.wikipedia.org/wiki/Same-origin_policy)) which prevents a malicious script on one page from obtaining access to sensitive data on another web page through the Document Object Model (DOM). If SOP is compromised, the security of the entire browser is compromised. 726 | 727 | Many browser exploits are based on social engineering as a means of gaining persistence. Always be mindful of opening untrusted sites and especially careful when downloading new software. 728 | 729 | Another important consideration about browser security is extensions. This is an issue affecting Firefox and [Chrome](https://courses.csail.mit.edu/6.857/2016/files/24.pdf) alike. The use of browser extensions should be limited to only critically necessary ones published by trustworthy developers. 730 | 731 | [Mozilla Firefox](https://www.mozilla.org/firefox/new), [Google Chrome](https://www.google.com/chrome), [Safari](https://www.apple.com/safari), and [Tor Browser](https://www.torproject.org/download) are all recommended browsers for their own unique and individual purposes. 732 | 733 | ## Firefox 734 | 735 | [Mozilla Firefox](https://www.mozilla.org/firefox/new) is a popular open source browser. Firefox replaced major parts of its infrastructure and code base under the projects [Quantum](https://wiki.mozilla.org/Quantum) and [Photon](https://wiki.mozilla.org/Firefox/Photon/Updates). Part of the Quantum project is to replace C++ code with [Rust](https://www.rust-lang.org). Rust is a systems programming language with a focus on security and thread safety. It is expected that Rust adoption will greatly improve the overall security posture of Firefox. 736 | 737 | Firefox offers a similar security model to Chrome: it has a [bug bounty program](https://www.mozilla.org/security/bug-bounty), although it is not as lucrative. Firefox follows a four-week release cycle. 738 | 739 | Firefox supports user-supplied configuration files. See [drduh/config/firefox.user.js](https://github.com/drduh/config/blob/main/firefox.user.js) and [arkenfox/user.js](https://github.com/arkenfox/user.js) for recommended preferences and hardening measures. Also see [NoScript](https://noscript.net), an extension which allows selective script blocking. 740 | 741 | Firefox [focuses on user privacy](https://www.mozilla.org/firefox/privacy). It supports [tracking protection](https://developer.mozilla.org/docs/Web/Privacy/Firefox_tracking_protection) in Private Browsing mode. The tracking protection can be enabled for the default account, although it may break the browsing experience on some websites. Firefox in Strict tracking protection mode will [randomize your fingerprint](https://support.mozilla.org/kb/firefox-protection-against-fingerprinting) to foil basic tracking scripts. Firefox offers separate user [profiles](https://support.mozilla.org/kb/profile-manager-create-remove-switch-firefox-profiles). You can separate your browsing inside a profile with [Multi-Account Containers](https://support.mozilla.org/kb/containers). 742 | 743 | Firefox only supports Web Extensions through the [Web Extension Api](https://developer.mozilla.org/docs/Mozilla/Add-ons/WebExtensions), which is very similar to Chrome. Submission of Web Extensions in Firefox is free. Web Extensions in Firefox most of the time are open source, although certain Web Extensions are proprietary. 744 | 745 | ## Chrome 746 | 747 | [Google Chrome](https://www.google.com/chrome) is based on the open source [Chromium project](https://www.chromium.org) with certain [proprietary components](https://fossbytes.com/difference-google-chrome-vs-chromium-browser): 748 | 749 | * Automatic updates with GoogleSoftwareUpdateDaemon 750 | * Usage tracking and crash reporting, which can be disabled through Chrome's settings 751 | * Media Codec support for proprietary codecs 752 | * Chrome Web Store 753 | * PDF viewer 754 | * Non-optional tracking. Google Chrome installer includes a randomly generated token. The token is sent to Google after the installation completes in order to measure the success rate. The RLZ identifier stores information – in the form of encoded strings – like the source of chrome download and installation week. It doesn’t include any personal information and it’s used to measure the effectiveness of a promotional campaign. **Chrome downloaded from Google’s website doesn’t have the RLZ identifier**. The source code to decode the strings is made open by Google. 755 | 756 | Chrome offers account sync between multiple devices. Part of the sync data includes credentials to Web sites. The data is encrypted with the account password. 757 | 758 | Chrome's Web Store for extensions requires a [5 USD lifetime fee](https://developer.chrome.com/docs/webstore/register) in order to submit extensions. The low cost allows the development of many quality Open Source Web Extensions that do not aim to monetize through usage. 759 | 760 | Chrome has the largest share of global usage and is the preferred target platform for the majority of developers. Major technologies are based on Chrome's Open Source components, such as [node.js](https://nodejs.org) which uses [Chrome's V8](https://developers.google.com/v8) Engine and the [Electron](https://electron.atom.io) framework, which is based on Chromium and node.js. Chrome's vast user base makes it the most attractive target for threat actors and security researchers. Despite constant attacks, Chrome has retained an impressive security track record over the years. This is not a small feat. 761 | 762 | Chrome offers [separate profiles](https://www.chromium.org/user-experience/multi-profiles), [robust sandboxing](https://chromium.googlesource.com/chromium/src/+/HEAD/docs/design/sandbox.md), [frequent updates](https://chromereleases.googleblog.com), and carries [impressive credentials](https://www.chromium.org/Home/chromium-security/brag-sheet). In addition, Google offers a very lucrative [bounty program](https://bughunters.google.com/about/rules/5745167867576320/chrome-vulnerability-reward-program-rules) for reporting vulnerabilities, along with its own [Project Zero](https://googleprojectzero.blogspot.com/) team. This means that a large number of highly talented and motivated people are constantly auditing and securing Chrome code. 763 | 764 | Create separate Chrome profiles to reduce XSS risk and compartmentalize cookies/identities. In each profile, either disable Javascript in Chrome settings and configure allowed origins. You should also disable the V8 Optimizer for sites where you do use Javascript to further reduce attack surface. Go to **Settings** -> **Privacy and security** -> **Security** -> **Manage v8 security** -> **Don't allow sites to use the V8 optimizer** 765 | 766 | Read more about the benefits of disabling this [here](https://microsoftedge.github.io/edgevr/posts/Super-Duper-Secure-Mode). 767 | 768 | You can block trackers with [uBlock Origin Lite](https://chromewebstore.google.com/detail/ublock-origin-lite/ddkjiahejlhfcafbddmgiahcphecmpfh). 769 | 770 | Change the default search engine from Google to reduce additional tracking. 771 | 772 | Disable [DNS prefetching](https://www.chromium.org/developers/design-documents/dns-prefetching) (see also [DNS Prefetching and Its Privacy Implications](https://www.usenix.org/legacy/event/leet10/tech/full_papers/Krishnan.pdf) (pdf)). Note that Chrome [may attempt](https://github.com/drduh/macOS-Security-and-Privacy-Guide/issues/350) to resolve DNS using Google's `8.8.8.8` and `8.8.4.4` public nameservers. 773 | 774 | Read [Chromium Security](https://www.chromium.org/Home/chromium-security) and [Chromium Privacy](https://www.chromium.org/Home/chromium-privacy) for more information. Read [Google's privacy policy](https://policies.google.com/privacy) to understand how personal information is collected and used. 775 | 776 | ## Safari 777 | 778 | [Safari](https://www.apple.com/safari) is the default browser on macOS. It is also the most optimized browser for reducing battery use. Safari, like Chrome, has both Open Source and proprietary components. Safari is based on the open source Web Engine [WebKit](https://webkit.org), which is ubiquitous among the macOS ecosystem. WebKit is used by Apple apps such as Mail, iTunes, iBooks, and the App Store. Chrome's [Blink](https://www.chromium.org/blink) engine is a fork of WebKit and both engines share a number of similarities. 779 | 780 | Safari supports certain unique features that benefit user security and privacy. [Content blockers](https://webkit.org/blog/3476/content-blockers-first-look) enables the creation of content blocking rules without using Javascript. This rule based approach greatly improves memory use, security, and privacy. Safari 11 introduced [Intelligent Tracking Prevention](https://webkit.org/blog/7675/intelligent-tracking-prevention), which removes tracking data stored in Safari after a period of non-interaction by the user from the tracker's website. Safari can randomize the browser fingerprint to reduce tracking. Safari doesn't support certain features like WebUSB or the Battery API intentionally for security and privacy reasons. Private tabs in Safari have isolated cookies and cache that is destroyed when you close the tab. Safari also support Profiles which are equivalent to Firefox's Multi-Account Containers for separating cookies and browsing. Safari can be made significantly more secure with [lockdown mode](#lockdown-mode), which can be disabled per-site. Read more about [tracking prevention](https://webkit.org/tracking-prevention) in Safari. 781 | 782 | Safari offers an invite-only [bounty program](https://developer.apple.com/bug-reporting) for bug reporting to a select number of security researchers. The bounty program was announced during Apple's [presentation](https://www.blackhat.com/docs/us-16/materials/us-16-Krstic.pdf) at [BlackHat](https://www.blackhat.com/us-16/briefings.html#behind-the-scenes-of-ios-security) 2016. 783 | 784 | Web Extensions in Safari have an additional option to use native code in the Safari's sandbox environment, in addition to Web Extension APIs. Web Extensions in Safari are also distributed through Apple's App store. App store submission comes with the added benefit of Web Extension code being audited by Apple. On the other hand App store submission comes at a steep cost. Yearly [developer subscription](https://developer.apple.com/support/compare-memberships) fee costs 100 USD (in contrast to Chrome's 5 USD fee and Firefox's free submission). The high cost is prohibitive for the majority of Open Source developers. As a result, Safari has very few extensions to choose from. However, you should keep the high cost in mind when installing extensions. It is expected that most Web Extensions will have some way of monetizing usage in order to cover developer costs. Be wary of Web Extensions whose source code is not open. 785 | 786 | Safari syncs user preferences and passwords with [iCloud Keychain](https://support.apple.com/HT202303). In order to be viewed in plain text, a user must input the account password of the current device. This means that users can sync data across devices with added security. 787 | 788 | Safari follows a slower release cycle than Chrome and Firefox (3-4 minor releases, 1 major release, per year). Newer features are slower to be adopted to the stable channel. Security updates in Safari are handled independent of the stable release schedule and are installed through the App Store. 789 | 790 | See also [el1t/uBlock-Safari](https://github.com/el1t/uBlock-Safari/wiki/Disable-hyperlink-auditing-beacon) to disable hyperlink auditing beacons. 791 | 792 | ## Other browsers 793 | 794 | Many Chromium-derived browsers are not recommended. They are usually [closed source](https://yro.slashdot.org/comments.pl?sid=4176879&cid=44774943), [poorly maintained](https://plus.google.com/+JustinSchuh/posts/69qw9wZVH8z), and make dubious claims to protect privacy. 795 | 796 | Other miscellaneous browsers, such as [Brave](https://github.com/drduh/macOS-Security-and-Privacy-Guide/issues/94), are not evaluated in this guide, so are neither recommended nor actively discouraged from use. 797 | 798 | ## Web browser privacy 799 | 800 | Web browsers reveal information in several ways, for example through the [Navigator](https://developer.mozilla.org/en-US/docs/Web/API/Navigator) interface, which may include information such as the browser version, operating system, site permissions, and the device's battery level. Many websites also use [canvas fingerprinting](https://en.wikipedia.org/wiki/Canvas_fingerprinting) to uniquely identify users across sessions. 801 | 802 | For more information about security conscious browsing and what data is sent by the browser, see [HowTo: Privacy & Security Conscious Browsing](https://gist.github.com/atcuno/3425484ac5cce5298932), [browserleaks.com](https://browserleaks.com/), [Am I Unique?](https://amiunique.org/fingerprint) and [EFF Cover Your Tracks](https://coveryourtracks.eff.org/) resources. 803 | 804 | To hinder third party trackers, it is recommended to **disable third-party cookies** altogether. Safari, Firefox, and Chrome all block third party cookies by default. A third party cookie is a cookie associated with a file requested by a different domain than the one the user is currently viewing. Most of the time third-party cookies are used to create browsing profiles by tracking a user's movement on the web. Disabling third-party cookies prevents HTTP responses and scripts from other domains from setting cookies. Moreover, cookies are removed from requests to domains that are not the document origin domain, so cookies are only sent to the current site that is being viewed. 805 | 806 | Also be aware of [WebRTC](https://en.wikipedia.org/wiki/WebRTC#Concerns), which may reveal local or public (if connected to VPN) IP address(es). In Firefox and Chrome/Chromium this can be disabled with extensions such as [uBlock Origin](https://github.com/gorhill/uBlock/wiki/Prevent-WebRTC-from-leaking-local-IP-address). [Lockdown mode](#lockdown-mode) [disables WebRTC](https://www.sevarg.net/2022/07/20/ios16-lockdown-mode-browser-analysis) in Safari. 807 | 808 | # Tor 809 | 810 | Tor is an anonymizing network which can be used for browsing the Web with additional privacy. Tor Browser is a modified version of Firefox with a proxy to access the Tor network. 811 | 812 | Download Tor Browser from [Tor Project](https://www.torproject.org/download/). 813 | 814 | Do **not** attempt to configure other browsers or applications to use Tor as you may make a mistake which will compromise anonymity. 815 | 816 | Download both the `dmg` and `asc` signature files, then verify the disk image has been signed by Tor developers: 817 | 818 | ```console 819 | $ cd ~/Downloads 820 | 821 | $ file Tor* 822 | TorBrowser-8.0.4-osx64_en-US.dmg: bzip2 compressed data, block size = 900k 823 | TorBrowser-8.0.4-osx64_en-US.dmg.asc: PGP signature Signature (old) 824 | 825 | $ gpg Tor*asc 826 | [...] 827 | gpg: Can't check signature: No public key 828 | 829 | $ gpg --recv 0x4E2C6E8793298290 830 | gpg: key 0x4E2C6E8793298290: public key "Tor Browser Developers (signing key) " imported 831 | gpg: no ultimately trusted keys found 832 | gpg: Total number processed: 1 833 | gpg: imported: 1 834 | 835 | $ gpg --verify Tor*asc 836 | gpg: assuming signed data in 'TorBrowser-8.0.4-osx64_en-US.dmg' 837 | gpg: Signature made Mon Dec 10 07:16:22 2018 PST 838 | gpg: using RSA key 0xEB774491D9FF06E2 839 | gpg: Good signature from "Tor Browser Developers (signing key) " [unknown] 840 | gpg: WARNING: This key is not certified with a trusted signature! 841 | gpg: There is no indication that the signature belongs to the owner. 842 | Primary key fingerprint: EF6E 286D DA85 EA2A 4BA7 DE68 4E2C 6E87 9329 8290 843 | Subkey fingerprint: 1107 75B5 D101 FB36 BC6C 911B EB77 4491 D9FF 06E2 844 | ``` 845 | 846 | Make sure `Good signature from "Tor Browser Developers (signing key) "` appears in the output. The warning about the key not being certified is benign, as it has not yet been assigned trust. 847 | 848 | See [How can I verify Tor Browser's signature?](https://support.torproject.org/tbb/how-to-verify-signature/) for more information. 849 | 850 | To finish installing Tor Browser, open the disk image and drag the it into the Applications folder, or with: 851 | 852 | ```console 853 | hdiutil mount TorBrowser-8.0.4-osx64_en-US.dmg 854 | 855 | cp -r /Volumes/Tor\ Browser/Tor\ Browser.app/ ~/Applications/ 856 | 857 | ``` 858 | 859 | Verify the Tor application's code signature was made by with The Tor Project's Apple developer ID **MADPSAYN6T**, using the `spctl -a -v` and/or `pkgutil --check-signature` commands: 860 | 861 | ```console 862 | $ spctl -a -vv ~/Applications/Tor\ Browser.app 863 | /Users/drduh/Applications/Tor Browser.app: accepted 864 | source=Developer ID 865 | origin=Developer ID Application: The Tor Project, Inc (MADPSAYN6T) 866 | 867 | $ pkgutil --check-signature ~/Applications/Tor\ Browser.app 868 | Package "Tor Browser.app": 869 | Status: signed by a certificate trusted by Mac OS X 870 | Certificate Chain: 871 | 1. Developer ID Application: The Tor Project, Inc (MADPSAYN6T) 872 | SHA1 fingerprint: 95 80 54 F1 54 66 F3 9C C2 D8 27 7A 29 21 D9 61 11 93 B3 E8 873 | ----------------------------------------------------------------------------- 874 | 2. Developer ID Certification Authority 875 | SHA1 fingerprint: 3B 16 6C 3B 7D C4 B7 51 C9 FE 2A FA B9 13 56 41 E3 88 E1 86 876 | ----------------------------------------------------------------------------- 877 | 3. Apple Root CA 878 | SHA1 fingerprint: 61 1E 5B 66 2C 59 3A 08 FF 58 D1 4A E2 24 52 D1 98 DF 6C 60 879 | ``` 880 | 881 | You can also use the `codesign` command to examine an application's code signature: 882 | 883 | ```console 884 | $ codesign -dvv ~/Applications/Tor\ Browser.app 885 | Executable=/Users/drduh/Applications/Tor Browser.app/Contents/MacOS/firefox 886 | Identifier=org.torproject.torbrowser 887 | Format=app bundle with Mach-O thin (x86_64) 888 | CodeDirectory v=20200 size=229 flags=0x0(none) hashes=4+3 location=embedded 889 | Library validation warning=OS X SDK version before 10.9 does not support Library Validation 890 | Signature size=4247 891 | Authority=Developer ID Application: The Tor Project, Inc (MADPSAYN6T) 892 | Authority=Developer ID Certification Authority 893 | Authority=Apple Root CA 894 | Signed Time=Dec 10, 2018 at 12:18:45 AM 895 | Info.plist entries=24 896 | TeamIdentifier=MADPSAYN6T 897 | Sealed Resources version=2 rules=12 files=128 898 | Internal requirements count=1 size=188 899 | ``` 900 | 901 | To view full certificate details for a signed application, extract them with `codesign` and decode it with `openssl`: 902 | 903 | ```console 904 | $ codesign -d --extract-certificates ~/Applications/Tor\ Browser.app 905 | Executable=/Users/drduh/Applications/Tor Browser.app/Contents/MacOS/firefox 906 | 907 | $ file codesign* 908 | codesign0: data 909 | codesign1: data 910 | codesign2: data 911 | 912 | $ openssl x509 -inform der -in codesign0 -subject -issuer -startdate -enddate -noout 913 | subject= /UID=MADPSAYN6T/CN=Developer ID Application: The Tor Project, Inc (MADPSAYN6T)/OU=MADPSAYN6T/O=The Tor Project, Inc/C=US 914 | issuer= /CN=Developer ID Certification Authority/OU=Apple Certification Authority/O=Apple Inc./C=US 915 | notBefore=Apr 12 22:40:13 2016 GMT 916 | notAfter=Apr 13 22:40:13 2021 GMT 917 | 918 | $ openssl x509 -inform der -in codesign0 -fingerprint -noout 919 | SHA1 Fingerprint=95:80:54:F1:54:66:F3:9C:C2:D8:27:7A:29:21:D9:61:11:93:B3:E8 920 | 921 | $ openssl x509 -inform der -in codesign0 -fingerprint -sha256 -noout 922 | SHA256 Fingerprint=B5:0D:47:F0:3E:CB:42:B6:68:1C:6F:38:06:2B:C2:9F:41:FA:D6:54:F1:29:D3:E4:DD:9C:C7:49:35:FF:F5:D9 923 | ``` 924 | 925 | Tor traffic is **encrypted** to the [exit node](https://en.wikipedia.org/wiki/Tor_(network)#Exit_node_eavesdropping) (i.e., cannot be read by a passive network eavesdropper), but Tor use **can** be identified - for example, TLS handshake "hostnames" will show up in plaintext: 926 | 927 | ```console 928 | $ sudo tcpdump -An "tcp" | grep "www" 929 | listening on pktap, link-type PKTAP (Apple DLT_PKTAP), capture size 262144 bytes 930 | .............". ...www.odezz26nvv7jeqz1xghzs.com......... 931 | .............#.!...www.bxbko3qi7vacgwyk4ggulh.com......... 932 | .6....m.....>...:.........|../* Z....W....X=..6...C../....................................0...0..0.......'....F./0.. *.H........0%1#0!..U....www.b6zazzahl3h3faf4x2.com0...160402000000Z..170317000000Z0'1%0#..U....www.tm3ddrghe22wgqna5u8g.net0..0.. 933 | ``` 934 | 935 | See [Tor Protocol Specification](https://spec.torproject.org/tor-spec/) and [Tor/TLSHistory](https://gitlab.torproject.org/legacy/trac/-/wikis/org/projects/Tor/TLSHistory) for more information. 936 | 937 | You may wish to additionally obfuscate Tor traffic using a [pluggable transport](https://tb-manual.torproject.org/circumvention/). 938 | 939 | This can be done by setting up a [Tor relay](https://support.torproject.org/relay-operators/) or finding an existing private or [public bridge](https://bridges.torproject.org/) to serve as an obfuscating entry node. 940 | 941 | For extra security, use Tor inside a [VirtualBox](https://www.virtualbox.org/wiki/Downloads) or [VMware](https://www.vmware.com/products/fusion.html) virtualized [GNU/Linux](https://www.brianlinkletter.com/2012/10/installing-debian-linux-in-a-virtualbox-virtual-machine/) or [OpenBSD](https://www.openbsd.org/faq/faq4.html) instance. 942 | 943 | Finally, remember the Tor network provides [anonymity](https://www.privateinternetaccess.com/blog/2013/10/how-does-privacy-differ-from-anonymity-and-why-are-both-important/), which is not necessarily synonymous with privacy. The Tor network does not guarantee protection against a global observer capable of traffic analysis and correlation. See also [Seeking Anonymity in an Internet Panopticon](https://bford.info/pub/net/panopticon-cacm.pdf) (pdf) and [Traffic Correlation on Tor by Realistic Adversaries](https://www.ohmygodel.com/publications/usersrouted-ccs13.pdf) (pdf). 944 | 945 | Also see [Invisible Internet Project (I2P)](https://geti2p.net/en/about/intro) and its [Tor comparison](https://geti2p.net/en/comparison/tor). 946 | 947 | # VPN 948 | 949 | When choosing a VPN service or self-hosting, be sure to research the protocols, key exchange algorithms, authentication mechanisms, and type of encryption being used. Some protocols, such as [PPTP](https://en.wikipedia.org/wiki/Point-to-Point_Tunneling_Protocol#Security), should be avoided in favor of [OpenVPN](https://en.wikipedia.org/wiki/OpenVPN) or Linux-based [Wireguard](https://www.wireguard.com/) [on a Linux VM](https://github.com/mrash/Wireguard-macOS-LinuxVM) or via a set of [cross platform tools](https://www.wireguard.com/xplatform/). 950 | 951 | Some clients may send traffic over the next available interface when VPN is interrupted or disconnected. See [scy/8122924](https://gist.github.com/scy/8122924) for an example on how to allow traffic only over VPN. 952 | 953 | There is an updated guide to setting up an IPSec VPN on a virtual machine ([hwdsl2/setup-ipsec-vpn](https://github.com/hwdsl2/setup-ipsec-vpn)) or a docker container ([hwdsl2/docker-ipsec-vpn-server](https://github.com/hwdsl2/docker-ipsec-vpn-server)). 954 | 955 | It may be worthwhile to consider the geographical location of the VPN provider. See further discussion in [issue 114](https://github.com/drduh/macOS-Security-and-Privacy-Guide/issues/114). 956 | 957 | Also see this [technical overview](https://blog.timac.org/2018/0717-macos-vpn-architecture/) of the macOS built-in VPN L2TP/IPSec and IKEv2 client. 958 | 959 | # PGP/GPG 960 | 961 | PGP is a standard for signing and encrypting data (especially email) end-to-end, so only the sender and recipient can access it. 962 | 963 | GPG, or **GNU Privacy Guard**, is a GPL-licensed open source program compliant with the PGP standard. 964 | 965 | GPG is used to verify signatures of software you download and install, as well as [symmetrically](https://en.wikipedia.org/wiki/Symmetric-key_algorithm) or [asymmetrically](https://en.wikipedia.org/wiki/Public-key_cryptography) encrypt files and text. 966 | 967 | Install from Homebrew with `brew install gnupg`. 968 | 969 | If you prefer a graphical application, download and install [GPG Suite](https://gpgtools.org/). 970 | 971 | Download [drduh/config/gpg.conf](https://github.com/drduh/config/blob/main/gpg.conf) to use recommended settings: 972 | 973 | ```console 974 | curl -o ~/.gnupg/gpg.conf https://raw.githubusercontent.com/drduh/config/main/gpg.conf 975 | ``` 976 | 977 | See [drduh/YubiKey-Guide](https://github.com/drduh/YubiKey-Guide) to securely generate and store GPG keys. 978 | 979 | Read [online](https://alexcabal.com/creating-the-perfect-gpg-keypair/) [guides](https://security.stackexchange.com/questions/31594/what-is-a-good-general-purpose-gnupg-key-setup) and [practice](https://help.riseup.net/en/security/message-security/openpgp/best-practices) encrypting and decrypting email to yourself and your friends. Get them interested in this stuff! 980 | 981 | # Messengers 982 | 983 | ## XMPP 984 | 985 | XMPP is an [open standard](https://xmpp.org/extensions) developed by the [IETF](https://www.ietf.org) that allows for cross-platform federated messaging. There are many options for [clients](https://xmpp.org/getting-started). Consider using one of the browser-based clients to take advantage of the browser's sandbox. 986 | 987 | Depending on the provider, you might not need anything other than a username and password to set up an account. 988 | 989 | XMPP isn't E2EE by default, you'll need to use [OMEMO](https://omemo.top) encryption, so make sure the client supports it. 990 | 991 | ## Signal 992 | 993 | [Signal](https://www.signal.org) is an advanced E2EE messenger whose [double-ratchet](https://signal.org/docs/specifications/doubleratchet/) protocol is used by countless other messengers including WhatsApp, Google Messages, and Facebook Messenger. 994 | 995 | Signal requires a phone number to sign up and you'll need to install it on a phone first before you can use it on desktop. 996 | 997 | ## iMessage 998 | 999 | iMessage is Apple's first party messenger. It requires an [Apple Account](#apple-account) in order to use it. 1000 | 1001 | Make sure to enable [Contact Key Verification](https://support.apple.com/118246) and verify with anyone you message to ensure that you're messaging the right person. 1002 | 1003 | You can use iMessage with either a [phone number or an email](https://support.apple.com/108758#help), so pick one that you're comfortable with contacts seeing. 1004 | 1005 | > [!WARNING] 1006 | > By default, iCloud backup is enabled, which stores copies of message encryption keys on [Apple's servers](https://support.apple.com/102651) without E2EE. Either [disable iCloud backup](https://support.apple.com/guide/icloud/view-and-manage-backups-mm122d3ef202/1.0/icloud/1.0) or enable [Advanced Data Protection](https://support.apple.com/guide/security/advanced-data-protection-for-icloud-sec973254c5f) to prevent this. Remind messaging recipients to do the same. 1007 | 1008 | # Viruses and malware 1009 | 1010 | There is an [ever-increasing](https://www.documentcloud.org/documents/2459197-bit9-carbon-black-threat-research-report-2015.html) amount of Mac malware in the wild. Macs aren't immune from viruses and malicious software! 1011 | 1012 | Some malware comes bundled with both legitimate software, such as the [Java bundling Ask Toolbar](https://www.zdnet.com/article/oracle-extends-its-adware-bundling-to-include-java-for-macs/), and some with illegitimate software, such as [Mac.BackDoor.iWorm](https://docs.google.com/document/d/1YOfXRUQJgMjJSLBSoLiUaSZfiaS_vU3aG4Bvjmz6Dxs/edit?pli=1) bundled with pirated programs. 1013 | 1014 | See [Methods of malware persistence on Mac OS X](https://www.virusbtn.com/pdf/conference/vb2014/VB2014-Wardle.pdf) (pdf) and [Malware Persistence on OS X Yosemite](https://www.rsaconference.com/events/us15/agenda/sessions/1591/malware-persistence-on-os-x-yosemite) to learn about how garden-variety malware functions. 1015 | 1016 | Subscribe to updates at the [Malwarebytes Blog](https://blog.malwarebytes.com/) for current Mac security news. 1017 | 1018 | Also check out [Hacking Team](https://www.schneier.com/blog/archives/2015/07/hacking_team_is.html) malware for macOS: [root installation for MacOS](https://github.com/hackedteam/vector-macos-root), [Support driver for Mac Agent](https://github.com/hackedteam/driver-macos) and [RCS Agent for Mac](https://github.com/hackedteam/core-macos), which is a good example of advanced malware with capabilities to hide from userland (e.g., `ps`, `ls`). For more, see [A Brief Analysis of an RCS Implant Installer](https://objective-see.com/blog/blog_0x0D.html) and [reverse.put.as](https://reverse.put.as/2016/02/29/the-italian-morons-are-back-what-are-they-up-to-this-time/) 1019 | 1020 | ## Downloading Software 1021 | 1022 | Only running programs from the App Store or that are [Notarized](https://support.apple.com/guide/security/app-code-signing-process-sec3ad8e6e53/web) by Apple will help mitigate malware. Apple performs an automated scan on notarized apps for malware. App Store apps undergo a [review](https://developer.apple.com/app-store/review/guidelines/) process to catch malware. 1023 | 1024 | Otherwise, get programs from trusted sources like directly from the developer's website or GitHub. Always make sure that the browser/terminal is using HTTPS when downloading any program. 1025 | 1026 | You should also avoid programs that ask for lots of permissions and third party closed source programs. Open source code allows anyone to audit and examine the code for security/privacy issues. 1027 | 1028 | ## App Sandbox 1029 | 1030 | Check if a program uses the [App Sandbox](https://developer.apple.com/documentation/security/app_sandbox/protecting_user_data_with_app_sandbox) before running it by running the following command: 1031 | 1032 | ```console 1033 | codesign -dvvv --entitlements - 1034 | ``` 1035 | 1036 | With the App Sandbox enabled: 1037 | 1038 | ```console 1039 | [Key] com.apple.security.app-sandbox 1040 | [Value] 1041 | [Bool] true 1042 | ``` 1043 | 1044 | Alternatively, you can check while the app is running by opening Activity Monitor and adding the "Sandbox" column. 1045 | 1046 | All App Store software is required to use the App Sandbox. 1047 | 1048 | Browsers like Google Chrome use their own [sandbox](https://chromium.googlesource.com/chromium/src/+/HEAD/docs/design/sandbox.md) so they don't use the App Sandbox. 1049 | 1050 | ## Hardened Runtime 1051 | 1052 | Check if a program uses the [Hardened Runtime](https://developer.apple.com/documentation/security/hardened_runtime) before running it using the following command: 1053 | 1054 | ```console 1055 | codesign --display --verbose /path/to/bundle.app 1056 | ``` 1057 | 1058 | If Hardened Runtime is enabled, you will see `flags=0x10000(runtime)`. The "runtime" means Hardened Runtime is enabled. There might be other flags, but the runtime flag is what we're looking for here. 1059 | 1060 | 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". 1061 | 1062 | Notarized applications are required to use the Hardened Runtime. 1063 | 1064 | ## Antivirus 1065 | 1066 | To scan an application with multiple AV products and examine its behavior, upload it to [VirusTotal](https://www.virustotal.com/#/home/upload) before running it. 1067 | 1068 | macOS comes with a built-in AV program called [XProtect](https://support.apple.com/guide/security/protecting-against-malware-sec469d47bd8). XProtect automatically runs in the background and updates its signatures that it uses to detect malware without you having to do anything. If it detects malware already running, it will work to remove and mitigate it just like any other AV program. 1069 | 1070 | Applications such as [BlockBlock](https://objective-see.com/products/blockblock.html) or [maclaunch.sh](https://github.com/hazcod/maclaunch) might help prevent persistent malware. 1071 | 1072 | Locally installed **Anti-virus** programs are generally a double-edged sword: they may catch "garden variety" malware, but also may increase the attack surface for sophisticated adversaries due to their privileged operating mode. They also typically phone home to send samples in order to catch the newest malware. This can be a privacy concern. 1073 | 1074 | See [Sophail: Applied attacks against Antivirus](https://lock.cmpxchg8b.com/sophailv2.pdf) (pdf), [Analysis and Exploitation of an ESET Vulnerability](https://googleprojectzero.blogspot.ro/2015/06/analysis-and-exploitation-of-eset.html), [Popular Security Software Came Under Relentless NSA and GCHQ Attacks](https://theintercept.com/2015/06/22/nsa-gchq-targeted-kaspersky/), and [How Israel Caught Russian Hackers Scouring the World for U.S. Secrets](https://www.nytimes.com/2017/10/10/technology/kaspersky-lab-israel-russia-hacking.html). 1075 | 1076 | ## Gatekeeper 1077 | 1078 | **Gatekeeper** tries to prevent non-notarized applications from running. 1079 | 1080 | If you try to run an app that isn't notarized, Gatekeeper will give you a warning. This can be easily bypassed if you go to **Privacy & Security**, scroll down to the bottom and click **Open** on your app. Then Gatekeeper will allow you to run it. 1081 | 1082 | Gatekeeper does not cover all binaries - only applications - so exercise caution when running other file types. 1083 | 1084 | # System Integrity Protection 1085 | 1086 | To verify SIP is enabled, use the command `csrutil status`, which should return: `System Integrity Protection status: enabled.` Otherwise, [enable SIP](https://developer.apple.com/documentation/security/disabling_and_enabling_system_integrity_protection) through Recovery Mode. 1087 | 1088 | # Metadata and artifacts 1089 | 1090 | macOS attaches metadata ([APFS extended attributes](https://en.wikipedia.org/wiki/Extended_file_attributes#OS_X)) to downloaded files, which can be viewed with the `mdls` and `xattr` commands: 1091 | 1092 | ```console 1093 | $ ls -l@ ~/Downloads/TorBrowser-8.0.4-osx64_en-US.dmg 1094 | -rw-r--r--@ 1 drduh staff 63M Jan 1 12:00 TorBrowser-8.0.4-osx64_en-US.dmg 1095 | com.apple.metadata:kMDItemWhereFroms 46B 1096 | com.apple.quarantine 57B 1097 | 1098 | $ mdls ~/Downloads/TorBrowser-8.0.4-osx64_en-US.dmg 1099 | kMDItemContentCreationDate = 2019-01-01 00:00:00 +0000 1100 | kMDItemContentCreationDate_Ranking = 2019-01-01 00:00:00 +0000 1101 | kMDItemContentModificationDate = 2019-01-01 00:00:00 +0000 1102 | kMDItemContentType = "com.apple.disk-image-udif" 1103 | kMDItemContentTypeTree = ( 1104 | "public.archive", 1105 | "public.item", 1106 | "public.data", 1107 | "public.disk-image", 1108 | "com.apple.disk-image", 1109 | "com.apple.disk-image-udif" 1110 | ) 1111 | kMDItemDateAdded = 2019-01-01 00:00:00 +0000 1112 | kMDItemDateAdded_Ranking = 2019-01-01 00:00:00 +0000 1113 | kMDItemDisplayName = "TorBrowser-8.0.4-osx64_en-US.dmg" 1114 | kMDItemFSContentChangeDate = 2019-01-01 00:00:00 +0000 1115 | kMDItemFSCreationDate = 2019-01-01 00:00:00 +0000 1116 | kMDItemFSCreatorCode = "" 1117 | kMDItemFSFinderFlags = 0 1118 | kMDItemFSHasCustomIcon = (null) 1119 | kMDItemFSInvisible = 0 1120 | kMDItemFSIsExtensionHidden = 0 1121 | kMDItemFSIsStationery = (null) 1122 | kMDItemFSLabel = 0 1123 | kMDItemFSName = "TorBrowser-8.0.4-osx64_en-US.dmg" 1124 | kMDItemFSNodeCount = (null) 1125 | kMDItemFSOwnerGroupID = 5000 1126 | kMDItemFSOwnerUserID = 501 1127 | kMDItemFSSize = 65840402 1128 | kMDItemFSTypeCode = "" 1129 | kMDItemInterestingDate_Ranking = 2019-01-01 00:00:00 +0000 1130 | kMDItemKind = "Disk Image" 1131 | kMDItemWhereFroms = ( 1132 | "https://dist.torproject.org/torbrowser/8.0.4/TorBrowser-8.0.4-osx64_en-US.dmg", 1133 | "https://www.torproject.org/projects/torbrowser.html.en" 1134 | ) 1135 | 1136 | $ xattr -l ~/Downloads/TorBrowser-8.0.4-osx64_en-US.dmg 1137 | com.apple.metadata:kMDItemWhereFroms: 1138 | 00000000  62 70 6C 69 73 74 30 30 A2 01 02 5F 10 4D 68 74  |bplist00..._.Mht| 1139 | 00000010  74 70 73 3A 2F 2F 64 69 73 74 2E 74 6F 72 70 72  |tps://dist.torpr| 1140 | 00000020  6F 6A 65 63 74 2E 6F 72 67 2F 74 6F 72 62 72 6F  |oject.org/torbro| 1141 | [...] 1142 | com.apple.quarantine: 0081;58519ffa;Google Chrome.app;1F032CAB-F5A1-4D92-84EB-CBECA971B7BC 1143 | ``` 1144 | 1145 | Metadata attributes can also be removed with the `-d` flag: 1146 | 1147 | ```console 1148 | xattr -d com.apple.metadata:kMDItemWhereFroms ~/Downloads/TorBrowser-8.0.4-osx64_en-US.dmg 1149 | 1150 | xattr -d com.apple.quarantine ~/Downloads/TorBrowser-8.0.4-osx64_en-US.dmg 1151 | 1152 | xattr -l ~/Downloads/TorBrowser-8.0.4-osx64_en-US.dmg 1153 | ``` 1154 | 1155 | Other metadata and artifacts may be found in the directories including, but not limited to, `~/Library/Preferences/`, `~/Library/Containers//Data/Library/Preferences`, `/Library/Preferences`, some of which is detailed below. 1156 | 1157 | `~/Library/Preferences/com.apple.sidebarlists.plist` contains historical list of volumes attached. To clear it, use the command `/usr/libexec/PlistBuddy -c "delete :systemitems:VolumesList" ~/Library/Preferences/com.apple.sidebarlists.plist` 1158 | 1159 | `/Library/Preferences/com.apple.Bluetooth.plist` contains Bluetooth metadata, including device history. If Bluetooth is not used, the metadata can be cleared with: 1160 | 1161 | ```console 1162 | sudo defaults delete /Library/Preferences/com.apple.Bluetooth.plist DeviceCache 1163 | sudo defaults delete /Library/Preferences/com.apple.Bluetooth.plist IDSPairedDevices 1164 | sudo defaults delete /Library/Preferences/com.apple.Bluetooth.plist PANDevices 1165 | sudo defaults delete /Library/Preferences/com.apple.Bluetooth.plist PANInterfaces 1166 | sudo defaults delete /Library/Preferences/com.apple.Bluetooth.plist SCOAudioDevices 1167 | ``` 1168 | 1169 | `/var/spool/cups` contains the CUPS printer job cache. To clear it, use the commands: 1170 | 1171 | ```console 1172 | sudo rm -rfv /var/spool/cups/c0* 1173 | sudo rm -rfv /var/spool/cups/tmp/* 1174 | sudo rm -rfv /var/spool/cups/cache/job.cache* 1175 | ``` 1176 | 1177 | To clear the list of iOS devices connected, use: 1178 | 1179 | ```console 1180 | sudo defaults delete /Users/$USER/Library/Preferences/com.apple.iPod.plist "conn:128:Last Connect" 1181 | sudo defaults delete /Users/$USER/Library/Preferences/com.apple.iPod.plist Devices 1182 | sudo defaults delete /Library/Preferences/com.apple.iPod.plist "conn:128:Last Connect" 1183 | sudo defaults delete /Library/Preferences/com.apple.iPod.plist Devices 1184 | sudo rm -rfv /var/db/lockdown/* 1185 | ``` 1186 | 1187 | Quicklook thumbnail data can be cleared using the `qlmanage -r cache` command, but this writes to the file `resetreason` in the Quicklook directories, and states that the Quicklook cache was manually cleared. Disable the thumbnail cache with `qlmanage -r disablecache` 1188 | 1189 | It can also be cleared by getting the directory names with `getconf DARWIN_USER_CACHE_DIR` and `sudo getconf DARWIN_USER_CACHE_DIR`, then removing them: 1190 | 1191 | ```console 1192 | rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/exclusive 1193 | rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/index.sqlite 1194 | rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/index.sqlite-shm 1195 | rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/index.sqlite-wal 1196 | rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/resetreason 1197 | rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/thumbnails.data 1198 | ``` 1199 | 1200 | Similarly, for the root user: 1201 | 1202 | ```console 1203 | sudo rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/thumbnails.fraghandler 1204 | sudo rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/exclusive 1205 | sudo rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/index.sqlite 1206 | sudo rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/index.sqlite-shm 1207 | sudo rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/index.sqlite-wal 1208 | sudo rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/resetreason 1209 | sudo rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/thumbnails.data 1210 | sudo rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/thumbnails.fraghandler 1211 | ``` 1212 | 1213 | Also see ['quicklook' cache may leak encrypted data](https://objective-see.com/blog/blog_0x30.html). 1214 | 1215 | To clear Finder preferences: 1216 | 1217 | ```console 1218 | defaults delete ~/Library/Preferences/com.apple.finder.plist FXDesktopVolumePositions 1219 | defaults delete ~/Library/Preferences/com.apple.finder.plist FXRecentFolders 1220 | defaults delete ~/Library/Preferences/com.apple.finder.plist RecentMoveAndCopyDestinations 1221 | defaults delete ~/Library/Preferences/com.apple.finder.plist RecentSearches 1222 | defaults delete ~/Library/Preferences/com.apple.finder.plist SGTRecentFileSearches 1223 | ``` 1224 | 1225 | Additional diagnostic files may be found in the following directories - but caution should be taken before removing any, as it may break logging or cause other issues: 1226 | 1227 | ``` 1228 | /var/db/CoreDuet/ 1229 | /var/db/diagnostics/ 1230 | /var/db/systemstats/ 1231 | /var/db/uuidtext/ 1232 | /var/log/DiagnosticMessages/ 1233 | ``` 1234 | 1235 | macOS stored preferred Wi-Fi data (including credentials) in NVRAM. To clear it, use the following commands: 1236 | 1237 | ```console 1238 | sudo nvram -d 36C28AB5-6566-4C50-9EBD-CBB920F83843:current-network 1239 | sudo nvram -d 36C28AB5-6566-4C50-9EBD-CBB920F83843:preferred-networks 1240 | sudo nvram -d 36C28AB5-6566-4C50-9EBD-CBB920F83843:preferred-count 1241 | ``` 1242 | 1243 | macOS may collect sensitive information about what you type, even if user dictionary and suggestions are off. To remove them, and prevent them from being created again, use the following commands: 1244 | 1245 | ```console 1246 | rm -rfv "~/Library/LanguageModeling/*" "~/Library/Spelling/*" "~/Library/Suggestions/*" 1247 | chmod -R 000 ~/Library/LanguageModeling ~/Library/Spelling ~/Library/Suggestions 1248 | chflags -R uchg ~/Library/LanguageModeling ~/Library/Spelling ~/Library/Suggestions 1249 | ``` 1250 | 1251 | QuickLook application support metadata can be cleared and locked with the following commands: 1252 | 1253 | ```console 1254 | rm -rfv "~/Library/Application Support/Quick Look/*" 1255 | chmod -R 000 "~/Library/Application Support/Quick Look" 1256 | chflags -R uchg "~/Library/Application Support/Quick Look" 1257 | ``` 1258 | 1259 | Document revision metadata is stored in `/.DocumentRevisions-V100` and can be cleared and locked with the following commands - caution should be taken as this may break some core Apple applications: 1260 | 1261 | ```console 1262 | sudo rm -rfv /.DocumentRevisions-V100/* 1263 | sudo chmod -R 000 /.DocumentRevisions-V100 1264 | sudo chflags -R uchg /.DocumentRevisions-V100 1265 | ``` 1266 | 1267 | Saved application state metadata may be cleared and locked with the following commands: 1268 | 1269 | ```console 1270 | rm -rfv ~/Library/Saved\ Application\ State/* 1271 | rm -rfv ~/Library/Containers//Data/Library/Saved\ Application\ State 1272 | chmod -R 000 ~/Library/Saved\ Application\ State/ 1273 | chmod -R 000 ~/Library/Containers//Data/Library/Saved\ Application\ State 1274 | chflags -R uchg ~/Library/Saved\ Application\ State/ 1275 | chflags -R uchg ~/Library/Containers//Data/Library/Saved\ Application\ State 1276 | ``` 1277 | 1278 | Autosave metadata can be cleared and locked with the following commands: 1279 | 1280 | ```console 1281 | rm -rfv "~/Library/Containers//Data/Library/Autosave Information" 1282 | rm -rfv "~/Library/Autosave Information" 1283 | chmod -R 000 "~/Library/Containers//Data/Library/Autosave Information" 1284 | chmod -R 000 "~/Library/Autosave Information" 1285 | chflags -R uchg "~/Library/Containers//Data/Library/Autosave Information" 1286 | chflags -R uchg "~/Library/Autosave Information" 1287 | ``` 1288 | 1289 | The Siri analytics database, which is created even if the Siri launch agent disabled, can be cleared and locked with the following commands: 1290 | 1291 | ```console 1292 | rm -rfv ~/Library/Assistant/SiriAnalytics.db 1293 | chmod -R 000 ~/Library/Assistant/SiriAnalytics.db 1294 | chflags -R uchg ~/Library/Assistant/SiriAnalytics.db 1295 | ``` 1296 | 1297 | `~/Library/Preferences/com.apple.iTunes.plist` contains iTunes metadata. Recent iTunes search data may be cleared with the following command: 1298 | 1299 | ```console 1300 | defaults delete ~/Library/Preferences/com.apple.iTunes.plist recentSearches 1301 | ``` 1302 | 1303 | If you do not use Apple Account-linked services, the following keys may be cleared, too, using the following commands: 1304 | 1305 | ```console 1306 | defaults delete ~/Library/Preferences/com.apple.iTunes.plist StoreUserInfo 1307 | defaults delete ~/Library/Preferences/com.apple.iTunes.plist WirelessBuddyID 1308 | ``` 1309 | 1310 | All media played in QuickTime Player can be found in: 1311 | 1312 | ```console 1313 | ~/Library/Containers/com.apple.QuickTimePlayerX/Data/Library/Preferences/com.apple.QuickTimePlayerX.plist 1314 | ``` 1315 | 1316 | Additional metadata may exist in the following files: 1317 | 1318 | ```console 1319 | ~/Library/Containers/com.apple.appstore/Data/Library/Preferences/com.apple.commerce.knownclients.plist 1320 | ~/Library/Preferences/com.apple.commerce.plist 1321 | ~/Library/Preferences/com.apple.QuickTimePlayerX.plist 1322 | ``` 1323 | 1324 | # Passwords 1325 | 1326 | The built-in **[Passwords](https://support.apple.com/guide/passwords/the-passwords-app-mchl901b1b95/mac)** app can generate [secure credentials](https://support.apple.com/guide/security/automatic-strong-passwords-secc84c811c4/web). 1327 | 1328 | The **Passwords** app also supports [passkeys](https://fidoalliance.org/passkeys/), FIDO credentials that can replace passwords and are much more secure against phishing, human error, and data breaches. Make sure to use them instead of passwords whenever you can. 1329 | 1330 | Consider using [Diceware](https://secure.research.vt.edu/diceware/) for memorable passwords. 1331 | 1332 | GnuPG can also be used to manage passwords and other encrypted files (see [drduh/Purse](https://github.com/drduh/Purse) and [drduh/pwd.sh](https://github.com/drduh/pwd.sh)). 1333 | 1334 | Ensure all eligible online accounts have [multi-factor authentication](https://en.wikipedia.org/wiki/Multi-factor_authentication) enabled. The strongest form of multi-factor authentication is [WebAuthn](https://en.wikipedia.org/wiki/WebAuthn), followed by [TOTP](https://datatracker.ietf.org/doc/html/rfc6238), then [HOTP](https://datatracker.ietf.org/doc/html/rfc4226), and SMS-based codes are weakest. 1335 | 1336 | [YubiKey](https://www.yubico.com/products/) is an affordable hardware token with WebAuthn support. It can also be used to store cryptographic keys for GnuPG encryption and SSH authentication - see [drduh/YubiKey-Guide](https://github.com/drduh/YubiKey-Guide). 1337 | 1338 | # Backup 1339 | 1340 | Encrypt files locally before backing them up to external media or online services. 1341 | 1342 | If the threat model allows it, you should follow the [3-2-1 backup model](https://www.cisa.gov/sites/default/files/publications/data_backup_options.pdf) as outlined by CISA. Keep 3 copies: the original and two backups. Keep backups on 2 different media types, e.g. on a local drive and cloud storage. Store 1 copy offsite. 1343 | 1344 | [Time Machine](https://support.apple.com/104984) is the built-in tool for handling backups on macOS. Get an external drive or network drive to back up to and [encrypt](https://support.apple.com/guide/mac-help/keep-your-time-machine-backup-disk-secure-mh21241) backups. 1345 | 1346 | GnuPG can be used with a static password or public key (with the private key stored on [YubiKey](https://github.com/drduh/YubiKey-Guide)). 1347 | 1348 | Compress and encrypt a directory using with a password: 1349 | 1350 | ```console 1351 | tar zcvf - ~/Downloads | gpg -c > ~/Desktop/backup-$(date +%F-%H%M).tar.gz.gpg 1352 | ``` 1353 | 1354 | Decrypt and decompress the directory: 1355 | 1356 | ```console 1357 | gpg -o ~/Desktop/decrypted-backup.tar.gz -d ~/Desktop/backup-*.tar.gz.gpg 1358 | 1359 | tar zxvf ~/Desktop/decrypted-backup.tar.gz 1360 | ``` 1361 | 1362 | Encrypted volumes can also be created using **Disk Utility** or `hdiutil`: 1363 | 1364 | ```console 1365 | hdiutil create ~/Desktop/encrypted.dmg -encryption -size 50M -volname "secretStuff" 1366 | 1367 | hdiutil mount ~/Desktop/encrypted.dmg 1368 | 1369 | cp -v ~/Documents/passwords.txt /Volumes/secretStuff 1370 | 1371 | hdiutil eject /Volumes/secretStuff 1372 | ``` 1373 | 1374 | Additional applications and services which offer backups include: 1375 | 1376 | * [Tresorit](https://www.tresorit.com) 1377 | * [restic](https://restic.github.io) 1378 | 1379 | # Wi-Fi 1380 | 1381 | Most Wi-Fi networks continuously broadcast their network name, called the **service set identifier (SSID)**, allowing devices to [passively](https://www.wi-fi.org/knowledge-center/faq/what-are-passive-and-active-scanning) scan for networks they have already connected to before. However, **hidden** networks don't transmit their SSID, meaning the device has to send a probe with the SSID to connect to it. This can reveal previously connected networks to an attacker. 1382 | 1383 | >Apple devices automatically detect when a network is hidden. If a network is hidden, the device sends a probe with the SSID included in the request—not otherwise. This helps prevent the device from broadcasting the name of previously hidden networks a user was connected to, thereby further ensuring privacy. 1384 | 1385 | As such, avoid connecting to [hidden networks](https://support.apple.com/guide/security/wi-fi-privacy-with-apple-devices-sec31e483abf/web#sec059998a98). 1386 | 1387 | Make sure to avoid setting personal networks to hidden and set the security mode to WPA3 or the highest your router supports. Follow Apple's [guidance](https://support.apple.com/en-us/102766) on how to set up your home Wi-Fi network to be as secure as possible. 1388 | 1389 | You can set your Mac to have a different, [random MAC address](https://support.apple.com/en-gb/guide/mac-help/mchlb1cb3eb4/mac) for each network that rotates over time. This is indended to reduce tracking across networks and on the same network over time. 1390 | 1391 | # SSH 1392 | 1393 | For outgoing SSH connections, use hardware or password-protected keys, [set up](http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/) remote hosts and consider [hashing](http://nms.csail.mit.edu/projects/ssh/) them for added privacy. See [drduh/config/ssh_config](https://github.com/drduh/config/blob/main/ssh_config) for recommended client options. 1394 | 1395 | You can also use ssh to create an [encrypted tunnel](http://blog.trackets.com/2014/05/17/ssh-tunnel-local-and-remote-port-forwarding-explained-with-examples.html) to send traffic through, similar to a VPN. 1396 | 1397 | For example, to use Privoxy running on a remote host port 8118: 1398 | 1399 | ```console 1400 | ssh -C -L 5555:127.0.0.1:8118 you@remote-host.tld 1401 | 1402 | sudo networksetup -setwebproxy "Wi-Fi" 127.0.0.1 5555 1403 | 1404 | sudo networksetup -setsecurewebproxy "Wi-Fi" 127.0.0.1 5555 1405 | ``` 1406 | 1407 | Or to use an ssh connection as a [SOCKS proxy](https://www.mikeash.com/ssh_socks.html): 1408 | 1409 | ```console 1410 | ssh -NCD 3000 you@remote-host.tld 1411 | ``` 1412 | 1413 | By default, macOS does **not** have sshd or *Remote Login* enabled. 1414 | 1415 | To enable sshd and allow incoming ssh connections: 1416 | 1417 | ```console 1418 | sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist 1419 | ``` 1420 | 1421 | Or use the **System Preferences** > **Sharing** menu. 1422 | 1423 | If enabling sshd, be sure to disable password authentication and consider further [hardening](https://stribika.github.io/2015/01/04/secure-secure-shell.html) the configuration. See [drduh/config/sshd_config](https://github.com/drduh/config/blob/main/sshd_config) for recommended options. 1424 | 1425 | Confirm whether sshd is running: 1426 | 1427 | ```console 1428 | sudo lsof -Pni TCP:22 1429 | ``` 1430 | 1431 | # Physical access 1432 | 1433 | Keep your Mac physically secure at all times and do not leave it unattended in public. 1434 | 1435 | A skilled attacker with unsupervised physical access could install a [hardware keylogger](https://trmm.net/Thunderstrike_31c3) to record all of your keystrokes. Using a Mac with a built-in keyboard or a bluetooth keyboard makes this more difficult as many off-the-shelf versions of this attack are designed to be plugged in between a USB keyboard and your computer. 1436 | 1437 | To protect against physical theft during use, you can use an anti-forensic tool like [BusKill](https://github.com/buskill/buskill-app) or [swiftGuard](https://github.com/Lennolium/swiftGuard) (updated usbkill, with graphical user interface). All respond to USB events and can immediately shutdown your computer if your device is physically separated from you or an unauthorized device is connected. 1438 | 1439 | Consider purchasing a privacy screen/filter for use in public. 1440 | 1441 | [Nail polish](https://trmm.net/Glitter) and tamper-evidence seals can be applied to components to detect tampering. 1442 | 1443 | # System monitoring 1444 | 1445 | ## OpenBSM audit 1446 | 1447 | macOS has a powerful OpenBSM (Basic Security Module) auditing capability. You can use it to monitor process execution, network activity, and much more. 1448 | 1449 | To tail audit logs, use the `praudit` utility: 1450 | 1451 | ```console 1452 | $ sudo praudit -l /dev/auditpipe 1453 | header,201,11,execve(2),0,Thu Sep 1 12:00:00 2015, + 195 msec,exec arg,/Applications/.evilapp/rootkit,path,/Applications/.evilapp/rootkit,path,/Applications/.evilapp/rootkit,attribute,100755,root,wheel,16777220,986535,0,subject,drduh,root,wheel,root,wheel,412,100005,50511731,0.0.0.0,return,success,0,trailer,201, 1454 | header,88,11,connect(2),0,Thu Sep 1 12:00:00 2015, + 238 msec,argument,1,0x5,fd,socket-inet,2,443,173.194.74.104,subject,drduh,root,wheel,root,wheel,326,100005,50331650,0.0.0.0,return,failure : Operation now in progress,4354967105,trailer,88 1455 | header,111,11,OpenSSH login,0,Thu Sep 1 12:00:00 2015, + 16 msec,subject_ex,drduh,drduh,staff,drduh,staff,404,404,49271,::1,text,successful login drduh,return,success,0,trailer,111, 1456 | ``` 1457 | 1458 | See the manual pages for `audit`, `praudit`, `audit_control` and other files in `/etc/security` 1459 | 1460 | Although `man audit` says the `-s` flag will synchronize the audit configuration, it appears necessary to reboot for changes to take effect. 1461 | 1462 | See articles on [ilostmynotes.blogspot.com](https://ilostmynotes.blogspot.com/2013/10/openbsm-auditd-on-os-x-these-are-logs.html) and [derflounder.wordpress.com](https://derflounder.wordpress.com/2012/01/30/openbsm-auditing-on-mac-os-x/) for more information. 1463 | 1464 | ## DTrace 1465 | 1466 | [System Integrity Protection](https://github.com/drduh/macOS-Security-and-Privacy-Guide#system-integrity-protection) interferes with DTrace, so it is not possible to use it in recent macOS versions without disabling SIP. 1467 | 1468 | * `iosnoop` monitors disk I/O 1469 | * `opensnoop` monitors file opens 1470 | * `execsnoop` monitors execution of processes 1471 | * `errinfo` monitors failed system calls 1472 | * `dtruss` monitors all system calls 1473 | 1474 | See `man -k dtrace` for more information. 1475 | 1476 | ## Execution 1477 | 1478 | `ps -ef` lists information about all running processes. 1479 | 1480 | You can also view processes with **Activity Monitor**. 1481 | 1482 | `launchctl list` and `sudo launchctl list` list loaded and running user and system launch daemons and agents. 1483 | 1484 | ## Network 1485 | 1486 | List open network files: 1487 | 1488 | ```console 1489 | sudo lsof -Pni 1490 | ``` 1491 | 1492 | List contents of various network-related data structures: 1493 | 1494 | ```console 1495 | sudo netstat -atln 1496 | ``` 1497 | 1498 | [Wireshark](https://www.wireshark.org/) can be used from the command line with `tshark`. 1499 | 1500 | Monitor DNS queries and replies: 1501 | 1502 | ```console 1503 | tshark -Y "dns.flags.response == 1" -Tfields \ 1504 | -e frame.time_delta \ 1505 | -e dns.qry.name \ 1506 | -e dns.a \ 1507 | -Eseparator=, 1508 | ``` 1509 | 1510 | Monitor HTTP requests and responses: 1511 | 1512 | ```console 1513 | tshark -Y "http.request or http.response" -Tfields \ 1514 | -e ip.dst \ 1515 | -e http.request.full_uri \ 1516 | -e http.request.method \ 1517 | -e http.response.code \ 1518 | -e http.response.phrase \ 1519 | -Eseparator=/s 1520 | ``` 1521 | 1522 | Monitor x509 (SSL/TLS) certificates: 1523 | 1524 | ```console 1525 | tshark -Y "ssl.handshake.certificate" -Tfields \ 1526 | -e ip.src \ 1527 | -e x509sat.uTF8String \ 1528 | -e x509sat.printableString \ 1529 | -e x509sat.universalString \ 1530 | -e x509sat.IA5String \ 1531 | -e x509sat.teletexString \ 1532 | -Eseparator=/s -Equote=d 1533 | ``` 1534 | 1535 | # Miscellaneous 1536 | 1537 | Disable [Diagnostics & Usage Data](https://support.apple.com/guide/mac-help/share-analytics-information-mac-apple-mh27990). 1538 | 1539 | If you want to play **music** or watch **videos**, use QuickTime Player, the built-in media player in macOS. It uses the [App Sandbox](https://developer.apple.com/documentation/security/app_sandbox/protecting_user_data_with_app_sandbox), [Hardened Runtime](https://developer.apple.com/documentation/xcode/configuring-the-hardened-runtime), and benefits from the [Signed System Volume](https://support.apple.com/guide/security/signed-system-volume-security-secd698747c9/web) as part of the base system. 1540 | 1541 | If you want to use **torrents**, use [Transmission](https://transmissionbt.com/download/) which is free and open source (note: like all software, even open source projects, [malware may still find its way in](http://researchcenter.paloaltonetworks.com/2016/03/new-os-x-ransomware-keranger-infected-transmission-bittorrent-client-installer/)). You may also wish to use a block list to avoid peering with known bad hosts - see [Which is the best blocklist for Transmission](https://giuliomac.wordpress.com/2014/02/19/best-blocklist-for-transmission/) and [johntyree/3331662](https://gist.github.com/johntyree/3331662). 1542 | 1543 | Manage [default file handlers](https://support.apple.com/guide/mac-help/choose-an-app-to-open-a-file-on-mac-mh35597). 1544 | 1545 | Monitor system logs with the **Console** application or `syslog -w` or `/usr/bin/log stream` commands. 1546 | 1547 | Set your screen to lock as soon as the screensaver starts: 1548 | 1549 | ```console 1550 | defaults write com.apple.screensaver askForPassword -int 1 1551 | 1552 | defaults write com.apple.screensaver askForPasswordDelay -int 0 1553 | ``` 1554 | 1555 | Expose hidden files and Library folder in Finder: 1556 | 1557 | ```console 1558 | defaults write com.apple.finder AppleShowAllFiles -bool true 1559 | 1560 | chflags nohidden ~/Library 1561 | ``` 1562 | 1563 | Show all filename extensions (so that "Evil.jpg.app" cannot masquerade easily). 1564 | 1565 | ```console 1566 | defaults write NSGlobalDomain AppleShowAllExtensions -bool true 1567 | ``` 1568 | 1569 | Don't default to saving documents to iCloud: 1570 | 1571 | ```console 1572 | defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false 1573 | ``` 1574 | 1575 | Enable [Secure Keyboard Entry](https://support.apple.com/guide/terminal/use-secure-keyboard-entry-trml109) in Terminal (unless you use [YubiKey](https://mig5.net/content/secure-keyboard-entry-os-x-blocks-interaction-yubikeys) or applications such as [TextExpander](https://smilesoftware.com/textexpander/secure-input)). 1576 | 1577 | Disable crash reporter (the dialog which appears after an application crashes and prompts to report the problem to Apple): 1578 | 1579 | ```console 1580 | defaults write com.apple.CrashReporter DialogType none 1581 | ``` 1582 | 1583 | Disable Bonjour multicast advertisements (also disabling AirPlay and AirPrint features): 1584 | 1585 | ```console 1586 | sudo defaults write /Library/Preferences/com.apple.mDNSResponder.plist NoMulticastAdvertisements -bool YES 1587 | ``` 1588 | 1589 | [Disable Handoff](https://support.apple.com/guide/mac-help/change-airdrop-handoff-settings-mchl6a407f99) and [Bluetooth](https://support.apple.com/guide/mac-help/turn-bluetooth-on-or-off-blth1008) features, if they aren't necessary. 1590 | 1591 | Validate applications are sandboxed in [Activity Monitor](https://developer.apple.com/documentation/security/app_sandbox/protecting_user_data_with_app_sandbox#4098972). 1592 | 1593 | macOS comes with this line in `/etc/sudoers`: 1594 | 1595 | ```console 1596 | Defaults env_keep += "HOME MAIL" 1597 | ``` 1598 | 1599 | Which stops sudo from changing the HOME variable when you elevate privileges. This means it will execute as root the zsh dotfiles in the non-root user's home directory when you run "sudo zsh". It is advisable to comment this line out to avoid a potentially easy way for malware or a local attacker to escalate privileges to root. 1600 | 1601 | If you want to retain the convenience of the root user having a non-root user's home directory, you can append an export line to /var/root/.zshrc, e.g.: 1602 | 1603 | ```console 1604 | export HOME=/Users/blah 1605 | ``` 1606 | 1607 | Set a [custom umask](https://support.apple.com/101914): 1608 | 1609 | ```console 1610 | sudo launchctl config user umask 077 1611 | ``` 1612 | 1613 | Reboot, create a file in Finder and verify its permissions (macOS default allows 'group/other' read access): 1614 | 1615 | ```console 1616 | $ ls -ld umask* 1617 | drwx------ 2 kevin staff 64 Dec 4 12:27 umask_testing_dir 1618 | -rw-------@ 1 kevin staff 2026566 Dec 4 12:28 umask_testing_file 1619 | ``` 1620 | 1621 | # Related software 1622 | 1623 | * [CISOfy/lynis](https://github.com/CISOfy/lynis) - Cross-platform security auditing tool and assists with compliance testing and system hardening. 1624 | * [Zentral](https://github.com/zentralopensource/zentral) - A log and configuration server for osquery. Run audit and probes on inventory, events, logfiles, combine with point-in-time alerting. A full Framework and Django web server build on top of the elastic stack (formerly known as ELK stack). 1625 | * [osquery](https://github.com/osquery/osquery) - Can be used to retrieve low level system information. Users can write SQL queries to retrieve system information. 1626 | * [Pareto Security](https://github.com/paretoSecurity/pareto-mac/) - A MenuBar app to automatically audit your Mac for basic security hygiene. 1627 | 1628 | # Additional resources 1629 | 1630 | * [Apple Open Source](https://opensource.apple.com/) 1631 | * [CIS Benchmarks](https://www.cisecurity.org/benchmark/apple_os/) 1632 | * [EFF Surveillance Self-Defense Guide](https://ssd.eff.org/) 1633 | * [iOS, The Future Of macOS, Freedom, Security And Privacy In An Increasingly Hostile Global Environment](https://gist.github.com/iosecure/357e724811fe04167332ef54e736670d) 1634 | * [Patrick Wardle's Objective-See blog](https://objective-see.com/blog.html) 1635 | * [Reverse Engineering macOS blog](https://reverse.put.as/) 1636 | * [Reverse Engineering Resources](http://samdmarshall.com/re.html) 1637 | * [The macOS Phishing Easy Button: AppleScript Dangers](https://duo.com/blog/the-macos-phishing-easy-button-applescript-dangers) 1638 | * [iCloud security and privacy overview](https://support.apple.com/102651) 1639 | --------------------------------------------------------------------------------