-
Notifications
You must be signed in to change notification settings - Fork 5
/
AMFI_test.sh
executable file
·277 lines (245 loc) · 9.67 KB
/
AMFI_test.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
271
272
273
274
275
276
277
#!/bin/bash
### EXPECTED RESULTS:
# Only 0x10000 with double entitlement ALLOWED to inject dylibs using DYLD_INSERT_LIBRARIES - 25.03.2024 (expected behaviour)
# Multiple issue with DEV pruned reported to Apple ->
###############
### STARTER ###
###############
# ent1.plist
echo '''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>
</dict>
</plist>''' > ent1.plist
# ent2.plist
echo '''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
</plist>''' > ent2.plist
# hello.c
echo '''#include <stdio.h>
int main() {
// Print "Hello, World!" to the console
printf("Hello, World!\n");
return 0;
}''' > hello.c
# NORMAL USER ACCESS BINARY SAMPLE
clang hello.c -o hello
# NORMAL USER ACCESS BINARY SAMPLE - RESTRICTED SEGMENT
mkdir RESTRICTED
clang -sectcreate __RESTRICT __restrict /dev/null hello.c -o RESTRICTED/hello_restricted
# SUIDS
mkdir SUIDS
# SUIDS - RESTRICTED SEGMENT
mkdir RESTRICTED_SUIDS
# SGIDS
mkdir SGIDS
# SGIDS - RESTRICTED SEGMENT
mkdir RESTRICTED_SGIDS
##############
### NORMAL ###
##############
## SIGNING
# CS_RESTRICT
cp hello hello_800
codesign -s - -f --option=0x800 hello_800
# CS_REQUIRE_LV
cp hello hello_2000
codesign -s - -f --option=0x2000 hello_2000
# CS_RUNTIME
cp hello hello_10000
codesign -s - -f --option=0x10000 hello_10000
# CS_RESTRICT + CS_REQUIRE_LV
cp hello hello_2800
codesign -s - -f --option=0x2800 hello_2800
# CS_RESTRICT + CS_RUNTIME
cp hello hello_10800
codesign -s - -f --option=0x10800 hello_10800
# CS_REQUIRE_LV + CS_RUNTIME
cp hello hello_12000
codesign -s - -f --option=0x12000 hello_12000
# CS_RESTRICT + CS_REQUIRE_LV + CS_RUNTIME
cp hello hello_12800
codesign -s - -f --option=0x12800 hello_12800
## SIGNING WITH ENTITLEMENTS - ent1.plist
cp hello hello_ent1
codesign --entitlements ent1.plist -s - -f hello_ent1
# CS_RESTRICT
cp hello hello_800_ent1
codesign --entitlements ent1.plist -s - -f --option=0x800 hello_800_ent1
# CS_REQUIRE_LV
cp hello hello_2000_ent1
codesign --entitlements ent1.plist -s - -f --option=0x2000 hello_2000_ent1
# CS_RUNTIME
cp hello hello_10000_ent1
codesign --entitlements ent1.plist -s - -f --option=0x10000 hello_10000_ent1
# CS_RESTRICT + CS_REQUIRE_LV
cp hello hello_2800_ent1
codesign --entitlements ent1.plist -s - -f --option=0x2800 hello_2800_ent1
# CS_RESTRICT + CS_RUNTIME
cp hello hello_10800_ent1
codesign --entitlements ent1.plist -s - -f --option=0x10800 hello_10800_ent1
# CS_REQUIRE_LV + CS_RUNTIME
cp hello hello_12000_ent1
codesign --entitlements ent1.plist -s - -f --option=0x12000 hello_12000_ent1
# CS_RESTRICT + CS_REQUIRE_LV + CS_RUNTIME
cp hello hello_12800_ent1
codesign --entitlements ent1.plist -s - -f --option=0x12800 hello_12800_ent1
## SIGNING WITH ENTITLEMENTS - ent2.plist
cp hello hello_ent2
codesign --entitlements ent2.plist -s - -f hello_ent2
# CS_RESTRICT
cp hello hello_800_ent2
codesign --entitlements ent2.plist -s - -f --option=0x800 hello_800_ent2
# CS_REQUIRE_LV
cp hello hello_2000_ent2
codesign --entitlements ent2.plist -s - -f --option=0x2000 hello_2000_ent2
# CS_RUNTIME
cp hello hello_10000_ent2
codesign --entitlements ent2.plist -s - -f --option=0x10000 hello_10000_ent2
# CS_RESTRICT + CS_REQUIRE_LV
cp hello hello_2800_ent2
codesign --entitlements ent2.plist -s - -f --option=0x2800 hello_2800_ent2
# CS_RESTRICT + CS_RUNTIME
cp hello hello_10800_ent2
codesign --entitlements ent2.plist -s - -f --option=0x10800 hello_10800_ent2
# CS_REQUIRE_LV + CS_RUNTIME
cp hello hello_12000_ent2
codesign --entitlements ent2.plist -s - -f --option=0x12000 hello_12000_ent2
# CS_RESTRICT + CS_REQUIRE_LV + CS_RUNTIME
cp hello hello_12800_ent2
codesign --entitlements ent2.plist -s - -f --option=0x12800 hello_12800_ent2
##################
### RESTRICTED ###
##################
## SIGNING
# CS_RESTRICT
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_800
codesign -s - -f --option=0x800 RESTRICTED/hello_restricted_800
# CS_REQUIRE_LV
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_2000
codesign -s - -f --option=0x2000 RESTRICTED/hello_restricted_2000
# CS_RUNTIME
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_10000
codesign -s - -f --option=0x10000 RESTRICTED/hello_restricted_10000
# CS_RESTRICT + CS_REQUIRE_LV
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_2800
codesign -s - -f --option=0x2800 RESTRICTED/hello_restricted_2800
# CS_RESTRICT + CS_RUNTIME
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_10800
codesign -s - -f --option=0x10800 RESTRICTED/hello_restricted_10800
# CS_REQUIRE_LV + CS_RUNTIME
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_12000
codesign -s - -f --option=0x12000 RESTRICTED/hello_restricted_12000
# CS_RESTRICT + CS_REQUIRE_LV + CS_RUNTIME
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_12800
codesign -s - -f --option=0x12800 RESTRICTED/hello_restricted_12800
## SIGNING WITH ENTITLEMENTS
# ent1
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_ent1
codesign --entitlements ent1.plist -s - -f RESTRICTED/hello_restricted_ent1
# CS_RESTRICT
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_800_ent1
codesign --entitlements ent1.plist -s - -f --option=0x800 RESTRICTED/hello_restricted_800_ent1
# CS_REQUIRE_LV
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_2000_ent1
codesign --entitlements ent1.plist -s - -f --option=0x2000 RESTRICTED/hello_restricted_2000_ent1
# CS_RUNTIME
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_10000_ent1
codesign --entitlements ent1.plist -s - -f --option=0x10000 RESTRICTED/hello_restricted_10000_ent1
# CS_RESTRICT + CS_REQUIRE_LV
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_2800_ent1
codesign --entitlements ent1.plist -s - -f --option=0x2800 RESTRICTED/hello_restricted_2800_ent1
# CS_RESTRICT + CS_RUNTIME
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_10800_ent1
codesign --entitlements ent1.plist -s - -f --option=0x10800 RESTRICTED/hello_restricted_10800_ent1
# CS_REQUIRE_LV + CS_RUNTIME
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_12000_ent1
codesign --entitlements ent1.plist -s - -f --option=0x12000 RESTRICTED/hello_restricted_12000_ent1
# CS_RESTRICT + CS_REQUIRE_LV + CS_RUNTIME
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_12800_ent1
codesign --entitlements ent1.plist -s - -f --option=0x12800 RESTRICTED/hello_restricted_12800_ent1
## SIGNING WITH ENTITLEMENTS - ent2.plist
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_ent2
codesign --entitlements ent2.plist -s - -f RESTRICTED/hello_restricted_ent2
# CS_RESTRICT
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_800_ent2
codesign --entitlements ent2.plist -s - -f --option=0x800 RESTRICTED/hello_restricted_800_ent2
# CS_REQUIRE_LV
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_2000_ent2
codesign --entitlements ent2.plist -s - -f --option=0x2000 RESTRICTED/hello_restricted_2000_ent2
# CS_RUNTIME
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_10000_ent2
codesign --entitlements ent2.plist -s - -f --option=0x10000 RESTRICTED/hello_restricted_10000_ent2
# CS_RESTRICT + CS_REQUIRE_LV
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_2800_ent2
codesign --entitlements ent2.plist -s - -f --option=0x2800 RESTRICTED/hello_restricted_2800_ent2
# CS_RESTRICT + CS_RUNTIME
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_10800_ent2
codesign --entitlements ent2.plist -s - -f --option=0x10800 RESTRICTED/hello_restricted_10800_ent2
# CS_REQUIRE_LV + CS_RUNTIME
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_12000_ent2
codesign --entitlements ent2.plist -s - -f --option=0x12000 RESTRICTED/hello_restricted_12000_ent2
# CS_RESTRICT + CS_REQUIRE_LV + CS_RUNTIME
cp RESTRICTED/hello_restricted RESTRICTED/hello_restricted_12800_ent2
codesign --entitlements ent2.plist -s - -f --option=0x12800 RESTRICTED/hello_restricted_12800_ent2
##############
### BACKUP ###
##############
mkdir ../BACKUP
mv hello.c ent1.plist ent2.plist "$0" ../BACKUP/
#############
### SUIDS ###
#############
cp * SUIDS/
sudo chown -R root:wheel SUIDS
sudo chmod -R +s SUIDS/*
##################################
### SUIDS - RESTRICTED SEGMENT ###
##################################
cp * RESTRICTED_SUIDS/
sudo chown -R root:wheel RESTRICTED_SUIDS
sudo chmod -R +s RESTRICTED_SUIDS/*
#############
### SGIDS ###
#############
cp * SGIDS/
sudo chown -R root:wheel SGIDS
sudo chmod -R +s SGIDS/*
##################################
### SGIDS - RESTRICTED SEGMENT ###
##################################
cp * RESTRICTED_SGIDS/
sudo chown -R root:wheel RESTRICTED_SGIDS
sudo chmod -R +s RESTRICTED_SGIDS/*
#####################
### TESTING PHASE ###
#####################
listFilesOnly() {
find . -type f ! -name "_testing.log"
}
testingCommand() {
local file="$1"
local log_file="$(basename "$(pwd)")_testing.log" # Create log file based on current directory
echo "$file" | tee -a "$log_file"
CrimsonUroboros -p "$file" --test_prune_dyld --injectable_dyld --test_insert_dylib --test_dyld_print_to_file | tee -a "$log_file"
}
executeTestingCommandOnFiles() {
for f in $(listFilesOnly); do
testingCommand "$f"
done
}
executeTestingCommandOnFiles
##################################
### CREATE FINAL CSV FOR EXCEL ###
##################################
paste -d ',' - - - - - < sample_testing.log | sed "s/:/,/g" > "final_$(date +%d_%m_%Y).csv"