我正在尝试在linux上对vsftpd服务器进程进行ptrace,以便能够在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;
}
答案 0 :(得分:2)
您需要拥有跟踪VSFTPD的权限。以root身份运行它。要进行测试,请将ptrace(PTRACE_ATTACH,child,NULL,NULL);
的结果放入变量并打印,即
long result = ptrace(PTRACE_ATTACH,child,NULL,NULL);
printf("%ld",result);
如果结果== -1,在我的系统上,我没有权限。如果结果== 0,我会这样做。