Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8441153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:29:29+00:00 2026-06-10T08:29:29+00:00

For some security purpose, I use ptrace to get the syscall number, and if

  • 0

For some security purpose, I use ptrace to get the syscall number, and if it’s a dangerous call (like 10 for unlink), I want to cancel this syscall.

Here’s the source code for the test program del.c. Compile with gcc -o del del.c.

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

Here’s the security manager source code test.c. Compile with gcc -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;
}

Create the abc.out file, then run the test program:

cd /root
touch abc.out
./test

The file /root/abc.out should still exist.

How do I implement this requirement?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:29:31+00:00Added an answer on June 10, 2026 at 8:29 am

    Well it seems that sometimes PTRACE_KILL does not work very well, you can use kill instead:

    if (orig_eax == 10)
    {
        kill(pid, SIGKILL);
    }
    

    EDIT : I test on my machine (Ubuntu kernel 3.4) with this program and all is ok:

    #include <sys/ptrace.h>
    #include <sys/types.h>
    #include <sys/wait.h>
    #include <unistd.h>
    #include <sys/reg.h>
    #include <stdio.h>
    
    int main(int argc, char **argv)
    {   
        pid_t child;
        long orig_eax;
        int status;
    
        child = fork();
        if(child == 0) 
        {
            ptrace(PTRACE_TRACEME, 0, NULL, NULL);
            execl("/bin/ls", "ls", NULL);
        }
        else 
        {
            /* Both wait and waitpid works */
            //wait(NULL);
            waitpid(child, &status, 0);
            orig_eax = ptrace(PTRACE_PEEKUSER, child, 4 * ORIG_EAX, NULL);
            /* Tracking execve syscall */
            if (orig_eax == 11)
            {
                /* Both PTRACE_KILL and kill() works on my 3.4.4 Kernel */
                fprintf(stdout, "GOT IT\n");
                //ptrace(PTRACE_KILL, child, NULL, NULL);
                kill(child, SIGKILL);
            }
        }
    
        return 0;
    }
    

    UPDATE : The problem is that you are using 10 for tracking system call instead of 11(because you are executing execve command), this code will work with your rm command:

    if (orig_eax == 11)
    {
        /* Both PTRACE_KILL and kill() works on my 3.4.4 Kernel */
        fprintf(stdout, "INSIDE THE TRAP, FILE WILL NOT BE REMOVED\n");
        ptrace(PTRACE_KILL, child, NULL, NULL);
        //kill(child, SIGKILL);
    }
    

    EDIT : I try this code and all wroks fine (the file abc.out still exist after the execution of CALL_REMOVE)

    /*
     * REMOVE.c
     * gcc -Wall REMOVE.c -o REMOVE
     */
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    
    int main(int argc, char **argv)
    {
            /* Both calls work */
            //remove("/root/abc.out");
            unlink("/root/abc.out");
    
            return 0;
    }
    
    /*
     * CALL_REMOVE.c
     * gcc -Wall CALL_REMOVE.c -o CALL_REMOVE
     */
    
    #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>
    #include <stdio.h>
    #include <string.h>
    
    int main(int argc, char **argv)
    {
            int i;
            pid_t child;
            int status;
            long orig_eax;
            int kill_ret = 0;
    
            child = fork();
    
            if(child == 0)
            {
                    ptrace(PTRACE_TRACEME, 0, NULL, NULL);
                    execl("/root/REMOVE", "REMOVE",  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_ret = kill(child, SIGKILL);
                                    if (kill_ret == -1)
                                    {
                                        fprintf(stderr, "Failed to kill ---> %s\n", strerror(errno));
                                    }
                            }
                            printf("%d time, system call %ld\n", i++, orig_eax);
                            ptrace(PTRACE_SYSCALL, child, NULL, NULL);
                    }
            }
    
            return 0;
    }
    

    We got this output:

    root@UnixServer:/root# ll
    total 28K
    -rw-r--r-- 1 root root    6 2012-08-18 19:37 abc.out
    -rw-r--r-- 1 root root 1023 2012-08-18 19:39 CALL_REMOVE.c
    -rw-r--r-- 1 root root  213 2012-08-18 19:39 REMOVE.c
    -rwxr-xr-x 1 root root 7,3K 2012-08-18 19:39 CALL_REMOVE
    -rwxr-xr-x 1 root root 7,0K 2012-08-18 19:39 REMOVE
    root@UnixServer:/root# ./CALL_REMOVE 
    0 time, system call 11
    1 time, system call 45
    2 time, system call 45
    3 time, system call 33
    4 time, system call 33
    5 time, system call 192
    6 time, system call 192
    7 time, system call 33
    8 time, system call 33
    9 time, system call 5
    10 time, system call 5
    11 time, system call 197
    12 time, system call 197
    13 time, system call 192
    14 time, system call 192
    15 time, system call 6
    16 time, system call 6
    17 time, system call 33
    18 time, system call 33
    19 time, system call 5
    20 time, system call 5
    21 time, system call 3
    22 time, system call 3
    23 time, system call 197
    24 time, system call 197
    25 time, system call 192
    26 time, system call 192
    27 time, system call 192
    28 time, system call 192
    29 time, system call 192
    30 time, system call 192
    31 time, system call 6
    32 time, system call 6
    33 time, system call 192
    34 time, system call 192
    35 time, system call 243
    36 time, system call 243
    37 time, system call 125
    38 time, system call 125
    39 time, system call 125
    40 time, system call 125
    41 time, system call 125
    42 time, system call 125
    43 time, system call 91
    44 time, system call 91
    Got it
    45 time, system call 10
    root@UnixServer:/root# ll
    total 28K
    -rw-r--r-- 1 root root    6 2012-08-18 19:37 abc.out
    -rw-r--r-- 1 root root 1023 2012-08-18 19:39 CALL_REMOVE.c
    -rw-r--r-- 1 root root  213 2012-08-18 19:39 REMOVE.c
    -rwxr-xr-x 1 root root 7,3K 2012-08-18 19:39 CALL_REMOVE
    -rwxr-xr-x 1 root root 7,0K 2012-08-18 19:39 REMOVE
    root@UnixServer:/root# 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for security purpose I do some queries in this way: SELECT avatar_data FROM users
I have created an Attribute, call MyAttribute, which is performing some security and for
I have on security purpose application,i need some security while uninstalling an application please
Hi all.. I want to get some information from my database and show into
I've looked into this, and I've seen some places saying you can use CURL
I have some code like this in a winforms app I was writing to
I have some security related service running on my machine (start type = automatic)
While implementing some security aspects with Spring Security, I have noticed that both Authentication
I'm trying to add some security to my ASP.NET 1.0 MVC app (VB), but
I gave a site full trust however I am still getting some security exceptions.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.