Anuluj wywołanie systemowe za pomocą ptrace ()

Ze względów bezpieczeństwa używam ptrace, aby uzyskać numer wywołania systemowego, a jeśli jest to niebezpieczne wywołanie (np. 10 dla odłączenia), chcę anulować to wywołanie systemowe.

Oto kod źródłowy programu testowegodel.c. Połącz zgcc -o del del.c.

#include <stdio.h>
#include <stdlib.h>
int main()
{
    remove("/root/abc.out");
    return 0;
}

Oto kod źródłowy menedżera bezpieczeństwatest.c. Połącz zgcc -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;
}

Utwórzabc.out plik, a następnie uruchom program testowy:

cd /root
touch abc.out
./test

Plik/root/abc.out powinien nadal istnieć.

Jak wdrożyć to wymaganie?

questionAnswers(2)

yourAnswerToTheQuestion