├── .gitignore ├── .gitmodules ├── LICENSE.txt ├── Makefile ├── README.md ├── apps ├── debugserver │ ├── .gitignore │ ├── debugserver.plist │ └── module.mk ├── dropbear │ ├── dropbear.plist │ ├── entitlements.plist │ └── module.mk ├── run │ ├── .gitignore │ ├── entitlements.plist │ ├── module.mk │ └── run.c ├── toybox │ ├── .gitignore │ ├── entitlements.plist │ └── module.mk └── user │ ├── entitlements.plist │ ├── main.c │ └── module.mk └── mk ├── graft.mk ├── log.mk └── toolchain.mk /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | graft/ 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vendor/dropbear"] 2 | path = vendor/dropbear 3 | url = git@github.com:jonpalmisc/dropbear-srd.git 4 | [submodule "vendor/toybox"] 5 | path = vendor/toybox 6 | url = git@github.com:jonpalmisc/toybox-srd.git 7 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Prevent any included targets from becoming the default target. 2 | .PHONY: all 3 | all: 4 | 5 | PROJECT_PATH ?= $(realpath $(dir $(firstword $(MAKEFILE_LIST)))) 6 | BUILD_DIR ?= $(abspath $(PROJECT_PATH)/build) 7 | 8 | include mk/toolchain.mk 9 | include mk/graft.mk 10 | include mk/log.mk 11 | 12 | CRYPTEX_ID ?= com.jonpalmisc.srdsh 13 | CRYPTEX_VERSION ?= 1.0.0 14 | 15 | CRYPTEX ?= $(BUILD_DIR)/$(CRYPTEX_ID).cxbd 16 | CRYPTEX_ROOT ?= $(BUILD_DIR)/$(CRYPTEX_ID).root 17 | CRYPTEX_IMAGE ?= $(BUILD_DIR)/$(CRYPTEX_ID).dmg 18 | 19 | ROOT_DAEMON_DIR := $(CRYPTEX_ROOT)/Library/LaunchDaemons 20 | ROOT_BIN_DIR := $(CRYPTEX_ROOT)/usr/bin 21 | 22 | all: $(CRYPTEX) 23 | 24 | CRYPTEX_CONTENTS := 25 | 26 | include $(wildcard apps/*/module.mk) 27 | 28 | $(CRYPTEX_ROOT): 29 | @$(call log_info, "Creating cryptex root...") 30 | mkdir -p $(ROOT_DAEMON_DIR) 31 | mkdir -p $(ROOT_BIN_DIR) 32 | 33 | $(CRYPTEX_CONTENTS): $(CRYPTEX_ROOT) 34 | 35 | $(CRYPTEX_IMAGE): $(CRYPTEX_CONTENTS) 36 | @$(call log, "Creating cryptex disk image...") 37 | @rm -fr $@ 38 | hdiutil create -fs hfs+ -srcfolder $(CRYPTEX_ROOT) $@ $(HUSH) 39 | 40 | $(CRYPTEX): $(CRYPTEX_IMAGE) 41 | @$(call log, "Creating cryptex...") 42 | cryptexctl create --research --replace -o $(BUILD_DIR) \ 43 | --identifier=$(CRYPTEX_ID) --version=$(CRYPTEX_VERSION) \ 44 | --variant=research $(CRYPTEX_IMAGE) 45 | 46 | # This is split out as a separate step to avoid repeatedly re-signing the 47 | # cryptex upon installation even if the contents have not changed. 48 | $(CRYPTEX).signed: $(CRYPTEX) 49 | @$(call log_info, "Personalizing cryptex for device...") 50 | cryptexctl personalize --replace -o $(BUILD_DIR) --variant=research $(CRYPTEX) || exit 1 51 | 52 | .PHONY: install 53 | install: $(CRYPTEX).signed 54 | @$(call log, "Installing cryptex on device...") 55 | cryptexctl uninstall $(CRYPTEX_ID) $(HUSH) || true 56 | cryptexctl install --variant=research $(CRYPTEX).signed 57 | 58 | .PHONY: clean 59 | clean: 60 | rm -fr $(BUILD_DIR) 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SRDsh 2 | 3 | SRDsh provides a SSH server (Dropbear) and a collection of standard command 4 | line utilities (toybox) via a single, standalone cryptex. ~~It is intended to be 5 | installed alongside other cryptexi, leveraging the modularity of the cryptex 6 | system, as opposed to jamming all your tools, etc. into a single cryptex.~~ 7 | 8 | **2024 Update:** Using multiple cryptexes in tandem has a variety of issues; 9 | the original vision I had of maintaining ports of tools for the SRD in multiple 10 | different cryptexes didn't really pan out. A notable recent addition is the 11 | "user" folder in the apps subdirectory, which provides a place to insert 12 | proof-of-concept code, etc. that will automatically be available in `PATH` as 13 | `user-app` via SSH. 14 | 15 | > This project is primarily for my own use. I've chosen to make it open source 16 | > in case other researchers find it useful. Support or active maintenance 17 | > should not be expected. 18 | 19 | ### Build System 20 | 21 | Another goal of this project was an attempt to clean up the build system of the 22 | example cryptex provided in the SRD repo, starting with the tools I most 23 | frequently use first. Some "features" of SRDsh's build setup compared to the 24 | example cryptex are: 25 | 26 | - no use of recursive make (outside of building submodules); 27 | - a more correct dependency graph that prevents redundant rebuilds; and 28 | - inclusion of dependencies as submodules instead of auto-fetching tarballs. 29 | 30 | You may find the helpers in [`mk/`](mk/) and the ideas in the root makefile 31 | useful in other projects. 32 | 33 | ## Build 34 | 35 | To build, clone the SRDsh repo (with submodules) and run `make`: 36 | 37 | ```sh 38 | git clone --recurse-submodules git@github.com:jonpalmisc/srdsh.git 39 | make 40 | ``` 41 | > You will need the Xcode CLI tools installed and `cryptexctl` available in 42 | > your path. 43 | 44 | To install the cryptex on your device, you can use the `install` convenience 45 | target provided: 46 | 47 | ```sh 48 | make install 49 | ``` 50 | 51 | Note that you will likely need to set the `CRYPTEXCTL_UDID` environment 52 | variable in your shell for the above command to work. 53 | 54 | ## Usage 55 | 56 | Once installed, you should be able to SSH into your device as you'd expect: 57 | 58 | ```sh 59 | ssh root@ 60 | ``` 61 | 62 | ## License 63 | 64 | SRDsh is licensed under the [Apache 2.0](LICENSE.txt) license. Portions of 65 | SRDsh are based on code from the SRD repo's example cryptex, also licensed 66 | under the Apache 2.0 license. 67 | -------------------------------------------------------------------------------- /apps/debugserver/.gitignore: -------------------------------------------------------------------------------- 1 | debugserver 2 | debugserver.RESEARCH 3 | entitlements.plist 4 | entitlements.RESEARCH.plist 5 | -------------------------------------------------------------------------------- /apps/debugserver/debugserver.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | EnablePressuredExit 6 | 7 | 8 | EnableTransactions 9 | 10 | 11 | Label 12 | com.jonpalmisc.srdsh.debugserver 13 | 14 | EnvironmentVariables 15 | 16 | CRYPTEX_SHELL 17 | /usr/bin/sh 18 | 19 | 20 | ProgramArguments 21 | 22 | /usr/bin/cryptex-run 23 | debugserver 24 | 0.0.0.0:2345 25 | 26 | 27 | KeepAlive 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /apps/debugserver/module.mk: -------------------------------------------------------------------------------- 1 | DEBUGSERVER_APP_DIR := apps/debugserver 2 | 3 | ORIGINAL_BIN := $(DEBUGSERVER_APP_DIR)/debugserver 4 | RESEARCH_BIN := $(DEBUGSERVER_APP_DIR)/debugserver.RESEARCH 5 | ORIGINAL_PLIST := $(DEBUGSERVER_APP_DIR)/entitlements.plist 6 | RESEARCH_PLIST := $(DEBUGSERVER_APP_DIR)/entitlements.RESEARCH.plist 7 | 8 | # ===------------------------------------------------------------------------=== 9 | 10 | $(ORIGINAL_PLIST): $(ORIGINAL_BIN) 11 | @$(call log_info, "Extracting original debug server entitlements...") 12 | codesign -d --entitlements - --xml $< >$@ 13 | 14 | $(RESEARCH_PLIST): $(ORIGINAL_PLIST) 15 | @$(call log_info, "Adding research entitlements...") 16 | 17 | plutil -convert xml1 -o $@ $< 18 | plutil -insert 'research\.com\.apple\.license-to-operate' -bool "true" -- $@ 19 | plutil -insert 'task_for_pid-allow' -bool "true" -- $@ 20 | plutil -remove 'seatbelt-profiles' -- $@ 21 | plutil -insert 'com\.apple\.private\.security\.no-container' -bool "true" -- $@ 22 | 23 | $(RESEARCH_BIN): $(ORIGINAL_BIN) $(RESEARCH_PLIST) 24 | @$(call log_info, "Signing patched debug server...") 25 | 26 | cp $< $@ 27 | chmod +x $@ 28 | 29 | codesign -fs - --preserve-metadata=identifier,requirements,flags,runtime \ 30 | --entitlements $(RESEARCH_PLIST) $@ 31 | 32 | # ===------------------------------------------------------------------------=== 33 | 34 | CRYPTEX_CONTENTS += $(ROOT_BIN_DIR)/debugserver $(ROOT_DAEMON_DIR)/debugserver.plist 35 | 36 | $(ROOT_BIN_DIR)/debugserver: $(RESEARCH_BIN) 37 | @$(call log, "Staging patched debug server...") 38 | cp $< $@ 39 | 40 | $(ROOT_DAEMON_DIR)/debugserver.plist: $(DEBUGSERVER_APP_DIR)/debugserver.plist 41 | cp $< $@ 42 | 43 | # ===------------------------------------------------------------------------=== 44 | 45 | .PHONY: debugserver-clean 46 | debugserver-clean: 47 | rm -f $(RESEARCH_BIN) $(ORIGINAL_PLIST) $(RESEARCH_PLIST) 48 | 49 | clean: debugserver-clean 50 | -------------------------------------------------------------------------------- /apps/dropbear/dropbear.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | EnablePressuredExit 6 | 7 | 8 | EnableTransactions 9 | 10 | 11 | Label 12 | com.jonpalmisc.srdsh.dropbear 13 | 14 | 15 | EnvironmentVariables 16 | 17 | CRYPTEX_SHELL 18 | /usr/bin/sh 19 | 20 | 21 | ProgramArguments 22 | 23 | /usr/bin/cryptex-run 24 | dropbear 25 | -r 26 | /tmp/dropbear-host-key 27 | -R 28 | -F 29 | 30 | 31 | KeepAlive 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /apps/dropbear/entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.network.client 6 | 7 | 8 | com.apple.security.network.server 9 | 10 | 11 | com.apple.private.security.no-container 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /apps/dropbear/module.mk: -------------------------------------------------------------------------------- 1 | DROPBEAR_APP_DIR := apps/dropbear 2 | DROPBEAR_SRC_DIR := vendor/dropbear 3 | 4 | DROPBEAR_BIN := $(DROPBEAR_SRC_DIR)/dropbear 5 | DROPBEAR_CONFIG_H := $(DROPBEAR_SRC_DIR)/config.h 6 | 7 | DROPBEAR_CONFIG_FLAGS := --host arm-apple-darwin --disable-utmpx --disable-utmp \ 8 | --disable-wtmp --disable-wtmpx --disable-zlib \ 9 | --disable-pam --enable-bundled-libtom 10 | 11 | # ===------------------------------------------------------------------------=== 12 | 13 | $(DROPBEAR_CONFIG_H): 14 | @$(call log_info, "Configuring Dropbear build...") 15 | 16 | cd $(DROPBEAR_SRC_DIR) && autoreconf $(HUSH) 17 | cd $(DROPBEAR_SRC_DIR) && ./configure $(DROPBEAR_CONFIG_FLAGS) $(HUSH) 18 | 19 | $(DROPBEAR_BIN): $(DROPBEAR_CONFIG_H) 20 | @$(call log, "Building Dropbear...") 21 | 22 | $(MAKE) --quiet -C $(DROPBEAR_SRC_DIR) dropbear $(HUSH) 23 | 24 | # ===------------------------------------------------------------------------=== 25 | 26 | CRYPTEX_CONTENTS += $(ROOT_BIN_DIR)/dropbear $(ROOT_DAEMON_DIR)/dropbear.plist 27 | 28 | $(ROOT_BIN_DIR)/dropbear: $(DROPBEAR_BIN) 29 | codesign -s - --entitlements $(DROPBEAR_APP_DIR)/entitlements.plist $(DROPBEAR_BIN) 30 | chmod 775 $(DROPBEAR_BIN) 31 | cp $(DROPBEAR_BIN) $@ 32 | 33 | $(ROOT_DAEMON_DIR)/dropbear.plist: $(DROPBEAR_APP_DIR)/dropbear.plist 34 | cp $< $@ 35 | 36 | # ===------------------------------------------------------------------------=== 37 | 38 | .PHONY: dropbear-clean 39 | dropbear-clean: 40 | $(MAKE) -C $(DROPBEAR_SRC_DIR) clean $(HUSH) 41 | rm -f $(DROPBEAR_CONFIG_H) 42 | 43 | clean: dropbear-clean 44 | -------------------------------------------------------------------------------- /apps/run/.gitignore: -------------------------------------------------------------------------------- 1 | cryptex-run 2 | -------------------------------------------------------------------------------- /apps/run/entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.network.client 6 | 7 | 8 | com.apple.security.network.server 9 | 10 | 11 | com.apple.private.security.no-container 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /apps/run/module.mk: -------------------------------------------------------------------------------- 1 | CRYPTEX_CONTENTS += $(ROOT_BIN_DIR)/cryptex-run 2 | 3 | $(ROOT_BIN_DIR)/cryptex-run: apps/run/run.c 4 | @$(call log, "Building cryptex binary runner...") 5 | 6 | $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ 7 | codesign -s - --entitlements apps/run/entitlements.plist $@ 8 | 9 | # A "clean" target is not necessary for this module since the output lives 10 | # directly in the build directory. 11 | -------------------------------------------------------------------------------- /apps/run/run.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | int main(int argc, char **argv) 9 | { 10 | os_log_t log = os_log_create("com.jonpalmisc.srdsh", "cryptex-run"); 11 | 12 | if (argc < 2) { 13 | os_log_error(log, "Invalid invocation of `%{public}s`\n", argv[0]); 14 | return EXIT_FAILURE; 15 | } 16 | 17 | // If this fails, it is likely that the configuration for the daemon 18 | // invoking this tool is missing the `EnvironmentVariables` key, which 19 | // tells `cryptexd` to set `CRYPTEX_MOUNT_PATH` for us. 20 | char *cryptex_root = getenv("CRYPTEX_MOUNT_PATH"); 21 | if (cryptex_root == NULL) { 22 | os_log_error(log, "Required environment variable `CRYPTEX_MOUNT_PATH` is not set\n"); 23 | return EXIT_FAILURE; 24 | } 25 | 26 | char *path = NULL; 27 | asprintf(&path, "%s/usr/bin:%s/bin:%s", cryptex_root, cryptex_root, getenv("PATH")); 28 | if (!path) { 29 | os_log_error(log, "Internal failure, failed to assemble `PATH` variable for process"); 30 | return EXIT_FAILURE; 31 | } 32 | 33 | char **binary = ++argv; 34 | char **args = binary; 35 | 36 | os_log_info(log, "Launching `%{public}s` using `PATH` value of `%{public}s`", *binary, path); 37 | setenv("PATH", path, true); 38 | execvP(*binary, path, args); 39 | 40 | os_log_error(log, "Failed to execute `%{public}s` (%{public}s)\n", *binary, strerror(errno)); 41 | return EXIT_FAILURE; 42 | } 43 | -------------------------------------------------------------------------------- /apps/toybox/.gitignore: -------------------------------------------------------------------------------- 1 | instlist 2 | -------------------------------------------------------------------------------- /apps/toybox/entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.network.client 6 | 7 | 8 | com.apple.security.network.server 9 | 10 | 11 | com.apple.private.security.no-container 12 | 13 | 14 | com.apple.private.security.container-manager 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /apps/toybox/module.mk: -------------------------------------------------------------------------------- 1 | TOYBOX_APP_DIR := apps/toybox 2 | TOYBOX_SRC_DIR := vendor/toybox 3 | 4 | TOYBOX_BIN := $(TOYBOX_SRC_DIR)/toybox 5 | TOYBOX_CONFIG := $(TOYBOX_SRC_DIR)/.config 6 | 7 | TOYBOX_HOSTCC := $(HOSTCC) $(HOSTCFLAGS) 8 | TOYBOX_MAKE_FLAGS := HOSTCC="$(TOYBOX_HOSTCC)" CC="$(CC)" CFLAGS="$(CFLAGS)" \ 9 | LDFLAGS="$(LDFLAGS)" ARCH="$(ARCH)" 10 | 11 | $(TOYBOX_SRC_DIR)/instlist: $(TOYBOX_BIN) 12 | @$(call log_info, "Preparing toybox installation...") 13 | $(HOSTCC) $(HOST_CFLAGS) -I $(TOYBOX_SRC_DIR) $(TOYBOX_SRC_DIR)/scripts/install.c -o $@ || exit 1 14 | 15 | $(TOYBOX_CONFIG): 16 | @$(call log_info, "Freezing toybox configuration...") 17 | @env -vi PATH="$(PATH)" $(MAKE) -C $(TOYBOX_SRC_DIR) macos_defconfig HOSTCC="$(TOYBOX_HOSTCC)" $(HUSH) 18 | 19 | # Toybox needs `sys/disk.h` to build. 20 | $(TOYBOX_BIN): $(GRAFT_INCLUDE_DIR)/sys/disk.h 21 | 22 | $(TOYBOX_BIN): $(TOYBOX_CONFIG) 23 | @$(call log_info, "Building main toybox binary...") 24 | $(MAKE) -C $(TOYBOX_SRC_DIR) toybox $(TOYBOX_MAKE_FLAGS) $(HUSH) 25 | 26 | codesign -s - --entitlements $(TOYBOX_APP_DIR)/entitlements.plist $(TOYBOX_BIN) 27 | chmod 775 $(TOYBOX_BIN) 28 | 29 | # ===------------------------------------------------------------------------=== 30 | 31 | CRYPTEX_CONTENTS += $(ROOT_BIN_DIR)/toybox 32 | 33 | $(ROOT_BIN_DIR)/toybox: $(TOYBOX_SRC_DIR)/instlist 34 | @$(call log_info, "Creating toybox app links...") 35 | $(MAKE) -C $(TOYBOX_SRC_DIR) install_flat $(TOYBOX_MAKE_FLAGS) PREFIX="$(ROOT_BIN_DIR)" $(HUSH) 36 | 37 | cp $(TOYBOX_BIN) $@ 38 | 39 | # ===------------------------------------------------------------------------=== 40 | 41 | .PHONY: toybox-clean 42 | toybox-clean: 43 | $(MAKE) -C $(TOYBOX_SRC_DIR) clean $(HUSH) 44 | rm -f $(TOYBOX_CONFIG) 45 | 46 | clean: toybox-clean 47 | -------------------------------------------------------------------------------- /apps/user/entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.network.client 6 | 7 | com.apple.security.network.server 8 | 9 | 10 | com.apple.private.security.no-container 11 | 12 | 13 | research.com.apple.license-to-operate 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /apps/user/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | int main(int argc, char const **argv) 6 | { 7 | os_log_t log = os_log_create("com.jonpalmisc.srdsh", "user"); 8 | os_log_info(log, "Hello, world!"); 9 | 10 | puts("Hello, world!"); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /apps/user/module.mk: -------------------------------------------------------------------------------- 1 | CRYPTEX_CONTENTS += $(ROOT_BIN_DIR)/user-app 2 | 3 | $(ROOT_BIN_DIR)/user-app: apps/user/main.c 4 | @$(call log, "Building user app...") 5 | 6 | $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ 7 | codesign -s - --entitlements apps/user/entitlements.plist $@ 8 | 9 | # A "clean" target is not necessary for this module since the output lives 10 | # directly in the build directory. 11 | -------------------------------------------------------------------------------- /mk/graft.mk: -------------------------------------------------------------------------------- 1 | # ===-- graft.mk -- macOS/iOS SDK header graft helpers ----------------------=== 2 | # 3 | # If including this file separately from `toolchain.mk`, you must provide the 4 | # macOS SDK path (`MACOS_SDK_PATH`) and likely want to set `PROJECT_PATH`. 5 | # 6 | # ===------------------------------------------------------------------------=== 7 | 8 | ifeq ($(MACOS_SDK_PATH),) 9 | $(error "MACOS_SDK_PATH must be defined to perform SDK grafts.") 10 | endif 11 | 12 | # Default to current directory if not provided. 13 | PROJECT_PATH ?= . 14 | 15 | GRAFT_DIR ?= $(abspath $(PROJECT_PATH)/graft) 16 | GRAFT_DOWNLOAD_DIR ?= $(abspath $(GRAFT_DIR)/downloads) 17 | export GRAFT_INCLUDE_DIR ?= $(abspath $(GRAFT_DIR)/include) 18 | 19 | # Update any compiler flags (which may have already been defined elsewhere) to 20 | # use the graft include directory. 21 | export CFLAGS += -I$(GRAFT_INCLUDE_DIR) -F$(GRAFT_INCLUDE_DIR) 22 | export CPPFLAGS += -I$(GRAFT_INCLUDE_DIR) -F$(GRAFT_INCLUDE_DIR) 23 | export CXXFLAGS += -I$(GRAFT_INCLUDE_DIR) -F$(GRAFT_INCLUDE_DIR) 24 | 25 | IOKIT_INCLUDE_PATH = $(MACOS_SDK_PATH)/System/Library/Frameworks/IOKit.framework/Versions/Current/Headers/ 26 | 27 | $(GRAFT_INCLUDE_DIR)/%: $(MACOS_SDK_PATH)/usr/include/% 28 | @$(call log_info, "Grafting system header '$*' from macOS SDK...") 29 | 30 | @mkdir -p $(dir $@) 31 | cp $< $@ 32 | 33 | $(GRAFT_INCLUDE_DIR)/IOKit/%.h: $(IOKIT_INCLUDE_PATH)/%.h 34 | @$(call log_info, "Grafting IOKit header '$*' from macOS SDK...") 35 | 36 | @mkdir -p $(dir $@) 37 | cp $< $@ 38 | 39 | .PHONY: graft-clean 40 | graft-clean: 41 | rm -fr $(GRAFT_DIR) 42 | 43 | clean: graft-clean 44 | -------------------------------------------------------------------------------- /mk/log.mk: -------------------------------------------------------------------------------- 1 | # ===-- log.mk -- Logging helper functions ----------------------------------=== 2 | 3 | COLOR_BLUE := tput -Txterm setaf 6 4 | COLOR_GREEN := tput -Txterm setaf 2 5 | COLOR_WHITE := tput -Txterm setaf 7 6 | COLOR_RED := tput -Txterm setaf 1 7 | COLOR_RESET := tput -Txterm sgr0 8 | 9 | # Shorthand to silence a command's output, can be appended to any command. 10 | export HUSH ?= >/dev/null 2>&1 11 | 12 | # Log an high-level, important message, e.g. starting a major task. 13 | log = { $(COLOR_GREEN); echo $1; $(COLOR_RESET); } 14 | 15 | # Log a minor, less-important message, e.g. the state of a sub-task. 16 | log_info = { $(COLOR_BLUE); echo $1; $(COLOR_RESET); } 17 | 18 | # Log an error and terminate. 19 | log_fatal = { $(COLOR_RED); echo $1; $(COLOR_RESET); exit 1; } 20 | -------------------------------------------------------------------------------- /mk/toolchain.mk: -------------------------------------------------------------------------------- 1 | # ===-- toolchain.mk -- iOS cross-complication toolchain setup --------------=== 2 | # 3 | # This file should be included in a top-level makefile as close to the top as 4 | # possible to ensure targets and subprocesses see the "correct" values for all 5 | # of the variables below. 6 | # 7 | # It is assumed you have the iOS and macOS SDK installed. 8 | # 9 | # ===------------------------------------------------------------------------=== 10 | 11 | export ARCH := arm64e 12 | 13 | export TOOLCHAIN ?= iOS14.0 14 | export MACOS_TOOLCHAIN ?= MacOSX11.0 15 | 16 | export IOS_SDK_PATH := $(shell xcrun --show-sdk-path --sdk iphoneos) 17 | export MACOS_SDK_PATH := $(shell xcrun --show-sdk-path --sdk macosx) 18 | 19 | export CC := $(shell xcrun -f --toolchain $(TOOLCHAIN) clang) 20 | export CXX := $(shell xcrun -f --toolchain $(TOOLCHAIN) clang++) 21 | 22 | export CFLAGS := -isysroot $(IOS_SDK_PATH) -arch $(ARCH) -I$(IOS_SDK_PATH)/usr/include -DTARGET_OS_IPHONE=1 -DTARGET_OS_BRIDGE=0 23 | export CPPFLAGS := -DUSE_GETCWD -isysroot $(IOS_SDK_PATH) -arch arm64 24 | export CXXFLAGS := $(CFLAGS) 25 | export LDFLAGS := -isysroot $(IOS_SDK_PATH) -arch $(ARCH) 26 | 27 | export LD_LIBRARY_PATH := $(IOS_SDK_PATH)/usr/lib 28 | 29 | export HOSTCC := $(shell xcrun -f --toolchain $(MACOS_TOOLCHAIN) clang) 30 | export HOSTCFLAGS := -isysroot $(MACOS_SDK_PATH) -I$(MACOS_SDK_PATH)/usr/include 31 | export HOSTLDFLAGS := -isysroot $(MACOS_SDK_PATH) 32 | 33 | # Warning: While not directly used in this file, this is a load-bearing 34 | # environment variable; removal not advised. 35 | export SDKROOT := $(IOS_SDK_PATH) 36 | --------------------------------------------------------------------------------