42_Override/level04/source.c
2025-05-06 18:19:06 +02:00

35 lines
683 B
C

#include <stdio.h>
#include <string.h>
#include <sys/prctl.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <unistd.h>
int main(void)
{
char s[128];
int wstatus;
pid_t pid;
pid = fork();
memset(s, 0, sizeof(s));
if (pid) { // parent code
do {
wait(&wstatus);
if (WIFSIGNALED(wstatus) ||
((char)(WIFSIGNALED(wstatus) + 1) >> 1 > 0)) {
puts("child is exiting...");
return 0;
}
} while (ptrace(PTRACE_PEEKUSER, pid, 44, 0) != 11);
puts("no exec() for you");
kill(pid, SIGKILL);
} else { // child code
prctl(1, PR_SET_PDEATHSIG);
ptrace(PTRACE_TRACEME, 0, NULL, NULL);
puts("Give me some shellcode, k");
gets(s);
}
return 0;
}