Skip to content
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

Merged
merged 4 commits into from
Aug 14, 2024
Merged

Feature/rules improvements #338

merged 4 commits into from
Aug 14, 2024

Conversation

amitschendel
Copy link
Collaborator

Overview

Signed-off-by: Amit Schendel <amitschendel@gmail.com>
Signed-off-by: Amit Schendel <amitschendel@gmail.com>
Signed-off-by: Amit Schendel <amitschendel@gmail.com>
Copy link

Summary:

  • License scan: success
  • Credentials scan: failure
  • Vulnerabilities scan: failure
  • Unit test: success
  • Go linting: success

Signed-off-by: Amit Schendel <amitschendel@gmail.com>
Copy link

Summary:

  • License scan: success
  • Credentials scan: failure
  • Vulnerabilities scan: failure
  • Unit test: success
  • Go linting: success

@amitschendel amitschendel added the release Create release label Aug 13, 2024
Comment on lines +74 to +105
// 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;
}
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Collaborator Author

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.

@amitschendel amitschendel merged commit 841ea43 into main Aug 14, 2024
16 checks passed
@matthyx matthyx deleted the feature/rules-improvements branch September 17, 2024 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release Create release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants