Skip to content

Hook cheat sheet: .NET ​

How to add a vulnboxd runtime hook to a .NET service by hand. Find your setup in the table, then follow its block.

  • Without source access: only the compose file changes; redeploy. With source access: you change the code or Dockerfile and rebuild.
  • Hub automation says how much the hub's proposals do for you. Fully: approve the proposal in the hub; the block is the fallback when it failed. With conditions: the same, when the conditions listed hold. Partly: the hub pushes the compose part, the rest is yours. Not at all: everything is by hand.
  • /usr/local/lib/vulnboxd/trace is the hook directory vulnboxd installs on the vulnbox. Compose snippets mount it read-only at /opt/vbxtrace in the container.
  • How to check that the hook works and undo it is at the end of the page.
  • Runtime hooks explains what a hook does.

.NET ​

SetupUse this whenChangeHub automation
Trace requests in this .NET service (startup hook)Depends on Microsoft.AspNetCore.App, Microsoft.NET.Sdk.Web or Grpc.AspNetCore (in the project file), and only if no *.csproj file matches the pattern belowcomposefully
Trace requests in this trimmed / Native AOT ASP.NET Core appDepends on Microsoft.NET.Sdk.Web (in the project file), and only if a **/*.csproj file matches the pattern belowsource, rebuildpartly
Trace sessions of this .NET TcpListener serverWith *.csproj files, and only if a **/*.cs file matches the pattern belowsource, rebuildpartly

Without source access ​

Only the compose file changes: the image and the code stay as they are.

Trace requests in this .NET service (startup hook) ​

  • Use this when: .NET service that depends on Microsoft.AspNetCore.App, Microsoft.NET.Sdk.Web or Grpc.AspNetCore (in the project file), and only if no *.csproj file matches the pattern below.
  • Hub automation: fully. The hub proposes exactly this change and pushes it (one commit per container) once you approve it. Do it by hand only when the proposal failed, e.g. on an unusual compose file.
  • Check and undo: hook mounted into the container

Mounts vulnboxd's hook directory read-only at /opt/vbxtrace and appends the vbxtrace startup hook to DOTNET_STARTUP_HOOKS. Works for framework-dependent .NET 6–10 apps (Kestrel: minimal APIs, MVC, Razor Pages, gRPC, SignalR). Older runtimes ignore it. Trimmed and Native AOT apps cannot load startup hooks: use the source-change proposal instead. Set VBXTRACE=0 to switch it off without a rebuild.

Compose: merge into the service (app is its name) and redeploy:

yaml
services:
  app:
    volumes:
      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro
    environment:
      DOTNET_STARTUP_HOOKS: "/opt/vbxtrace/dotnet/VbxTrace.StartupHook.dll"   # already set? append, separated by ":"
Exact detection rules

Package D1 (.NET startup hook), proposal D1:compose, defined in hooks/dotnet/d1/proposals/compose.toml.

  • Image matches (regex): ^mcr\.microsoft\.com/dotnet/(nightly/)?(aspnet|runtime|sdk):(6|7|8|9|10)\.
  • Command matches (regex): \bdotnet\s+\S+\.dll\b, \bdotnet\s+run\b
  • Dependency on: Microsoft.AspNetCore.App, Microsoft.NET.Sdk.Web, Grpc.AspNetCore
  • Files: *.csproj, *.fsproj, *.vbproj, global.json, *.sln, *.slnx, Directory.Build.props
  • Excluded: a *.csproj file matching <(PublishAot|PublishTrimmed)>\s*true\s*</

With source access ​

These change the service's code or Dockerfile, then it is rebuilt.

Trace requests in this trimmed / Native AOT ASP.NET Core app ​

  • Use this when: .NET service that depends on Microsoft.NET.Sdk.Web (in the project file), and only if a **/*.csproj file matches the pattern below.
  • Hub automation: partly. The hub pushes the compose lines; the source change is yours.
  • Check and undo: hook mounted into the container

Native AOT and trimmed .NET apps ignore DOTNET_STARTUP_HOOKS. This copies VbxTrace.cs and VbxTrace.AspNetCore.cs into the project, allows unsafe code and adds app.UseVbxTrace(); as the first middleware. Both files are trim- and AOT-safe. Also mounts the hook directory, where the core library lives.

1. Compose: merge into the service (app is its name) and redeploy:

yaml
services:
  app:
    volumes:
      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro

2. Source change, then rebuild:

  1. copy /usr/local/lib/vulnboxd/trace/dotnet/vendor/VbxTrace.cs and VbxTrace.AspNetCore.cs to <project dir>/vendor/vbxtrace/
  2. add <AllowUnsafeBlocks>true</AllowUnsafeBlocks> to the project's first <PropertyGroup> (skip if already there)
  3. add using Vulnboxd.Trace; to Program.cs and app.UseVbxTrace(); right after var app = builder.Build();, before any other middleware
  4. add the read-only mount /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro to the service in docker-compose.yml

Example change on a sample service (hooks/dotnet/d1/proposals/aspnetcore-aot.diff):

diff
# Example for source-aspnetcore-aot.toml. <service> and <project> are placeholders.
--- /dev/null
+++ b/<service>/<project>/vendor/vbxtrace/VbxTrace.cs
@@ -0,0 +1 @@
+// (copied from /usr/local/lib/vulnboxd/trace/dotnet/vendor/VbxTrace.cs)
--- /dev/null
+++ b/<service>/<project>/vendor/vbxtrace/VbxTrace.AspNetCore.cs
@@ -0,0 +1 @@
+// (copied from /usr/local/lib/vulnboxd/trace/dotnet/vendor/VbxTrace.AspNetCore.cs)
--- a/<service>/<project>/<project>.csproj
+++ b/<service>/<project>/<project>.csproj
@@ -3,5 +3,6 @@
     <TargetFramework>net10.0</TargetFramework>
     <PublishAot>true</PublishAot>
     <InvariantGlobalization>true</InvariantGlobalization>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
   </PropertyGroup>
 </Project>
--- a/<service>/<project>/Program.cs
+++ b/<service>/<project>/Program.cs
@@ -1,6 +1,9 @@
+using Vulnboxd.Trace;
+
 var builder = WebApplication.CreateSlimBuilder(args);
 var app = builder.Build();
+app.UseVbxTrace();
 
 app.MapGet("/", () => "hello");
 app.Run();
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -2,4 +2,6 @@
   <service>:
     build: <service>
     ports:
       - "8080:8080"
+    volumes:
+      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro
Exact detection rules

Package D1 (.NET startup hook), proposal D1:source-aspnetcore-aot, defined in hooks/dotnet/d1/proposals/source-aspnetcore-aot.toml.

  • Dependency on: Microsoft.NET.Sdk.Web
  • Files: *.csproj
  • Required: a **/*.csproj file matching <(PublishAot|PublishTrimmed)>\s*true\s*</

Trace sessions of this .NET TcpListener server ​

  • Use this when: .NET service with *.csproj files, and only if a **/*.cs file matches the pattern below.
  • Hub automation: partly. The hub pushes the compose lines; the source change is yours.
  • Check and undo: hook mounted into the container

Copies VbxTrace.cs (one file, base class library only) into the project, allows unsafe code (the file calls the core through function pointers) and wraps each accepted connection in using var _ = VbxTrace.Session(client);. Also mounts the hook directory, where the core library lives. Without the mount, or with VBXTRACE=0, the added line does nothing.

1. Compose: merge into the service (app is its name) and redeploy:

yaml
services:
  app:
    volumes:
      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro

2. Source change, then rebuild:

  1. copy /usr/local/lib/vulnboxd/trace/dotnet/vendor/VbxTrace.cs to <project dir>/vendor/vbxtrace/VbxTrace.cs (the SDK compiles it automatically)
  2. add <AllowUnsafeBlocks>true</AllowUnsafeBlocks> to the project's first <PropertyGroup> (skip if already there)
  3. add using Vulnboxd.Trace; and, as the first statement of the per-connection handler, using var _ = VbxTrace.Session(client); (client: the accepted TcpClient or Socket)
  4. add the read-only mount /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro to the service in docker-compose.yml

Example change on a sample service (hooks/dotnet/d1/proposals/tcplistener.diff):

diff
# Example for source-tcplistener.toml. <service>, <project> and the handler are placeholders.
--- /dev/null
+++ b/<service>/<project>/vendor/vbxtrace/VbxTrace.cs
@@ -0,0 +1 @@
+// (copied from /usr/local/lib/vulnboxd/trace/dotnet/vendor/VbxTrace.cs)
--- a/<service>/<project>/<project>.csproj
+++ b/<service>/<project>/<project>.csproj
@@ -3,4 +3,5 @@
     <OutputType>Exe</OutputType>
     <TargetFramework>net8.0</TargetFramework>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
   </PropertyGroup>
 </Project>
--- a/<service>/<project>/Program.cs
+++ b/<service>/<project>/Program.cs
@@ -1,6 +1,7 @@
 using System.Net;
 using System.Net.Sockets;
+using Vulnboxd.Trace;
 
 var listener = new TcpListener(IPAddress.Any, 9000);
 listener.Start();
@@ -12,6 +13,7 @@
 static async Task Handle(TcpClient client)
 {
+    using var _ = VbxTrace.Session(client);
     using (client)
     {
         var stream = client.GetStream();
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -2,4 +2,6 @@
   <service>:
     build: <service>
     ports:
       - "9000:9000"
+    volumes:
+      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro
Exact detection rules

Package D1 (.NET startup hook), proposal D1:source-tcplistener, defined in hooks/dotnet/d1/proposals/source-tcplistener.toml.

  • Image matches (regex): ^mcr\.microsoft\.com/dotnet/(runtime|sdk|runtime-deps):(6|7|8|9|10)\.
  • Files: *.csproj
  • Required: a **/*.cs file matching \b(AcceptTcpClient|AcceptSocket|Accept)(Async)?\s*\(

Check that it works, and undo ​

Each block links the variant it needs.

Hook mounted into the container ​

Check: After the redeploy, this lists the processes that loaded the hook (empty: it is not loaded):

sh
docker compose exec app sh -c 'grep -l vbxtrace /proc/[0-9]*/maps'

The hub's Trace tab then shows links whose method starts with hook:.

Undo: Set VBXTRACE: "0" in the service's environment and restart it, or revert the commit (the hub's proposal screen has a revert per container). Remove the mount of /opt/vbxtrace only together with what loads from it: a runtime told to preload a missing file may refuse to start.