Skip to content

Commit

Permalink
update README, lint code files
Browse files Browse the repository at this point in the history
  • Loading branch information
shsingh committed May 18, 2023
1 parent cae38b3 commit 382756a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 58 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Say goodbye to constantly monitoring your servers with tcpdump and hello to a mo
**Available for ~~Windows~~, Linux and Ubuntu.**

<p align="center">
<img src = "https://github.com/ebpfshield-io/eBPFShield/blob/main/.github/images/linux_ubuntu.png" width=350>
<img src = "https://github.com/ebpfshield-io/eBPFShield/blob/main/docs/images/linux_ubuntu.png" width=350>
</p>

## 🛠 Features
Expand Down
114 changes: 58 additions & 56 deletions ebpfshield.c
Original file line number Diff line number Diff line change
@@ -1,81 +1,83 @@
#include <linux/file.h>
#include <linux/net.h>
#include <linux/sched.h>
#include <linux/socket.h>
#include <linux/net.h>
#include <linux/file.h>
#include <net/sock.h>
#include <uapi/linux/in.h>

BPF_PERF_OUTPUT(events);

struct netevent_t {
u32 pid;
u64 ts;
char comm[TASK_COMM_LEN];
int fd;
int uid;
unsigned short port;
unsigned int address;
int inet_family;
u32 pid;
u64 ts;
char comm[TASK_COMM_LEN];
int fd;
int uid;
unsigned short port;
unsigned int address;
int inet_family;
};

extern struct socket *sockfd_lookup(int fd, int *err);
extern unsigned long __fdget(unsigned int fd);
extern unsigned long __fdget_raw(unsigned int fd);

int probe_connect_enter(struct pt_regs *ctx, int sockfd, struct sockaddr *addr,
int addrlen) {
struct sockaddr_in *poop = (struct sockaddr_in *)addr;
if (poop->sin_family != AF_INET) {
return 0;
}

int probe_connect_enter (struct pt_regs *ctx, int sockfd, struct sockaddr* addr, int addrlen) {
struct sockaddr_in* poop = (struct sockaddr_in*) addr;
if (poop->sin_family != AF_INET) {
return 0;
}

//__fdget_raw(sockfd);
//struct socket* test = sockfd_lookup(sockfd, NULL);
struct netevent_t netevent = {};
netevent.pid = bpf_get_current_pid_tgid();
netevent.ts = bpf_ktime_get_ns();
//netevent.fd = sk->__sk_common.skc_family;
netevent.uid = bpf_get_current_uid_gid();
netevent.port = poop->sin_port;
netevent.address = poop->sin_addr.s_addr;
bpf_get_current_comm(&netevent.comm, sizeof(netevent.comm));
events.perf_submit(ctx, &netevent, sizeof(netevent));
//__fdget_raw(sockfd);
// struct socket* test = sockfd_lookup(sockfd, NULL);
struct netevent_t netevent = {};
netevent.pid = bpf_get_current_pid_tgid();
netevent.ts = bpf_ktime_get_ns();
// netevent.fd = sk->__sk_common.skc_family;
netevent.uid = bpf_get_current_uid_gid();
netevent.port = poop->sin_port;
netevent.address = poop->sin_addr.s_addr;
bpf_get_current_comm(&netevent.comm, sizeof(netevent.comm));
events.perf_submit(ctx, &netevent, sizeof(netevent));

return 0;
return 0;
}

int tcp_v4 (struct pt_regs *ctx, struct sock *sk, struct sockaddr *uaddr, int addr_len) {
struct sockaddr_in* poop = (struct sockaddr_in*) uaddr;
if (poop->sin_family != AF_INET) {
return 0;
}
int tcp_v4(struct pt_regs *ctx, struct sock *sk, struct sockaddr *uaddr,
int addr_len) {
struct sockaddr_in *poop = (struct sockaddr_in *)uaddr;
if (poop->sin_family != AF_INET) {
return 0;
}

struct netevent_t netevent = {};
netevent.pid = bpf_get_current_pid_tgid();
netevent.ts = bpf_ktime_get_ns();
netevent.fd = sk->__sk_common.skc_family;
netevent.uid = bpf_get_current_uid_gid();
netevent.port = poop->sin_port;
netevent.address = poop->sin_addr.s_addr;
bpf_get_current_comm(&netevent.comm, sizeof(netevent.comm));
events.perf_submit(ctx, &netevent, sizeof(netevent));
struct netevent_t netevent = {};
netevent.pid = bpf_get_current_pid_tgid();
netevent.ts = bpf_ktime_get_ns();
netevent.fd = sk->__sk_common.skc_family;
netevent.uid = bpf_get_current_uid_gid();
netevent.port = poop->sin_port;
netevent.address = poop->sin_addr.s_addr;
bpf_get_current_comm(&netevent.comm, sizeof(netevent.comm));
events.perf_submit(ctx, &netevent, sizeof(netevent));

return 0;
return 0;
}

int udp_v4 (struct pt_regs *ctx, struct sock *sk, struct msghdr *msg, size_t len) {
struct netevent_t netevent = {};
sk = (struct sock *)PT_REGS_PARM1(ctx);
int udp_v4(struct pt_regs *ctx, struct sock *sk, struct msghdr *msg,
size_t len) {
struct netevent_t netevent = {};
sk = (struct sock *)PT_REGS_PARM1(ctx);

netevent.pid = bpf_get_current_pid_tgid();
netevent.ts = bpf_ktime_get_ns();
netevent.fd = sk->__sk_common.skc_family;
netevent.uid = bpf_get_current_uid_gid();
netevent.port = 0x35;//poop->sin_port;
netevent.address = 0;//poop->sin_addr.s_addr;
strcpy(netevent.comm, "sagar");
// bpf_get_current_comm(&netevent.comm, sizeof(netevent.comm));
events.perf_submit(ctx, &netevent, sizeof(netevent));
netevent.pid = bpf_get_current_pid_tgid();
netevent.ts = bpf_ktime_get_ns();
netevent.fd = sk->__sk_common.skc_family;
netevent.uid = bpf_get_current_uid_gid();
netevent.port = 0x35; // poop->sin_port;
netevent.address = 0; // poop->sin_addr.s_addr;
strcpy(netevent.comm, "sagar");
// bpf_get_current_comm(&netevent.comm, sizeof(netevent.comm));
events.perf_submit(ctx, &netevent, sizeof(netevent));

return 0;
return 0;
}
1 change: 1 addition & 0 deletions ebpfshield/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

from functools import reduce


class TaggedIpList:
def __init__(self, tag, handle):
self.addresses = []
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env python3
#!/usr/bin/python3

from ebpfshield.helpers import TaggedIpList
import argcomplete
Expand Down

0 comments on commit 382756a

Please sign in to comment.