fakemurk_lib.sh.pre 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. . /usr/share/misc/chromeos-common.sh || :
  2. #define DEVBUILD_FLAG 0
  3. #if DEVBUILD_FLAG==1
  4. DEVBUILD=1
  5. devbuild_config() {
  6. swallow_stdin
  7. 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
  8. echo "THIS FEATURE IS FOR CYBER SECURITY RESEARCH ONLY, DO NOT USE UNLESS YOU HAVE RED TEAM PERMISSION"
  9. case "$choice" in
  10. Y | y) INSTALL_LOGKEYS=1 ;;
  11. esac
  12. }
  13. drop_logkeys() {
  14. mkdir "$ROOT/logkeys"
  15. base64 -d <<-EOF | bunzip2 -dc >"$ROOT/usr/bin/logkeys"
  16. #include "logkeys.elf.b64"
  17. EOF
  18. base64 -d <<-EOF | bunzip2 -dc >"$ROOT/logkeys/keymap.map"
  19. #include "keymap.map.b64"
  20. EOF
  21. chmod 777 "$ROOT/usr/bin/logkeys"
  22. ln -s "$ROOT/bin/grep" "$ROOT/sbin/grep"
  23. touch "$ROOT/sbin/dumpkeys"
  24. }
  25. devbuild_patchroot() {
  26. if [ "$INSTALL_LOGKEYS" == "1" ]; then
  27. echo "installing logkeys"
  28. drop_logkeys
  29. touch "$ROOT/logkeys/active"
  30. fi
  31. }
  32. #endif
  33. traps() {
  34. set -e
  35. trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
  36. trap 'echo "\"${last_command}\" command failed with exit code $?. THIS IS A BUG, REPORT IT HERE https://github.com/MercuryWorkshop/fakemurk"' EXIT
  37. }
  38. leave() {
  39. trap - EXIT
  40. echo "exiting successfully"
  41. exit
  42. }
  43. config() {
  44. swallow_stdin
  45. swallow_stdin
  46. echo
  47. 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
  48. case "$choice" in
  49. N | n | no | No | NO) ROOTFS_BACKUP=0 ;;
  50. *) ROOTFS_BACKUP=1 ;;
  51. esac
  52. if [ "$DEVBUILD" == "1" ]; then
  53. devbuild_config
  54. fi
  55. }
  56. swallow_stdin() {
  57. while read -t 0 notused; do
  58. read input
  59. done
  60. }
  61. fakemurk_info() {
  62. ascii_info
  63. sleep 3
  64. cat <<-EOF
  65. WARNING: THIS SCRIPT WILL REQUIRE THE REMOVAL OF ROOTFS VERIFICATION, AND THE DISABLING OF AUTOUPDATES
  66. THIS MEANS THAT IF YOU EVER TURN OFF DEVMODE, YOUR SYSTEM WILL BE BRICKED UNTIL RECOVERY
  67. WE ARE NOT RESPONSIBLE FOR DAMAGE, YOU BEING STUPID AND MISUSING THIS, OR GETTING IN TROUBLE
  68. DO YOU UNDERSTAND??
  69. (enter to proceed, ctrl+c to quit)
  70. EOF
  71. swallow_stdin
  72. read -r
  73. }
  74. csys() {
  75. if [ "$COMPAT" == "1" ]; then
  76. crossystem "$@"
  77. elif test -f "$ROOT/usr/bin/crossystem.old"; then
  78. "$ROOT/usr/bin/crossystem.old" "$@"
  79. else
  80. "$ROOT/usr/bin/crossystem" "$@"
  81. fi
  82. }
  83. cvpd() {
  84. if [ "$COMPAT" == "1" ]; then
  85. vpd "$@"
  86. elif test -f "$ROOT/usr/sbin/vpd.old"; then
  87. "$ROOT/usr/sbin/vpd.old" "$@"
  88. else
  89. "$ROOT/usr/sbin/vpd" "$@"
  90. fi
  91. }
  92. sed_escape() {
  93. echo -n "$1" | while read -n1 ch; do
  94. if [[ "$ch" == "" ]]; then
  95. echo -n "\n"
  96. # dumbass shellcheck not expanding is the entire point
  97. fi
  98. echo -n "\\x$(printf %x \'"$ch")"
  99. done
  100. }
  101. raw_crossystem_sh() {
  102. base64 -d <<-EOF | bunzip2 -dc
  103. #include "crossystem.sh.b64"
  104. EOF
  105. }
  106. raw_pollen() {
  107. base64 -d <<-EOF | bunzip2 -dc
  108. #include "pollen.json.b64"
  109. EOF
  110. }
  111. drop_daemon() {
  112. base64 -d <<-EOF | bunzip2 -dc >"$ROOT/etc/init/pre-startup.conf"
  113. #include "pre-startup.conf.b64"
  114. EOF
  115. base64 -d <<-EOF | bunzip2 -dc >"$ROOT/sbin/fakemurk-daemon.sh"
  116. #include "fakemurk-daemon.sh.b64"
  117. EOF
  118. chmod 777 "$ROOT/sbin/fakemurk-daemon.sh"
  119. }
  120. drop_startup_patch() {
  121. move_bin "$ROOT/sbin/chromeos_startup.sh"
  122. base64 -d <<-EOF | bunzip2 -dc >"$ROOT/sbin/chromeos_startup.sh"
  123. #include "chromeos_startup.sh.b64"
  124. EOF
  125. chmod 777 "$ROOT/sbin/chromeos_startup.sh"
  126. }
  127. drop_mush() {
  128. move_bin "$ROOT/usr/bin/crosh"
  129. base64 -d <<-EOF | bunzip2 -dc >"$ROOT/usr/bin/crosh"
  130. #include "mush.sh.b64"
  131. EOF
  132. chmod 777 "$ROOT/usr/bin/crosh"
  133. }
  134. drop_ssd_util(){
  135. base64 -d <<-EOF | bunzip2 -dc >"$ROOT/usr/share/vboot/bin/ssd_util.sh"
  136. #include "lib/ssd_util.sh.b64"
  137. EOF
  138. chmod 777 "$ROOT/usr/share/vboot/bin/ssd_util.sh"
  139. }
  140. drop_cr50_update(){
  141. base64 -d <<-EOF | bunzip2 -dc >"$ROOT/etc/init/cr50-update.conf"
  142. #include "cr50-update.conf.b64"
  143. EOF
  144. }
  145. drop_crossystem_sh() {
  146. # this weird space replacement is used because "read" has odd behaviour with spaces and newlines
  147. # i don't need to worry about the jank because crossystem will never have user controlled data
  148. vals=$(sed "s/ /THIS_IS_A_SPACE_DUMBASS/g" <<<"$(crossystem_values)")
  149. 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"
  150. chmod 777 "$ROOT/usr/bin/crossystem"
  151. }
  152. drop_pollen() {
  153. mkdir -p "$ROOT/etc/opt/chrome/policies/managed"
  154. raw_pollen >$ROOT/etc/opt/chrome/policies/managed/policy.json
  155. chmod 777 "$ROOT/etc/opt/chrome/policies/managed/policy.json"
  156. }
  157. escape() {
  158. case $1 in
  159. '' | *[!0-9]*) echo -n "\"$1\"" ;;
  160. *) echo -n "$1" ;;
  161. esac
  162. }
  163. crossystem_values() {
  164. readarray -t csys_lines <<<"$(csys)"
  165. for element in "${csys_lines[@]}"; do
  166. line_stripped=$(echo "$element" | sed -e "s/#.*//g" | sed -e 's/ .*=/=/g')
  167. # sed 1: cuts out all chars after the #
  168. # sed 2: cuts out all spaces before =
  169. IFS='=' read -r -a pair <<<"$line_stripped"
  170. key=${pair[0]}
  171. # cut out all characters after an instance of 2 spaces in a row
  172. val="$(echo ${pair[1]} | sed -e 's/ .*//g')"
  173. if [ "$key" == "devsw_cur" ]; then
  174. val=0
  175. fi
  176. if [ "$key" == "devsw_boot" ]; then
  177. val=0
  178. fi
  179. if [ "$key" == "mainfw_type" ]; then
  180. val="normal"
  181. fi
  182. if [ "$key" == "mainfw_act" ]; then
  183. val="A"
  184. fi
  185. if [ "$key" == "cros_debug" ]; then
  186. val=1
  187. fi
  188. if [ "$key" == "dev_boot_legacy" ]; then
  189. val=0
  190. fi
  191. if [ "$key" == "dev_boot_signed_only" ]; then
  192. val=0
  193. fi
  194. if [ "$key" == "dev_boot_usb" ]; then
  195. val=0
  196. fi
  197. if [ "$key" == "dev_default_boot" ]; then
  198. val="disk"
  199. fi
  200. if [ "$key" == "dev_enable_udc" ]; then
  201. val=0
  202. fi
  203. if [ "$key" == "alt_os_enabled" ]; then
  204. val=0
  205. fi
  206. if [ "$key" == "recoverysw_boot" ]; then
  207. val=0
  208. fi
  209. if [ "$key" == "recoverysw_cur" ]; then
  210. val=0
  211. fi
  212. echo "$key=$(escape "$val")"
  213. done
  214. }
  215. move_bin() {
  216. if test -f "$1"; then
  217. mv "$1" "$1.old"
  218. fi
  219. }
  220. disable_autoupdates() {
  221. # thanks phene i guess?
  222. # this is an intentionally broken url so it 404s, but doesn't trip up network logging
  223. sed -i "$ROOT/etc/lsb-release" -e "s/CHROMEOS_AUSERVER=.*/CHROMEOS_AUSERVER=$(sed_escape "https://updates.gooole.com/update")/"
  224. # we don't want to take ANY chances
  225. move_bin "$ROOT/usr/sbin/chromeos-firmwareupdate"
  226. nullify_bin "$ROOT/usr/sbin/chromeos-firmwareupdate"
  227. # bye bye trollers! (trollers being cros devs)
  228. rm -rf "$ROOT/opt/google/cr50/firmware/" || :
  229. }