ptrace 附加到 vsftpd 挂起

发布于 2024-10-24 13:01:41 字数 2048 浏览 7 评论 0原文

我正在尝试 ptrace linux 上的 vsftpd 服务器进程,以便在 vsftpd 进程进行系统调用时能够获得控制权。我启动 vsftpd 进程并将此进程 ID 作为命令行传递给以下跟踪 vsftpd 的程序。

但是,当我运行以下程序时,它只是挂起并且不打印任何内容。任何人都可以指出可能出了什么问题吗?非常感谢您的帮助!

#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <linux/user.h> 
#include <sys/syscall.h>   /* For SYS_write etc */
#include<sys/reg.h>
int main(int argc,char* argv[])
{   pid_t child;
long orig_eax, eax;
long params[3];
int status;
int insyscall = 0;
child = atoi(argv[1]);
ptrace(PTRACE_ATTACH,child,NULL,NULL);
   while(1) {
      wait(&status);
      if(WIFEXITED(status))
          break;
      orig_eax = ptrace(PTRACE_PEEKUSER,
                 child, 4 * ORIG_EAX, NULL);

    if(orig_eax == __NR_clone || orig_eax == __NR_open || orig_eax == __NR_write)
        { 
if(insyscall == 0) {
            /* Syscall entry */
            insyscall = 1;
            params[0] = ptrace(PTRACE_PEEKUSER,
                               child, 4 * EBX,
                               NULL);
            params[1] = ptrace(PTRACE_PEEKUSER,
                               child, 4 * ECX,
                               NULL);
            params[2] = ptrace(PTRACE_PEEKUSER,
                               child, 4 * EDX,
                               NULL);
    if(orig_eax == __NR_clone)
    {
        printf("\nClone");
    }
    else if(orig_eax == __NR_open)
        printf("\nOpen");
    else if(orig_eax == __NR_write)
        printf("\nWrite");
            printf(" called with "
                   "%ld, %ld, %ld\n",
                   params[0], params[1],
                   params[2]);
            }
      else { /* Syscall exit */
            eax = ptrace(PTRACE_PEEKUSER,
                         child, 4 * EAX, NULL);
                printf("Returned "
                       "with %ld\n", eax);
                insyscall = 0;
            }
        }
        ptrace(PTRACE_SYSCALL,
               child, NULL, NULL);
    }

 return 0;
}

I am trying to ptrace a vsftpd server process on linux to be able to get control whenever vsftpd process makes a system call. I start the vsftpd process and pass this process id as command line to the following program which traces vsftpd.

however, when I run the following program it just hangs and does not print anything.Can anyone point out what could be wrong? Thanks a lot for your help!!

#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <linux/user.h> 
#include <sys/syscall.h>   /* For SYS_write etc */
#include<sys/reg.h>
int main(int argc,char* argv[])
{   pid_t child;
long orig_eax, eax;
long params[3];
int status;
int insyscall = 0;
child = atoi(argv[1]);
ptrace(PTRACE_ATTACH,child,NULL,NULL);
   while(1) {
      wait(&status);
      if(WIFEXITED(status))
          break;
      orig_eax = ptrace(PTRACE_PEEKUSER,
                 child, 4 * ORIG_EAX, NULL);

    if(orig_eax == __NR_clone || orig_eax == __NR_open || orig_eax == __NR_write)
        { 
if(insyscall == 0) {
            /* Syscall entry */
            insyscall = 1;
            params[0] = ptrace(PTRACE_PEEKUSER,
                               child, 4 * EBX,
                               NULL);
            params[1] = ptrace(PTRACE_PEEKUSER,
                               child, 4 * ECX,
                               NULL);
            params[2] = ptrace(PTRACE_PEEKUSER,
                               child, 4 * EDX,
                               NULL);
    if(orig_eax == __NR_clone)
    {
        printf("\nClone");
    }
    else if(orig_eax == __NR_open)
        printf("\nOpen");
    else if(orig_eax == __NR_write)
        printf("\nWrite");
            printf(" called with "
                   "%ld, %ld, %ld\n",
                   params[0], params[1],
                   params[2]);
            }
      else { /* Syscall exit */
            eax = ptrace(PTRACE_PEEKUSER,
                         child, 4 * EAX, NULL);
                printf("Returned "
                       "with %ld\n", eax);
                insyscall = 0;
            }
        }
        ptrace(PTRACE_SYSCALL,
               child, NULL, NULL);
    }

 return 0;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦初启 2024-10-31 13:01:41

您需要具有跟踪 VSFTPD 的权限。以 root 身份运行它。要进行测试,请将 ptrace(PTRACE_ATTACH,child,NULL,NULL); 的结果放入变量中并打印它,即。

long result = ptrace(PTRACE_ATTACH,child,NULL,NULL);
printf("%ld",result);

在我的系统上,如果结果== -1,我没有权限。如果结果 == 0,我就这样做。

You need to have the privilege to trace VSFTPD. Run this as root. To test, put the result of ptrace(PTRACE_ATTACH,child,NULL,NULL); into a variable and print it, ie.

long result = ptrace(PTRACE_ATTACH,child,NULL,NULL);
printf("%ld",result);

On my system if result == -1, I do not have permission. If result == 0, I do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文