Skip to content

Commit

Permalink
logging parent process
Browse files Browse the repository at this point in the history
Signed-off-by: Kohei Morita <[email protected]>
  • Loading branch information
mrtc0 committed Nov 8, 2021
1 parent cb68380 commit ebd9e27
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
Binary file modified pkg/bpf/bytecode/restricted-network.bpf.o
Binary file not shown.
1 change: 1 addition & 0 deletions pkg/bpf/c/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct audit_event_header {
enum audit_event_type type;
char nodename[NEW_UTS_LEN + 1];
char task[TASK_COMM_LEN];
char parent_task[TASK_COMM_LEN];
};

struct audit_event_blocked_ipv4 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/bpf/c/restricted-network.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ static inline void report_ip4_block(void *ctx, u64 cg, enum action action, enum
ev.hdr.type = BLOCKED_IPV4;
bpf_get_current_comm(&ev.hdr.task, sizeof(ev.hdr.task));

struct task_struct *parent_task = BPF_CORE_READ(current_task, real_parent);
bpf_probe_read_kernel_str(&ev.hdr.parent_task, sizeof(ev.hdr.parent_task), &parent_task->comm);

ev.dport = __builtin_bswap16(daddr->sin_port);
ev.src = src_addr4(sock);
ev.dst = BPF_CORE_READ(daddr, sin_addr);
Expand Down
28 changes: 15 additions & 13 deletions pkg/commands/network/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ const SRCIP_LEN = 4
const DSTIP_LEN = 4

type eventHeader struct {
CGroupID uint64
PID uint32
EventType int32
Nodename [NEW_UTS_LEN + 1]byte
Command [TASK_COMM_LEN]byte
_ [PADDING_LEN]byte
CGroupID uint64
PID uint32
EventType int32
Nodename [NEW_UTS_LEN + 1]byte
Command [TASK_COMM_LEN]byte
ParentCommand [TASK_COMM_LEN]byte
_ [PADDING_LEN]byte
}

type eventBlockedIPv4 struct {
Expand Down Expand Up @@ -103,13 +104,14 @@ func RunAudit(conf *config.Config) {
}

log.WithFields(logrus.Fields{
"Action": body.ActionResult(),
"Hostname": nodename2string(header.Nodename),
"PID": header.PID,
"Comm": comm2string(header.Command),
"Addr": byte2IPv4(body.DstIP),
"Port": body.DstPort,
"Protocol": sockTypeToProtocolName(body.SockType),
"Action": body.ActionResult(),
"Hostname": nodename2string(header.Nodename),
"PID": header.PID,
"Comm": comm2string(header.Command),
"ParentComm": comm2string(header.ParentCommand),
"Addr": byte2IPv4(body.DstIP),
"Port": body.DstPort,
"Protocol": sockTypeToProtocolName(body.SockType),
}).Info("Traffic is trapped in the filter.")
}
}
Expand Down

0 comments on commit ebd9e27

Please sign in to comment.