Assignment 1 for System Security Course
A simple program to trace and log the system calls made by a target program during its execution. The tracer uses ptrace to monitor the child process and captures system call numbers, which are then saved to a file.
- Tracks and logs unique system call numbers invoked by a target program.
- Saves the list of system call numbers to a specified output file (
syscalls.txt). - Implements process tracing using the
ptracesystem call. - Demonstrates fundamental concepts of process management and system call monitoring in Linux.
- A Linux-based system (required for
ptraceand system call tracing). - GCC or any C++ compiler that supports modern standards.
- You can install these by the following commands
sudo apt update
sudo apt install build-essential
sudo apt install gdb
- The program forks a child process to run the target application.
- The parent process attaches to the child process using
ptrace. - Each time the child process invokes a system call, the parent intercepts it and logs the system call number.
- Once the target program completes execution, all unique system call numbers are saved to
syscalls.txt.
- The program loads the allowed syscalls from the
syscalls.txt. - Then using
sigactionwe create a custom handler for theSystem calls. - In the handler if we receive a system call that is not in our allowed_syscalls array we terminate the process, otherwise we emulate the system call.
Compile the program using a C++ compiler (being in the folder where the ccp file is):
g++ tracer.cpp -o tracerRun the program by using the following command:
sudo ./tracer /bin/lsThe program will:
- Execute
/bin/ls. - Log all unique system call numbers made by
/bin/ls. - Save the results to
./syscalls.txt
The file contains the syscall codes but not the commands(e.g., code=0, command=read). Here is the table with the code-command matches.
LD_PRELOAD=./sandbox.so /bin/lsThe program will:
- Execute
/bin/ls. - Check all system call numbers made by
/bin/ls. - Kill the process if the program tries to execute some system calls that are not present in the
./syscalls.txt
The output file I have in the repository is the one after running the tracer for times.