Skip to content

Hook cheat sheet: Perl ​

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

Perl ​

SetupUse this whenChangeHub automation
Perl runtime hook (PERL5OPT)Depends on Mojolicious, AnyEvent, Plack, Twiggy, Starman or 7 more (in cpanfile)composefully
Perl runtime hook (use VbxTrace in the script)With *.pl or *.psgi filessource, rebuildpartly

Without source access ​

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

Perl runtime hook (PERL5OPT) ​

  • Use this when: Perl service that depends on Mojolicious, AnyEvent, Plack, Twiggy, Starman or 7 more (in cpanfile).
  • 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 adds -Mlib=/opt/vbxtrace/perl -MVbxTrace to PERL5OPT, so Mojolicious, PSGI servers (Twiggy, Starman, plackup) and AnyEvent services report which request started a child process, opened a connection or a file. Image and source stay untouched; set VBXTRACE=0 to switch it off.

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

yaml
services:
  app:
    volumes:
      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro
    environment:
      PERL5OPT: "-Mlib=/opt/vbxtrace/perl -MVbxTrace"   # already set? append, separated by a space
Exact detection rules

Package L1 (Perl hook), proposal L1:perl5opt, defined in hooks/perl/l1/proposals/perl5opt.toml.

  • Image matches (regex): ^(docker\.io/)?(library/)?perl:, ^[^ ]*/perl:, ^(docker\.io/)?bitnami/perl
  • Command matches (regex): \bperl\b, \bmorbo\b, \bhypnotoad\b, \bplackup\b, \btwiggy\b, \bstarman\b, \bstarlet\b, \bcarton\s+exec\b, \bdaemon\b.*\.pl\b
  • Dependency on: Mojolicious, AnyEvent, Plack, Twiggy, Starman, Starlet, Dancer2, Dancer, Catalyst::Runtime, PSGI, EV, AnyEvent::HTTPD
  • Files: cpanfile, cpanfile.snapshot, Makefile.PL, Build.PL, dist.ini, *.psgi, *.pl, *.pm, script/*, lib/**/*.pm

With source access ​

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

Perl runtime hook (use VbxTrace in the script) ​

  • Use this when: Perl service with *.pl or *.psgi files.
  • Hub automation: partly. The hub pushes the compose lines; the source change is yours.
  • Check and undo: hook mounted into the container

Mounts vulnboxd's hook directory read-only at /opt/vbxtrace and loads the hook at the top of the service's main script. Use when PERL5OPT has no effect (taint mode, a wrapper that drops the environment). The BEGIN block skips the hook when the mount is missing, so the service still starts without it.

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. add the read-only mount of /usr/local/lib/vulnboxd/trace at /opt/vbxtrace to the service
  2. add BEGIN { if (-e '/opt/vbxtrace/perl/VbxTrace.pm') { unshift @INC, '/opt/vbxtrace/perl'; require VbxTrace } } right after the #! line of the main script (before the framework's use lines)

Example change on a sample service (hooks/perl/l1/proposals/taint.diff):

diff
--- a/app.pl
+++ b/app.pl
@@ -1,4 +1,5 @@
 #!/usr/bin/perl -T
+BEGIN { if (-e '/opt/vbxtrace/perl/VbxTrace.pm') { unshift @INC, '/opt/vbxtrace/perl'; require VbxTrace } }
 use strict;
 use warnings;
 use Mojolicious::Lite;
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,3 +3,5 @@ services:
   <service>:
     build: .
+    volumes:
+      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro
Exact detection rules

Package L1 (Perl hook), proposal L1:taint, defined in hooks/perl/l1/proposals/taint.toml.

  • Command matches (regex): \bperl\s+(-\w*\s+)*-\w*T
  • Files: *.pl, *.psgi

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.