{"id":13578325,"url":"https://github.com/b1tg/rust-windows-shellcode","last_synced_at":"2025-04-09T23:18:24.005Z","repository":{"id":41269885,"uuid":"336291218","full_name":"b1tg/rust-windows-shellcode","owner":"b1tg","description":"Windows shellcode development in Rust","archived":false,"fork":false,"pushed_at":"2021-02-06T15:20:12.000Z","size":301,"stargazers_count":289,"open_issues_count":0,"forks_count":34,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-09T23:18:19.288Z","etag":null,"topics":["offensive-security","rust","shellcode","shellcode-development"],"latest_commit_sha":null,"homepage":"","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/b1tg.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-02-05T14:14:30.000Z","updated_at":"2025-04-09T08:11:23.000Z","dependencies_parsed_at":"2022-07-21T22:18:35.393Z","dependency_job_id":null,"html_url":"https://github.com/b1tg/rust-windows-shellcode","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b1tg%2Frust-windows-shellcode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b1tg%2Frust-windows-shellcode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b1tg%2Frust-windows-shellcode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b1tg%2Frust-windows-shellcode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/b1tg","download_url":"https://codeload.github.com/b1tg/rust-windows-shellcode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125593,"owners_count":21051771,"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":["offensive-security","rust","shellcode","shellcode-development"],"created_at":"2024-08-01T15:01:29.464Z","updated_at":"2025-04-09T23:18:23.976Z","avatar_url":"https://github.com/b1tg.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Write Windows Shellcode in Rust\n\n\n## Project overview\n\nWindows shellcode project is located in `shellcode/`, it can build into a PE file with only `.text` section \nand has no external dependencies.\n\n![shellcode.exe in pe-bear](./images/show_in_pe_bear.png)\n\nThen we can dump the `.text` section and do some patches to make it position-independent. this idea \nwas from [hasherezade](https://twitter.com/hasherezade)'s project [masm_shc](https://github.com/hasherezade/masm_shc).\n\n\n## How to build it\n\n(Only tested on Win10 x64)\n\n\n### Build shellcode binary\n\n\n\n```sh\nrustup default nightly-x86_64-pc-windows-msvc\ncd shellcode/\ncargo build --release\n```\n\nIf everthing goes well, we will get `shellcode\\target\\x86_64-pc-windows-msvc\\release\\shellcode.exe`\n\n### Dump .text section and do some patches \n\nWe patch at the start of `.text` section, make it jump to entry point. In this way, we can have some strings store in the merged section, or we have to use `u8` and `u16` bytes array on stack to represent string.\n\n```sh\ncd ..\ncargo run\n```\n\n\nWe will get  `shellcode\\target\\x86_64-pc-windows-msvc\\release\\shellcode.bin`, this is the final shellcode file.\n\n\n### Test shellcode\n\nTest the shellcode use your favorite shellcode loader, i use my own little tool [rs_shellcode](https://github.com/b1tg/rs_shellcode) for demonstration.\n\n```sh\ngit clone https://github.com/b1tg/rs_shellcode\ncd rs_shellcode/\ncargo build\n./target/debug/rs_shellcode.exe -f \"shellcode\\target\\x86_64-pc-windows-msvc\\release\\shellcode.bin\" \n```\n\nThis demo shellcode will popup a message box and print some log use `OutputDebugStringA`, you can check it out in [debugview](https://docs.microsoft.com/en-us/sysinternals/downloads/debugview) or windbg.\n\n![run shellcode](./images/run_shellcode.png)\n\n\n\n## References\n\n- https://github.com/mcountryman/min-sized-rust-windows\n- https://github.com/hasherezade/masm_shc\n- https://github.com/Trantect/win_driver_example\n- https://not-matthias.github.io/kernel-driver-with-rust/\n- https://github.com/pravic/winapi-kmd-rs\n- https://github.com/johnthagen/min-sized-rust\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb1tg%2Frust-windows-shellcode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fb1tg%2Frust-windows-shellcode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb1tg%2Frust-windows-shellcode/lists"}