Qubes-VM-hardening/README.md

124 lines
11 KiB
Markdown
Raw Normal View History

2018-04-14 11:18:55 -04:00
## Qubes VM hardening
Leverage Qubes template non-persistence to fend off malware at VM startup: Lock-down, quarantine and check contents of /rw private storage that affect the execution environment.
2017-03-14 22:03:31 -04:00
2017-04-21 12:03:15 -04:00
2018-04-14 11:18:55 -04:00
### vm-boot-protect.service
2018-04-03 10:53:15 -04:00
* Acts at VM startup before private volume /rw mounts
* User: Protect /home desktop & shell startup executables
2018-04-03 10:53:15 -04:00
* Root: Quarantine all /rw configs & scripts, with whitelisting
2019-08-13 13:46:52 -04:00
* Organize configurations with named tags
* Deploy trusted custom files to /rw on each boot
2018-04-14 11:18:55 -04:00
* SHA256 hash checking against unwanted changes
2018-04-03 10:53:15 -04:00
* Provides rescue shell on error or request
* Works with template-based AppVMs, sys-net and sys-vpn
2018-02-20 17:40:29 -05:00
2018-03-29 02:18:52 -04:00
2018-04-14 11:18:55 -04:00
### Installing
2017-04-21 12:03:15 -04:00
2018-04-02 10:38:47 -04:00
1. In a template VM, install the service files
2018-03-29 03:12:55 -04:00
```
2018-03-29 07:19:20 -04:00
cd Qubes-VM-hardening
2019-08-13 16:22:27 -04:00
sudo bash install
2018-03-29 03:12:55 -04:00
```
2018-03-29 07:19:20 -04:00
2. Activate by specifying one of the following Qubes services for your VM(s)...
- `vm-boot-protect` - Protects executables/scripts within /home/user and may be used with wide array of Qubes VMs including standalone, appVMs, netVMs, Whonix, etc.
2018-03-29 02:57:06 -04:00
- `vm-boot-protect-root` - Protects /home/user as above, automatic /rw executable deactivation, whitelisting, checksumming, deployment. Works with appVMs, netVMs, etc. that are _template-based_.
2017-04-21 12:03:15 -04:00
CAUTION: The -root option by default **removes** prior copies of /rw/config, /rw/usrlocal and /rw/bind-dirs. This can delete data!
2017-04-21 12:03:15 -04:00
3. Disable Qubes default passwordless-root. This is necessary for the above measures to work effectively...
2018-04-14 11:18:55 -04:00
For Debian-based templates the installer will launch `configure-sudo-prompt` automatically to enable a sudo [yes/no prompt](https://www.qubes-os.org/doc/vm-sudo/#replacing-password-less-root-access-with-dom0-user-prompt) that appears in dom0. This handles the template configuration then displays several commands to manually configure dom0 (the dom0 step is required only once, regardless of how many templates you configure). You may test the `configure-sudo-prompt` script in a regular template-based appVM to see if it works, although the effect will be temporary.
Alternately, you can uninstall the `qubes-core-agent-passwordless-root` package from the template. After doing this, you will have to use `qvm-run -u root` from dom0 to run any VM commands as root.
2019-08-13 13:46:52 -04:00
2017-04-21 12:03:15 -04:00
---
2018-03-29 03:12:55 -04:00
### Usage
2018-04-03 10:53:15 -04:00
Operation is automatic and will result in either a normal boot process with full access to the private volume at /rw, or a rescue service mode providing an xterm shell and the private volume quarantined at /dev/badxvdb.
2018-03-29 03:12:55 -04:00
2019-01-29 23:09:53 -05:00
At the `vm-boot-protect` level, certain executable files in /home will be made immutable so PATH and `alias` cannot be used to hijack commands like `su` and `sudo`, nor can impostor apps autostart whenever a VM starts. This can be added to virtually any Debian or Fedora VM and prevents unprivileged attacks from gaining persistence at startup.
2018-03-29 03:12:55 -04:00
2018-04-03 10:53:15 -04:00
At the `vm-boot-protect-root` level, the $privdirs paths will be renamed as backups, effectively removing them from the VM startup. Then whitelisting, hash/checksumming and deployment are done (if configured). This protects VM startup from attacks that had previously achieved privilege escalation.
The special `vm-boot-protect-cli` level unconditionally runs an xterm rescue shell.
2018-03-29 02:18:52 -04:00
2018-04-02 10:55:55 -04:00
2018-03-29 03:54:01 -04:00
### Configuration
2017-04-10 10:39:15 -04:00
2019-08-13 13:46:52 -04:00
Files can be added to /etc/default/vms in the template to configure the following `vm-boot-protect-root` features...
2018-03-29 07:19:20 -04:00
**Hashes/Checksums** are checked in ../vms/vms.all.SHA and ../vms/$vmname.SHA files. File paths contained in them must be absolute, and references to '/home' must be prefixed with '/rw/'. Hashes in $vmname.SHA will override hashes specified for the same paths in vms.all.SHA. See also man page for `sha256sum -c`.
2017-04-10 10:39:15 -04:00
2018-04-03 16:40:00 -04:00
**Whitelists** are checked in ../vms/vms.all.whitelist and ../vms/$vmname.whitelist files, and file paths contained in them must start with `/rw/`. A default is provided in ..vms/sys-net.whitelist to preserve Network Manager connections and sleep module list in sys-net.
2017-04-10 10:39:15 -04:00
2019-01-29 23:09:53 -05:00
**Deployment** files are copied _recursively_ from ../vms/vms.all/rw/ and ../vms/$vmname/rw/ dirs. Example is to place the .bashrc file in /etc/default/vms/vms.all/rw/home/user/.bashrc for deployment to /rw/home/user/.bashrc. Once copying is complete,
the /etc/defaults/vms folder is deleted from the running VM (this has no effect on the original in the template).
2019-08-11 06:26:26 -04:00
**rc files** are sh script fragments sourced from ../vms/vms.all.rc and ../vms/$vmname.rc. They run near the beginning of the vm-boot-protect service before mounting /rw, and can be used to override variable definitions like `privdirs` as well as the `vm_boot_finish` function which runs near the end before dismount. Another use for rc files is to run threat detection tools such as antivirus.
2019-08-13 13:46:52 -04:00
**Tags** may be defined with all of the above features so that you are not limited to specifying them for either all VMs or specifically-named VMs. Simply configure them as you would acccording to the above directions, but place the files under the '@tags' subdir instead. For example '/etc/default/vms/@tags/special.whitelist' defines a whitelist for the tag 'special'. A tag can be activated for one or more VMs by adding a Qubes service prefixed with `vm-boot-tag-` (i.e. vm-boot-tag-special) to the VMs. Also, multiple tags may be activated for a VM.
2019-08-11 06:26:26 -04:00
2019-01-29 23:09:53 -05:00
### Where to use: Basic examples
After installing into a template, simply enable `vm-boot-protect-root` service without configuration. Recommended for the following types of VMs:
2019-07-13 05:39:42 -04:00
* Service VMs: sys-usb and sys-net.
* App VMs: untrusted, personal, banking, vault, etc. This assumes using regular Linux apps without tailored Qubes-specific settings in /rw such as *Firefox, Chromium, Thunderbird, KeePassX, office apps, media playback & editing*, etc. For these and many more, no configuration should be necessary.
2019-01-29 23:09:53 -05:00
Examples where `vm-boot-protect-root` requires configuration: sys-vpn (see Notes), Martus and Whonix (needs testing). Note that VMs sys-vpn and sys-firewall are fairly low-risk VMs so there may not be a compelling reason to use the service with them.
Examples where -root should *not* be enabled:
2019-07-13 05:39:42 -04:00
* DispVMs. Sensible option is to enable sudo security for DispVM templates; service can be installed into template and left unused.
* Whonix VMs. Plain `vm-boot-protect` is best used until Whonix persistence files can be mapped.
* Standalone VMs. Plain `vm-boot-protect` makes more sense for these.
* Non-Linux VMs (currently unsupported for any mode)
2018-03-29 02:18:52 -04:00
2019-08-13 13:46:52 -04:00
### Example configs
2019-08-13 15:55:13 -04:00
Some useful configurations have been supplied in /etc/default/vms:
2019-08-13 13:46:52 -04:00
* vm-boot-tag-network: Contains a whitelist for Network Manager connections and the module blacklist which is often used with network interfaces in Qubes. By default, this config also activates for any VM named 'sys-net'.
2019-08-13 15:55:13 -04:00
* vm-boot-tag-qhome: Quarantines /home in addition to the /rw system dirs. Useful for 'sys-usb' and DispVM-like functionality.
* vm-boot-tag-noqbackup: Deletes all quarantined files that are not whitelisted.
2019-08-13 13:46:52 -04:00
* vm-boot-tag-ibrowse: Preserves Firefox bookmarks while quarantining the rest of /home folder. (To preserve pre-existing bookmarks, existing Firefox profile folder must be renamed to "profile.default" before activating this tag.)
2018-03-29 02:18:52 -04:00
2018-04-03 16:40:00 -04:00
### Scope and Limitations
2018-03-29 02:18:52 -04:00
2018-04-03 16:40:00 -04:00
The *vm-boot-protect* concept enhances the guest operating system's own defenses by using the *root volume non-persistence* provided by the Qubes template system; thus a relatively pristine startup state may be achieved if the *private* volume is brought online in a controlled manner. Protecting the init/autostart files should result in Qubes template-based VMs that boot 'cleanly' with much less chance of being affected by malware initially. Even if malware persists in a VM, it should be possible to run other apps and terminals without interference if the malware has not escalated to root (admittedly, a big 'if').
2018-03-29 07:19:20 -04:00
Conversely, attacks which damage/exploit the Ext4 private filesystem itself or quickly re-exploit network vulnerabilities could conceivably still persist at startup. Further, repeated running of some apps such as Firefox, Chrome, LibreOffice, PDF viewers, online games, etc. may reactivate malware; this is not only because of the complexity of the formats handled by such apps, but also because of settings contained in javascript or which specify commands to be executed by the app. Therefore, setting apps to autostart can diminish protection of the startup environment.
2019-08-13 13:46:52 -04:00
Note that as vulnerabilities are patched via system updates, malware that used those vulns to gain entry may cease to function without the kind of loopholes that *vm-boot-protect* closes.
2018-03-29 02:18:52 -04:00
2018-03-29 02:57:06 -04:00
### Notes
2019-08-13 15:55:13 -04:00
* The /rw/home directory can be added to `privdirs` so it is quarantined much like the other /rw dirs. The easiest way to configure this is to define `privdirs_add=/rw/home` in an rc file; see 'qhome.rc' for an exmaple.
2019-08-11 06:26:26 -04:00
2019-07-19 12:48:40 -04:00
* A bug in v0.8.4 will erase anything in '/etc/default/vms' when booting into the template. For proper
future operation with sys-net or other VMs you may have customized in that path, updating Qubes-VM-hardening
to the latest version (using the install script) is recommended, along with restoring any custom files
in '/etc/default/vms'. Thanks to Daniel Moerner for submitting the patch!
2018-03-29 03:54:01 -04:00
* All the user-writable startup files in /home should be protected by the immutable flag; See issue #9 if you notice an omission or other problem. An extra step of disabling the flag using `sudo chattr -i` is required whenever the user wants to modify these startup files.
2019-01-29 23:09:53 -05:00
* The sys-net VM should work 'out of the box' with the vm-boot-protect-root service via the included whitelist file. Additional network VMs may require configuration, such as `cp sys-net.whitelist sys-net2.whitelist`.
2018-04-14 11:18:55 -04:00
* Using the -root service with a [VPN VM](https://github.com/tasket/Qubes-vpn-support) requires manual configuration in the template and can be approached different ways: Whitelist (optionally with SHA) can be made for the appropriate files. Alternately, all VPN configs can be added under /etc/default/vms/vmname/rw so they'll be automatically deployed.
* Currently the service cannot seamlessly handle 'first boot' when the private volume must be initialized. If you enabled the service on a VM before its first startup, on first start the shell will display a notice telling you to restart the VM. Subsequent starts will proceed normally.
2019-08-13 16:22:27 -04:00
* The service can be removed from the system with `cd Qubes-VM-hardening; sudo bash install --uninstall`
2018-03-29 02:18:52 -04:00
## Releases
2019-08-13 13:46:52 -04:00
- v0.9.0 Add tags and rc files, protect more home scripts, reinitialize home
2019-07-19 12:48:40 -04:00
- v0.8.5 Fix template detection, /etc/default/vms erasure
2019-07-13 05:39:42 -04:00
- v0.8.4 Add protection to /home/user/.config/systemd
2019-01-29 23:09:53 -05:00
- v0.8.3 Fix for install script copying to /etc/default/vms
2018-04-15 15:21:56 -04:00
- v0.8.2 Working rescue shell. Add sys-net whitelist, sudo config, fixes.
2018-04-03 10:53:15 -04:00
- v0.8.0 Adds protection to /rw, file SHA checksums, whitelists, deployment
- v0.2.0 Protects /home/user files and dirs