How minhnt02/powerrat works
Project Type and Purpose
• This is a niche penetration testing or post-exploitation tool (often called a “RAT” or Remote Access Tool), built in C#. Its key purpose is to execute PowerShell commands indirectly via .NET’s runspace, bypassing restrictions set by system policies.
• The README highlights its bypass of the “DISABLE POWERSHELL.EXE” policy by leveraging .NET Runspace and explains the workflow—from receiving and encoding PowerShell commands (split if needed) to executing them via methods using the PowerShell class (Create, AddScript, Invoke).
File Structure
• Top-Level Files/Directories:
• The solution and project files (PowerRAT.sln, PowerRAT.csproj) indicate the primary C# project.
• Source files like Program.cs, Persistent.cs, and PublicResource.cs suggest the main logic, persistence mechanism (ensuring continued execution/persistence), and shared resources.
• Configuration: App.config holds settings that likely affect runtime behavior.
• build artifacts (bin and obj folders) are present, but not part of the conceptual architecture.
• Also see PowerShell-related scripts (decode.ps1, encode.ps1) which likely serve to encode/decode payloads and manage payload integrity respectively.
• Development-Environment Artifacts: The .vs directory contains Visual Studio-specific settings which aren’t central to the runtime architecture.
Components and Their Relationships
• Main Application Module:
• Represents the bootstrapping logic (Program.cs) that initializes the application. This module mainly orchestrates the creation of a PowerShell runspace using System.Management.Automation.dll.
• PowerShell Execution Module:
• Within the application, a key component is the PowerShell thread. Its responsibilities include instantiating a new PowerShell instance (and therefore runspace), feeding commands (via AddScript), and invoking them (via Invoke). This is highlighted in the README.
• Payload Encoding/Decoding Components:
• The presence of decode.ps1 and encode.ps1 suggests there is a pre-processing stage to manage payload strings. These scripts encode or split long payloads before they’re injected into the runspace.
• AMSI Bypass Routine:
• The README includes a snippet that patches AMSI (Anti-Malware Scan Interface) variables using reflection. This can be drawn as a separate function or routine that’s invoked early in the execution chain.
• Persistence Mechanism:
• Persistent.cs may imply that part of the design is to ensure the tool maintains its presence on the system even after execution stops. This could be modeled as a background/persistence service within the application.
• External or System Dependencies:
• The configuration file (App.config) plays a role in setting up various runtime parameters and should be noted.
Architectural Patterns and Data Flow
• The system follows a layered/process pipeline architecture:
• Input Stage: Reception of a command or script payload.
• Preparation Stage: Payload encoding/decoding (via provided .ps1 scripts and/or internal processing).
• Execution Stage: Creation of the runspace and command execution (using the PowerShell class’s Create, AddScript, and Invoke methods).
• Bypass Logic: The AMSI bypass routine runs early in the execution chain to disable scanning.
• Persistence Handling: An optional persistence layer ensures the RAT’s survival.
• Data Flow is sequential:
• Input command (or payload) → encoding/decoding → runspace creation → AMSI bypass patch → command injection (AddScript) → command invocation (Invoke) → output/result.