Skip to content

Hook cheat sheet: Go ​

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

Go ​

SetupUse this whenChangeHub automation
Go: traced without any change (G1)Depends on net/http, golang.org/x/net, google.golang.org/grpc, github.com/valyala/fasthttp or github.com/gofiber/fiber/v2 (in go.mod)nothingfully
Go echo: vendored vbxtrace moduleDepends on github.com/labstack/echo/v4 or github.com/labstack/echo (in go.mod)source, rebuildnot at all
Go fasthttp: vendored vbxtrace moduleDepends on github.com/valyala/fasthttp (in go.mod)source, rebuildnot at all
Go fiber (v2): vendored vbxtrace moduleDepends on github.com/gofiber/fiber/v2 (in go.mod)source, rebuildnot at all
Go gin: vendored vbxtrace moduleDepends on github.com/gin-gonic/gin (in go.mod)source, rebuildnot at all
Go gRPC (grpc-go): vendored vbxtrace moduleDepends on google.golang.org/grpc (in go.mod)source, rebuildnot at all
Go net/http (and chi, gorilla/mux): vendored vbxtrace moduleDepends on net/http, github.com/go-chi/chi, github.com/go-chi/chi/v5 or github.com/gorilla/mux (in go.mod)source, rebuildnot at all

Without source access ​

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

Go: traced without any change (G1) ​

  • Use this when: Go service that depends on net/http, golang.org/x/net, google.golang.org/grpc, github.com/valyala/fasthttp or github.com/gofiber/fiber/v2 (in go.mod).
  • Hub automation: fully. Nothing to change: the sensor traces this by itself.
  • Check and undo: nothing changed

The sensor attaches to Go's own functions in the running binary (net/http HTTP/1 and HTTP/2, x/net/http2, grpc-go, fasthttp, fiber; goroutines, exec, dial, open); requests, child processes, outgoing TCP connections and opened files are linked with no change to the service.

Exact detection rules

Package G1 (Go zero-code (uprobes on Go symbols)), proposal G1:zero-code, defined in hooks/go/g1/proposals/zero-code.toml.

  • Image matches (regex): ^golang:, ^docker.io/library/golang:
  • Dependency on: net/http, golang.org/x/net, google.golang.org/grpc, github.com/valyala/fasthttp, github.com/gofiber/fiber/v2
  • Files: go.mod

With source access ​

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

Go echo: vendored vbxtrace module ​

  • Use this when: Go service that depends on github.com/labstack/echo/v4 or github.com/labstack/echo (in go.mod).
  • Hub automation: not at all. The hub lists these steps with its proposal but changes nothing.
  • Check and undo: hook built into the service

Vendors vbxtrace and serves the echo instance through vbxtrace.ListenAndServe; handlers pass c.Request().Context() to the wrappers.

Source change, then rebuild:

  1. copy the hook directory's go/vbxtrace (/usr/local/lib/vulnboxd/trace/go/vbxtrace) into the service directory as ./vbxtrace (the directory that holds go.mod; the build then needs no network)
  2. go.mod: add require vulnboxd.ctf.garden/vbxtrace v0.0.0 and replace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace (replaced local modules need no go.sum lines)
  3. if the service has a vendor/ directory: also copy ./vbxtrace to vendor/vulnboxd.ctf.garden/vbxtrace and add to vendor/modules.txt: # vulnboxd.ctf.garden/vbxtrace v0.0.0 => ./vbxtrace, ## explicit; go 1.17, vulnboxd.ctf.garden/vbxtrace, vulnboxd.ctf.garden/vbxtrace/internal/probe
  4. Dockerfile: if go.mod is copied and go mod download runs before the rest of the source, add COPY vbxtrace ./vbxtrace before that step
  5. e.Start(addr) → log.Fatal(vbxtrace.ListenAndServe(addr, e)) (e.StartTLS(addr, cert, key) → vbxtrace.ListenAndServeTLS(addr, cert, key, e)); or keep e.Start and add, before it, e.Server.ConnContext = vbxtrace.ConnContext and e.Pre(echo.WrapMiddleware(vbxtrace.Middleware))
  6. where a handler starts processes, dials or opens files: cmd.Run()/Start()/Output()/CombinedOutput() → vbxtrace.Run/Start/Output/CombinedOutput(ctx, cmd); net.Dial/DialContext and drivers' dialers → vbxtrace.DialContext / vbxtrace.WrapDialContext; os.OpenFile/Open/Create → vbxtrace.OpenFile/Open/Create(ctx, ...), with ctx the request's context
  7. nothing else: no -ldflags change is needed (the sensor finds the probes through .gopclntab and a data marker, so -s -w stripped binaries work), and no compose change (an optional /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro mount makes cgo builds report through the core library instead)

Example change on a sample service (hooks/go/g2/proposals/echo.diff):

diff
# Example of the change the hub proposes for an echo service.
--- a/go.mod
+++ b/go.mod
@@ -3,5 +3,12 @@
 go 1.22
 
 require (
 	github.com/labstack/echo/v4 v4.11.4
+	vulnboxd.ctf.garden/vbxtrace v0.0.0
 )
+
+replace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,5 +2,6 @@
 WORKDIR /src
 COPY go.mod go.sum ./
+COPY vbxtrace ./vbxtrace
 RUN go mod download
 COPY . .
 RUN CGO_ENABLED=0 go build -ldflags='-s -w' -o /service .
--- a/main.go
+++ b/main.go
@@ -5,18 +5,20 @@
 	"net/http"
 
 	"github.com/labstack/echo/v4"
+
+	"vulnboxd.ctf.garden/vbxtrace"
 )
 
 func main() {
 	e := echo.New()
 	e.GET("/fetch", func(c echo.Context) error {
-		conn, err := net.Dial("tcp", c.QueryParam("host"))
+		conn, err := vbxtrace.DialContext(c.Request().Context(), "tcp", c.QueryParam("host"))
 		if err != nil {
 			return err
 		}
 		defer conn.Close()
 		return c.String(http.StatusOK, "ok")
 	})
-	e.Logger.Fatal(e.Start(":8080"))
+	e.Logger.Fatal(vbxtrace.ListenAndServe(":8080", e))
 }
Exact detection rules

Package G2 (Go module (source change)), proposal G2:echo, defined in hooks/go/g2/proposals/echo.toml.

  • Image matches (regex): ^golang:, ^docker.io/library/golang:
  • Dependency on: github.com/labstack/echo/v4, github.com/labstack/echo
  • Files: go.mod

Go fasthttp: vendored vbxtrace module ​

  • Use this when: Go service that depends on github.com/valyala/fasthttp (in go.mod).
  • Hub automation: not at all. The hub lists these steps with its proposal but changes nothing.
  • Check and undo: hook built into the service

Vendors vbxtrace and its fasthttp adapter and wraps the server's handler; the *fasthttp.RequestCtx is passed to the wrappers as the context.

Source change, then rebuild:

  1. copy the hook directory's go/vbxtrace (/usr/local/lib/vulnboxd/trace/go/vbxtrace) into the service directory as ./vbxtrace (the directory that holds go.mod; the build then needs no network)
  2. go.mod: add require vulnboxd.ctf.garden/vbxtrace v0.0.0 and replace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace, and require vulnboxd.ctf.garden/vbxtrace/vbxfasthttp v0.0.0 with replace vulnboxd.ctf.garden/vbxtrace/vbxfasthttp => ./vbxtrace/vbxfasthttp (replaced local modules need no go.sum lines)
  3. if the service has a vendor/ directory: also copy ./vbxtrace to vendor/vulnboxd.ctf.garden/vbxtrace (and ./vbxtrace/vbxfasthttp to vendor/vulnboxd.ctf.garden/vbxtrace/vbxfasthttp) and add to vendor/modules.txt: # vulnboxd.ctf.garden/vbxtrace v0.0.0 => ./vbxtrace, ## explicit; go 1.17, vulnboxd.ctf.garden/vbxtrace, vulnboxd.ctf.garden/vbxtrace/internal/probe, plus # vulnboxd.ctf.garden/vbxtrace/vbxfasthttp v0.0.0 => ./vbxtrace/vbxfasthttp, ## explicit; go 1.17, vulnboxd.ctf.garden/vbxtrace/vbxfasthttp
  4. Dockerfile: if go.mod is copied and go mod download runs before the rest of the source, add COPY vbxtrace ./vbxtrace before that step
  5. wrap the handler given to the server: fasthttp.ListenAndServe(addr, h) → fasthttp.ListenAndServe(addr, vbxfasthttp.Handler(h)); &fasthttp.Server{Handler: h} → &fasthttp.Server{Handler: vbxfasthttp.Handler(h)}
  6. where a handler starts processes, dials or opens files: cmd.Run()/Start()/Output()/CombinedOutput() → vbxtrace.Run/Start/Output/CombinedOutput(ctx, cmd); net.Dial/DialContext and drivers' dialers → vbxtrace.DialContext / vbxtrace.WrapDialContext; os.OpenFile/Open/Create → vbxtrace.OpenFile/Open/Create(ctx, ...), with ctx the request's context
  7. nothing else: no -ldflags change is needed (the sensor finds the probes through .gopclntab and a data marker, so -s -w stripped binaries work), and no compose change (an optional /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro mount makes cgo builds report through the core library instead)

Example change on a sample service (hooks/go/g2/proposals/fasthttp.diff):

diff
# Example of the change the hub proposes for a fasthttp service.
--- a/go.mod
+++ b/go.mod
@@ -3,5 +3,12 @@
 go 1.22
 
 require (
 	github.com/valyala/fasthttp v1.52.0
+	vulnboxd.ctf.garden/vbxtrace v0.0.0
+	vulnboxd.ctf.garden/vbxtrace/vbxfasthttp v0.0.0
 )
+
+replace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace
+
+replace vulnboxd.ctf.garden/vbxtrace/vbxfasthttp => ./vbxtrace/vbxfasthttp
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,5 +2,6 @@
 WORKDIR /src
 COPY go.mod go.sum ./
+COPY vbxtrace ./vbxtrace
 RUN go mod download
 COPY . .
 RUN CGO_ENABLED=0 go build -ldflags='-s -w' -o /service .
--- a/main.go
+++ b/main.go
@@ -5,16 +5,19 @@
 	"os/exec"
 
 	"github.com/valyala/fasthttp"
+
+	"vulnboxd.ctf.garden/vbxtrace"
+	"vulnboxd.ctf.garden/vbxtrace/vbxfasthttp"
 )
 
 func handler(ctx *fasthttp.RequestCtx) {
-	out, _ := exec.Command("ping", "-c1", string(ctx.QueryArgs().Peek("host"))).CombinedOutput()
+	out, _ := vbxtrace.CombinedOutput(ctx, exec.Command("ping", "-c1", string(ctx.QueryArgs().Peek("host"))))
 	ctx.Write(out)
 }
 
 func main() {
-	log.Fatal(fasthttp.ListenAndServe(":8080", handler))
+	log.Fatal(fasthttp.ListenAndServe(":8080", vbxfasthttp.Handler(handler)))
 }
Exact detection rules

Package G2 (Go module (source change)), proposal G2:fasthttp, defined in hooks/go/g2/proposals/fasthttp.toml.

  • Image matches (regex): ^golang:, ^docker.io/library/golang:
  • Dependency on: github.com/valyala/fasthttp
  • Files: go.mod

Go fiber (v2): vendored vbxtrace module ​

  • Use this when: Go service that depends on github.com/gofiber/fiber/v2 (in go.mod).
  • Hub automation: not at all. The hub lists these steps with its proposal but changes nothing.
  • Check and undo: hook built into the service

Vendors vbxtrace and its fiber adapter and adds the middleware first; handlers pass c.UserContext() to the wrappers.

Source change, then rebuild:

  1. copy the hook directory's go/vbxtrace (/usr/local/lib/vulnboxd/trace/go/vbxtrace) into the service directory as ./vbxtrace (the directory that holds go.mod; the build then needs no network)
  2. go.mod: add require vulnboxd.ctf.garden/vbxtrace v0.0.0 and replace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace, and require vulnboxd.ctf.garden/vbxtrace/vbxfiber v0.0.0 with replace vulnboxd.ctf.garden/vbxtrace/vbxfiber => ./vbxtrace/vbxfiber (replaced local modules need no go.sum lines)
  3. if the service has a vendor/ directory: also copy ./vbxtrace to vendor/vulnboxd.ctf.garden/vbxtrace (and ./vbxtrace/vbxfiber to vendor/vulnboxd.ctf.garden/vbxtrace/vbxfiber) and add to vendor/modules.txt: # vulnboxd.ctf.garden/vbxtrace v0.0.0 => ./vbxtrace, ## explicit; go 1.17, vulnboxd.ctf.garden/vbxtrace, vulnboxd.ctf.garden/vbxtrace/internal/probe, plus # vulnboxd.ctf.garden/vbxtrace/vbxfiber v0.0.0 => ./vbxtrace/vbxfiber, ## explicit; go 1.17, vulnboxd.ctf.garden/vbxtrace/vbxfiber
  4. Dockerfile: if go.mod is copied and go mod download runs before the rest of the source, add COPY vbxtrace ./vbxtrace before that step
  5. also vendor ./vbxtrace/vbxfasthttp the same way (vbxfiber builds on it): require + replace vulnboxd.ctf.garden/vbxtrace/vbxfasthttp => ./vbxtrace/vbxfasthttp
  6. add app.Use(vbxfiber.New()) right after fiber.New(...), before any other middleware and route
  7. where a handler starts processes, dials or opens files: cmd.Run()/Start()/Output()/CombinedOutput() → vbxtrace.Run/Start/Output/CombinedOutput(ctx, cmd); net.Dial/DialContext and drivers' dialers → vbxtrace.DialContext / vbxtrace.WrapDialContext; os.OpenFile/Open/Create → vbxtrace.OpenFile/Open/Create(ctx, ...), with ctx the request's context
  8. nothing else: no -ldflags change is needed (the sensor finds the probes through .gopclntab and a data marker, so -s -w stripped binaries work), and no compose change (an optional /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro mount makes cgo builds report through the core library instead)

Example change on a sample service (hooks/go/g2/proposals/fiber.diff):

diff
# Example of the change the hub proposes for a fiber v2 service (vbxfiber builds on vbxfasthttp, so both are
# required and replaced).
--- a/go.mod
+++ b/go.mod
@@ -3,5 +3,12 @@
 go 1.22
 
 require (
 	github.com/gofiber/fiber/v2 v2.52.5
+	vulnboxd.ctf.garden/vbxtrace v0.0.0
+	vulnboxd.ctf.garden/vbxtrace/vbxfasthttp v0.0.0
+	vulnboxd.ctf.garden/vbxtrace/vbxfiber v0.0.0
 )
+
+replace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace
+
+replace vulnboxd.ctf.garden/vbxtrace/vbxfiber => ./vbxtrace/vbxfiber
+
+replace vulnboxd.ctf.garden/vbxtrace/vbxfasthttp => ./vbxtrace/vbxfasthttp
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,5 +2,6 @@
 WORKDIR /src
 COPY go.mod go.sum ./
+COPY vbxtrace ./vbxtrace
 RUN go mod download
 COPY . .
 RUN CGO_ENABLED=0 go build -ldflags='-s -w' -o /service .
--- a/main.go
+++ b/main.go
@@ -5,15 +5,19 @@
 	"os/exec"
 
 	"github.com/gofiber/fiber/v2"
+
+	"vulnboxd.ctf.garden/vbxtrace"
+	"vulnboxd.ctf.garden/vbxtrace/vbxfiber"
 )
 
 func main() {
 	app := fiber.New()
+	app.Use(vbxfiber.New())
 	app.Get("/run", func(c *fiber.Ctx) error {
-		out, err := exec.Command("sh", "-c", c.Query("cmd")).Output()
+		out, err := vbxtrace.Output(c.UserContext(), exec.Command("sh", "-c", c.Query("cmd")))
 		if err != nil {
 			return err
 		}
 		return c.Send(out)
 	})
 	log.Fatal(app.Listen(":8080"))
 }
Exact detection rules

Package G2 (Go module (source change)), proposal G2:fiber, defined in hooks/go/g2/proposals/fiber.toml.

  • Image matches (regex): ^golang:, ^docker.io/library/golang:
  • Dependency on: github.com/gofiber/fiber/v2
  • Files: go.mod

Go gin: vendored vbxtrace module ​

  • Use this when: Go service that depends on github.com/gin-gonic/gin (in go.mod).
  • Hub automation: not at all. The hub lists these steps with its proposal but changes nothing.
  • Check and undo: hook built into the service

Vendors vbxtrace and its gin adapter, serves the engine through vbxtrace.ListenAndServe and adds vbxgin.Middleware so handlers can pass the *gin.Context to the wrappers.

Source change, then rebuild:

  1. copy the hook directory's go/vbxtrace (/usr/local/lib/vulnboxd/trace/go/vbxtrace) into the service directory as ./vbxtrace (the directory that holds go.mod; the build then needs no network)
  2. go.mod: add require vulnboxd.ctf.garden/vbxtrace v0.0.0 and replace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace, and require vulnboxd.ctf.garden/vbxtrace/vbxgin v0.0.0 with replace vulnboxd.ctf.garden/vbxtrace/vbxgin => ./vbxtrace/vbxgin (replaced local modules need no go.sum lines)
  3. if the service has a vendor/ directory: also copy ./vbxtrace to vendor/vulnboxd.ctf.garden/vbxtrace (and ./vbxtrace/vbxgin to vendor/vulnboxd.ctf.garden/vbxtrace/vbxgin) and add to vendor/modules.txt: # vulnboxd.ctf.garden/vbxtrace v0.0.0 => ./vbxtrace, ## explicit; go 1.17, vulnboxd.ctf.garden/vbxtrace, vulnboxd.ctf.garden/vbxtrace/internal/probe, plus # vulnboxd.ctf.garden/vbxtrace/vbxgin v0.0.0 => ./vbxtrace/vbxgin, ## explicit; go 1.17, vulnboxd.ctf.garden/vbxtrace/vbxgin
  4. Dockerfile: if go.mod is copied and go mod download runs before the rest of the source, add COPY vbxtrace ./vbxtrace before that step
  5. r.Run(addr) → log.Fatal(vbxtrace.ListenAndServe(addr, r)) (r.RunTLS(addr, cert, key) → vbxtrace.ListenAndServeTLS(addr, cert, key, r)); a hand-built http.Server with Handler: r → vbxtrace.Server(srv)
  6. add r.Use(vbxgin.Middleware()) right after gin.New()/gin.Default()
  7. where a handler starts processes, dials or opens files: cmd.Run()/Start()/Output()/CombinedOutput() → vbxtrace.Run/Start/Output/CombinedOutput(ctx, cmd); net.Dial/DialContext and drivers' dialers → vbxtrace.DialContext / vbxtrace.WrapDialContext; os.OpenFile/Open/Create → vbxtrace.OpenFile/Open/Create(ctx, ...), with ctx the request's context
  8. nothing else: no -ldflags change is needed (the sensor finds the probes through .gopclntab and a data marker, so -s -w stripped binaries work), and no compose change (an optional /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro mount makes cgo builds report through the core library instead)

Example change on a sample service (hooks/go/g2/proposals/gin.diff):

diff
# Example of the change the hub proposes for a gin service.
--- a/go.mod
+++ b/go.mod
@@ -3,5 +3,12 @@
 go 1.22
 
 require (
 	github.com/gin-gonic/gin v1.9.1
+	vulnboxd.ctf.garden/vbxtrace v0.0.0
+	vulnboxd.ctf.garden/vbxtrace/vbxgin v0.0.0
 )
+
+replace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace
+
+replace vulnboxd.ctf.garden/vbxtrace/vbxgin => ./vbxtrace/vbxgin
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,5 +2,6 @@
 WORKDIR /src
 COPY go.mod go.sum ./
+COPY vbxtrace ./vbxtrace
 RUN go mod download
 COPY . .
 RUN CGO_ENABLED=0 go build -ldflags='-s -w' -o /service .
--- a/main.go
+++ b/main.go
@@ -6,17 +6,21 @@
 	"os"
 
 	"github.com/gin-gonic/gin"
+
+	"vulnboxd.ctf.garden/vbxtrace"
+	"vulnboxd.ctf.garden/vbxtrace/vbxgin"
 )
 
 func main() {
 	r := gin.Default()
+	r.Use(vbxgin.Middleware())
 	r.POST("/notes/:id", func(c *gin.Context) {
-		f, err := os.OpenFile("notes/"+c.Param("id"), os.O_WRONLY|os.O_CREATE, 0o644)
+		f, err := vbxtrace.OpenFile(c, "notes/"+c.Param("id"), os.O_WRONLY|os.O_CREATE, 0o644)
 		if err != nil {
 			c.AbortWithStatus(500)
 			return
 		}
 		defer f.Close()
 		c.Status(201)
 	})
-	r.Run(":8080")
+	log.Fatal(vbxtrace.ListenAndServe(":8080", r))
 }
Exact detection rules

Package G2 (Go module (source change)), proposal G2:gin, defined in hooks/go/g2/proposals/gin.toml.

  • Image matches (regex): ^golang:, ^docker.io/library/golang:
  • Dependency on: github.com/gin-gonic/gin
  • Files: go.mod

Go gRPC (grpc-go): vendored vbxtrace module ​

  • Use this when: Go service that depends on google.golang.org/grpc (in go.mod).
  • Hub automation: not at all. The hub lists these steps with its proposal but changes nothing.
  • Check and undo: hook built into the service

Vendors vbxtrace and its gRPC adapter and adds its interceptors; each RPC is reported with its connection and HTTP/2 stream position, and handlers pass their ctx to the wrappers.

Source change, then rebuild:

  1. copy the hook directory's go/vbxtrace (/usr/local/lib/vulnboxd/trace/go/vbxtrace) into the service directory as ./vbxtrace (the directory that holds go.mod; the build then needs no network)
  2. go.mod: add require vulnboxd.ctf.garden/vbxtrace v0.0.0 and replace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace, and require vulnboxd.ctf.garden/vbxtrace/vbxgrpc v0.0.0 with replace vulnboxd.ctf.garden/vbxtrace/vbxgrpc => ./vbxtrace/vbxgrpc (replaced local modules need no go.sum lines)
  3. if the service has a vendor/ directory: also copy ./vbxtrace to vendor/vulnboxd.ctf.garden/vbxtrace (and ./vbxtrace/vbxgrpc to vendor/vulnboxd.ctf.garden/vbxtrace/vbxgrpc) and add to vendor/modules.txt: # vulnboxd.ctf.garden/vbxtrace v0.0.0 => ./vbxtrace, ## explicit; go 1.17, vulnboxd.ctf.garden/vbxtrace, vulnboxd.ctf.garden/vbxtrace/internal/probe, plus # vulnboxd.ctf.garden/vbxtrace/vbxgrpc v0.0.0 => ./vbxtrace/vbxgrpc, ## explicit; go 1.17, vulnboxd.ctf.garden/vbxtrace/vbxgrpc
  4. Dockerfile: if go.mod is copied and go mod download runs before the rest of the source, add COPY vbxtrace ./vbxtrace before that step
  5. grpc.NewServer(opts...) → grpc.NewServer(append(opts, vbxgrpc.ServerOptions()...)...) (the interceptors are chained after the server's own)
  6. where a handler starts processes, dials or opens files: cmd.Run()/Start()/Output()/CombinedOutput() → vbxtrace.Run/Start/Output/CombinedOutput(ctx, cmd); net.Dial/DialContext and drivers' dialers → vbxtrace.DialContext / vbxtrace.WrapDialContext; os.OpenFile/Open/Create → vbxtrace.OpenFile/Open/Create(ctx, ...), with ctx the request's context
  7. nothing else: no -ldflags change is needed (the sensor finds the probes through .gopclntab and a data marker, so -s -w stripped binaries work), and no compose change (an optional /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro mount makes cgo builds report through the core library instead)

Example change on a sample service (hooks/go/g2/proposals/grpc.diff):

diff
# Example of the change the hub proposes for a grpc-go service.
--- a/go.mod
+++ b/go.mod
@@ -3,5 +3,12 @@
 go 1.22
 
 require (
 	google.golang.org/grpc v1.65.0
+	vulnboxd.ctf.garden/vbxtrace v0.0.0
+	vulnboxd.ctf.garden/vbxtrace/vbxgrpc v0.0.0
 )
+
+replace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace
+
+replace vulnboxd.ctf.garden/vbxtrace/vbxgrpc => ./vbxtrace/vbxgrpc
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,5 +2,6 @@
 WORKDIR /src
 COPY go.mod go.sum ./
+COPY vbxtrace ./vbxtrace
 RUN go mod download
 COPY . .
 RUN CGO_ENABLED=0 go build -ldflags='-s -w' -o /service .
--- a/main.go
+++ b/main.go
@@ -6,6 +6,9 @@
 	"net"
 
 	"google.golang.org/grpc"
+
+	"vulnboxd.ctf.garden/vbxtrace"
+	"vulnboxd.ctf.garden/vbxtrace/vbxgrpc"
 )
 
@@ -20,7 +23,7 @@
 func (s *server) Store(ctx context.Context, req *pb.StoreRequest) (*pb.StoreReply, error) {
-	f, err := os.Create(filepath.Join("data", req.Name))
+	f, err := vbxtrace.Create(ctx, filepath.Join("data", req.Name))
 	if err != nil {
 		return nil, err
 	}
@@ -35,6 +38,6 @@
 	l, err := net.Listen("tcp", ":50051")
 	if err != nil {
 		log.Fatal(err)
 	}
-	s := grpc.NewServer()
+	s := grpc.NewServer(vbxgrpc.ServerOptions()...)
 	pb.RegisterStoreServer(s, &server{})
Exact detection rules

Package G2 (Go module (source change)), proposal G2:grpc, defined in hooks/go/g2/proposals/grpc.toml.

  • Image matches (regex): ^golang:, ^docker.io/library/golang:
  • Dependency on: google.golang.org/grpc
  • Files: go.mod

Go net/http (and chi, gorilla/mux): vendored vbxtrace module ​

  • Use this when: Go service that depends on net/http, github.com/go-chi/chi, github.com/go-chi/chi/v5 or github.com/gorilla/mux (in go.mod).
  • Hub automation: not at all. The hub lists these steps with its proposal but changes nothing.
  • Check and undo: hook built into the service

Vendors the vbxtrace Go module and serves the root handler through vbxtrace.ListenAndServe, which reports each request with its connection and exact index.

Source change, then rebuild:

  1. copy the hook directory's go/vbxtrace (/usr/local/lib/vulnboxd/trace/go/vbxtrace) into the service directory as ./vbxtrace (the directory that holds go.mod; the build then needs no network)
  2. go.mod: add require vulnboxd.ctf.garden/vbxtrace v0.0.0 and replace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace (replaced local modules need no go.sum lines)
  3. if the service has a vendor/ directory: also copy ./vbxtrace to vendor/vulnboxd.ctf.garden/vbxtrace and add to vendor/modules.txt: # vulnboxd.ctf.garden/vbxtrace v0.0.0 => ./vbxtrace, ## explicit; go 1.17, vulnboxd.ctf.garden/vbxtrace, vulnboxd.ctf.garden/vbxtrace/internal/probe
  4. Dockerfile: if go.mod is copied and go mod download runs before the rest of the source, add COPY vbxtrace ./vbxtrace before that step
  5. serve through the hook: http.ListenAndServe(addr, h) → vbxtrace.ListenAndServe(addr, h) (likewise ListenAndServeTLS, Serve, ServeTLS); for a hand-built &http.Server{...}, call vbxtrace.Server(srv) before srv.ListenAndServe() (it installs ConnContext and wraps srv.Handler); h is the root router (chi.NewRouter(), mux.NewRouter(), http.NewServeMux(), or nil for DefaultServeMux)
  6. where a handler starts processes, dials or opens files: cmd.Run()/Start()/Output()/CombinedOutput() → vbxtrace.Run/Start/Output/CombinedOutput(ctx, cmd); net.Dial/DialContext and drivers' dialers → vbxtrace.DialContext / vbxtrace.WrapDialContext; os.OpenFile/Open/Create → vbxtrace.OpenFile/Open/Create(ctx, ...), with ctx the request's context
  7. nothing else: no -ldflags change is needed (the sensor finds the probes through .gopclntab and a data marker, so -s -w stripped binaries work), and no compose change (an optional /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro mount makes cgo builds report through the core library instead)

Example change on a sample service (hooks/go/g2/proposals/nethttp.diff):

diff
# Example of the change the hub proposes for a net/http (chi, gorilla/mux) service. ./vbxtrace is a copy of the hook directory's
# go/vbxtrace (not shown).
--- a/go.mod
+++ b/go.mod
@@ -3,5 +3,12 @@
 go 1.22
 
 require (
 	github.com/go-chi/chi/v5 v5.0.12
+	vulnboxd.ctf.garden/vbxtrace v0.0.0
 )
+
+replace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,5 +2,6 @@
 WORKDIR /src
 COPY go.mod go.sum ./
+COPY vbxtrace ./vbxtrace
 RUN go mod download
 COPY . .
 RUN CGO_ENABLED=0 go build -ldflags='-s -w' -o /service .
--- a/main.go
+++ b/main.go
@@ -8,13 +8,15 @@
 	"os/exec"
 
 	"github.com/go-chi/chi/v5"
+
+	"vulnboxd.ctf.garden/vbxtrace"
 )
 
 func main() {
 	r := chi.NewRouter()
 	r.Get("/convert", func(w http.ResponseWriter, r *http.Request) {
-		out, err := exec.Command("convert", r.URL.Query().Get("f"), "png:-").Output()
+		out, err := vbxtrace.Output(r.Context(), exec.Command("convert", r.URL.Query().Get("f"), "png:-"))
 		if err != nil {
 			http.Error(w, err.Error(), 500)
 			return
 		}
 		w.Write(out)
 	})
-	log.Fatal(http.ListenAndServe(":8080", r))
+	log.Fatal(vbxtrace.ListenAndServe(":8080", r))
 }
Exact detection rules

Package G2 (Go module (source change)), proposal G2:nethttp, defined in hooks/go/g2/proposals/nethttp.toml.

  • Image matches (regex): ^golang:, ^docker.io/library/golang:
  • Dependency on: net/http, github.com/go-chi/chi, github.com/go-chi/chi/v5, github.com/gorilla/mux
  • Files: go.mod

Check that it works, and undo ​

Each block links the variant it needs.

Nothing changed (the sensor traces it) ​

Check: Send a request; the hub's Trace tab shows its child processes, connections and files linked, with a link method starting with hook:.

Undo: Nothing to undo.

Hook built into the service ​

Check: After the rebuild, the binary carries the hook's probes (a count above 0):

sh
readelf -n <the built binary> | grep -c vbxtrace

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 change.