Hook cheat sheet: D
How to add a vulnboxd runtime hook to a D 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/traceis the hook directory vulnboxd installs on the vulnbox. Compose snippets mount it read-only at/opt/vbxtracein 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.
D
| Setup | Use this when | Change | Hub automation |
|---|---|---|---|
| D: request tracing for vibe.d | Depends on vibe-d, vibe-http or vibe-core (in its manifest) | source, rebuild | partly |
With source access
These change the service's code or Dockerfile, then it is rebuilt.
D: request tracing for vibe.d
- Use this when: D service that depends on
vibe-d,vibe-httporvibe-core(in its manifest). - Hub automation: partly. The hub pushes the compose lines; the source change is yours.
- Check and undo: hook mounted into the container
Vendors vbxtrace.d, vbxtrace_vibe.d and C1's vbxhook into vbxtrace/, builds vbxhook.o in dub's preBuildCommands, and wraps the handler given to listenHTTP in traced(settings, ...): every request is reported with its exact per-connection index (a TaskLocal counter on the connection's task) and status; the vbxtrace helpers with current() link child processes, files and outgoing connections. Needs the read-only hook mount at /opt/vbxtrace.
1. Compose: merge into the service (app is its name) and redeploy:
services:
app:
volumes:
- /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro2. Source change, then rebuild:
- copy
/usr/local/lib/vulnboxd/trace/native/d/(vbxtrace.d,vbxtrace_vibe.d) into./vbxtrace/, andnative/c/vbxhook.h,native/c/vbxhook.candinclude/vbxtrace.htoo dub.sdl:sourcePaths/importPathsadd"vbxtrace";preBuildCommands "cc -O2 -c -I$PACKAGE_DIR/vbxtrace -o $PACKAGE_DIR/vbxtrace/vbxhook.o $PACKAGE_DIR/vbxtrace/vbxhook.c";sourceFiles "vbxtrace/vbxhook.o"(dub.json: the same keys)import vbxtrace; import vbxtrace_vibe;andlistenHTTP(settings, traced(settings, router))instead oflistenHTTP(settings, router)- optional:
vbxtrace.spawnProcess(current(), ...),openFile(current(), ...),vbxtrace_vibe.connected(current(), conn)afterconnectTCP,tracedTaskforrunTask - add the read-only mount of
/usr/local/lib/vulnboxd/traceat/opt/vbxtraceto the service indocker-compose.yml
Example change on a sample service (hooks/native/c2/proposals/d-vibed.diff):
Adds vulnboxd request tracing to a vibe.d service. Vendor first (not shown):
vbxtrace/vbxtrace.d, vbxtrace_vibe.d <- /usr/local/lib/vulnboxd/trace/native/d/
vbxtrace/vbxhook.h, vbxhook.c <- /usr/local/lib/vulnboxd/trace/native/c/
vbxtrace/vbxtrace.h <- /usr/local/lib/vulnboxd/trace/include/vbxtrace.h
diff --git a/docker-compose.yml b/docker-compose.yml
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,3 +3,5 @@
build: .
ports:
- "8080:8080"
+ volumes:
+ - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro
diff --git a/dub.sdl b/dub.sdl
--- a/dub.sdl
+++ b/dub.sdl
@@ -1,2 +1,7 @@
name "notes"
dependency "vibe-d" version="~>0.10.1"
+// vulnboxd request tracing: the vendored binding and vbxhook.c (built by cc into an object)
+sourcePaths "source" "vbxtrace"
+importPaths "source" "vbxtrace"
+preBuildCommands "cc -O2 -c -I$PACKAGE_DIR/vbxtrace -o $PACKAGE_DIR/vbxtrace/vbxhook.o $PACKAGE_DIR/vbxtrace/vbxhook.c"
+sourceFiles "vbxtrace/vbxhook.o"
diff --git a/source/app.d b/source/app.d
--- a/source/app.d
+++ b/source/app.d
@@ -1,5 +1,7 @@
import vibe.vibe;
import std.process : execute;
+import vbxtrace; // vulnboxd request tracing
+import vbxtrace_vibe;
void main() {
auto router = new URLRouter;
@@ -7,12 +9,12 @@
res.writeBody(execute(["ping", "-c", "1", req.query["host"]]).output);
});
router.post("/save", (HTTPServerRequest req, HTTPServerResponse res) {
- auto f = File("/data/" ~ req.query["name"], "w");
+ auto f = openFile(current(), "/data/" ~ req.query["name"], "w");
f.write(req.bodyReader.readAllUTF8());
res.writeBody("saved\n");
});
auto settings = new HTTPServerSettings;
settings.port = 8080;
- listenHTTP(settings, router);
+ listenHTTP(settings, traced(settings, router));
runApplication();
}Exact detection rules
Package C2 (Zig, Nim, Crystal, D, Odin, V), proposal C2:d, defined in hooks/native/c2/proposals/d.toml.
- Image matches (regex):
^dlang2/,ldc,dmd,gdc - Command matches (regex):
\bdub\s+(build|run)\b,\b(ldc2|dmd|gdc)\b - Dependency on:
vibe-d,vibe-http,vibe-core - Files:
dub.json,dub.sdl,dub.selections.json,source/*.d,*.d
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):
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.