{"id":27140445,"url":"https://github.com/joaoviictorti/runas-rs","last_synced_at":"2025-04-08T05:52:10.612Z","repository":{"id":286649665,"uuid":"958015044","full_name":"joaoviictorti/runas-rs","owner":"joaoviictorti","description":"A runas implementation with extra features in Rust","archived":false,"fork":false,"pushed_at":"2025-04-07T16:27:49.000Z","size":28,"stargazers_count":34,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-07T17:36:48.707Z","etag":null,"topics":["offensive-security","runas","rust","windows"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/runas-rs","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/joaoviictorti.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":"2025-03-31T14:00:17.000Z","updated_at":"2025-04-07T16:27:52.000Z","dependencies_parsed_at":"2025-04-07T17:37:59.674Z","dependency_job_id":null,"html_url":"https://github.com/joaoviictorti/runas-rs","commit_stats":null,"previous_names":["joaoviictorti/runas-rs"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joaoviictorti%2Frunas-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joaoviictorti%2Frunas-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joaoviictorti%2Frunas-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joaoviictorti%2Frunas-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joaoviictorti","download_url":"https://codeload.github.com/joaoviictorti/runas-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247703012,"owners_count":20982246,"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","runas","rust","windows"],"created_at":"2025-04-08T05:52:10.053Z","updated_at":"2025-04-08T05:52:10.597Z","avatar_url":"https://github.com/joaoviictorti.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# runas-rs 🦀\n\n![Rust](https://img.shields.io/badge/made%20with-Rust-red)\n![crate](https://img.shields.io/crates/v/runas-rs.svg)\n![docs](https://docs.rs/runas-rs/badge.svg)\n![Forks](https://img.shields.io/github/forks/joaoviictorti/runas-rs)\n![Stars](https://img.shields.io/github/stars/joaoviictorti/runas-rs)\n![License](https://img.shields.io/github/license/joaoviictorti/runas-rs)\n\nAn offensive version of `runas` in Rust with extra features\n\nThis crate provides both a CLI and a Rust crate for spawning processes under different Windows user accounts, with support for privileges, secure token manipulation, profile/environment loading, and more.\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n    - [Creating and Running a Process as Another User](#creating-and-running-a-process-as-another-user)\n    - [Checking Privileges and Token Integrity](#checking-privileges-and-token-integrity)\n    - [Available Options](#available-options)\n- [CLI](#cli)\n    - [CLI Help](#cli-help)\n- [Contributing to runas-rs](#contributing-to-runas-rs)\n- [References](#references)\n- [License](#license)\n\n## Installation\n\nAdd `runas-rs` to your project by updating your `Cargo.toml`:\n\n```powershell\ncargo add runas-rs\n```\n\n## Usage\n\n`runas-rs` offers fine-grained control over user impersonation and process spawning on Windows. It allows you to run commands under different user credentials, while dynamically selecting the most appropriate Windows API for process creation based on current privileges and token integrity.\n\n### Creating and Running a Process as Another User\n\nThis crate chooses among `CreateProcessAsUserW`, `CreateProcessWithTokenW`, or `CreateProcessWithLogonW` depending on the privileges and integrity level available to the current process.\n\n| API                        | Required Privilege                   | Required Integrity Level | \n|----------------------------|--------------------------------------|--------------------------|\n| `CreateProcessAsUserW`     | `SeAssignPrimaryTokenPrivilege`      | Medium or higher         |\n| `CreateProcessWithTokenW`  | `SeImpersonatePrivilege`             | High or System           |\n| `CreateProcessWithLogonW`  | _None_                               | Any                      |\n\nExample:\n\n```rs\nuse runas_rs::{Runas, Options};\nuse anyhow::Result;\n\nfn main() -\u003e Result\u003c()\u003e {\n    let output = Runas::new(\"username\", \"password\", Some(\"DOMAIN\"))\n        .options(Options::Env | Options::Profile)?\n        .run(\"cmd.exe /c whoami\")?;\n\n    println!(\"Output: {}\", output);\n    Ok(())\n}\n```\n\n### Checking Privileges and Token Integrity\n\nYou can inspect and manipulate the current process token to determine what kind of impersonation is possible.\n\n```rs\nuse runas_rs::Token;\nuse anyhow::Result;\n\nfn main() -\u003e Result\u003c()\u003e {\n    // Check the current integrity level\n    let level = Token::integrity_level()?;\n    println!(\"Integrity Level: {}\", level);\n\n    // Check if privileges are available\n    if Token::has_privilege(\"SeAssignPrimaryTokenPrivilege\")? {\n        println!(\"Privilege SeAssignPrimaryTokenPrivilege is available.\");\n    }\n\n    if Token::has_privilege(\"SeImpersonatePrivilege\")? {\n        println!(\"Privilege SeImpersonatePrivilege is available.\");\n    }\n\n    // Try enabling a privilege manually\n    if Token::enable_privilege(\"SeImpersonatePrivilege\")? {\n        println!(\"Privilege SeImpersonatePrivilege successfully enabled.\");\n    } else {\n        println!(\"Failed to enable SeImpersonatePrivilege.\");\n    }\n\n    Ok(())\n}\n```\n\n### Available Options\n\nYou can combine the following options using | (bitflags):\n\n| Option               | Description                                                   |\n|----------------------|---------------------------------------------------------------|\n| `Options::Env`       | Use the current user's environment block.                     |\n| `Options::Profile`   | Load the full user profile.                                   |\n| `Options::NoProfile` | Do not load the user profile.                                 |\n| `Options::NetOnly`   | Use credentials for remote access only (e.g., network shares).|\n\n## CLI\n\nThe CLI binary lets you run processes as other users directly from the command line, similar to runas.exe.\n\nExample:\n```cmd\nC:\\\u003e runas.exe -u joao -p joao -c \"whoami\" --profile\ndesktop-34dc0j2\\joao\n```\n\n### CLI Help\n\n```\nUsage: runas.exe [OPTIONS] -u \u003cUSERNAME\u003e -p \u003cPASSWORD\u003e --command \u003cCOMMAND\u003e \u003c--profile|--noprofile|--netonly\u003e\n\nOptions:\n  -u \u003cUSERNAME\u003e            Username to run the command\n  -p \u003cPASSWORD\u003e            Password for the user\n  -d, --domain \u003cDOMAIN\u003e    Domain of the user (optional)\n  -c, --command \u003cCOMMAND\u003e  Command to execute as the specified user\n  -e                       Use the environment of the current user\n      --profile            Load user profile\n      --noprofile          Do not load user profile\n      --netonly            Use credentials for remote access only\n  -h, --help               Print help\n  -V, --version            Print version\n```\n\n## References\n\nI want to express my gratitude to these projects that inspired me to create `runas-rs` and contribute with some features:\n\n* [Pavel - CreateProcessAsUser vs. CreateProcessWithTokenW](https://www.youtube.com/watch?v=y42BsQJhd5w\u0026t=816s)\n* [Pavel - Window Stations and Desktops](https://scorpiosoftware.net/2023/06/20/window-stations-and-desktops/)\n* [RunasCs](https://github.com/antonioCoco/RunasCs)\n\n## License\n\nThis project is licensed under the [**GPL-3.0 license**](/LICENSE). See the LICENSE file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoaoviictorti%2Frunas-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoaoviictorti%2Frunas-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoaoviictorti%2Frunas-rs/lists"}