Qubes-VM-hardening/README.md

77 lines
5.2 KiB
Markdown
Raw Normal View History

2017-03-14 21:53:06 -04:00
# Qubes-VM-hardening
2017-03-14 22:03:31 -04:00
2018-04-02 10:38:47 -04:00
Fend off malware at VM startup: Lock-down and remove scripts in /rw private storage that affect the execution environment.
Leverage Qubes template non-persistence to enhance the guest operating system's own defenses.
2017-04-21 12:03:15 -04:00
2018-03-29 02:57:06 -04:00
## vm-boot-protect.service
2018-02-20 17:40:29 -05:00
* Protect /home (user) executable files as immutable
2018-04-02 10:55:55 -04:00
* Quarantine /rw (root) configs & scripts, with Whitelisting
2018-02-20 17:40:29 -05:00
* SHA256 checksumming guards against unwanted changes
2018-04-02 10:38:47 -04:00
* Re-deploy custom 'default' files to /rw on each boot
2018-02-20 17:40:29 -05:00
* Runs at VM start before /rw mounts
2018-04-02 10:38:47 -04:00
* Provides rescue shell with non-persistent /home
2018-02-20 17:40:29 -05:00
2018-03-29 02:18:52 -04:00
2018-02-20 17:40:29 -05: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
2018-03-29 03:12:55 -04:00
sudo sh ./install
```
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
2018-04-02 10:38:47 -04:00
CAUTION: The root option **removes** dirs /rw/config, /rw/usrlocal and /rw/bind-dirs.
2017-04-21 12:03:15 -04:00
2018-03-29 07:19:20 -04:00
3. Disabling the Qubes default passwordless-root is necessary for the above measures to work effectively. Here are two recommended ways (choose one):
- [Enabling auth prompt for sudo](https://www.qubes-os.org/doc/vm-sudo/#replacing-password-less-root-access-with-dom0-user-prompt) configures a simple yes/no prompt that appears in dom0.
- 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.
2017-04-21 12:03:15 -04:00
---
2018-03-29 03:12:55 -04:00
### Usage
2018-04-02 10:55:55 -04:00
Operation is automatic and will result in either a normal process with full access to the private volume at /rw, or a rescue service mode with the private volume quarantined at /mnt/rwtmp.
2018-03-29 03:12:55 -04:00
2018-04-02 10:38:47 -04: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 prevents normal-privilege attacks from gaining persistence at startup.
2018-03-29 03:12:55 -04:00
2018-04-02 10:38:47 -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.
2018-03-29 02:18:52 -04:00
2018-04-02 10:55:55 -04:00
The special `vm-boot-protect-cli` level unconditionally goes to the service shell.
2018-03-29 03:54:01 -04:00
### Configuration
2017-04-10 10:39:15 -04:00
2018-04-02 10:38:47 -04:00
Files can be added to /etc/default/vms in the template to enable the following 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. See man page for `sha256sum -c`.
2017-04-10 10:39:15 -04:00
2018-03-29 07:19:20 -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/`.
2017-04-10 10:39:15 -04:00
2018-04-02 10:38:47 -04: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 .
2018-03-29 02:18:52 -04:00
### Limitations
2018-04-02 10:38:47 -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
2018-04-02 10:38:47 -04:00
Conversely, attacks which damage/exploit the private filesystem itself or quickly re-exploit network vulnerabilities could conceivably still persist at startup. Repeated running of some apps such as Firefox, Chrome, LibreOffice, PDF viewers, online games, etc. may allow malware to persist in a VM; 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.
2018-03-29 02:18:52 -04:00
2018-03-29 02:57:06 -04:00
### Notes
* The service name has been changed from `vm-sudo-protect` in pre-release to `vm-boot-protect`. The install script will automatically try to disable the old service.
* Currently if a vm-boot-protect check fails there is no immediate way to alert the user at startup. The VM will attempt to shutdown instead. See issue #7 for discussion.
2018-03-29 03:54:01 -04:00
2018-03-29 07:19:20 -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` whenever the user wants to modify these startup files.
2017-03-14 22:23:43 -04:00
2018-03-29 02:18:52 -04:00
## Releases
2018-04-02 10:55:55 -04:00
- v0.8.1 Rescue service mode on error or request
2018-03-29 02:18:52 -04:00
- v0.8.0 Adds protection to /rw, file SHA checksums, whitelists, deployment
- v0.2.0 Protects /home/user files and dirs