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/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.
Go
| Setup | Use this when | Change | Hub 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) | nothing | fully |
| Go echo: vendored vbxtrace module | Depends on github.com/labstack/echo/v4 or github.com/labstack/echo (in go.mod) | source, rebuild | not at all |
| Go fasthttp: vendored vbxtrace module | Depends on github.com/valyala/fasthttp (in go.mod) | source, rebuild | not at all |
| Go fiber (v2): vendored vbxtrace module | Depends on github.com/gofiber/fiber/v2 (in go.mod) | source, rebuild | not at all |
| Go gin: vendored vbxtrace module | Depends on github.com/gin-gonic/gin (in go.mod) | source, rebuild | not at all |
| Go gRPC (grpc-go): vendored vbxtrace module | Depends on google.golang.org/grpc (in go.mod) | source, rebuild | not at all |
| Go net/http (and chi, gorilla/mux): vendored vbxtrace module | Depends on net/http, github.com/go-chi/chi, github.com/go-chi/chi/v5 or github.com/gorilla/mux (in go.mod) | source, rebuild | not 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/fasthttporgithub.com/gofiber/fiber/v2(ingo.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/v4orgithub.com/labstack/echo(ingo.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:
- copy the hook directory's
go/vbxtrace(/usr/local/lib/vulnboxd/trace/go/vbxtrace) into the service directory as./vbxtrace(the directory that holdsgo.mod; the build then needs no network) go.mod: addrequire vulnboxd.ctf.garden/vbxtrace v0.0.0andreplace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace(replaced local modules need nogo.sumlines)- if the service has a
vendor/directory: also copy./vbxtracetovendor/vulnboxd.ctf.garden/vbxtraceand add tovendor/modules.txt:# vulnboxd.ctf.garden/vbxtrace v0.0.0 => ./vbxtrace,## explicit; go 1.17,vulnboxd.ctf.garden/vbxtrace,vulnboxd.ctf.garden/vbxtrace/internal/probe Dockerfile: ifgo.modis copied andgo mod downloadruns before the rest of the source, addCOPY vbxtrace ./vbxtracebefore that stepe.Start(addr)→log.Fatal(vbxtrace.ListenAndServe(addr, e))(e.StartTLS(addr, cert, key)→vbxtrace.ListenAndServeTLS(addr, cert, key, e)); or keepe.Startand add, before it,e.Server.ConnContext = vbxtrace.ConnContextande.Pre(echo.WrapMiddleware(vbxtrace.Middleware))- where a handler starts processes, dials or opens files:
cmd.Run()/Start()/Output()/CombinedOutput()→vbxtrace.Run/Start/Output/CombinedOutput(ctx, cmd);net.Dial/DialContextand drivers' dialers →vbxtrace.DialContext/vbxtrace.WrapDialContext;os.OpenFile/Open/Create→vbxtrace.OpenFile/Open/Create(ctx, ...), withctxthe request's context - nothing else: no
-ldflagschange is needed (the sensor finds the probes through.gopclntaband a data marker, so-s -wstripped binaries work), and no compose change (an optional/usr/local/lib/vulnboxd/trace:/opt/vbxtrace:romount makes cgo builds report through the core library instead)
Example change on a sample service (hooks/go/g2/proposals/echo.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(ingo.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:
- copy the hook directory's
go/vbxtrace(/usr/local/lib/vulnboxd/trace/go/vbxtrace) into the service directory as./vbxtrace(the directory that holdsgo.mod; the build then needs no network) go.mod: addrequire vulnboxd.ctf.garden/vbxtrace v0.0.0andreplace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace, andrequire vulnboxd.ctf.garden/vbxtrace/vbxfasthttp v0.0.0withreplace vulnboxd.ctf.garden/vbxtrace/vbxfasthttp => ./vbxtrace/vbxfasthttp(replaced local modules need nogo.sumlines)- if the service has a
vendor/directory: also copy./vbxtracetovendor/vulnboxd.ctf.garden/vbxtrace(and./vbxtrace/vbxfasthttptovendor/vulnboxd.ctf.garden/vbxtrace/vbxfasthttp) and add tovendor/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 Dockerfile: ifgo.modis copied andgo mod downloadruns before the rest of the source, addCOPY vbxtrace ./vbxtracebefore that step- 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)} - where a handler starts processes, dials or opens files:
cmd.Run()/Start()/Output()/CombinedOutput()→vbxtrace.Run/Start/Output/CombinedOutput(ctx, cmd);net.Dial/DialContextand drivers' dialers →vbxtrace.DialContext/vbxtrace.WrapDialContext;os.OpenFile/Open/Create→vbxtrace.OpenFile/Open/Create(ctx, ...), withctxthe request's context - nothing else: no
-ldflagschange is needed (the sensor finds the probes through.gopclntaband a data marker, so-s -wstripped binaries work), and no compose change (an optional/usr/local/lib/vulnboxd/trace:/opt/vbxtrace:romount makes cgo builds report through the core library instead)
Example change on a sample service (hooks/go/g2/proposals/fasthttp.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(ingo.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:
- copy the hook directory's
go/vbxtrace(/usr/local/lib/vulnboxd/trace/go/vbxtrace) into the service directory as./vbxtrace(the directory that holdsgo.mod; the build then needs no network) go.mod: addrequire vulnboxd.ctf.garden/vbxtrace v0.0.0andreplace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace, andrequire vulnboxd.ctf.garden/vbxtrace/vbxfiber v0.0.0withreplace vulnboxd.ctf.garden/vbxtrace/vbxfiber => ./vbxtrace/vbxfiber(replaced local modules need nogo.sumlines)- if the service has a
vendor/directory: also copy./vbxtracetovendor/vulnboxd.ctf.garden/vbxtrace(and./vbxtrace/vbxfibertovendor/vulnboxd.ctf.garden/vbxtrace/vbxfiber) and add tovendor/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 Dockerfile: ifgo.modis copied andgo mod downloadruns before the rest of the source, addCOPY vbxtrace ./vbxtracebefore that step- also vendor
./vbxtrace/vbxfasthttpthe same way (vbxfiberbuilds on it): require + replacevulnboxd.ctf.garden/vbxtrace/vbxfasthttp => ./vbxtrace/vbxfasthttp - add
app.Use(vbxfiber.New())right afterfiber.New(...), before any other middleware and route - where a handler starts processes, dials or opens files:
cmd.Run()/Start()/Output()/CombinedOutput()→vbxtrace.Run/Start/Output/CombinedOutput(ctx, cmd);net.Dial/DialContextand drivers' dialers →vbxtrace.DialContext/vbxtrace.WrapDialContext;os.OpenFile/Open/Create→vbxtrace.OpenFile/Open/Create(ctx, ...), withctxthe request's context - nothing else: no
-ldflagschange is needed (the sensor finds the probes through.gopclntaband a data marker, so-s -wstripped binaries work), and no compose change (an optional/usr/local/lib/vulnboxd/trace:/opt/vbxtrace:romount makes cgo builds report through the core library instead)
Example change on a sample service (hooks/go/g2/proposals/fiber.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(ingo.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:
- copy the hook directory's
go/vbxtrace(/usr/local/lib/vulnboxd/trace/go/vbxtrace) into the service directory as./vbxtrace(the directory that holdsgo.mod; the build then needs no network) go.mod: addrequire vulnboxd.ctf.garden/vbxtrace v0.0.0andreplace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace, andrequire vulnboxd.ctf.garden/vbxtrace/vbxgin v0.0.0withreplace vulnboxd.ctf.garden/vbxtrace/vbxgin => ./vbxtrace/vbxgin(replaced local modules need nogo.sumlines)- if the service has a
vendor/directory: also copy./vbxtracetovendor/vulnboxd.ctf.garden/vbxtrace(and./vbxtrace/vbxgintovendor/vulnboxd.ctf.garden/vbxtrace/vbxgin) and add tovendor/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 Dockerfile: ifgo.modis copied andgo mod downloadruns before the rest of the source, addCOPY vbxtrace ./vbxtracebefore that stepr.Run(addr)→log.Fatal(vbxtrace.ListenAndServe(addr, r))(r.RunTLS(addr, cert, key)→vbxtrace.ListenAndServeTLS(addr, cert, key, r)); a hand-builthttp.ServerwithHandler: r→vbxtrace.Server(srv)- add
r.Use(vbxgin.Middleware())right aftergin.New()/gin.Default() - where a handler starts processes, dials or opens files:
cmd.Run()/Start()/Output()/CombinedOutput()→vbxtrace.Run/Start/Output/CombinedOutput(ctx, cmd);net.Dial/DialContextand drivers' dialers →vbxtrace.DialContext/vbxtrace.WrapDialContext;os.OpenFile/Open/Create→vbxtrace.OpenFile/Open/Create(ctx, ...), withctxthe request's context - nothing else: no
-ldflagschange is needed (the sensor finds the probes through.gopclntaband a data marker, so-s -wstripped binaries work), and no compose change (an optional/usr/local/lib/vulnboxd/trace:/opt/vbxtrace:romount makes cgo builds report through the core library instead)
Example change on a sample service (hooks/go/g2/proposals/gin.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(ingo.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:
- copy the hook directory's
go/vbxtrace(/usr/local/lib/vulnboxd/trace/go/vbxtrace) into the service directory as./vbxtrace(the directory that holdsgo.mod; the build then needs no network) go.mod: addrequire vulnboxd.ctf.garden/vbxtrace v0.0.0andreplace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace, andrequire vulnboxd.ctf.garden/vbxtrace/vbxgrpc v0.0.0withreplace vulnboxd.ctf.garden/vbxtrace/vbxgrpc => ./vbxtrace/vbxgrpc(replaced local modules need nogo.sumlines)- if the service has a
vendor/directory: also copy./vbxtracetovendor/vulnboxd.ctf.garden/vbxtrace(and./vbxtrace/vbxgrpctovendor/vulnboxd.ctf.garden/vbxtrace/vbxgrpc) and add tovendor/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 Dockerfile: ifgo.modis copied andgo mod downloadruns before the rest of the source, addCOPY vbxtrace ./vbxtracebefore that stepgrpc.NewServer(opts...)→grpc.NewServer(append(opts, vbxgrpc.ServerOptions()...)...)(the interceptors are chained after the server's own)- where a handler starts processes, dials or opens files:
cmd.Run()/Start()/Output()/CombinedOutput()→vbxtrace.Run/Start/Output/CombinedOutput(ctx, cmd);net.Dial/DialContextand drivers' dialers →vbxtrace.DialContext/vbxtrace.WrapDialContext;os.OpenFile/Open/Create→vbxtrace.OpenFile/Open/Create(ctx, ...), withctxthe request's context - nothing else: no
-ldflagschange is needed (the sensor finds the probes through.gopclntaband a data marker, so-s -wstripped binaries work), and no compose change (an optional/usr/local/lib/vulnboxd/trace:/opt/vbxtrace:romount makes cgo builds report through the core library instead)
Example change on a sample service (hooks/go/g2/proposals/grpc.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/v5orgithub.com/gorilla/mux(ingo.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:
- copy the hook directory's
go/vbxtrace(/usr/local/lib/vulnboxd/trace/go/vbxtrace) into the service directory as./vbxtrace(the directory that holdsgo.mod; the build then needs no network) go.mod: addrequire vulnboxd.ctf.garden/vbxtrace v0.0.0andreplace vulnboxd.ctf.garden/vbxtrace => ./vbxtrace(replaced local modules need nogo.sumlines)- if the service has a
vendor/directory: also copy./vbxtracetovendor/vulnboxd.ctf.garden/vbxtraceand add tovendor/modules.txt:# vulnboxd.ctf.garden/vbxtrace v0.0.0 => ./vbxtrace,## explicit; go 1.17,vulnboxd.ctf.garden/vbxtrace,vulnboxd.ctf.garden/vbxtrace/internal/probe Dockerfile: ifgo.modis copied andgo mod downloadruns before the rest of the source, addCOPY vbxtrace ./vbxtracebefore that step- serve through the hook:
http.ListenAndServe(addr, h)→vbxtrace.ListenAndServe(addr, h)(likewiseListenAndServeTLS,Serve,ServeTLS); for a hand-built&http.Server{...}, callvbxtrace.Server(srv)beforesrv.ListenAndServe()(it installsConnContextand wrapssrv.Handler);his the root router (chi.NewRouter(),mux.NewRouter(),http.NewServeMux(), ornilforDefaultServeMux) - where a handler starts processes, dials or opens files:
cmd.Run()/Start()/Output()/CombinedOutput()→vbxtrace.Run/Start/Output/CombinedOutput(ctx, cmd);net.Dial/DialContextand drivers' dialers →vbxtrace.DialContext/vbxtrace.WrapDialContext;os.OpenFile/Open/Create→vbxtrace.OpenFile/Open/Create(ctx, ...), withctxthe request's context - nothing else: no
-ldflagschange is needed (the sensor finds the probes through.gopclntaband a data marker, so-s -wstripped binaries work), and no compose change (an optional/usr/local/lib/vulnboxd/trace:/opt/vbxtrace:romount makes cgo builds report through the core library instead)
Example change on a sample service (hooks/go/g2/proposals/nethttp.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):
readelf -n <the built binary> | grep -c vbxtraceThe 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.