我正在尝试在linux上ptrace一个vsftpd服务器进程,以便能够在vsftpd进程进行系统调用时获得控制权。我启动vsftpd进程,并将此进程id作为命令行传递给以下跟踪vsftpd的程序。
但是,当我运行下面的程序时,它就挂起了,并且没有打印anything.Can。有人指出可能是哪里出了问题吗?非常感谢你的帮助!
#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;
}发布于 2011-03-29 01:13:37
您需要具有跟踪VSFTPD的权限。以root用户身份运行此命令。要进行测试,请将ptrace(PTRACE_ATTACH,child,NULL,NULL);的结果放入一个变量并打印出来,即。
long result = ptrace(PTRACE_ATTACH,child,NULL,NULL);
printf("%ld",result);在我的系统上,如果结果为== -1,我没有权限。如果结果==为0,我会这样做。
https://stackoverflow.com/questions/5386307
复制相似问题