{"id":13840539,"url":"https://github.com/djhohnstein/macos_shell_memory","last_synced_at":"2026-01-17T15:04:48.472Z","repository":{"id":45508218,"uuid":"368011630","full_name":"djhohnstein/macos_shell_memory","owner":"djhohnstein","description":"Execute MachO binaries in memory using CGo","archived":false,"fork":false,"pushed_at":"2021-05-24T16:11:11.000Z","size":1309,"stargazers_count":81,"open_issues_count":0,"forks_count":14,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-11T11:16:09.350Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/djhohnstein.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-17T00:14:21.000Z","updated_at":"2025-04-03T00:24:17.000Z","dependencies_parsed_at":"2022-09-02T01:21:55.368Z","dependency_job_id":null,"html_url":"https://github.com/djhohnstein/macos_shell_memory","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/djhohnstein/macos_shell_memory","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djhohnstein%2Fmacos_shell_memory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djhohnstein%2Fmacos_shell_memory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djhohnstein%2Fmacos_shell_memory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djhohnstein%2Fmacos_shell_memory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/djhohnstein","download_url":"https://codeload.github.com/djhohnstein/macos_shell_memory/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djhohnstein%2Fmacos_shell_memory/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28510928,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T13:38:16.342Z","status":"ssl_error","status_checked_at":"2026-01-17T13:37:44.060Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T17:00:50.139Z","updated_at":"2026-01-17T15:04:48.419Z","avatar_url":"https://github.com/djhohnstein.png","language":"C","readme":"# Execute Thin Mach-O Binaries in Memory\n\nThis is a CGo implementation of the initial technique put forward by [Stephanie Archibald](https://twitter.com/@ParchedMind) in her blog, [Running Executables on macOS From Memory](https://blogs.blackberry.com/en/2017/02/running-executables-on-macos-from-memory).\n\n## Usage\n\n```\n./macos_shell_memory [bin] [args]\n```\n\n## Description\n\nGiven that `[bin]` is in `$PATH`, `[bin]` is loaded into memory and executed with `[args]` (if provided). Stdout and Stderr will be redirected during binary execution. Normally, when a Mach-O binary finishes execution, the program exits and returns back to the caller (like your terminal); however, this exit call, when called from your current process, will exit your loading process.\n\nTo disable this functionality, a new `atexit` routine is registered to rewind stack-state back to before the in-memory Mach-O `main()` function ever executed. Doing so causes instability, and as such, we call `C._Exit` over letting the Go program exit normally.\n\nThis weaponization could be modified to point to any thin Mach-O binary, and enforcing the `[bin]` to be in `$PATH` is an arbitrary constraint I've added.\n\n## Important Caveats\n\nThis works _only_ for thin Mach-O binaries. This can be seen by issuing the following command:\n\n```\ncodesign -vvvv -d /path/to/bin\n```\n\nFor example, `codesign -vvvv -d /bin/ps` returns:\n```\nExecutable=/bin/ps\nIdentifier=com.apple.ps\nFormat=Mach-O thin (x86_64)\n... snip ...\n```\n\nThere are certain nuances that I haven't worked out for fat and ARM binaries. Doing so will cause the program to irrecoverably segfault.\n\n## Examples\n\n```\n╭─djh@bifrost ~/go/src/github.com/djhohnstein/macos_shell_memory  ‹main*›\n╰─$ ./macos_shell_memory ps                                                                      [21/05/20 |12:18PM]\n[Go Code] Redirecting STDOUT...\n[Go Code] Successfully recovered from bin exit(), captured the following output:\n\n   PID TTY           TIME CMD\n72116 ttys000    0:00.00 zsh\n47918 ttys003    0:00.00 zsh\n78749 ttys003    0:00.01 ./macos_shell_memory ps\n  612 ttys004    0:00.00 zsh\n\n╭─djh@bifrost ~/go/src/github.com/djhohnstein/macos_shell_memory  ‹main*›\n╰─$ ./macos_shell_memory ls -alht                                                                [21/05/20 |12:18PM]\n[Go Code] Redirecting STDOUT...\n[Go Code] Successfully recovered from bin exit(), captured the following output:\n\n total 4752\ndrwxr-xr-x  13 djh  staff   416B May 20 12:18 .git\n-rwxr-xr-x   1 djh  staff   2.3M May 20 12:16 macos_shell_memory\ndrwxr-xr-x  11 djh  staff   352B May 20 11:50 .\n-rw-r--r--   1 djh  staff     0B May 20 11:50 README.md\n-rw-r--r--   1 djh  staff   3.1K May 20 11:30 main.go\n-rw-r--r--   1 djh  staff   3.9K May 20 11:23 shell_memory.c\ndrwxr-xr-x   5 djh  staff   160B May 18 16:04 ..\n-rw-r--r--   1 djh  staff   883B May 17 16:43 go.sum\n-rw-r--r--   1 djh  staff   253B May 17 16:43 go.mod\n-rw-r--r--   1 djh  staff    19B May 16 17:15 .gitignore\n-rw-r--r--   1 djh  staff   143B May 16 17:09 shell_memory.h\n\n```\n\n## References\n- https://blogs.blackberry.com/en/2017/02/running-executables-on-macos-from-memory\n- https://github.com/MythicAgents/poseidon/blob/master/Payload_Type/poseidon/agent_code/execute_memory/execute_memory_darwin.m\n","funding_links":[],"categories":["Operating Systems","C"],"sub_categories":["macOS/iOS"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjhohnstein%2Fmacos_shell_memory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdjhohnstein%2Fmacos_shell_memory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjhohnstein%2Fmacos_shell_memory/lists"}