Cancelar una llamada al sistema con ptrace ()
Por algún motivo de seguridad, uso ptrace para obtener el número de syscall, y si es una llamada peligrosa (como 10 para desvincular), quiero cancelar esta syscall.
Aquí está el código fuente para el programa de pruebadel.c
. Compilar congcc -o del del.c
.
#include <stdio.h>
#include <stdlib.h>
int main()
{
remove("/root/abc.out");
return 0;
}
Aquí está el código fuente del administrador de seguridadtest.c
. Compilar congcc -o test test.c
.
#include <signal.h>
#include <syscall.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
#include <sys/user.h>
#include <sys/reg.h>
#include <sys/syscall.h>
int main()
{
int i;
pid_t child;
int status;
long orig_eax;
child = fork();
if(child == 0) {
ptrace(PTRACE_TRACEME, 0, NULL, NULL);
execl("/root/del", "del", NULL);
}
else {
i = 0;
while(1){
wait(&status);
if (WIFEXITED(status) || WIFSIGNALED(status) )break;
orig_eax = ptrace(PTRACE_PEEKUSER,
child, 4 * ORIG_EAX,
NULL);
if (orig_eax == 10){
fprintf(stderr, "Got it\n");
kill(child, SIGKILL);
}
printf("%d time,"
"system call %ld\n", i++, orig_eax);
ptrace(PTRACE_SYSCALL, child, NULL, NULL);
}
}
return 0;
}
Crear elabc.out
archivo, a continuación, ejecute el programa de prueba:
cd /root
touch abc.out
./test
El archivo/root/abc.out
Todavía debería existir.
¿Cómo implemento este requisito?