-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec_logger.c
More file actions
28 lines (24 loc) · 760 Bytes
/
exec_logger.c
File metadata and controls
28 lines (24 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// exec_logger.c
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
static int (*real_execve)(const char *filename, char *const argv[], char *const envp[]) = NULL;
int execve(const char *filename, char *const argv[], char *const envp[]) {
if (!real_execve) {
real_execve = dlsym(RTLD_NEXT, "execve");
}
// Log the command to a file
FILE *log = fopen("/var/log/execve.log", "a");
if (log) {
fprintf(log, "Executed command: %s\n", filename);
for (int i = 0; argv[i] != NULL; i++) {
fprintf(log, "Arg[%d]: %s\n", i, argv[i]);
}
fclose(log);
}
return real_execve(filename, argv, envp);
}