Hook cheat sheet: C and C++
How to add a vulnboxd runtime hook to a C and C++ 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.
C / C++
| Setup | Use this when | Change | Hub automation |
|---|---|---|---|
| Add the vulnboxd hook to a Boost.Asio / Asio service | Depends on boost, boost-asio, boost_asio, asio, libboost-dev or 6 more (in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs) | source, rebuild | partly |
| Add the vulnboxd hook to a Boost.Beast HTTP server | Depends on boost, boost-beast, boost_beast, libboost-dev, libboost-all-dev or 2 more (in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs) | source, rebuild | partly |
| Add the vulnboxd hook to a C/C++ service (vendored vbxhook) | On the image gcc, alpine, debian or ubuntu | source, rebuild | partly |
| Add the vulnboxd hook to a static C/C++ binary (vendored vbxhook + libvbxtrace.a) | On the image scratch, gcr.io/distroless/static or busybox | source, rebuild | not at all |
| Add the vulnboxd hook to a CivetWeb service | Depends on civetweb, libcivetweb-dev or civetweb-devel (in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs) | source, rebuild | partly |
| Add the vulnboxd hook to a Crow server | Depends on crow, Crow, crowcpp or crowcpp-crow (in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs) | source, rebuild | partly |
| Add the vulnboxd hook to a Drogon server | Depends on drogon, Drogon, libdrogon-dev, drogon-devel, drogonframework/drogon or 1 more (in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs) | source, rebuild | partly |
| Add the vulnboxd hook to a cpp-httplib server | Depends on cpp-httplib, httplib, libcpp-httplib-dev, cpp-httplib-devel or yhirose/cpp-httplib (in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs) | source, rebuild | partly |
| Add the vulnboxd hook to a libev service | Depends on libev, libev-dev or libev-devel (in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs) | source, rebuild | partly |
| Add the vulnboxd hook to a libevent (evhttp/bufferevent) service | Depends on libevent, libevent_core, libevent_extra, libevent-dev or libevent-devel (in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs) | source, rebuild | partly |
| Add the vulnboxd hook to a libuv service | Depends on libuv, libuv1-dev, libuv-dev or libuv-devel (in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs) | source, rebuild | partly |
| Add the vulnboxd hook to a Mongoose (7.x) service | Depends on mongoose or cesanta/mongoose (in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs) | source, rebuild | partly |
| Add the vulnboxd hook to a Pistache server | Depends on pistache, libpistache-dev, pistache-devel or pistacheio/pistache (in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs) | source, rebuild | partly |
| Add the vulnboxd hook to a Seastar service | Depends on seastar, Seastar, seastar-dev, seastar-devel or scylladb/seastar (in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs) | source, rebuild | partly |
With source access
These change the service's code or Dockerfile, then it is rebuilt.
Add the vulnboxd hook to a Boost.Asio / Asio service
- Use this when: C / C++ service that depends on
boost,boost-asio,boost_asio,asio,libboost-devor 6 more (in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs). - Hub automation: partly. The hub pushes the compose lines; the source change is yours.
- Check and undo: hook mounted into the container
Vendors vbxhook and its Asio integration header into vendor/vbxtrace/, adds a vbxhook::asio::Connection and a vbxhook::Request to the session class, starts the request (or raw session) when the session starts or a request is parsed, ends it when the reply is written or the session closes, and reports spawns/opens/connects; mounts the hook directory read-only.
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/c/vbxhook.{h,c,hpp}, the directory/usr/local/lib/vulnboxd/trace/native/c/integrations/and/usr/local/lib/vulnboxd/trace/include/vbxtrace.hinto<service>/vendor/vbxtrace/(keepingintegrations/as a subdirectory) - build: add
vendor/vbxtrace/vbxhook.cto the sources (CMake:enable_language(C)orproject(... C CXX)) andvendor/vbxtraceto the include directories (and-ldl/${CMAKE_DL_LIBS}on glibc older than 2.34); C++17; make sure the Dockerfile copiesvendor/before compiling #include "integrations/vbxhook_asio.hpp"after the Asio headers; in the session class (one object per accepted socket) addvbxhook::asio::Connection vbx_;andvbxhook::Request req_;- raw / line protocols, one session = one request:
req_ = vbx_.session(socket_);when the session starts,req_.finish();when it closes (or let~sessionend it) - request/response protocols:
req_ = vbx_.begin(socket_, VBXH_PROTO_HTTP1);after each request is parsed,req_.status(code);when the reply is built,req_.finish();in the write completion handler - in the request code: after
fork()/posix_spawn()vbxh_spawned(ctx, pid); afteropen()vbxh_opened(ctx, fd, flags); after a blockingconnect()vbxh_connected_fd(ctx, sock); an outgoing Asio socket:vbxhook::asio::connected(ctx, socket)in the connect completion ctxisreq_.ctx(); handlers that needvbxh_current()are wrapped:vbxhook::asio::bind_context(req_.ctx(), handler); work posted to anotherio_context/thread pool:auto job = vbxh_handoff(ctx);thenvbxhook::Enter e(job);inside the job
Example change on a sample service (hooks/native/c1/proposals/asio.diff):
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.16)
-project(service CXX)
+project(service C CXX)
set(CMAKE_CXX_STANDARD 17)
find_package(Boost REQUIRED)
find_package(Threads REQUIRED)
-add_executable(service main.cpp)
-target_link_libraries(service PRIVATE Boost::boost Threads::Threads)
+add_executable(service main.cpp vendor/vbxtrace/vbxhook.c)
+target_include_directories(service PRIVATE vendor/vbxtrace)
+target_link_libraries(service PRIVATE Boost::boost Threads::Threads ${CMAKE_DL_LIBS})
--- a/main.cpp
+++ b/main.cpp
@@ -3,20 +3,24 @@
#include <memory>
#include <string>
+#include "integrations/vbxhook_asio.hpp"
+
namespace net = boost::asio;
using net::ip::tcp;
-std::string run_command(const std::string &line); // forks a helper for some commands
+std::string run_command(const std::string &line); // forks a helper for some commands; calls
+ // vbxh_spawned(vbxh_current(), pid) after fork()
class session : public std::enable_shared_from_this<session> {
public:
explicit session(tcp::socket s) : socket_(std::move(s)) {}
void start() {
- net::async_read_until(socket_, buf_, '\n', [self = shared_from_this()](boost::system::error_code ec, std::size_t n) {
+ req_ = vbx_.session(socket_);
+ net::async_read_until(socket_, buf_, '\n', vbxhook::asio::bind_context(req_.ctx(), [self = shared_from_this()](boost::system::error_code ec, std::size_t n) {
if (!ec)
self->on_line(n);
- });
+ }));
}
private:
@@ -26,10 +30,13 @@
net::async_write(socket_, net::buffer(reply_), [self = shared_from_this()](boost::system::error_code, std::size_t) {
boost::system::error_code ignored;
self->socket_.close(ignored);
+ self->req_.finish();
});
}
tcp::socket socket_;
net::streambuf buf_;
std::string reply_;
+ vbxhook::asio::Connection vbx_;
+ vbxhook::Request req_;
};Exact detection rules
Package C1 (C / C++), proposal C1:asio, defined in hooks/native/c1/proposals/asio.toml.
- Dependency on:
boost,boost-asio,boost_asio,asio,libboost-dev,libboost-all-dev,libasio-dev,boost-dev,asio-dev,boost-devel,asio-devel - Files:
CMakeLists.txt,conanfile.txt,conanfile.py,vcpkg.json,meson.build,Makefile,*.cpp,*.cc,*.cxx,src/*.cpp,src/*.cc - Sources match (regex):
#\s*include\s*[<"](boost/)?asio\.hpp[>"],\b(async_accept|async_read_until|async_read_some)\s*\(,find_package\(\s*Boost[^)]*,find_package\(\s*asio
Add the vulnboxd hook to a Boost.Beast HTTP server
- Use this when: C / C++ service that depends on
boost,boost-beast,boost_beast,libboost-dev,libboost-all-devor 2 more (in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs). - Hub automation: partly. The hub pushes the compose lines; the source change is yours.
- Check and undo: hook mounted into the container
Vendors vbxhook and its Asio integration header into vendor/vbxtrace/, adds a vbxhook::asio::Connection and a vbxhook::Request to the HTTP session class, begins a request after each http::async_read, records the response status and ends it in the async_write completion handler, and reports spawns/opens/connects; mounts the hook directory read-only.
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/c/vbxhook.{h,c,hpp}, the directory/usr/local/lib/vulnboxd/trace/native/c/integrations/and/usr/local/lib/vulnboxd/trace/include/vbxtrace.hinto<service>/vendor/vbxtrace/(keepingintegrations/as a subdirectory) - build: add
vendor/vbxtrace/vbxhook.cto the sources (CMake:enable_language(C)orproject(... C CXX)) andvendor/vbxtraceto the include directories (and-ldl/${CMAKE_DL_LIBS}on glibc older than 2.34); C++17; make sure the Dockerfile copiesvendor/before compiling #include "integrations/vbxhook_asio.hpp"after the Boost headers; in the HTTP session class addvbxhook::asio::Connection vbx_;andvbxhook::Request vreq_;- in the
http::async_readcompletion (success):vreq_ = vbx_.begin(stream_.socket(), VBXH_PROTO_HTTP1);before the handler runs - when the response is ready:
vreq_.status(res.result_int());in thehttp::async_writecompletion handler:vreq_.finish(); - in the request code: after
fork()/posix_spawn()vbxh_spawned(ctx, pid); afteropen()vbxh_opened(ctx, fd, flags); after a blockingconnect()vbxh_connected_fd(ctx, sock); an outgoing Asio socket:vbxhook::asio::connected(ctx, socket) ctxisvreq_.ctx(); jobs posted to a thread pool:auto job = vbxh_handoff(ctx);vbxhook::Enter e(job);inside the job
Example change on a sample service (hooks/native/c1/proposals/beast.diff):
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.16)
-project(service CXX)
+project(service C CXX)
set(CMAKE_CXX_STANDARD 17)
find_package(Boost REQUIRED)
find_package(Threads REQUIRED)
-add_executable(service main.cpp)
-target_link_libraries(service PRIVATE Boost::boost Threads::Threads)
+add_executable(service main.cpp vendor/vbxtrace/vbxhook.c)
+target_include_directories(service PRIVATE vendor/vbxtrace)
+target_link_libraries(service PRIVATE Boost::boost Threads::Threads ${CMAKE_DL_LIBS})
--- a/main.cpp
+++ b/main.cpp
@@ -3,6 +3,8 @@
#include <memory>
+#include "integrations/vbxhook_asio.hpp"
+
namespace beast = boost::beast;
namespace http = beast::http;
@@ -23,8 +25,12 @@
}
void on_read() {
+ vreq_ = vbx_.begin(stream_.socket(), VBXH_PROTO_HTTP1);
+ vbxhook::Scope current(vreq_.ctx()); // handle() may call vbxh_spawned(vbxh_current(), pid) etc.
res_ = handle(req_);
+ vreq_.status(static_cast<std::uint16_t>(res_.result_int()));
http::async_write(stream_, res_, [self = shared_from_this()](beast::error_code ec, std::size_t) {
+ self->vreq_.finish();
if (!ec && self->res_.keep_alive())
self->do_read();
});
@@ -34,4 +40,6 @@
beast::flat_buffer buf_;
http::request<http::string_body> req_;
http::response<http::string_body> res_;
+ vbxhook::asio::Connection vbx_;
+ vbxhook::Request vreq_;
};Exact detection rules
Package C1 (C / C++), proposal C1:beast, defined in hooks/native/c1/proposals/beast.toml.
- Dependency on:
boost,boost-beast,boost_beast,libboost-dev,libboost-all-dev,boost-dev,boost-devel - Files:
CMakeLists.txt,conanfile.txt,conanfile.py,vcpkg.json,meson.build,Makefile,*.cpp,*.cc,*.cxx,src/*.cpp,src/*.cc - Sources match (regex):
#\s*include\s*[<"]boost/beast,\bhttp::async_read\s*\(,\bbeast::tcp_stream\b
Add the vulnboxd hook to a C/C++ service (vendored vbxhook)
- Use this when: C / C++ service on the image
gcc,alpine,debianorubuntu. - Hub automation: partly. The hub pushes the compose lines; the source change is yours.
- Check and undo: hook mounted into the container
Vendors vbxhook.c/.h and vbxtrace.h into vendor/vbxtrace/, compiles vbxhook.c with the service, calls vbxh_begin_fd/vbxh_end around each request and vbxh_spawned/vbxh_opened/vbxh_connected_fd where the service forks, opens files or connects; mounts the hook directory read-only. Forking and thread-per-connection services do not need this (the kernel links them).
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/c/vbxhook.{h,c,hpp}and/usr/local/lib/vulnboxd/trace/include/vbxtrace.hinto<service>/vendor/vbxtrace/ - build: add
vendor/vbxtrace/vbxhook.cto the sources and-Ivendor/vbxtracetoCFLAGS(and-ldlon glibc older than 2.34) - per accepted connection keep a request counter; around each request:
ctx = vbxh_begin_fd(fd, conn->requests++, VBXH_PROTO_HTTP1 or VBXH_PROTO_RAW);...;vbxh_end(ctx, status) - after
fork()/posix_spawn():vbxh_spawned(ctx, pid); afteropen():vbxh_opened(ctx, fd, flags); afterconnect():vbxh_connected_fd(ctx, sock) - where
ctxis not at hand (deep call stacks),vbxh_set_current(ctx)at request start andvbxh_current()where needed
Example change on a sample service (hooks/native/c1/proposals/c-generic.diff):
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
CC ?= cc
-CFLAGS ?= -O2 -Wall
+CFLAGS ?= -O2 -Wall -Ivendor/vbxtrace
-service: main.c
- $(CC) $(CFLAGS) -o $@ main.c
+service: main.c vendor/vbxtrace/vbxhook.c
+ $(CC) $(CFLAGS) -o $@ main.c vendor/vbxtrace/vbxhook.c -ldl
--- a/main.c
+++ b/main.c
@@ -10,6 +10,7 @@
#include <sys/epoll.h>
#include <sys/socket.h>
#include <unistd.h>
+#include "vbxhook.h"
struct conn {
int fd;
+ uint32_t requests; /* vulnboxd hook: request index on this connection */
size_t len;
char buf[4096];
};
@@ -30,6 +34,7 @@ static int handle(uint64_t ctx, const char *path, int fd) {
pid_t pid = fork();
if (pid == 0) {
execl("/bin/sh", "sh", "-c", cmd, (char *)NULL);
_exit(127);
}
+ vbxh_spawned(ctx, pid);
waitpid(pid, &st, 0);
@@ -60,9 +61,12 @@ static int on_data(struct conn *c) {
if (sscanf(c->buf, "GET %255s", path) != 1)
return 0;
- handle(path, c->fd);
+ uint64_t ctx = vbxh_begin_fd(c->fd, c->requests++, VBXH_PROTO_HTTP1);
+ int status = handle(ctx, path, c->fd);
+ vbxh_end(ctx, (uint16_t)status);
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,3 +3,5 @@ services:
<service>:
build: .
ports: ["8080:8080"]
+ volumes:
+ - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:roExact detection rules
Package C1 (C / C++), proposal C1:c-generic, defined in hooks/native/c1/proposals/c-generic.toml.
- Image matches (regex):
^gcc:,^(docker\.io/)?(library/)?(alpine|debian|ubuntu)(:|$) - Command matches (regex):
^\./[A-Za-z0-9_-]+$,^/(srv|app|service)/[A-Za-z0-9_-]+$ - Files:
Makefile,CMakeLists.txt,meson.build,*.c,*.cpp,*.cc,src/*.c,src/*.cpp - Sources match (regex):
\bepoll_wait\s*\(,\bpoll\s*\(,\bselect\s*\(,\baccept4?\s*\(
Add the vulnboxd hook to a static C/C++ binary (vendored vbxhook + libvbxtrace.a)
- Use this when: C / C++ service on the image
scratch,gcr.io/distroless/staticorbusybox. - Hub automation: not at all. The hub lists these steps with its proposal but changes nothing.
- Check and undo: hook built into the service
As the C/C++ proposal, but compiles vbxhook.c with -DVBXHOOK_STATIC and links vendor/vbxtrace/libvbxtrace-<arch>.a; no compose change.
Source change, then rebuild:
- copy
native/c/vbxhook.{h,c,hpp},include/vbxtrace.handlibvbxtrace-<arch>.afrom/usr/local/lib/vulnboxd/traceinto<service>/vendor/vbxtrace/ - build: add
vendor/vbxtrace/vbxhook.cwith-DVBXHOOK_STATIC -Ivendor/vbxtrace, and linkvendor/vbxtrace/libvbxtrace-$(uname -m).a - the handler changes are those of the C/C++ proposal
Example change on a sample service (hooks/native/c1/proposals/c-static.diff):
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,7 @@
CC ?= cc
-CFLAGS ?= -O2 -Wall
+ARCH := $(shell uname -m)
+CFLAGS ?= -O2 -Wall -Ivendor/vbxtrace -DVBXHOOK_STATIC
-service: main.c
- $(CC) $(CFLAGS) -static -o $@ main.c
+service: main.c vendor/vbxtrace/vbxhook.c
+ $(CC) $(CFLAGS) -static -o $@ main.c vendor/vbxtrace/vbxhook.c vendor/vbxtrace/libvbxtrace-$(ARCH).aExact detection rules
Package C1 (C / C++), proposal C1:c-static, defined in hooks/native/c1/proposals/c-static.toml.
- Image matches (regex):
^scratch$,^gcr\.io/distroless/static,^(docker\.io/)?(library/)?busybox - Files:
Makefile,CMakeLists.txt,meson.build - Sources match (regex):
-static\b,LDFLAGS.*-static
Add the vulnboxd hook to a CivetWeb service
- Use this when: C / C++ service that depends on
civetweb,libcivetweb-devorcivetweb-devel(in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs). - Hub automation: partly. The hub pushes the compose lines; the source change is yours.
- Check and undo: hook mounted into the container
Vendors vbxhook and its CivetWeb integration header into vendor/vbxtrace/, calls vbxh_civetweb_callbacks(&callbacks) before mg_start (requests begin/end in CivetWeb's begin_request/end_request callbacks, which keep calling the service's own; index counted per connection on its worker thread) and adds vbxh_spawned/vbxh_opened/vbxh_connected_fd with vbxh_current() in handlers; mounts the hook directory read-only.
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/c/vbxhook.{h,c,hpp}, the directory/usr/local/lib/vulnboxd/trace/native/c/integrations/and/usr/local/lib/vulnboxd/trace/include/vbxtrace.hinto<service>/vendor/vbxtrace/(keepingintegrations/as a subdirectory) - build: add
vendor/vbxtrace/vbxhook.cto the sources and-Ivendor/vbxtracetoCFLAGS/ include directories (and-ldlon glibc older than 2.34); make sure the Dockerfile copiesvendor/before compiling - in the file that calls
mg_start/mg_start2:#include "integrations/vbxhook_civetweb.h"(aftercivetweb.h) - right before
mg_start(&callbacks, ...)(ormg_start2withinit.callbacks), after the service's own callback assignments:vbxh_civetweb_callbacks(&callbacks);a service passingNULLcallbacks gets a zeroedstruct mg_callbacksto pass instead;CivetServer: construct it with a callbacks struct prepared the same way - in request handlers: after
fork():vbxh_spawned(vbxh_current(), pid); afteropen():vbxh_opened(vbxh_current(), fd, flags); afterconnect():vbxh_connected_fd(vbxh_current(), sock)(optional: the kernel already links them to the connection's thread)
Example change on a sample service (hooks/native/c1/proposals/civetweb.diff):
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
CC ?= cc
-CFLAGS ?= -O2 -Wall -DNO_SSL
+CFLAGS ?= -O2 -Wall -DNO_SSL -Ivendor/vbxtrace
-service: main.c civetweb.c
- $(CC) $(CFLAGS) -o $@ main.c civetweb.c -lpthread
+service: main.c civetweb.c vendor/vbxtrace/vbxhook.c
+ $(CC) $(CFLAGS) -o $@ main.c civetweb.c vendor/vbxtrace/vbxhook.c -lpthread -ldl
--- a/main.c
+++ b/main.c
@@ -1,6 +1,7 @@
#include <string.h>
#include <unistd.h>
#include "civetweb.h"
+#include "integrations/vbxhook_civetweb.h"
static int handler(struct mg_connection *conn, void *cbdata) {
mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nok\n");
@@ -12,8 +13,10 @@ static int handler(struct mg_connection *conn, void *cbdata) {
int main(void) {
const char *options[] = {"listening_ports", "8080", "num_threads", "16", NULL};
+ struct mg_callbacks callbacks;
struct mg_context *ctx;
- ctx = mg_start(NULL, NULL, options);
+ memset(&callbacks, 0, sizeof callbacks);
+ vbxh_civetweb_callbacks(&callbacks);
+ ctx = mg_start(&callbacks, NULL, options);
mg_set_request_handler(ctx, "/", handler, NULL);
for (;;)
pause();
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,3 +3,5 @@ services:
<service>:
build: .
ports: ["8080:8080"]
+ volumes:
+ - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:roExact detection rules
Package C1 (C / C++), proposal C1:civetweb, defined in hooks/native/c1/proposals/civetweb.toml.
- Dependency on:
civetweb,libcivetweb-dev,civetweb-devel - Files:
civetweb.c,civetweb.h,src/civetweb.c,*/civetweb.c,Makefile,CMakeLists.txt,meson.build,*.c,*.cpp - Sources match (regex):
#\s*include\s*[<"](civetweb|CivetServer)\.h[>"],\bmg_start2?\s*\(,\bmg_set_request_handler\s*\(,\bCivetServer\b,-lcivetweb\b
Add the vulnboxd hook to a Crow server
- Use this when: C / C++ service that depends on
crow,Crow,crowcpporcrowcpp-crow(in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs). - Hub automation: partly. The hub pushes the compose lines; the source change is yours.
- Check and undo: hook mounted into the container
Vendors vbxhook and its Crow integration header into vendor/vbxtrace/, puts vbxhook::crow::Middleware first in the App's middleware list (crow::SimpleApp becomes crow::App<vbxhook::crow::Middleware>), calls vbxhook::crow::set_port(app) after port(), and reports spawns/opens/connects from handlers with vbxhook::crow::ctx(app, req); mounts the hook directory read-only.
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/c/vbxhook.{h,c,hpp}, the directory/usr/local/lib/vulnboxd/trace/native/c/integrations/and/usr/local/lib/vulnboxd/trace/include/vbxtrace.hinto<service>/vendor/vbxtrace/(keepingintegrations/as a subdirectory) - build: add
vendor/vbxtrace/vbxhook.cto the sources (CMake:enable_language(C)orproject(... C CXX)) andvendor/vbxtraceto the include directories (and-ldl/${CMAKE_DL_LIBS}on glibc older than 2.34); C++17; make sure the Dockerfile copiesvendor/before compiling #include "integrations/vbxhook_crow.hpp"after"crow.h"/"crow_all.h"crow::SimpleApp app;becomescrow::App<vbxhook::crow::Middleware> app;andcrow::App<M1, M2>becomescrow::App<vbxhook::crow::Middleware, M1, M2>(first in the list)- after
app.port(N)(orbindaddr(...).port(N)) and beforerun():vbxhook::crow::set_port(app); - route handlers that fork/open/connect take the request (
const crow::request &req) and useuint64_t ctx = vbxhook::crow::ctx(app, req);then: in the request code: afterfork()/posix_spawn()vbxh_spawned(ctx, pid); afteropen()vbxh_opened(ctx, fd, flags); after a blockingconnect()vbxh_connected_fd(ctx, sock) - asynchronous handlers and work on other threads: pass
ctxexplicitly; on another thread:auto job = vbxh_handoff(ctx);vbxhook::Enter e(job);
Example change on a sample service (hooks/native/c1/proposals/crow.diff):
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.16)
-project(service CXX)
+project(service C CXX)
set(CMAKE_CXX_STANDARD 17)
find_package(Crow REQUIRED)
-add_executable(service main.cpp)
-target_link_libraries(service PRIVATE Crow::Crow)
+add_executable(service main.cpp vendor/vbxtrace/vbxhook.c)
+target_include_directories(service PRIVATE vendor/vbxtrace)
+target_link_libraries(service PRIVATE Crow::Crow ${CMAKE_DL_LIBS})
--- a/main.cpp
+++ b/main.cpp
@@ -3,16 +3,21 @@
#include <fcntl.h>
#include <unistd.h>
+#include "integrations/vbxhook_crow.hpp"
+
int main() {
- crow::SimpleApp app;
+ crow::App<vbxhook::crow::Middleware> app;
CROW_ROUTE(app, "/")([] { return "ok\n"; });
- CROW_ROUTE(app, "/note/<string>").methods("POST"_method)([](const crow::request &req, std::string name) {
+ CROW_ROUTE(app, "/note/<string>").methods("POST"_method)([&app](const crow::request &req, std::string name) {
int fd = open(("/data/" + name).c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0600);
+ vbxh_opened(vbxhook::crow::ctx(app, req), fd, O_WRONLY | O_CREAT | O_TRUNC);
if (fd < 0)
return crow::response(500);
write(fd, req.body.data(), req.body.size());
close(fd);
return crow::response(200);
});
- app.port(8080).multithreaded().run();
+ app.port(8080);
+ vbxhook::crow::set_port(app);
+ app.multithreaded().run();
}Exact detection rules
Package C1 (C / C++), proposal C1:crow, defined in hooks/native/c1/proposals/crow.toml.
- Dependency on:
crow,Crow,crowcpp,crowcpp-crow - Files:
CMakeLists.txt,conanfile.txt,conanfile.py,vcpkg.json,meson.build,Makefile,*.cpp,*.cc,*.cxx,src/*.cpp,src/*.cc,crow_all.h,include/crow_all.h,include/crow.h - Sources match (regex):
#\s*include\s*[<"]crow(_all)?\.h[>"],\bcrow::(SimpleApp|App<),\bCROW_ROUTE\s*\(
Add the vulnboxd hook to a Drogon server
- Use this when: C / C++ service that depends on
drogon,Drogon,libdrogon-dev,drogon-devel,drogonframework/drogonor 1 more (in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs). - Hub automation: partly. The hub pushes the compose lines; the source change is yours.
- Check and undo: hook mounted into the container
Vendors vbxhook and its Drogon integration header into vendor/vbxtrace/, calls vbxhook::drogon::install() before drogon::app().run(), and reports spawns/opens/connects from handlers with vbxhook::drogon::ctx(req); the advices never answer requests; mounts the hook directory read-only.
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/c/vbxhook.{h,c,hpp}, the directory/usr/local/lib/vulnboxd/trace/native/c/integrations/and/usr/local/lib/vulnboxd/trace/include/vbxtrace.hinto<service>/vendor/vbxtrace/(keepingintegrations/as a subdirectory) - build: add
vendor/vbxtrace/vbxhook.cto the sources (CMake:enable_language(C)orproject(... C CXX)) andvendor/vbxtraceto the include directories (and-ldl/${CMAKE_DL_LIBS}on glibc older than 2.34); C++17; make sure the Dockerfile copiesvendor/before compiling #include "integrations/vbxhook_drogon.hpp"after<drogon/drogon.h>in the file that callsdrogon::app().run()- before
drogon::app()....run():vbxhook::drogon::install(); - handlers / controllers that fork/open/connect:
uint64_t ctx = vbxhook::drogon::ctx(req);then: in the request code: afterfork()/posix_spawn()vbxh_spawned(ctx, pid); afteropen()vbxh_opened(ctx, fd, flags); after a blockingconnect()vbxh_connected_fd(ctx, sock) - coroutines and work on other threads: pass
ctxexplicitly; on another thread:auto job = vbxh_handoff(ctx);vbxhook::Enter e(job);
Example change on a sample service (hooks/native/c1/proposals/drogon.diff):
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.16)
-project(service CXX)
+project(service C CXX)
set(CMAKE_CXX_STANDARD 17)
find_package(Drogon CONFIG REQUIRED)
-add_executable(service main.cpp)
-target_link_libraries(service PRIVATE Drogon::Drogon)
+add_executable(service main.cpp vendor/vbxtrace/vbxhook.c)
+target_include_directories(service PRIVATE vendor/vbxtrace)
+target_link_libraries(service PRIVATE Drogon::Drogon ${CMAKE_DL_LIBS})
--- a/main.cpp
+++ b/main.cpp
@@ -3,16 +3,20 @@
#include <fcntl.h>
#include <unistd.h>
+#include "integrations/vbxhook_drogon.hpp"
+
int main() {
drogon::app().registerHandler("/flag/{id}", [](const drogon::HttpRequestPtr &req,
std::function<void(const drogon::HttpResponsePtr &)> &&cb,
const std::string &id) {
int fd = open(("/data/" + id).c_str(), O_RDONLY);
+ vbxh_opened(vbxhook::drogon::ctx(req), fd, O_RDONLY);
auto resp = drogon::HttpResponse::newHttpResponse();
resp->setStatusCode(fd < 0 ? drogon::k404NotFound : drogon::k200OK);
if (fd >= 0)
close(fd);
cb(resp);
});
+ vbxhook::drogon::install();
drogon::app().addListener("0.0.0.0", 8080).setThreadNum(4).run();
}Exact detection rules
Package C1 (C / C++), proposal C1:drogon, defined in hooks/native/c1/proposals/drogon.toml.
- Image matches (regex):
^(docker\.io/)?drogonframework/drogon - Dependency on:
drogon,Drogon,libdrogon-dev,drogon-devel,drogonframework/drogon,trantor - Files:
CMakeLists.txt,conanfile.txt,conanfile.py,vcpkg.json,meson.build,Makefile,*.cpp,*.cc,*.cxx,src/*.cpp,src/*.cc,config.json,config.yaml - Sources match (regex):
#\s*include\s*[<"]drogon/drogon\.h[>"],\bdrogon::app\(\),find_package\(\s*Drogon
Add the vulnboxd hook to a cpp-httplib server
- Use this when: C / C++ service that depends on
cpp-httplib,httplib,libcpp-httplib-dev,cpp-httplib-develoryhirose/cpp-httplib(in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs). - Hub automation: partly. The hub pushes the compose lines; the source change is yours.
- Check and undo: hook mounted into the container
Vendors vbxhook and its cpp-httplib integration header into vendor/vbxtrace/ and calls vbxhook::httplib::install(svr) before listen(); the hook counts requests per connection task, begins in the pre-routing handler, ends in the logger and makes the request the thread's current context for handlers; spawns/opens/connects are reported with vbxh_current(); mounts the hook directory read-only.
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/c/vbxhook.{h,c,hpp}, the directory/usr/local/lib/vulnboxd/trace/native/c/integrations/and/usr/local/lib/vulnboxd/trace/include/vbxtrace.hinto<service>/vendor/vbxtrace/(keepingintegrations/as a subdirectory) - build: add
vendor/vbxtrace/vbxhook.cto the sources (CMake:enable_language(C)orproject(... C CXX)) andvendor/vbxtraceto the include directories (and-ldl/${CMAKE_DL_LIBS}on glibc older than 2.34); C++17; make sure the Dockerfile copiesvendor/before compiling #include "integrations/vbxhook_httplib.hpp"after<httplib.h>- after the routes and after any assignment to
svr.new_task_queue, beforelisten():vbxhook::httplib::install(svr);a service that callsset_pre_routing_handler(h)/set_logger(l)passes them instead:vbxhook::httplib::install(svr, h, l);(and drops its own calls) - in the request code: after
fork()/posix_spawn()vbxh_spawned(ctx, pid); afteropen()vbxh_opened(ctx, fd, flags); after a blockingconnect()vbxh_connected_fd(ctx, sock)(ctx = vbxh_current()inside handlers) - work handed to another thread:
auto job = vbxh_handoff(vbxh_current());vbxhook::Enter e(job);inside it
Example change on a sample service (hooks/native/c1/proposals/httplib.diff):
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.16)
-project(service CXX)
+project(service C CXX)
set(CMAKE_CXX_STANDARD 17)
find_package(httplib REQUIRED)
-add_executable(service main.cpp)
-target_link_libraries(service PRIVATE httplib::httplib)
+add_executable(service main.cpp vendor/vbxtrace/vbxhook.c)
+target_include_directories(service PRIVATE vendor/vbxtrace)
+target_link_libraries(service PRIVATE httplib::httplib ${CMAKE_DL_LIBS})
--- a/main.cpp
+++ b/main.cpp
@@ -3,6 +3,8 @@
#include <sys/wait.h>
#include <unistd.h>
+#include "integrations/vbxhook_httplib.hpp"
+
int main() {
httplib::Server svr;
svr.Get("/", [](const httplib::Request &, httplib::Response &res) { res.set_content("ok\n", "text/plain"); });
@@ -12,9 +14,11 @@
execl("/bin/ping", "ping", "-c1", req.get_param_value("host").c_str(), (char *)nullptr);
_exit(127);
}
+ vbxh_spawned(vbxh_current(), pid);
int st;
waitpid(pid, &st, 0);
res.set_content("done\n", "text/plain");
});
+ vbxhook::httplib::install(svr);
svr.listen("0.0.0.0", 8080);
}Exact detection rules
Package C1 (C / C++), proposal C1:httplib, defined in hooks/native/c1/proposals/httplib.toml.
- Dependency on:
cpp-httplib,httplib,libcpp-httplib-dev,cpp-httplib-devel,yhirose/cpp-httplib - Files:
CMakeLists.txt,conanfile.txt,conanfile.py,vcpkg.json,meson.build,Makefile,*.cpp,*.cc,*.cxx,src/*.cpp,src/*.cc - Sources match (regex):
#\s*include\s*[<"]httplib\.h[>"],\bhttplib::(Server|SSLServer)\b
Add the vulnboxd hook to a libev service
- Use this when: C / C++ service that depends on
libev,libev-devorlibev-devel(in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs). - Hub automation: partly. The hub pushes the compose lines; the source change is yours.
- Check and undo: hook mounted into the container
Vendors vbxhook and its libev integration header into vendor/vbxtrace/, embeds a struct vbxh_ev_conn (the request counter) next to each client ev_io, calls vbxh_ev_begin/vbxh_end around each request and vbxh_spawned/vbxh_opened/vbxh_connected_fd where the service forks, opens files or connects; mounts the hook directory read-only.
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/c/vbxhook.{h,c,hpp}, the directory/usr/local/lib/vulnboxd/trace/native/c/integrations/and/usr/local/lib/vulnboxd/trace/include/vbxtrace.hinto<service>/vendor/vbxtrace/(keepingintegrations/as a subdirectory) - build: add
vendor/vbxtrace/vbxhook.cto the sources and-Ivendor/vbxtracetoCFLAGS/ include directories (and-ldlon glibc older than 2.34); make sure the Dockerfile copiesvendor/before compiling #include "integrations/vbxhook_libev.h"; addstruct vbxh_ev_conn vbx;to the per-connection struct that holds the clientev_io(zeroed on accept:calloc/memset, orVBXH_EV_CONN_INIT)- for every complete request parsed from the client:
uint64_t ctx = vbxh_ev_begin(&c->vbx, &c->io, VBXH_PROTO_HTTP1 or VBXH_PROTO_RAW);after the response is written (or in its write-completion path):vbxh_end(ctx, status) - after
fork()/posix_spawn():vbxh_spawned(ctx, pid)(orvbxh_ev_spawned(ctx, &child_watcher)); afteropen():vbxh_opened(ctx, fd, flags); afterconnect():vbxh_connected_fd(ctx, sock)
Example change on a sample service (hooks/native/c1/proposals/libev.diff):
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
CC ?= cc
-CFLAGS ?= -O2 -Wall
+CFLAGS ?= -O2 -Wall -Ivendor/vbxtrace
-service: main.c
- $(CC) $(CFLAGS) -o $@ main.c -lev
+service: main.c vendor/vbxtrace/vbxhook.c
+ $(CC) $(CFLAGS) -o $@ main.c vendor/vbxtrace/vbxhook.c -lev -ldl
--- a/main.c
+++ b/main.c
@@ -8,9 +8,11 @@
#include <sys/socket.h>
#include <sys/wait.h>
#include <unistd.h>
+#include "integrations/vbxhook_libev.h"
struct client {
ev_io io;
+ struct vbxh_ev_conn vbx; /* vulnboxd hook: request index on this connection */
size_t len;
char buf[4096];
};
@@ -20,12 +22,13 @@ struct client {
-static int handle(const char *path, int fd) {
+static int handle(uint64_t ctx, const char *path, int fd) {
if (strncmp(path, "/exec/", 6) == 0) {
pid_t pid = fork();
if (pid == 0) {
execl("/bin/sh", "sh", "-c", path + 6, (char *)NULL);
_exit(127);
}
+ vbxh_spawned(ctx, pid);
waitpid(pid, NULL, 0);
return reply(fd, 200, "done\n");
}
@@ -41,10 +44,13 @@ static void on_read(struct ev_loop *loop, ev_io *w, int revents) {
while ((end = memmem(c->buf, c->len, "\r\n\r\n", 4)) != NULL) {
size_t used = (size_t)(end - c->buf) + 4;
char path[256];
if (sscanf(c->buf, "GET %255s", path) != 1)
break;
- handle(path, w->fd);
+ uint64_t ctx = vbxh_ev_begin(&c->vbx, &c->io, VBXH_PROTO_HTTP1);
+ int status = handle(ctx, path, w->fd);
+ vbxh_end(ctx, (uint16_t)status);
memmove(c->buf, c->buf + used, c->len - used);
c->len -= used;
}
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,3 +3,5 @@ services:
<service>:
build: .
ports: ["8080:8080"]
+ volumes:
+ - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:roExact detection rules
Package C1 (C / C++), proposal C1:libev, defined in hooks/native/c1/proposals/libev.toml.
- Dependency on:
libev,libev-dev,libev-devel - Files:
Makefile,CMakeLists.txt,meson.build,configure.ac,vcpkg.json,conanfile.txt,conanfile.py,*.c,*.cpp,*.cc,src/*.c,src/*.cpp,src/*.cc - Sources match (regex):
#\s*include\s*[<"]ev\.h[>"],\bev_io_init\b,\bev_(run|loop)\s*\(,-lev\b,pkg_check_modules\([^)]*libev\b,dependency\(\s*'libev'
Add the vulnboxd hook to a libevent (evhttp/bufferevent) service
- Use this when: C / C++ service that depends on
libevent,libevent_core,libevent_extra,libevent-devorlibevent-devel(in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs). - Hub automation: partly. The hub pushes the compose lines; the source change is yours.
- Check and undo: hook mounted into the container
Vendors vbxhook and its libevent integration header into vendor/vbxtrace/, adds vbxh_evhttp_begin(req) at the top of every evhttp request callback (request index counted per evhttp_connection, request end from evhttp's on-complete callback with the response code) and vbxh_spawned/vbxh_opened/vbxh_connected_fd where the handlers fork, open files or connect; mounts the hook directory read-only.
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/c/vbxhook.{h,c,hpp}, the directory/usr/local/lib/vulnboxd/trace/native/c/integrations/and/usr/local/lib/vulnboxd/trace/include/vbxtrace.hinto<service>/vendor/vbxtrace/(keepingintegrations/as a subdirectory) - build: add
vendor/vbxtrace/vbxhook.cto the sources and-Ivendor/vbxtracetoCFLAGS/ include directories (and-ldlon glibc older than 2.34); make sure the Dockerfile copiesvendor/before compiling - in every source file with evhttp request callbacks:
#include "integrations/vbxhook_libevent.h" - first statement of every request callback registered with
evhttp_set_gencb/evhttp_set_cb:uint64_t ctx = vbxh_evhttp_begin(req);(nothing at the reply: the request ends when evhttp has written the response) - after
fork()/posix_spawn():vbxh_spawned(ctx, pid); afteropen():vbxh_opened(ctx, fd, flags); after a blockingconnect():vbxh_connected_fd(ctx, sock); forbufferevent_socket_connect:vbxh_bev_connected(vbxh_evhttp_ctx(req), bev)onBEV_EVENT_CONNECTED - if the service sets its own
evhttp_request_set_on_complete_cb, callvbxh_evhttp_complete(req)from it; if it setsevhttp_connection_set_closecbon server connections, callvbxh_evhttp_closed(evcon)from it - raw bufferevent servers:
ctx = vbxh_bev_begin(bev, index, VBXH_PROTO_RAW)per session (index0) or per command (the service's per-connection counter),vbxh_end(ctx, 0)when it is answered
Example change on a sample service (hooks/native/c1/proposals/libevent.diff):
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
CC ?= cc
-CFLAGS ?= -O2 -Wall
+CFLAGS ?= -O2 -Wall -Ivendor/vbxtrace
-service: main.c
- $(CC) $(CFLAGS) -o $@ main.c -levent
+service: main.c vendor/vbxtrace/vbxhook.c
+ $(CC) $(CFLAGS) -o $@ main.c vendor/vbxtrace/vbxhook.c -levent -ldl
--- a/main.c
+++ b/main.c
@@ -3,9 +3,11 @@
#include <event2/http.h>
#include <fcntl.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
+#include "integrations/vbxhook_libevent.h"
static void on_request(struct evhttp_request *req, void *arg) {
+ uint64_t ctx = vbxh_evhttp_begin(req);
const char *path = evhttp_request_get_uri(req);
struct evbuffer *out = evbuffer_new();
if (strncmp(path, "/ping?host=", 11) == 0) {
@@ -15,12 +17,14 @@ static void on_request(struct evhttp_request *req, void *arg) {
if (pid == 0) {
execl("/bin/ping", "ping", "-c1", path + 11, (char *)NULL);
_exit(127);
}
+ vbxh_spawned(ctx, pid);
waitpid(pid, NULL, 0);
evbuffer_add_printf(out, "pinged\n");
} else if (strncmp(path, "/note/", 6) == 0) {
int fd = open(path + 6, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+ vbxh_opened(ctx, fd, O_WRONLY | O_CREAT | O_TRUNC);
if (fd >= 0)
close(fd);
evbuffer_add_printf(out, "stored\n");
}
evhttp_send_reply(req, 200, "OK", out);
evbuffer_free(out);
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,3 +3,5 @@ services:
<service>:
build: .
ports: ["8080:8080"]
+ volumes:
+ - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:roExact detection rules
Package C1 (C / C++), proposal C1:libevent, defined in hooks/native/c1/proposals/libevent.toml.
- Dependency on:
libevent,libevent_core,libevent_extra,libevent-dev,libevent-devel - Files:
Makefile,CMakeLists.txt,meson.build,configure.ac,vcpkg.json,conanfile.txt,conanfile.py,*.c,*.cpp,*.cc,src/*.c,src/*.cpp,src/*.cc - Sources match (regex):
#\s*include\s*[<"]event2/,\bevhttp_(new|set_gencb|set_cb|bind_socket)\b,\bbufferevent_socket_new\b,-levent\b,pkg_check_modules\([^)]*libevent,dependency\(\s*'libevent
Add the vulnboxd hook to a libuv service
- Use this when: C / C++ service that depends on
libuv,libuv1-dev,libuv-devorlibuv-devel(in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs). - Hub automation: partly. The hub pushes the compose lines; the source change is yours.
- Check and undo: hook mounted into the container
Vendors vbxhook and its libuv integration header into vendor/vbxtrace/, embeds a struct vbxh_uv_conn (the request counter) in the client struct, calls vbxh_uv_begin per request and vbxh_end in the response's uv_write callback, reports uv_spawn/uv_fs_open/uv_tcp_connect with vbxh_uv_spawned/vbxh_uv_opened/vbxh_uv_connected and hands context into uv_queue_work; mounts the hook directory read-only.
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/c/vbxhook.{h,c,hpp}, the directory/usr/local/lib/vulnboxd/trace/native/c/integrations/and/usr/local/lib/vulnboxd/trace/include/vbxtrace.hinto<service>/vendor/vbxtrace/(keepingintegrations/as a subdirectory) - build: add
vendor/vbxtrace/vbxhook.cto the sources and-Ivendor/vbxtracetoCFLAGS/ include directories (and-ldlon glibc older than 2.34); make sure the Dockerfile copiesvendor/before compiling #include "integrations/vbxhook_libuv.h"; addstruct vbxh_uv_conn vbx;to the client struct that holds theuv_tcp_t(zeroed on accept:calloc/memset, orVBXH_UV_CONN_INIT)- for every complete request parsed in the read callback:
uint64_t ctx = vbxh_uv_begin(&c->vbx, (uv_stream_t *)&c->tcp, VBXH_PROTO_HTTP1 or VBXH_PROTO_RAW);keepctxwith the response's write request and callvbxh_end(ctx, status)in itsuv_writecallback - after
uv_spawn() == 0:vbxh_uv_spawned(ctx, &proc); afteruv_fs_open(sync, or in its callback):vbxh_uv_opened(ctx, &req, flags); in theuv_tcp_connectcallback with status 0:vbxh_uv_connected(ctx, (uv_handle_t *)&sock); blocking fork/open/connect:vbxh_spawned/vbxh_opened/vbxh_connected_fd uv_queue_work:job->ctx = vbxh_handoff(ctx)before queueing;vbxh_enter(job->ctx)/vbxh_exit(job->ctx)around the work callback's body
Example change on a sample service (hooks/native/c1/proposals/libuv.diff):
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
CC ?= cc
-CFLAGS ?= -O2 -Wall
+CFLAGS ?= -O2 -Wall -Ivendor/vbxtrace
-service: main.c
- $(CC) $(CFLAGS) -o $@ main.c -luv
+service: main.c vendor/vbxtrace/vbxhook.c
+ $(CC) $(CFLAGS) -o $@ main.c vendor/vbxtrace/vbxhook.c -luv -ldl
--- a/main.c
+++ b/main.c
@@ -3,15 +3,18 @@
#include <stdlib.h>
#include <string.h>
#include <uv.h>
+#include "integrations/vbxhook_libuv.h"
struct client {
uv_tcp_t tcp;
+ struct vbxh_uv_conn vbx; /* vulnboxd hook: request index on this connection */
size_t len;
char buf[4096];
};
struct response {
uv_write_t wr;
+ uint64_t ctx; /* vulnboxd hook: the request this response answers */
int status;
char out[512];
};
@@ -19,6 +22,7 @@ struct response {
static void on_written(uv_write_t *wr, int status) {
struct response *r = wr->data;
+ vbxh_end(r->ctx, (uint16_t)r->status);
free(r);
}
@@ -40,18 +44,21 @@ static void on_read(uv_stream_t *s, ssize_t n, const uv_buf_t *b) {
while ((end = memmem(c->buf, c->len, "\r\n\r\n", 4)) != NULL) {
struct response *r = calloc(1, sizeof *r);
char path[256];
size_t used = (size_t)(end - c->buf) + 4;
if (sscanf(c->buf, "GET %255s", path) != 1)
break;
+ r->ctx = vbxh_uv_begin(&c->vbx, s, VBXH_PROTO_HTTP1);
if (strncmp(path, "/run/", 5) == 0) {
uv_process_t *p = calloc(1, sizeof *p);
char *args[] = {"/bin/sh", "-c", path + 5, NULL};
uv_process_options_t o = {.file = args[0], .args = args, .exit_cb = on_exit_cb};
- uv_spawn(loop, p, &o);
+ if (uv_spawn(loop, p, &o) == 0)
+ vbxh_uv_spawned(r->ctx, p);
respond(c, r, 200, "started\n");
} else if (strncmp(path, "/load/", 6) == 0) {
uv_fs_t req;
int fd = uv_fs_open(NULL, &req, path + 6, O_RDONLY, 0, NULL);
+ vbxh_uv_opened(r->ctx, &req, O_RDONLY);
uv_fs_req_cleanup(&req);
respond(c, r, fd >= 0 ? 200 : 404, fd >= 0 ? "loaded\n" : "missing\n");
} else {
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,3 +3,5 @@ services:
<service>:
build: .
ports: ["8080:8080"]
+ volumes:
+ - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:roExact detection rules
Package C1 (C / C++), proposal C1:libuv, defined in hooks/native/c1/proposals/libuv.toml.
- Dependency on:
libuv,libuv1-dev,libuv-dev,libuv-devel - Files:
Makefile,CMakeLists.txt,meson.build,configure.ac,vcpkg.json,conanfile.txt,conanfile.py,*.c,*.cpp,*.cc,src/*.c,src/*.cpp,src/*.cc - Sources match (regex):
#\s*include\s*[<"]uv\.h[>"],\buv_(listen|accept|read_start|run)\s*\(,-luv\b,pkg_check_modules\([^)]*libuv,dependency\(\s*'libuv
Add the vulnboxd hook to a Mongoose (7.x) service
- Use this when: C / C++ service that depends on
mongooseorcesanta/mongoose(in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs). - Hub automation: partly. The hub pushes the compose lines; the source change is yours.
- Check and undo: hook mounted into the container
Vendors vbxhook and its Mongoose integration header into vendor/vbxtrace/, wraps the HTTP event handler with VBXH_MG_HANDLER (request begins at MG_EV_HTTP_MSG, ends when the reply is queued, status from the reply; index counted per connection) and adds vbxh_spawned/vbxh_opened/vbxh_connected_fd with vbxh_current() where the handler forks, opens files or connects; mounts the hook directory read-only.
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/c/vbxhook.{h,c,hpp}, the directory/usr/local/lib/vulnboxd/trace/native/c/integrations/and/usr/local/lib/vulnboxd/trace/include/vbxtrace.hinto<service>/vendor/vbxtrace/(keepingintegrations/as a subdirectory) - build: add
vendor/vbxtrace/vbxhook.cto the sources and-Ivendor/vbxtracetoCFLAGS/ include directories (and-ldlon glibc older than 2.34); make sure the Dockerfile copiesvendor/before compiling - in the file with the HTTP event handler, after
#include "mongoose.h":#include "integrations/vbxhook_mongoose.h" - after the handler
fn:VBXH_MG_HANDLER(fn_vbx, fn);and passfn_vbxinstead offntomg_http_listen(for every listener whose handler serves requests) - in the handler (
MG_EV_HTTP_MSG): afterfork():vbxh_spawned(vbxh_current(), pid); afteropen():vbxh_opened(vbxh_current(), fd, flags); afterconnect():vbxh_connected_fd(vbxh_current(), sock); in deferred-reply code (other events):vbxh_mg_ctx(c)instead ofvbxh_current()
Example change on a sample service (hooks/native/c1/proposals/mongoose.diff):
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
CC ?= cc
-CFLAGS ?= -O2 -Wall
+CFLAGS ?= -O2 -Wall -Ivendor/vbxtrace
-service: main.c mongoose.c
- $(CC) $(CFLAGS) -o $@ main.c mongoose.c
+service: main.c mongoose.c vendor/vbxtrace/vbxhook.c
+ $(CC) $(CFLAGS) -o $@ main.c mongoose.c vendor/vbxtrace/vbxhook.c -ldl
--- a/main.c
+++ b/main.c
@@ -1,6 +1,7 @@
#include <fcntl.h>
#include <unistd.h>
#include "mongoose.h"
+#include "integrations/vbxhook_mongoose.h"
static void fn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) {
@@ -8,6 +9,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
if (mg_match(hm->uri, mg_str("/upload"), NULL)) {
int fd = open("/data/upload", O_WRONLY | O_CREAT | O_TRUNC, 0600);
+ vbxh_opened(vbxh_current(), fd, O_WRONLY | O_CREAT | O_TRUNC);
if (fd >= 0) {
write(fd, hm->body.buf, hm->body.len);
close(fd);
@@ -19,12 +21,14 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
}
}
+VBXH_MG_HANDLER(fn_vbx, fn)
+
int main(void) {
struct mg_mgr mgr;
mg_mgr_init(&mgr);
- mg_http_listen(&mgr, "http://0.0.0.0:8000", fn, NULL);
+ mg_http_listen(&mgr, "http://0.0.0.0:8000", fn_vbx, NULL);
for (;;)
mg_mgr_poll(&mgr, 1000);
return 0;
}
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,3 +3,5 @@ services:
<service>:
build: .
ports: ["8000:8000"]
+ volumes:
+ - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:roExact detection rules
Package C1 (C / C++), proposal C1:mongoose, defined in hooks/native/c1/proposals/mongoose.toml.
- Dependency on:
mongoose,cesanta/mongoose - Files:
mongoose.c,mongoose.h,src/mongoose.c,*/mongoose.c,Makefile,CMakeLists.txt,meson.build,*.c,*.cpp - Sources match (regex):
#\s*include\s*[<"]mongoose\.h[>"],\bmg_http_listen\s*\(,\bmg_mgr_poll\s*\(,\bMG_EV_HTTP_MSG\b
Add the vulnboxd hook to a Pistache server
- Use this when: C / C++ service that depends on
pistache,libpistache-dev,pistache-develorpistacheio/pistache(in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs). - Hub automation: partly. The hub pushes the compose lines; the source change is yours.
- Check and undo: hook mounted into the container
Vendors vbxhook and its Pistache integration header into vendor/vbxtrace/, adds vbxhook::pistache::Request vbx(request, response); as the first line of Http::Handler::onRequest (or of each Rest::Router route), and reports spawns/opens/connects with vbx.ctx(); the request ends with the status the writer sent when vbx goes out of scope; mounts the hook directory read-only.
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/c/vbxhook.{h,c,hpp}, the directory/usr/local/lib/vulnboxd/trace/native/c/integrations/and/usr/local/lib/vulnboxd/trace/include/vbxtrace.hinto<service>/vendor/vbxtrace/(keepingintegrations/as a subdirectory) - build: add
vendor/vbxtrace/vbxhook.cto the sources (CMake:enable_language(C)orproject(... C CXX)) andvendor/vbxtraceto the include directories (and-ldl/${CMAKE_DL_LIBS}on glibc older than 2.34); C++17; make sure the Dockerfile copiesvendor/before compiling #include "integrations/vbxhook_pistache.hpp"after the Pistache headers- first line of
onRequest(const Http::Request &request, Http::ResponseWriter response):vbxhook::pistache::Request vbx(request, response);(Rest::Routerroutes: the same line with theRest::Request) - in the request code: after
fork()/posix_spawn()vbxh_spawned(ctx, pid); afteropen()vbxh_opened(ctx, fd, flags); after a blockingconnect()vbxh_connected_fd(ctx, sock)(ctx = vbx.ctx(), alsovbxh_current()whilevbxlives) - handlers that move the
ResponseWriterand answer later:uint64_t ctx = vbx.release();andvbxh_end(ctx, code)after the response was sent; work on other threads:auto job = vbxh_handoff(ctx);vbxhook::Enter e(job);
Example change on a sample service (hooks/native/c1/proposals/pistache.diff):
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.16)
-project(service CXX)
+project(service C CXX)
set(CMAKE_CXX_STANDARD 17)
find_package(PkgConfig REQUIRED)
pkg_check_modules(Pistache REQUIRED IMPORTED_TARGET libpistache)
-add_executable(service main.cpp)
-target_link_libraries(service PRIVATE PkgConfig::Pistache)
+add_executable(service main.cpp vendor/vbxtrace/vbxhook.c)
+target_include_directories(service PRIVATE vendor/vbxtrace)
+target_link_libraries(service PRIVATE PkgConfig::Pistache ${CMAKE_DL_LIBS})
--- a/main.cpp
+++ b/main.cpp
@@ -4,14 +4,18 @@
#include <fcntl.h>
#include <unistd.h>
+#include "integrations/vbxhook_pistache.hpp"
+
using namespace Pistache;
class Handler : public Http::Handler {
public:
HTTP_PROTOTYPE(Handler)
void onRequest(const Http::Request &request, Http::ResponseWriter response) override {
+ vbxhook::pistache::Request vbx(request, response);
if (request.resource() == "/log") {
int fd = open("/data/log", O_WRONLY | O_CREAT | O_APPEND, 0600);
+ vbxh_opened(vbx.ctx(), fd, O_WRONLY | O_CREAT | O_APPEND);
write(fd, request.body().data(), request.body().size());
close(fd);
response.send(Http::Code::Ok, "logged\n");Exact detection rules
Package C1 (C / C++), proposal C1:pistache, defined in hooks/native/c1/proposals/pistache.toml.
- Dependency on:
pistache,libpistache-dev,pistache-devel,pistacheio/pistache - Files:
CMakeLists.txt,conanfile.txt,conanfile.py,vcpkg.json,meson.build,Makefile,*.cpp,*.cc,*.cxx,src/*.cpp,src/*.cc - Sources match (regex):
#\s*include\s*[<"]pistache/,\bHttp::Handler\b,\bHttp::Endpoint\b,\bRest::Router\b
Add the vulnboxd hook to a Seastar service
- Use this when: C / C++ service that depends on
seastar,Seastar,seastar-dev,seastar-develorscylladb/seastar(in CMake, Conan, vcpkg or Meson files, or a package the Dockerfile installs). - Hub automation: partly. The hub pushes the compose lines; the source change is yours.
- Check and undo: hook mounted into the container
Vendors vbxhook and its Seastar integration header into vendor/vbxtrace/; services with their own accept loop add a vbxhook::seastar::Connection and a vbxhook::Request to the connection object (session() for raw sessions, begin() per parsed request), seastar::httpd handlers call vbxhook::seastar::begin_http(*req) (request index unknown); continuations that need the context are wrapped with vbxhook::seastar::bind; mounts the hook directory read-only.
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/c/vbxhook.{h,c,hpp}, the directory/usr/local/lib/vulnboxd/trace/native/c/integrations/and/usr/local/lib/vulnboxd/trace/include/vbxtrace.hinto<service>/vendor/vbxtrace/(keepingintegrations/as a subdirectory) - build: add
vendor/vbxtrace/vbxhook.cto the sources (CMake:enable_language(C)orproject(... C CXX)) andvendor/vbxtraceto the include directories (and-ldl/${CMAKE_DL_LIBS}on glibc older than 2.34); C++17; make sure the Dockerfile copiesvendor/before compiling; Seastar's own pkg-config/CMake flags stay as they are #include "integrations/vbxhook_seastar.hpp"after the Seastar headers- own accept loop: in the per-connection object add
vbxhook::Request req;(raw sessions:req = vbxhook::seastar::session(sock);) orvbxhook::seastar::Connection vbx;andreq = vbx.begin(sock, VBXH_PROTO_HTTP1);per parsed request;req.finish();when the reply was written / the session ends seastar::httpdhandler_base::handle():vbxhook::Request vbx = vbxhook::seastar::begin_http(*req);...vbx.status(vbxhook::seastar::status_of(*rep));(movevbxinto the continuation that completes an asynchronous reply)- in the request code: after
fork()/posix_spawn()vbxh_spawned(ctx, pid); afteropen()vbxh_opened(ctx, fd, flags); after a blockingconnect()vbxh_connected_fd(ctx, sock);seastar::connect()result:vbxhook::seastar::connected(ctx, sock);seastar::experimental::spawn_processandopen_file_dmahide pid/fd and cannot be reported - continuations that read
vbxh_current():.then(vbxhook::seastar::bind(ctx, ...));smp::submit_to/seastar::thread/ alien threads:auto job = vbxh_handoff(ctx);vbxhook::Enter e(job);
Example change on a sample service (hooks/native/c1/proposals/seastar.diff):
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.16)
-project(service CXX)
+project(service C CXX)
find_package(Seastar REQUIRED)
-add_executable(service main.cpp)
-target_link_libraries(service PRIVATE Seastar::seastar)
+add_executable(service main.cpp vendor/vbxtrace/vbxhook.c)
+target_include_directories(service PRIVATE vendor/vbxtrace)
+target_link_libraries(service PRIVATE Seastar::seastar ${CMAKE_DL_LIBS})
--- a/main.cpp
+++ b/main.cpp
@@ -4,17 +4,22 @@
#include <fcntl.h>
#include <unistd.h>
+#include "integrations/vbxhook_seastar.hpp"
+
using namespace seastar;
struct store_handler : httpd::handler_base {
future<std::unique_ptr<http::reply>> handle(const sstring &, std::unique_ptr<http::request> req,
std::unique_ptr<http::reply> rep) override {
+ vbxhook::Request vbx = vbxhook::seastar::begin_http(*req); // request_index unknown (httpd)
int fd = ::open("/data/store", O_WRONLY | O_CREAT | O_APPEND, 0600);
+ vbxh_opened(vbx.ctx(), fd, O_WRONLY | O_CREAT | O_APPEND);
if (fd >= 0) {
::write(fd, req->content.data(), req->content.size());
::close(fd);
}
rep->write_body("txt", "stored\n");
+ vbx.status(vbxhook::seastar::status_of(*rep));
return make_ready_future<std::unique_ptr<http::reply>>(std::move(rep));
}
};Exact detection rules
Package C1 (C / C++), proposal C1:seastar, defined in hooks/native/c1/proposals/seastar.toml.
- Dependency on:
seastar,Seastar,seastar-dev,seastar-devel,scylladb/seastar - Files:
CMakeLists.txt,conanfile.txt,conanfile.py,vcpkg.json,meson.build,Makefile,*.cpp,*.cc,*.cxx,src/*.cpp,src/*.cc - Sources match (regex):
#\s*include\s*[<"]seastar/,\bseastar::app_template\b,\bhttpd::http_server\b,find_package\(\s*Seastar
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.
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.