Skip to content
Glitched_CatGlitched_CatGlitched_Cat

RASP.Net

JV Botelho
Published date:
10 min read

๐Ÿ›ก๏ธ RASP.Net

Build codecov NuGet OpenSSF Best Practices OpenSSF Scorecard Threat Model Reverse Engineering

Runtime Application Self-Protection (RASP) for High-Scale .NET Services
Defense that lives inside your application process, operating at the speed of code.

[!IMPORTANT] ๐Ÿšง ARCHITECTURAL PREVIEW / ALPHA STAGE

This project is currently in Active Research & Development.

  • Do not deploy to production environments handling real assets (PII, Financial Data) without a full security audit.
  • API Stability: Public interfaces and interception signatures may undergo breaking changes to optimize for zero-allocation performance.
  • Security: While designed to block attacks, this engine is currently being tuned for false positives/negatives.

[!CAUTION] โš ๏ธ modules/ contains intentionally vulnerable code.

The modules/dotnet-grpc-library-api subdirectory is a deliberately vulnerable demo target used to validate RASP.Net detection logic. Its NuGet packages are intentionally pinned to known-vulnerable versions โ€” they are not product dependencies. Do not run dotnet list package --vulnerable against the full solution; use Rasp.Product.slnf instead (see modules/README.md).


๐Ÿ“ฆ Installation

Packages are published to NuGet.org under lockstep SemVer (see RELEASING.md). Install the meta-package for the default experience โ€” Phase A only, no runtime patching pulled in transitively:

dotnet add package Rasp.Net

Then wire it up:

builder.Services.AddRasp();

Individual guards are also available standalone (useful if you only need one, e.g. for trimming): Rasp.Net.Core, Rasp.Net.AspNetCore, Rasp.Net.Grpc, Rasp.Net.EntityFrameworkCore, Rasp.Net.AdoNet, Rasp.Net.HttpClient, Rasp.Net.SystemTextJson.

Rasp.Net.RuntimePatching (MonoMod-based guards) is opt-in only โ€” it is never a transitive dependency of Rasp.Net โ€” and carries its own AOT-incompatibility and AV/EDR-flagging warnings. See ADR 008 for the full package map and risk boundary.


๐ŸŽฎ Why This Matters for Gaming Security

The Problem: Multiplayer game services process millions of transactions per second. Traditional WAFs introduce network latency and cannot see inside encrypted gRPC payloads or understand game logic context.

The Solution: RASP.Net acts as a last line of defense inside the game server process. It instruments the runtime to detect attacks that bypass perimeter defensesโ€”detecting logic flaws like item duplication exploits or economy manipulation.

Key Engineering Goals:

  1. Zero GC Pressure: Security checks must NOT trigger Garbage Collection pauses that cause frame drops/lag
  2. Sub-Microsecond Latency: Checks happen in nanoseconds, not milliseconds
  3. Defense in Depth: Complements kernel-level Anti-Cheat (BattlEye/EAC) by protecting the backend API layer

โšก Performance Benchmarks

Perimeter scan: Source Generator vs. Reflection

Methodology: BenchmarkDotNet comparing Source Generator (compile-time) vs Reflection (runtime) instrumentation.
Hardware: AMD Ryzen 7 7800X3D | Runtime: .NET 10.0.2 (RyuJIT AVX-512)

MethodScenarioMeanAllocatedSpeedup
Source Generatorโœ… Clean Scan108.9 ns136 B10.3x faster ๐Ÿš€
Reflectionโœ… Clean Scan1,120.0 ns136 Bbaseline
Source Generator๐Ÿ›ก๏ธ Attack Blocked4,090 ns1,912 B1.04x faster
Reflection๐Ÿ›ก๏ธ Attack Blocked4,260 ns1,552 Bbaseline

Key Insights:

  • 10x Faster Hot Path: Source-generated interceptors eliminate runtime reflection overhead, critical for high-throughput game servers
  • Sub-Microsecond Latency: Clean traffic passes through in ~109 nanosecondsโ€”invisible
  • SIMD Optimization: Uses SearchValues<T> for vectorized character scanning before deep inspection

Sink overhead under sustained load (RASP on vs. off)

Methodology: real Kestrel host, real backends (Postgres via Testcontainers, real subprocess, real outbound HTTP), 25 concurrent workers sustained for 20s per endpoint. Not a synthetic Inspect() call in isolation โ€” these are p50/p99 request latencies with the entire sink wired in or fully absent. Full methodology and per-guard micro-benchmarks in ADR 006.

SinkRASP off (p50 / p99)RASP on (p50 / p99)Verdict
Path Traversal (FileStream)851 ยตs / 1349 ยตs858 ยตs / 1404 ยตsindistinguishable from noise
Command Injection (Process.Start)60.76 ms / 108.22 ms61.50 ms / 104.59 msindistinguishable from noise
SQL (EF Core โ†’ Postgres)7.76 ms / 16.97 ms7.50 ms / 16.50 msindistinguishable from noise
SSRF (HttpClient)299 ยตs / 756 ยตs306 ยตs / 914 ยตsindistinguishable from noise

Key Insight: RASPโ€™s own cost never surfaces above the real I/O itโ€™s guarding โ€” a file open, a process spawn, a database round trip, or an outbound HTTP call already costs orders of magnitude more than the guardโ€™s inspection. SSRFโ€™s guard has a real DNS-rebinding check (SocketsHttpHandler.ConnectCallback), but connection pooling means it fires roughly once per pooled connection, not once per request โ€” see ADR 006 for why that makes an opt-in DNS cache redundant in exactly the traffic pattern where itโ€™s safe to use.


๐Ÿ›ก๏ธ Security Analysis & Threat Modeling

Professional-grade security documentation demonstrating Purple Team capabilities.

DocumentDescription
๐Ÿ“„ Threat Model & Attack ScenariosSTRIDE analysis: gRPC SQL Injection, Protobuf Tampering, GC Pressure DoS
๐Ÿ•ต๏ธ Reverse Engineering & Anti-TamperNative C++ protection: IsDebuggerPresent, PEB manipulation, timing checks
๐Ÿ“ฆ Release Process & SemVer PolicyThe release pipeline and semantic versioning policy for security updates

๐Ÿ—๏ธ Architecture

This repository uses a Composite Architecture Strategyโ€”developing and validating the Security SDK by instrumenting a real-world โ€œVictimโ€ application without polluting its source code.

RASP.Net/
โ”œโ”€โ”€ src/                           # ๐Ÿ›ก๏ธ RASP SDK (Defense)
โ”‚   โ”œโ”€โ”€ Rasp.Core/                 # Detection engines & telemetry
โ”‚   โ”œโ”€โ”€ Rasp.SourceGenerators/     # Roslyn code generation
โ”‚   โ”œโ”€โ”€ Rasp.Instrumentation.Grpc/ # gRPC interceptors
โ”‚   โ””โ”€โ”€ Rasp.Bootstrapper/         # DI extensions (AddRasp())
โ”œโ”€โ”€ modules/                       # ๐ŸŽฏ Victim App (Target)
โ”‚   โ””โ”€โ”€ dotnet-grpc-library-api/   # Git submodule - Clean Architecture sample
โ”œโ”€โ”€ attack/                        # โš”๏ธ Red Team Tools
โ”‚   โ”œโ”€โ”€ exploit_xss.py             # XSS attack suite
โ”‚   โ””โ”€โ”€ exploit_grpc.py            # SQLi attack suite
โ””โ”€โ”€ scripts/                       # Automation scripts

๐Ÿ›ก๏ธ How It Works

sequenceDiagram
    participant Attacker
    participant gRPC as gRPC Gateway
    participant RASP as ๐Ÿ›ก๏ธ RASP.Net
    participant GameAPI as Game Service
    participant DB as Database
    
    Note over Attacker,RASP: ๐Ÿ”ด Attack Scenario
    Attacker->>gRPC: POST /inventory/add {item: "Sword' OR 1=1"}
    gRPC->>RASP: Intercept Request
    activate RASP
    RASP->>RASP: โšก Zero-Alloc Inspection
    RASP-->>Attacker: โŒ 403 Forbidden (Threat Detected)
    deactivate RASP
    
    Note over Attacker,DB: ๐ŸŸข Legitimate Scenario
    Attacker->>gRPC: POST /inventory/add {item: "Legendary Sword"}
    gRPC->>RASP: Intercept Request
    activate RASP
    RASP->>GameAPI: โœ… Clean - Forward Request
    deactivate RASP
    GameAPI->>DB: INSERT INTO inventory...
    DB-->>GameAPI: Success
    GameAPI-->>Attacker: 200 OK

๐Ÿš€ Quick Start (Development)

The composite/submodule setup below is the development workflow โ€” for consuming the SDK in your own project, use the Installation section above instead.

1. Clone with Submodules

git clone --recursive https://github.com/JVBotelho/RASP.Net.git
cd RASP.Net

# If already cloned without --recursive:
git submodule update --init --recursive

2. Build & Run

# Option A: Use automated setup script
./scripts/pack-local.ps1   # Windows
./scripts/pack-local.sh    # Linux/macOS

# Option B: Build directly
dotnet build Rasp.sln

3. Run the Victim App

cd modules/dotnet-grpc-library-api
dotnet run --project LibrarySystem.Grpc

โš”๏ธ Security Testing (Red Team)

Prerequisites

pip install grpcio grpcio-tools

Generate Attack Protos

# Windows
python -m grpc_tools.protoc `
  -I ./modules/dotnet-grpc-library-api/LibrarySystem.Contracts/Protos `
  --python_out=./attack --grpc_python_out=./attack `
  ./modules/dotnet-grpc-library-api/LibrarySystem.Contracts/Protos/library.proto
# Linux/macOS
python3 -m grpc_tools.protoc \
  -I ./modules/dotnet-grpc-library-api/LibrarySystem.Contracts/Protos \
  --python_out=./attack --grpc_python_out=./attack \
  ./modules/dotnet-grpc-library-api/LibrarySystem.Contracts/Protos/library.proto

Run Exploit Suites

# Target app must be running on localhost:5049
python attack/exploit_xss.py localhost:5049
python attack/exploit_grpc.py localhost:5049

Expected Output:

๐Ÿ“Š XSS Security Report
========================================
Attacks Blocked:  โœ… 7
Bypasses Found:   โŒ 0
False Positives:  โœ… 0

๐Ÿ”ง Troubleshooting

ProblemSolution
Submodule not foundRun git submodule update --init --recursive
Namespace 'Rasp' not foundOpen Rasp.sln, not individual .csproj files
gRPC UNAVAILABLECheck target port matches (default: localhost:5049)
Proto files not foundRun pip install --upgrade grpcio-tools

๐ŸŽฏ Roadmap

Sequenced for the projectโ€™s goal: a production-grade OSS RASP for the .NET ecosystem, submitted to OWASP (Incubator โ†’ Lab) and โ€” once packages are published and community traction exists โ€” to the .NET Foundation. Adoption infrastructure (Stages 1โ€“2) deliberately comes before new detection features (Stage 3): a security product nobody can dotnet add package is a repository, not a product.

โœ… Shipped โ€” the foundation

โœ… Stage 1 โ€” Ship it as a product (NuGet) โ€” shipped 2026-07-06

๐ŸŒ Stage 2 โ€” OWASP Incubator submission

Before submitting:

After acceptance:

๐Ÿ›ก๏ธ Stage 3 โ€” OWASP Top 10 (2025) coverage (feature track)

The main feature track once the product is installable โ€” closing the โฌœ rows below is what drives Incubator โ†’ Lab progression.

A sink-based RASP is a natural fit for the injection/integrity/exception-handling families and a poor fit for categories that are really about access-control policy, cryptography, or supply chain โ€” mapping kept honest rather than padded. Note the 2025 edition folded SSRF (CWE-918) into A01 Broken Access Control rather than keeping it a standalone category, and added A10 Mishandling of Exceptional Conditions, a much more precise fit for the deferred Lean Sentinel work than the 2021 editionโ€™s A04/A09 had been:

CategoryCoverageMechanism
A01 Broken Access Control (SSRF โ€” CWE-918, Path Traversal)โœ… DoneSsrfGuard (DNS-rebinding-safe HttpClient handler, ADR 006), PathTraversalGuard (MonoMod). The rest of A01 โ€” IDOR, JWT/session handling, CORS โ€” is access-control policy, not a sink a RASP can validate.
A02 Security Misconfiguration (headers)โœ… DoneRaspSecurityHeadersMiddleware (CSP, etc.)
A02 / A05 XXE (XmlReader / XmlDocument.Load)โฌœ Plannedpolicy guard disabling DTD/external entities (MonoMod)
A05 Injection (SQLi, XSS, Command Injection)โœ… DoneSqlSinkGuard, source-generated XSS/SQLi scan, CommandInjectionGuard (MonoMod)
A05 Injection (LDAP Injection โ€” DirectorySearcher)โฌœ Plannednew LdapInjectionDetectionEngine (MonoMod)
A08 Software or Data Integrity Failures (insecure deserialization)โœ… DoneDeserializationGuard + System.Text.Json type-info modifier
A09 Security Logging & Alerting Failuresโœ… DoneRaspAlertBus, correlated structured alerts (ADR 007), audit mode, metrics
A10 Mishandling of Exceptional Conditions (error messages/stack traces leaking system detail)โฌœ DeferredLean Sentinel (ADR 004 โ€” accepted, implementation deferred)
A03 (Software Supply Chain), A04 (Cryptographic Failures), A06 (Insecure Design), A07 (Authentication Failures)Out of scopeDependency/CI-CD integrity, cryptography, architecture-level design review, and authentication are a different tooling category than a sink-based RASP; deliberately not attempted here.

Second half of the Stage 3 track: the AI/LLM boundary (ADR 011), covering the OWASP LLM Top 10 (2025) and Agentic Top 10 (2026) where a sink-based RASP has ground truth. The position is deliberately narrow: treat the model as an untrusted source (its output becomes tainted data, enforced by the existing sink guards โ€” LLM05/ASI05) and the agent tool call as an instrumentable boundary (function allowlist, argument inspection, system-prompt canary โ€” LLM06/LLM07/ASI02). No claim of detecting prompt injection itself โ€” that is probabilistic classification, kept behind an opt-in, audit-mode seam. Ships as a separate package, Rasp.Instrumentation.Ai, so services without LLM traffic never carry it.

๐Ÿ”ญ Stage 4 โ€” Depth, platform reach, foundation


๐Ÿ“š References


๐Ÿ“œ License

MIT License - Free and open source. See LICENSE for full terms.


๐Ÿ” Found a security issue? See SECURITY.md for responsible disclosure.

โšก Built with .NET 10 | Powered by Clean Architecture

Previous
GhostHound
Next
Skewrun