-
Notifications
You must be signed in to change notification settings - Fork 4
/
MacOSThreatTrack.sh
270 lines (248 loc) · 7.17 KB
/
MacOSThreatTrack.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/bin/bash
getSystemInfo() {
hostname=$(hostname)
uuid=$(system_profiler SPHardwareDataType | awk '/UUID/ {print $3}')
macos_version=$(sw_vers -productVersion)
kernel_version=$(sysctl -n kern.version)
processor_info=$(sysctl -n machdep.cpu.brand_string)
memory_info=$(sysctl -n hw.memsize)
total_memory=$((memory_info/(1024*1024)))
disk_info=$(diskutil list)
network_info=$(ifconfig -a)
echo ""
echo "[*] Hostname: $hostname"
echo "[*] UUID: $uuid"
echo "[*] macOS Version: $macos_version"
echo "[*] Kernel Version: $kernel_version"
echo "[*] Processor: $processor_info"
echo "[*] Total Memory: $total_memory MB"
echo "[*] Disk Info: "
echo "$disk_info"
echo "----------------------------"
echo "[*] Network Info: "
echo "$network_info"
echo "----------------------------"
echo ""
}
getEnv(){
echo ""
printenv
}
getProcessList(){
pslist=$(ps aux)
echo ""
echo "$pslist"
}
getUUID() {
ioreg -rd1 -c IOPlatformExpertDevice | grep -E '(UUID)' | awk '{ print $3; }'
}
getSystemUsers() {
allUsersArray=()
results=$(ls /Users | grep -v '^_')
while read user; do
uuid=$(dscl . -read /Users/$user GeneratedUID | awk '{print $2}')
admin=$(dscl . -read /Groups/admin GroupMembership | grep -w "$user")
allUsersArray+=("username: $user, uuid: $uuid, isAdmin: $admin")
done <<< "$results"
echo ""
printf '%s\n' "${allUsersArray[@]}"
}
getZshHistory() {
echo ""
users=( $(ls /Users | grep -v '^_') )
for user in "${users[@]}"; do
path="/Users/$user/.zsh_history"
if [ -f "$path" ]; then
zsh_commands=$(<"$path")
echo "User: $user"
echo "ZSH commands:"
echo "$zsh_commands"
echo "------------------"
fi
done
}
getBashHistory() {
echo ""
users=( $(ls /Users | grep -v '^_') )
for user in "${users[@]}"; do
path="/Users/$user/.bash_history"
if [ -f "$path" ]; then
bash_commands=$(<"$path")
echo "User: $user"
echo "Bash commands:"
echo "$bash_commands"
echo "------------------"
fi
done
}
getShellStartupScripts() {
echo ""
# users=( $(dscl . -list /Users UniqueID | awk '$2 >= 500 { print $1 }') )
users=( $(ls /Users | grep -v '^_') )
files=(".bash_profile" ".bashrc" ".profile")
shell_startup_scripts=()
for user in "${users[@]}"; do
for f in "${files[@]}"; do
if [[ -f "/Users/$user/$f" ]]; then
contents=$(cat "/Users/$user/$f")
echo "User: $user"
echo "Shell_startup_filename: $f"
echo "Shell_startup_data:"
echo "$contents"
echo "---------------------------"
fi
done
done
}
getPeriodic(){
dirs=("/etc/periodic/daily" "/etc/periodic/weekly" "/etc/periodic/monthly")
daily=()
weekly=()
monthly=()
for i in "${dirs[@]}"; do
files=($(ls "$i"))
if [[ "$i" == "/etc/periodic/daily" ]]; then
daily+=( "${files[@]}" )
elif [[ "$i" == "/etc/periodic/weekly" ]]; then
weekly+=( "${files[@]}" )
elif [[ "$i" == "/etc/periodic/monthly" ]]; then
monthly+=( "${files[@]}" )
fi
done
periodic_scripts=(
"daily: ${daily[*]}"
"weekly: ${weekly[*]}"
"monthly: ${monthly[*]}"
)
echo ""
printf "%s\n" "${periodic_scripts[@]}"
}
getPfRules(){
pfrule="/etc/pf.conf"
if [ ! -f "$pfrule" ]; then
echo "Error: /etc/pf.conf not found"
exit 1
fi
contents=$(cat "$pfrule")
echo ""
echo "$contents"
}
getSIPStatus() {
output=$(csrutil status)
status=$(echo "$output" | grep "System Integrity Protection status" | cut -d ':' -f2 | tr -d '.' | tr -d ' ')
echo "status: $status"
}
getGateKeeperStatus(){
gatekeeper_status=$(/usr/sbin/spctl --status)
echo "$gatekeeper_status"
}
getCronJobs(){
echo ""
users=( $(ls /Users | grep -v '^_') )
for user in "${users[@]}"; do
crontab=$(crontab -u "$i" -l)
echo "User: $user"
echo "Crontab: $crontab"
echo "-----------------"
done
}
getListApps(){
echo ""
app_path="/Applications/"
apps=$(ls "${app_path}")
for app in $apps; do
app_full_path="${app_path}${app}"
echo "${app_full_path}"
done
}
getInstallHistory(){
echo ""
if [ -f "/Library/Receipts/InstallHistory.plist" ]; then
cat "/Library/Receipts/InstallHistory.plist"
fi
}
getChromeExtensions(){
users=( $(ls /Users | grep -v '^_') )
for user in "${users[@]}"; do
base_path="/Users/${user}/Library/Application Support/Google/Chrome/Default/Extensions/"
extensions=$(ls "${base_path}")
if [ $? -eq 0 ]; then
for ext in $extensions; do
full_ext="${base_path}${ext}"
files=$(ls "${full_ext}")
for file in $files; do
if [[ $file == "manifest.json" ]]; then
manifest=$(cat "${full_ext}/${file}")
echo "Extension path: ${full_ext}"
echo "Extension manifest.json content:"
echo "${manifest}"
echo "----------------------"
fi
done
done
fi
done
}
getActiveNetworkConnections(){
echo ""
echo "ProcessName ProcessID User FD IPvProtocol UniqueIdentifier TCP/UDP LocalEndpoint RemoteEndpoint"
lsof -i -w | grep "ESTABLISHED"
}
getLaunchDaemons(){
launchdaemons=( $(ls /Library/LaunchDaemons/ | grep 'plist') )
echo ""
for daemon in "${launchdaemons[@]}"; do
echo "LaunchDaemon name: $daemon"
cat $daemon
done
}
getKernelExtensions(){
echo ""
if [ -d "/Library/Extensions/" ]; then
for i in /Library/Extensions/*/; do
if [ -f "${i}Contents/Info.plist" ]; then
info_plist_data=$(cat "${i}Contents/Info.plist")
echo "${i}"
echo "$info_plist_data"
echo "--------------------------------"
fi
done
fi
}
# Run the functions
echo "[+] System info: $(getSystemInfo)"
echo "*****************************************************"
echo "[+] Users list: $(getSystemUsers)"
echo "*****************************************************"
echo "[+] Environment variables: $(getEnv)"
echo "*****************************************************"
echo "[+] Process list: $(getProcessList)"
echo "*****************************************************"
echo "[+] Active network connections: $(getActiveNetworkConnections)"
echo "*****************************************************"
echo "[+] SIP $(getSIPStatus)"
echo "*****************************************************"
echo "[+] GateKeeper $(getGateKeeperStatus)"
echo "*****************************************************"
echo "[+] Zsh history: $(getZshHistory)"
echo "*****************************************************"
echo "[+] Bash history: $(getBashHistory)"
echo "*****************************************************"
echo "[+] Shell startup: $(getShellStartupScripts)"
echo "*****************************************************"
echo "[+] PF rules: $(getPfRules)"
echo "*****************************************************"
echo "[+] Periodic scripts: $(getPeriodic)"
echo "*****************************************************"
echo "[+] CronJobs list: $(getCronJobs)"
echo "*****************************************************"
echo "[+] LaunchDaemons list: $(getLaunchDaemons)"
echo "*****************************************************"
echo "[+] Kernel extensions: $(getKernelExtensions)"
echo "*****************************************************"
echo "[+] Installed applications: $(getListApps)"
echo "*****************************************************"
echo "[+] Installation history: $(getInstallHistory)"
echo "*****************************************************"
echo "[+] Chrome extensions: $(getChromeExtensions)"
echo "*****************************************************"