Questo contenuto non è disponibile nella lingua selezionata.
Chapter 11. Protecting systems against intrusive USB devices
Use USBGuard to protect your Red Hat Enterprise Linux system against intrusive USB devices. This framework helps prevent attacks, such as those involving malware or trojans loaded onto USB drives.
11.1. USBGuard intrusion prevention Copia collegamentoCollegamento copiato negli appunti!
With the USBGuard software framework, you can protect your systems against intrusive USB devices by using basic lists of permitted and forbidden devices based on the USB device authorization feature in the kernel.
The USBGuard framework provides the following components:
- The system service component with an inter-process communication (IPC) interface for dynamic interaction and policy enforcement
-
The command-line interface to interact with a running
usbguardsystem service - The rule language for writing USB device authorization policies
- The C++ API for interacting with the system service component implemented in a shared library
The usbguard system service configuration file (/etc/usbguard/usbguard-daemon.conf) includes the options to authorize the users and groups to use the IPC interface.
The system service provides the USBGuard public IPC interface. In Red Hat Enterprise Linux, the access to this interface is limited to only the root user by default.
Consider setting either the IPCAccessControlFiles option (recommended) or the IPCAllowedUsers and IPCAllowedGroups options to limit access to the IPC interface.
Ensure that you do not leave the Access Control List (ACL) unconfigured because this exposes the IPC interface to all local users and allows them to manipulate the authorization state of USB devices and modify the USBGuard policy.
11.2. Installing USBGuard Copia collegamentoCollegamento copiato negli appunti!
Install the USBGuard framework to begin defining policies that govern which USB devices are allowed to connect to your Red Hat Enterprise Linux system. This is the first step in defending against physical security breaches.
Procedure
Install the
usbguardpackage:# dnf install usbguardCreate an initial rule set:
# usbguard generate-policy > /etc/usbguard/rules.confStart the
usbguarddaemon and ensure that it starts automatically on boot:# systemctl enable --now usbguard
Verification
Verify that the
usbguardservice is running:# systemctl status usbguard ● usbguard.service - USBGuard daemon Loaded: loaded (/usr/lib/systemd/system/usbguard.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2019-11-07 09:44:07 CET; 3min 16s ago Docs: man:usbguard-daemon(8) Main PID: 6122 (usbguard-daemon) Tasks: 3 (limit: 11493) Memory: 1.2M CGroup: /system.slice/usbguard.service └─6122 /usr/sbin/usbguard-daemon -f -s -c /etc/usbguard/usbguard-daemon.conf Nov 07 09:44:06 localhost.localdomain systemd[1]: Starting USBGuard daemon... Nov 07 09:44:07 localhost.localdomain systemd[1]: Started USBGuard daemon.List USB devices recognized by USBGuard:
# usbguard list-devices 4: allow id 1d6b:0002 serial "0000:02:00.0" name "xHCI Host Controller" hash...
11.3. Blocking and authorizing a USB device by using the CLI Copia collegamentoCollegamento copiato negli appunti!
You can set USBGuard to allow, block, or reject a specific USB device by using the usbguard command in your terminal. This setting persists while USBGuard is running.
USBGuard uses the terms block and reject with the following meanings:
block- Do not interact with this device for now.
reject- Ignore this device as if it does not exist.
For more information, see the built-in help listed by using the usbguard --help command and the usbguard(1) man page on your system.
Prerequisites
-
The
usbguardservice is installed and running.
Procedure
Determine the ID of the USB device by listing the devices recognized by USBGuard:
# usbguard list-devices 1: allow id 1d6b:0002 serial "0000:00:06.7" name "EHCI Host Controller" hash "JDOb0BiktYs2ct3mSQKopnOOV2h9MGYADwhT+oUtF2s=" parent-hash "4PHGcaDKWtPjKDwYpIRG722cB9SlGz9l9Iea93+Gt9c=" via-port "usb1" with-interface 09:00:00 ... 6: block id 1b1c:1ab1 serial "000024937962" name "Voyager" hash "CrXgiaWIf2bZAU+5WkzOE7y0rdSO82XMzubn7HDb95Q=" parent-hash "JDOb0BiktYs2ct3mSQKopnOOV2h9MGYADwhT+oUtF2s=" via-port "1-3" with-interface 08:06:50Authorize a device to interact with the system:
# usbguard allow-device <ID>Deauthorize and remove a device:
# usbguard reject-device <ID>Deauthorize and retain a device:
# usbguard block-device <ID>
11.4. Permanently blocking and authorizing a USB device Copia collegamentoCollegamento copiato negli appunti!
You can permanently block and authorize a USB device by using the -p option. This adds a device-specific rule to the current policy and persists across restarts and reboots.
USBGuard uses the terms block and reject with the following meanings:
block- Do not interact with this device for now.
reject- Ignore this device as if it does not exist.
Prerequisites
-
The
usbguardservice is installed and running.
Procedure
Configure SELinux to allow the
usbguarddaemon to write rules.Display the
semanageBooleans relevant tousbguard.# semanage boolean -l | grep usbguard usbguard_daemon_write_conf (off , off) Allow usbguard to daemon write conf usbguard_daemon_write_rules (on , on) Allow usbguard to daemon write rulesIf the
usbguard_daemon_write_rulesBoolean is turned off, turn it on.# semanage boolean -m --on usbguard_daemon_write_rules
Determine the ID of the USB device by listing the devices recognized by USBGuard:
# usbguard list-devices 1: allow id 1d6b:0002 serial "0000:00:06.7" name "EHCI Host Controller" hash "JDOb0BiktYs2ct3mSQKopnOOV2h9MGYADwhT+oUtF2s=" parent-hash "4PHGcaDKWtPjKDwYpIRG722cB9SlGz9l9Iea93+Gt9c=" via-port "usb1" with-interface 09:00:00 ... 6: block id 1b1c:1ab1 serial "000024937962" name "Voyager" hash "CrXgiaWIf2bZAU+5WkzOE7y0rdSO82XMzubn7HDb95Q=" parent-hash "JDOb0BiktYs2ct3mSQKopnOOV2h9MGYADwhT+oUtF2s=" via-port "1-3" with-interface 08:06:50Permanently authorize a device to interact with the system:
# usbguard allow-device <ID> -pPermanently deauthorize and remove a device:
# usbguard reject-device <ID> -pPermanently deauthorize and retain a device:
# usbguard block-device <ID> -p
Verification
Check that the USBGuard rules include the changes you made.
# usbguard list-rules
11.5. Creating a custom policy for USB devices Copia collegamentoCollegamento copiato negli appunti!
Create a custom USBGuard policy to meet your specific security requirements. By defining multiple rules, you gain fine-grained control over which USB devices are authorized to interact with your system.
Prerequisites
-
The
usbguardservice is installed and running. -
The
/etc/usbguard/rules.conffile contains an initial rule set generated by theusbguard generate-policycommand.
Procedure
Create a policy which authorizes the currently connected USB devices, and store the generated rules to the
rules.conffile:# usbguard generate-policy --no-hashes > ./rules.confThe
--no-hashesoption does not generate hash attributes for devices. Avoid hash attributes in your configuration settings because they might not be persistent.In the
rules.conffile, add, remove, or edit the rules as required by using a text editor. For example, the following rule allows only devices with a single mass storage interface to interact with the system:allow with-interface equals { 08:*:* }See the
usbguard-rules.conf(5)man page for a detailed rule-language description and more examples.Install the updated policy:
# install -m 0600 -o root -g root rules.conf /etc/usbguard/rules.confRestart the
usbguarddaemon to apply your changes:# systemctl restart usbguard
Verification
Check that your custom rules are in the active policy, for example:
# usbguard list-rules … 4: allow with-interface 08:*:* …
11.6. Creating a structured custom policy for USB devices Copia collegamentoCollegamento copiato negli appunti!
Create a structured custom USBGuard policy in RHEL to manage complex security scenarios. By organizing rules into separate configuration files, you ensure easier maintenance and comprehensive security coverage.
You can organize your custom USBGuard policy in several .conf files within the /etc/usbguard/rules.d/ directory. The usbguard-daemon then combines the main rules.conf file with the .conf files within the directory in alphabetical order.
Prerequisites
-
The
usbguardservice is installed and running.
Procedure
Create a policy which authorizes the currently connected USB devices, and store the generated rules to a new
.conffile, for example,<policy.conf>.# usbguard generate-policy --no-hashes > ./<policy.conf>The
--no-hashesoption does not generate hash attributes for devices. Avoid hash attributes in your configuration settings because they might not be persistent.Open the
<policy.conf>file with a text editor of your choice, and select the lines with the rules that you want to record, for example:… allow id 04f2:0833 serial "" name "USB Keyboard" via-port "7-2" with-interface { 03:01:01 03:00:00 } with-connect-type "unknown" …Copy the selected lines into a separate
.conffile.NoteThe two digits at the beginning of the file name specify the order in which the daemon reads the configuration files.
For example, to copy the rules for your keyboards into a new
.conffile:# grep "USB Keyboard" ./<policy.conf> > ./<10keyboards.conf>Install the new policy to the
/etc/usbguard/rules.d/directory.# install -m 0600 -o root -g root <10keyboards.conf> /etc/usbguard/rules.d/<10keyboards.conf>Move the rest of the lines to the main
rules.conffile.# grep -v "USB Keyboard" ./policy.conf > ./rules.confInstall the remaining rules.
# install -m 0600 -o root -g root rules.conf /etc/usbguard/rules.confRestart the
usbguarddaemon to apply your changes.# systemctl restart usbguard
Verification
Display all active USBGuard rules.
# usbguard list-rules … 15: allow id 04f2:0833 serial "" name "USB Keyboard" hash "kxM/iddRe/WSCocgiuQlVs6Dn0VEza7KiHoDeTz0fyg=" parent-hash "2i6ZBJfTl5BakXF7Gba84/Cp1gslnNc1DM6vWQpie3s=" via-port "7-2" with-interface { 03:01:01 03:00:00 } with-connect-type "unknown" …Display the contents of the
rules.conffile and all the.conffiles in the/etc/usbguard/rules.d/directory.# cat /etc/usbguard/rules.conf /etc/usbguard/rules.d/*.conf- Verify that the active rules contain all the rules from the files and are in the correct order.
11.7. Authorizing users and groups to use the USBGuard IPC interface Copia collegamentoCollegamento copiato negli appunti!
Authorize specific users or groups to use the USBGuard public IPC interface in RHEL to allow non-root management of USB devices. Grant access by using the usbguard add-user subcommand or editing the configuration file to prevent unauthorized manipulation of USB device authorization policies.
Prerequisites
-
The
usbguardservice is installed and running. -
The
/etc/usbguard/rules.conffile contains an initial rule set generated by theusbguard generate-policycommand.
Procedure
Edit the
/etc/usbguard/usbguard-daemon.conffile with the rules you want to add. For example, to allow all users in thewheelgroup to use the IPC interface, add this line:IPCAllowGroups=wheelYou can add users or groups also with the
usbguardcommand. For example, the following command enables a user to have full access to theDevicesandExceptionssections and to list and modify the current policy:# usbguard add-user <user_name> --devices ALL --policy modify,list --exceptions ALLReplace
<user_name>with the user name that should receive these permissions.You can remove the granted permissions for a user by using the
usbguard remove-user <user_name>command.Restart the
usbguarddaemon to apply your changes:# systemctl restart usbguard
11.8. Logging USBguard authorization events to the Linux Audit log Copia collegamentoCollegamento copiato negli appunti!
By default, the usbguard daemon logs events to the /var/log/usbguard/usbguard-audit.log file. You can integrate logging of USBguard authorization events to the standard Linux Audit log.
Prerequisites
-
The
usbguardservice is installed and running. -
The
auditdservice is running.
Procedure
In the
/etc/usbguard/usbguard-daemon.conffile, change theAuditBackendoption fromFileAudittoLinuxAudit:AuditBackend=LinuxAuditRestart the
usbguarddaemon to apply the configuration change:# systemctl restart usbguard
Verification
Query the
auditdaemon log for a USB authorization event, for example:# ausearch -ts recent -m USER_DEVICE