#include #include #include #include #include #include #include #include #include int main(int argc, char *argv[]) { int rc; int status; pid_t pid; if (argc < 2) { fprintf(stderr, "usage: %s \n", argv[0]); exit(1); } pid=(pid_t)atoi(argv[1]); if (ptrace(PT_ATTACH, pid, 0, 0) == -1) { perror("ptrace(attach)"); exit(1); } printf("[+] Attaching pid %s\n", argv[1]); printf("[+] Sleeping 10s\n"); sleep(10); if (waitpid(pid, &status, WUNTRACED) == -1) errx(1, "waitpid()"); if (ptrace(PT_DETACH, pid, 0, 0) == -1) { perror("ptrace(detach)"); exit(1); } printf("[+] Detaching pid %s\n", argv[1]); return (0); }