-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathtoggle_nousb.sh
executable file
·86 lines (72 loc) · 1.77 KB
/
toggle_nousb.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
#
# Script: toggle_usb (part of system-hardening)
# Description: RHEL 6 Hardening Script to enbale or disable a device
# License: GPL (see COPYING)
# Copyright: Red Hat Consulting, Sep 2013
# Author: Frank Caviggia <fcaviggi (at) redhat.com>
# Determine the Path
function realpath() {
local r=$1; local t=$(readlink $r)
while [ $t ]; do
r=$(cd $(dirname $r) && cd $(dirname $t) && pwd -P)/$(basename $t)
t=$(readlink $r)
done
echo $r
}
# GLOBAL VARIABLES
BASE_DIR=`dirname $(realpath $0)`
BASE_BACKUP=$BASE_DIR/backups
# USAGE STATEMENT
usage() {
cat << EOF
usage: $0 [options]
-h Show this message
RHEL 6 Hardening Script
Toggles 'nousb' Kernel Argument on and off.
Included to resolve issues with usb keyboards and mice.
EOF
}
# APPLY SYSTEM CONFIGURATION
apply_configuration() {
echo -n "Remove 'nousb' Kernel Arguement ... "
/sbin/grubby --update-kernel=ALL --remove-args="nousb"
/usr/bin/logger -p security.info "Disabled 'nousb' Kernel Argument (system-hardening)"
echo "Done."
}
# RESTORE ORIGINAL CONFIGURATION
remove_configuration() {
echo -n "Enable 'nousb' Kernel Arguement ... "
/sbin/grubby --update-kernel=ALL --args="nousb"
/usr/bin/logger -p security.info "Enabled 'nousb' Kernel Argument (system-hardening)"
echo "Done."
}
# Check for root user
if [[ $EUID -ne 0 ]]; then
if [ -z "$QUIET" ]; then
echo
tput setaf 1;echo -e "\033[1mPlease re-run this script as root!\033[0m";tput sgr0
fi
exit 1
fi
while getopts ":h" OPTION; do
case $OPTION in
h)
usage
exit 0
;;
?)
echo "ERROR: Invalid Option Provided!"
echo
usage
exit 1
;;
esac
done
NOUSB=$( cat /boot/grub/grub.conf | grep -i kernel | grep -i nousb | wc -l )
if [ $NOUSB -eq 0 ]; then
apply_configuration
else
remove_confiruation
fi
exit 0