-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcafee-cleaner.sh
executable file
Β·145 lines (120 loc) Β· 3.13 KB
/
mcafee-cleaner.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env bash
#
#
STEP_REMOVE_INSTALLATION="Removing McAfee"
STEP_STOP_SERVICES="Stopping McAfee services"
STEP_REMOVE_SERVICES="Removing McAfee services"
STEP_KILL_PROCESSES="Killing all remaining McAfee processes"
STEP_REMOVE_USER="Removing McAfee user and group from the system"
STEP_REMOVE_DIRS="Removing McAfee directories"
STEP_REMOVE_FILES="Removing McAfee files"
STEP_UNLOAD_KEXTS="Unloading McAfee kernel extensions"
STEP_PREVENT_INSTALLATION="Preventing McAfee from installing itself again"
STEP_RECREATE_DIRS="Recreate McAfee directory structure and make it immutable"
STEP_COUNTER=1
MCAFEE_DIR_PATHS=(
"/usr/local/McAfee/"
"/Library/Application Support/McAfee/"
"/Library/McAfee/"
"/var/McAfee/"
"/etc/ma.d"
"/etc/cma.d/"
"/Library/StartupItems/ma"
"/Library/StartupItems/cma"
"/Applications/McAfee Endpoint Security for Mac.app/"
)
MCAFEE_FILE_GLOBS=(
"/private/var/db/receipts/com.mcafee*"
"/private/var/log/McAfeeSecurity.log*"
"/Library/LaunchDaemons/com.mcafee*"
"/etc/ma.conf"
)
MCAFEE_SERVICES=(
"com.mcafee.menulet"
"com.mcafee.reporter"
"com.mcafee.virusscan.fmpd"
"com.mcafee.ssm.ScanManager"
"com.mcafee.virusscan.ssm.ScanFactory"
"com.mcafee.ssm.Eupdate"
"com.mcafee.agent.macompat"
"com.mcafee.agent.ma"
"com.mcafee.agent.macmn"
)
MCAFEE_KEXTS=(
"com.McAfee.FMPSysCore"
"com.McAfee.AVKext"
"com.McAfee.FileCore"
)
MCAFEE_USER="mfe"
MCAFEE_GROUP="mfe"
main() {
echo "$STEP_REMOVE_INSTALLATION"
report_step "$STEP_STOP_SERVICES"
launchctl_action_on_services "stop"
report_step "$STEP_REMOVE_SERVICES"
launchctl_action_on_services "remove"
report_step "$STEP_KILL_PROCESSES"
pkill -i -f mcafee
report_step "$STEP_REMOVE_USER"
delete_user "$MCAFEE_USER" "$MCAFEE_GROUP"
report_step "$STEP_REMOVE_DIRS"
remove_dirs
report_step "$STEP_REMOVE_FILES"
remove_files
report_step "$STEP_UNLOAD_KEXTS"
unload_kexts
echo ""
echo "$STEP_PREVENT_INSTALLATION"
report_step "$STEP_RECREATE_DIRS"
create_immutable_dirs
}
report_step() {
local __step="$1"
echo "${STEP_COUNTER}. ${__step} ..."
STEP_COUNTER=$((STEP_COUNTER+1))
}
launchctl_action_on_services() {
local __action="$1"
for i in "${MCAFEE_SERVICES[@]}"; do
launchctl "${__action}" "${i}"
done
}
delete_user() {
local __user="$1"
local __group="$2"
# Ignore errors if user already deleted
dscl . -delete "/Users/${__user}" &> /dev/null
dscl . -delete "/groups/${__group}" &> /dev/null
}
remove_dirs() {
for i in "${MCAFEE_DIR_PATHS[@]}"; do
echo "${i}"
ls -laO "${i}"
# Check if the directory is already marked by us as immutable
if [[ ! $(ls -laO "${i}" | grep schg | grep -c uchg) -ge 1 ]]; then
rm -rf "${i}"
fi
done
}
remove_files() {
for i in "${MCAFEE_FILE_GLOBS[@]}"; do
rm -rf "${i}"
done
}
create_immutable_dirs() {
for i in "${MCAFEE_DIR_PATHS[@]}"; do
# Create dir
mkdir -p "${i}"
# Make it immutable by user
chflags -R uchg "${i}"
# Make it immutable to system
chflags -R schg "${i}"
done
}
unload_kexts() {
for i in "${MCAFEE_KEXTS[@]}"; do
kextunload -b "${i}" &> /dev/null
done
}
# Execute
main