Qubes-VM-hardening/README.md

77 lines
4.9 KiB
Markdown
Raw Normal View History

2017-03-14 21:53:06 -04:00
# Qubes-VM-hardening
2018-03-29 03:54:01 -04:00
## *README under construction*
Fends off malware at VM startup: Lock-down and remove scripts in /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-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
* Deactivate /rw (root) executables
* Whitelisting for specifying persistent files
* SHA256 checksumming guards against unwanted changes
* Deploy custom defaut files
* Runs at VM start before /rw mounts
2018-03-29 02:18:52 -04:00
2018-02-20 17:40:29 -05:00
## Installing
2018-03-29 03:12:55 -04:00
### Pre-requisites
Disable default passwordless-root access for VMs (see notes below).
2017-04-21 12:03:15 -04:00
2018-02-20 17:40:29 -05:00
1. In a template VM, install the two service files
2018-03-29 03:12:55 -04:00
```
sudo sh ./install
```
2018-02-20 17:40:29 -05:00
2. Activate by specifying as a Qubes service for each VM; There are two levels...
2018-03-29 02:57:06 -04:00
- `vm-boot-protect` - Protects executables/scripts within /home/user and may be used with wide array of Qubes VMs including standalone, netVMs and Whonix.
- `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-02-20 17:40:29 -05:00
2018-03-29 03:12:55 -04:00
CAUTION: The root option **removes** dirs specified in $privdirs; Default is /rw/config, /rw/usrlocal and /rw/bind-dirs.
2017-04-21 12:03:15 -04:00
---
2018-03-29 03:12:55 -04:00
### Usage
2018-03-29 03:54:01 -04:00
Operation is automatic, although particular configuration options such as hash checks are possible.
2018-03-29 03:12:55 -04:00
2018-03-29 03:54:01 -04:00
At the most basic 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-03-29 03:54:01 -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 acheived privilege escalation.
2018-03-29 02:18:52 -04:00
2018-03-29 03:54:01 -04:00
### Configuration
2017-04-10 10:39:15 -04:00
2018-03-29 03:54:01 -04:00
Although protecting init/autostart files should result in Qubes template-based VMs that boot 'cleanly' with much less chance of being affected by malware initially, it should be noted that subsequent running of some apps such as Firefox could conceivably 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 code. Even if malware persists in a VM, it should be possible to run other apps and terminals without interference if passwordless is disabled and malware has not escalated to root via an exploit (admittedly, a big 'if').
2017-04-10 10:39:15 -04:00
All in all, this is one of the easy steps a Qubes user can take to make their VMs much less hospitable to intrusion and malware. Security can be further enhanced by enabling AppArmor or similar controls.
Note this sets the Linux immutable flag on files and directories, so intended modifications to the target files and dirs will require the extra step of disabling the flag using `sudo chattr -i`. Immutable is necessary because normal read-write permissions cannot prevent a normal user from removing other users' files (even root) from a dir they own; once removed, an init file like .bashrc can be re-created by the user process which opens the door to hijacking.
2018-03-29 02:18:52 -04:00
### Limitations
2018-03-29 03:12:55 -04:00
vm-boot-protect relies mostly on the guest operating system's own defenses, with one added advantage of root volume non-persistence provided by the Qubes template system. This means that attacks which can profoundly undermine the guest OS, i.e. by damaging the private filesystem itself or quickly re-exploiting network vulnerabilities, could conceivably still persist at startup.
2018-03-29 02:18:52 -04:00
Further, if the user configures a vulnerable app to run at startup, this introduces a malware risk -- although not to the VM's whole execution environment if no privilege escalation is available to the attacker.
2018-03-29 02:57:06 -04:00
### Notes
* Disabling the Qubes default passwordless-root is necessary for this project to have a meaningful impact. Here are two recommended ways:
1. [Enabling dom0 prompt for sudo](https://www.qubes-os.org/doc/vm-sudo/#replacing-password-less-root-access-with-dom0-user-prompt)
2018-03-29 03:12:55 -04:00
2. 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 VM commands as root.
2018-03-29 02:57:06 -04:00
* 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
* All the user-writable startup files in /home should be protected. See issue #9 if you see an omission or other problem.
2017-03-14 22:23:43 -04:00
2018-03-29 02:18:52 -04:00
## Releases
- v0.8.0 Adds protection to /rw, file SHA checksums, whitelists, deployment
- v0.2.0 Protects /home/user files and dirs
2017-03-14 22:23:43 -04:00
## See also:
[AppArmor Profiles](https://github.com/tasket/AppArmor-Profiles)