Skip to content

Hook cheat sheet: V ​

How to add a vulnboxd runtime hook to a V 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.

V ​

SetupUse this whenChangeHub automation
V: request tracing for vebDepends on veb (in its manifest)source, rebuildpartly

With source access ​

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

V: request tracing for veb ​

  • Use this when: V service that depends on veb (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 the vbxtrace V module (with vbxtrace.vebhook) and C1's vbxhook into vbxtrace/, builds vbxhook.o in the Dockerfile, and adds before_request / not_found on the veb Context plus a last after-middleware: every request is reported from veb's client socket with its exact per-connection index (per fd, reset when the socket inode changes) and status; vbxtrace.process_run / create / open_file / dial_tcp 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:

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

2. Source change, then rebuild:

  1. copy /usr/local/lib/vulnboxd/trace/native/v/vbxtrace/ to ./vbxtrace/, and native/c/vbxhook.h, native/c/vbxhook.c and include/vbxtrace.h into it
  2. Dockerfile, before v build: RUN cc -O2 -c -Ivbxtrace -o vbxtrace/vbxhook.o vbxtrace/vbxhook.c
  3. import vbxtrace and vbxtrace.vebhook; add pub fn (mut ctx Context) before_request() { vebhook.begin(mut ctx.Context) } and pub fn (mut ctx Context) not_found() veb.Result { return vebhook.not_found(mut ctx.Context) } (or call them from existing ones)
  4. register the after-middleware last: app.use(handler: fn (mut ctx Context) bool { return vebhook.after(mut ctx.Context) }, after: true)
  5. optional: vbxtrace.process_run(vbxtrace.current(), mut p), vbxtrace.create / open_file, vbxtrace.dial_tcp
  6. add the read-only mount of /usr/local/lib/vulnboxd/trace at /opt/vbxtrace to the service in docker-compose.yml

Example change on a sample service (hooks/native/c2/proposals/v-veb.diff):

diff
Adds vulnboxd request tracing to a veb service (V 0.5). Vendor first (not shown):
  vbxtrace/ (vbxtrace.v, vebhook/)       <- /usr/local/lib/vulnboxd/trace/native/v/vbxtrace/
  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/Dockerfile b/Dockerfile
--- a/Dockerfile
+++ b/Dockerfile
@@ -3,5 +3,7 @@
 RUN curl -fsSLo /tmp/v.zip https://github.com/vlang/v/releases/download/0.5.2/v_linux.zip && unzip -q /tmp/v.zip -d /opt
 WORKDIR /app
 COPY . .
+# vulnboxd request tracing: vbxhook.c (vendored in vbxtrace/) as the object vbxtrace.v links
+RUN cc -O2 -c -Ivbxtrace -o vbxtrace/vbxhook.o vbxtrace/vbxhook.c
 RUN /opt/v/v -prod -o /app/notes .
 CMD ["/app/notes"]
diff --git a/main.v b/main.v
--- a/main.v
+++ b/main.v
@@ -2,22 +2,37 @@
 
 import os
 import veb
+import vbxtrace // vulnboxd request tracing
+import vbxtrace.vebhook
 
 pub struct Context {
 	veb.Context
 }
 
+pub fn (mut ctx Context) before_request() {
+	vebhook.begin(mut ctx.Context)
+}
+
+pub fn (mut ctx Context) not_found() veb.Result {
+	return vebhook.not_found(mut ctx.Context)
+}
+
 pub struct App {
 	veb.Middleware[Context]
 }
 
 @['/save'; post]
 pub fn (app &App) save(mut ctx Context) veb.Result {
-	os.write_file('/data/${ctx.query['name']}', ctx.req.data) or { return ctx.server_error('') }
+	mut f := vbxtrace.create(vbxtrace.current(), '/data/${ctx.query['name']}') or { return ctx.server_error('') }
+	f.write_string(ctx.req.data) or {}
+	f.close()
 	return ctx.text('saved\n')
 }
 
 fn main() {
 	mut app := &App{}
+	app.use(handler: fn (mut ctx Context) bool {
+		return vebhook.after(mut ctx.Context)
+	}, after: true)
 	veb.run[App, Context](mut app, 8080)
 }
Exact detection rules

Package C2 (Zig, Nim, Crystal, D, Odin, V), proposal C2:v, defined in hooks/native/c2/proposals/v.toml.

  • Image matches (regex): vlang, thevlang/
  • Command matches (regex): \bv\s+(-prod\s+)?(run|build|-o)\b
  • Dependency on: veb
  • Files: v.mod, *.v, src/*.v

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.