{"id":21051724,"url":"https://github.com/novafacing/memfd-exec","last_synced_at":"2025-04-05T14:04:13.791Z","repository":{"id":62445072,"uuid":"544211041","full_name":"novafacing/memfd-exec","owner":"novafacing","description":"Execute binaries straight from memory, without touching disk, with a friendly interface!","archived":false,"fork":false,"pushed_at":"2024-11-15T00:18:07.000Z","size":142,"stargazers_count":42,"open_issues_count":2,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-29T13:05:21.685Z","etag":null,"topics":["rust"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/memfd-exec","language":"Rust","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/novafacing.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-01T23:40:27.000Z","updated_at":"2025-03-12T11:00:39.000Z","dependencies_parsed_at":"2024-12-25T08:53:05.292Z","dependency_job_id":null,"html_url":"https://github.com/novafacing/memfd-exec","commit_stats":{"total_commits":18,"total_committers":1,"mean_commits":18.0,"dds":0.0,"last_synced_commit":"b1e28f9853338ab268c9553b02d567465d0fb552"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novafacing%2Fmemfd-exec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novafacing%2Fmemfd-exec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novafacing%2Fmemfd-exec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novafacing%2Fmemfd-exec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/novafacing","download_url":"https://codeload.github.com/novafacing/memfd-exec/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247345850,"owners_count":20924102,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["rust"],"created_at":"2024-11-19T15:59:31.112Z","updated_at":"2025-04-05T14:04:13.772Z","avatar_url":"https://github.com/novafacing.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# memfd_exec ![crates.io](https://img.shields.io/crates/v/memfd-exec.svg)\n\nThis is a very simple crate that allows execution of in-memory only programs. Simply\nput, if you have the contents of a Linux executable in a `Vec\u003cu8\u003e`, you can use\n`memfd_exec` to execute the program without it ever touching your hard disk. Use\ncases for this may include:\n\n* Bundling a static executable with another program (for example, my motivation to\n  create this package is that I want to ship a statically built QEMU with\n  [cantrace](https://github.com/novafacing/cannoli))\n* Sending executables over the network and running them, to reduce footprint and increase\n  throughput\n* Really hacky stuff that I haven't thought of, if you have a cool use case, feel free\n  to make a PR to the README or add an example in [examples](examples)\n\n## Using\n\nJust include `memfd-exec = \"0.1.4\"` in your `Cargo.toml` file.\n\n## Features\n\n* Feature-parity API with `process::Command`, the only difference is we don't execute\n  anything from disk.\n* Only two dependencies\n\n## Examples\n\n### Run an executable downloaded over the network\n\nFor redteamers, this example will download and run an executable without ever writing it\nto disk. It may not bypass Advanced Threat Protection, but it at least won't leave\na huge disk footprint!\n\n```rust\nuse memfd_exec::{MemFdExecutable, Stdio};\nuse reqwest::blocking::get;\n\nconst URL: \u0026str = \"https://novafacing.github.io/assets/qemu-x86_64\";\nlet resp = get(URL).unwrap();\n\n// The `MemFdExecutable` struct is at near feature-parity with `std::process::Command`,\n// so you can use it in the same way. The only difference is that you must provide the\n// argv[0] to use as well as the executable contents as a byte slice.\nlet qemu = MemFdExecutable::new(\"qemu-x86_64\", resp.bytes().unwrap().to_vec())\n    // We'll just get the version here, but you can do anything you want with the\n    // args.\n    .arg(\"-version\")\n    // We'll capture the stdout of the process, so we need to set up a pipe.\n    .stdout(Stdio::piped())\n    // Spawn the process as a forked child\n    .spawn()\n    .unwrap();\n\n// Get the output and status code of the process (this will block until the process\n// exits)\nlet output = qemu.wait_with_output().unwrap();\nassert!(output.status.into_raw() == 0);\n// Print out the version we got!\nprintln!(\"{}\", String::from_utf8_lossy(\u0026output.stdout));\n```\n\n### Bundle and run a local static executable\n\nThe motivating example for this project is to bundle an executable along with a rust\nprogram and be able to run the executable straight from memory instead of going\nthrough the tedious and slow process of writing the executable file to disk and then\ninvoking it as a command.\n\nThis example creates an executable with a bundled [program](tests/test_static.c) that\nopens a socket, reads a bit of input, and then prints out the input. Of course, the\nlogical extension of the idea would be to use a static\n[netcat](https://github.com/openbsd/src/blob/master/usr.bin/nc/netcat.c) build or some\nsuch thing.\n\n```rust\n\nuse memfd_exec::{MemFdExecutable, Stdio};\n\nconst EXECUTABLE_FILE: \u0026[u8] = include_bytes!(\"tets/test_static\");\n\nfn main() {\n    const PORT = 1234;\n    // We create an in-memory executable with an argv[0] \"test\" and an executable file\n    // that we embedded in our rust binary\n    let exe = MemFdExecutable::new(\"test\", EXECUTABLE_FILE.to_vec())\n        // We pass one arg, the port number to listen on\n        .arg(format!(\"{}\", PORT))\n        // We tell it to use a pipe for stdout (stdin and stderr will default to Stdio::inherit())\n        .stdout(Stdio::piped())\n        // We spawn the child process as a forked child process\n        .spawn()\n        .expect(\"Failed to create process!\");\n\n    // Wait until the process finishes and print its output\n    let output = exe.wait_with_output().unwrap();\n    println!(\"Got output: {:?}\", output.stdout);\n}\n```\n\n## Testing\n\nFor testing purposes, you need to install:\n\n- `clang`\n- `glibc-static`\n- `glibc`\n\nYou should also have `/bin/cat` and `/bin/ls` on your system. This is default on the\nvast majority of Linux systems, but don't panic if this test fails if they are missing.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnovafacing%2Fmemfd-exec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnovafacing%2Fmemfd-exec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnovafacing%2Fmemfd-exec/lists"}