This kernel module intercepts and logs specific system calls (open
, read
, write
) in the Linux kernel. It is designed for educational purposes and advanced debugging. The module dynamically hooks into the system call table, logs the intercepted calls, and restores the original behavior upon unloading.
- Intercepts System Calls: Hooks into the
open
,read
, andwrite
system calls. - Logs System Call Activity: Logs intercepted system calls to the kernel log buffer (viewable using
dmesg
). - Dynamic Loading: Can be loaded and unloaded dynamically using
insmod
andrmmod
. - Educational Tool: Demonstrates kernel hooking, system call table manipulation, and kernel module development.
- Linux Kernel Development Environment:
- GCC compiler
- Linux kernel headers
make
utility
- Root Access: Required to load and unload kernel modules.
Clone the repository to your local machine:
git clone https://github.com/umarsync/system-call-interceptor.git
cd system-call-interceptor
Use the provided Makefile
to compile the module:
make
This will generate a kernel object file named syscall_interceptor.ko
.
Load the module into the kernel using insmod
:
sudo insmod syscall_interceptor.ko
Use dmesg
to view the intercepted system call logs:
dmesg
Unload the module when done:
sudo rmmod syscall_interceptor
When the module is loaded, it logs intercepted system calls to the kernel log buffer. For example:
[ 123.456789] syscall_interceptor: open("/etc/passwd", 0, 0)
[ 123.567890] syscall_interceptor: read(3, 0x7ffd12345678, 1024)
[ 123.678901] syscall_interceptor: write(1, 0x7ffd12345678, 512)
open
: Logs the file path, flags, and mode.read
: Logs the file descriptor, buffer address, and byte count.write
: Logs the file descriptor, buffer address, and byte count.
To log system calls only for specific processes, modify the new_open
, new_read
, and new_write
functions to check the current process ID (current->pid
).
Instead of logging to the kernel log buffer, you can write logs to a file in /var/log
. Use filp_open
, vfs_write
, and filp_close
to implement file-based logging.
To avoid flooding the log buffer, implement rate limiting using a timer or a counter.
- System Stability: Modifying the system call table can lead to system instability or kernel panics. Use this module in a controlled environment.
- Security Risks: This module can be used for malicious purposes. Ensure you have proper authorization before using it on any system.
- Kernel Version Compatibility: This module is tested on Linux kernels 5.x. It may require adjustments for other versions.
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Commit your changes.
- Submit a pull request.
- Inspired by Linux kernel development tutorials and system call interception techniques.
- Special thanks to the Linux kernel community for their extensive documentation.