forked from hc0d3r/sshd-poison
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ptrace.c
98 lines (79 loc) · 1.83 KB
/
ptrace.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <sys/ptrace.h>
#include <sys/reg.h>
#include <sys/wait.h>
#include <stdio.h>
#include "ptrace.h"
int ptrace_seize(pid_t pid, unsigned long opts){
if(ptrace(PTRACE_SEIZE, pid, NULL, opts) == 0 &&
ptrace(PTRACE_INTERRUPT, pid) == 0){
return 0;
}
else {
return 1;
}
}
unsigned long getip(pid_t pid){
return ptrace(PTRACE_PEEKUSER, pid, RIP*sizeof(long), 0);
}
const char *ptrace_stropt(int opt){
const char *ret;
static char buf[64];
switch(opt){
case PTRACE_CONT:
ret = "PTRACE_CONT";
break;
case PTRACE_DETACH:
ret = "PTRACE_DETACH";
break;
case PTRACE_LISTEN:
ret = "PTRACE_LISTEN";
break;
default:
sprintf(buf, "/*PTRACE_%d*/", opt);
ret = buf;
}
return ret;
}
int status_info(int *opt, int *sig, int *event, int status){
int ret = 1;
if(WIFSTOPPED(status)){
*sig = WSTOPSIG(status);
}
else if(WIFSIGNALED(status)){
goto end;
}
else if(WIFEXITED(status)){
goto end;
}
else {
*sig = 0;
}
*event = status >> 16;
*opt = PTRACE_CONT;
switch(*event){
case PTRACE_EVENT_FORK:
if(*sig == SIGTRAP)
*sig = 0;
break;
case PTRACE_EVENT_EXEC:
if(*sig == SIGTRAP)
*sig = 0;
break;
case PTRACE_EVENT_STOP:
switch(*sig){
case SIGSTOP:
case SIGTSTP:
case SIGTTIN:
case SIGTTOU:
*opt = PTRACE_LISTEN;
break;
/* signal suppression */
default:
*sig = 0;
}
break;
}
ret = 0;
end:
return ret;
}