-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/rules improvements #338
Conversation
Signed-off-by: Amit Schendel <amitschendel@gmail.com>
Signed-off-by: Amit Schendel <amitschendel@gmail.com>
Signed-off-by: Amit Schendel <amitschendel@gmail.com>
Summary:
|
Signed-off-by: Amit Schendel <amitschendel@gmail.com>
Summary:
|
// Check for SSH signature using memcmp | ||
if (__builtin_memcmp(payload, SSH_SIGNATURE, SSH_SIG_LEN) == 0) { | ||
struct event *event; | ||
__u32 zero = 0; | ||
event = bpf_map_lookup_elem(&empty_event, &zero); | ||
if (!event) { | ||
return 0; | ||
} | ||
|
||
// Enrich event with process metadata | ||
struct sockets_value *skb_val = gadget_socket_lookup(skb); | ||
if (skb_val != NULL) { | ||
event->netns = skb->cb[0]; // cb[0] initialized by dispatcher.bpf.c | ||
event->mntns_id = skb_val->mntns; | ||
event->pid = skb_val->pid_tgid >> 32; | ||
event->uid = (__u32)(skb_val->uid_gid); | ||
event->gid = (__u32)(skb_val->uid_gid >> 32); | ||
__builtin_memcpy(&event->comm, skb_val->task, sizeof(event->comm)); | ||
|
||
event->src_ip = iph.saddr; | ||
event->dst_ip = iph.daddr; | ||
event->src_port = bpf_ntohs(tcph.source); | ||
event->dst_port = bpf_ntohs(tcph.dest); | ||
|
||
event->timestamp = bpf_ktime_get_boot_ns(); | ||
} | ||
__u64 skb_len = skb->len; | ||
bpf_perf_event_output(skb, &events, skb_len << 32 | BPF_F_CURRENT_CPU, event, sizeof(struct event)); | ||
} | ||
|
||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amitschendel , if I understand correctly, this will fire an event for every SSH frame. I am not sure we need event per packet, maybe per connection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take the above back. The SSH_
header is only there in the handshake messages (one that client sends to server, the second when the server sends to the client)
Still, will we get two alerts here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, this is why I am filtering out the response in the rule.
Overview