int
main()
{
pid_t pid;
int
status;
if
((pid
=
fork())
=
=
0
) {
/
*
目前是跟踪
open
系统调用
*
/
struct sock_filter
filter
[]
=
{
BPF_STMT(BPF_LD
+
BPF_W
+
BPF_ABS, offsetof(struct seccomp_data, nr)),
BPF_JUMP(BPF_JMP
+
BPF_JEQ
+
BPF_K, __NR_openat,
0
,
1
),
BPF_STMT(BPF_RET
+
BPF_K, SECCOMP_RET_TRACE),
BPF_STMT(BPF_RET
+
BPF_K, SECCOMP_RET_ALLOW),
};
struct sock_fprog prog
=
{
.
filter
=
filter
,
.
len
=
(unsigned short) (sizeof(
filter
)
/
sizeof(
filter
[
0
])),
};
/
/
告诉父进程允许子进程跟踪
ptrace(PTRACE_TRACEME,
0
,
0
,
0
);
/
*
避免需要 CAP_SYS_ADMIN
*
/
if
(prctl(PR_SET_NO_NEW_PRIVS,
1
,
0
,
0
,
0
)
=
=
-
1
) {
perror(
"prctl(PR_SET_NO_NEW_PRIVS)"
);
return
1
;
}
if
(prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog)
=
=
-
1
) {
perror(
"when setting seccomp filter"
);
return
1
;
}
kill(getpid(), SIGSTOP);
ssize_t count;
char buf[
256
];
int
fd;
fd
=
syscall(__NR_openat,fd,
"/data/local/tmp/tuzi.txt"
, O_RDONLY);
syscall(__NR_openat,fd,
"/data/local/tmp/asdss.txt"
, O_RDONLY);
syscall(__NR_openat,fd,
"/data/local/tmp/asda.txt"
, O_RDONLY);
syscall(__NR_openat,fd,
"/data/local/tmp/TsdsaWO.txt"
, O_RDONLY);
syscall(__NR_openat,fd,
"/data/local/tmp/sadas.txt"
, O_RDONLY);
syscall(__NR_openat,fd,
"/data/local/tmp/sad.txt"
, O_RDONLY);
syscall(__NR_openat,fd,
"/data/local/tmp/asda.txt"
, O_RDONLY);
/
/
printf(
"fd : %d \n"
,fd);
if
(fd
=
=
-
1
) {
perror(
"open"
);
return
1
;
}
while
((count
=
syscall(__NR_read, fd, buf, sizeof(buf))) >
0
) {
syscall(__NR_write, STDOUT_FILENO, buf, count);
}
syscall(__NR_close, fd);
}
else
{
waitpid(pid, &status,
0
);
/
/
尝试开启ptrace
+
seccomp
ptrace(PTRACE_SETOPTIONS, pid,
0
, PTRACE_O_TRACESECCOMP);
process_signals(pid);
return
0
;
}
}