__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
#!/usr/bin/python
#
# dddos.py DDOS dectection system.
#
# Written as a basic tracing example of using ePBF
# to detect a potential DDOS attack against a system.
#
# Copyright (c) 2019 Jugurtha BELKALEM.
# Licensed under the Apache License, Version 2.0 (the "License")
#
# 14-Jan-2019 Jugurtha BELKALEM Created this.
from bcc import BPF
import ctypes as ct
import datetime
prog = """
#include <linux/skbuff.h>
#include <uapi/linux/ip.h>
#define MAX_NB_PACKETS 1000
#define LEGAL_DIFF_TIMESTAMP_PACKETS 1000000
BPF_HASH(rcv_packets);
struct detectionPackets {
u64 nb_ddos_packets;
};
BPF_PERF_OUTPUT(events);
int detect_ddos(struct pt_regs *ctx, void *skb){
struct detectionPackets detectionPacket = {};
// Used to count number of received packets
u64 rcv_packets_nb_index = 0, rcv_packets_nb_inter=1, *rcv_packets_nb_ptr;
// Used to measure elapsed time between 2 successive received packets
u64 rcv_packets_ts_index = 1, rcv_packets_ts_inter=0, *rcv_packets_ts_ptr;
/* The algorithm analyses packets received by ip_rcv function
* and measures the difference in reception time between each packet.
* DDOS flooders send millions of packets such that difference of
* timestamp between 2 successive packets is so small
* (which is not like regular applications behaviour).
* This script looks for this difference in time and if it sees
* more than MAX_NB_PACKETS successive packets with a difference
* of timestamp between each one of them less than
* LEGAL_DIFF_TIMESTAMP_PACKETS ns,
* ------------------ It Triggers an ALERT -----------------
* Those settings must be adapted depending on regular network traffic
* -------------------------------------------------------------------
* Important: this is a rudimentary intrusion detection system, one can
* test a real case attack using hping3. However; if regular network
* traffic increases above predefined detection settings, a false
* positive alert will be triggered (an example would be the
* case of large file downloads).
*/
rcv_packets_nb_ptr = rcv_packets.lookup(&rcv_packets_nb_index);
rcv_packets_ts_ptr = rcv_packets.lookup(&rcv_packets_ts_index);
if(rcv_packets_nb_ptr != 0 && rcv_packets_ts_ptr != 0){
rcv_packets_nb_inter = *rcv_packets_nb_ptr;
rcv_packets_ts_inter = bpf_ktime_get_ns() - *rcv_packets_ts_ptr;
if(rcv_packets_ts_inter < LEGAL_DIFF_TIMESTAMP_PACKETS){
rcv_packets_nb_inter++;
} else {
rcv_packets_nb_inter = 0;
}
if(rcv_packets_nb_inter > MAX_NB_PACKETS){
detectionPacket.nb_ddos_packets = rcv_packets_nb_inter;
events.perf_submit(ctx, &detectionPacket, sizeof(detectionPacket));
}
}
rcv_packets_ts_inter = bpf_ktime_get_ns();
rcv_packets.update(&rcv_packets_nb_index, &rcv_packets_nb_inter);
rcv_packets.update(&rcv_packets_ts_index, &rcv_packets_ts_inter);
return 0;
}
"""
# Loads eBPF program
b = BPF(text=prog)
# Attach kprobe to kernel function and sets detect_ddos as kprobe handler
b.attach_kprobe(event="ip_rcv", fn_name="detect_ddos")
class DetectionTimestamp(ct.Structure):
_fields_ = [("nb_ddos_packets", ct.c_ulonglong)]
# Show message when ePBF starts
print("DDOS detector started ... Hit Ctrl-C to end!")
print("%-26s %-10s" % ("TIME(s)", "MESSAGE"))
def trigger_alert_event(cpu, data, size):
event = ct.cast(data, ct.POINTER(DetectionTimestamp)).contents
print("%-26s %s %ld" % (datetime.datetime.now(),
"DDOS Attack => nb of packets up to now : ", event.nb_ddos_packets))
# loop with callback to trigger_alert_event
b["events"].open_perf_buffer(trigger_alert_event)
while 1:
try:
b.perf_buffer_poll()
except KeyboardInterrupt:
exit()
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| CMakeLists.txt | File | 276 B | 0644 |
|
| biolatpcts.py | File | 3.23 KB | 0755 |
|
| biolatpcts_example.txt | File | 650 B | 0644 |
|
| bitehist.py | File | 1.36 KB | 0755 |
|
| bitehist_example.txt | File | 1.18 KB | 0644 |
|
| dddos.py | File | 3.73 KB | 0755 |
|
| dddos_example.txt | File | 2.06 KB | 0644 |
|
| disksnoop.py | File | 1.9 KB | 0755 |
|
| disksnoop_example.txt | File | 1.55 KB | 0644 |
|
| hello_fields.py | File | 679 B | 0755 |
|
| hello_perf_output.py | File | 1.24 KB | 0755 |
|
| hello_perf_output_using_ns.py | File | 1.8 KB | 0755 |
|
| kvm_hypercall.py | File | 1.48 KB | 0755 |
|
| kvm_hypercall.txt | File | 1.74 KB | 0644 |
|
| mallocstacks.py | File | 1.9 KB | 0755 |
|
| mysqld_query.py | File | 1.66 KB | 0755 |
|
| mysqld_query_example.txt | File | 499 B | 0644 |
|
| nflatency.py | File | 6.07 KB | 0755 |
|
| nodejs_http_server.py | File | 1.34 KB | 0755 |
|
| nodejs_http_server_example.txt | File | 276 B | 0644 |
|
| stack_buildid_example.py | File | 3.03 KB | 0755 |
|
| stacksnoop.py | File | 3.18 KB | 0755 |
|
| stacksnoop_example.txt | File | 2.8 KB | 0644 |
|
| strlen_count.py | File | 1.3 KB | 0755 |
|
| strlen_hist.py | File | 1.81 KB | 0755 |
|
| strlen_hist_ifunc.py | File | 3.71 KB | 0755 |
|
| strlen_snoop.py | File | 1.35 KB | 0755 |
|
| sync_timing.py | File | 1.36 KB | 0755 |
|
| task_switch.c | File | 499 B | 0644 |
|
| task_switch.py | File | 486 B | 0755 |
|
| tcpv4connect.py | File | 2.36 KB | 0755 |
|
| tcpv4connect_example.txt | File | 1.04 KB | 0644 |
|
| trace_fields.py | File | 589 B | 0755 |
|
| trace_perf_output.py | File | 1.56 KB | 0755 |
|
| undump.py | File | 3.52 KB | 0755 |
|
| undump_example.txt | File | 886 B | 0644 |
|
| urandomread-explicit.py | File | 1.48 KB | 0755 |
|
| urandomread.py | File | 1.01 KB | 0755 |
|
| urandomread_example.txt | File | 675 B | 0644 |
|
| vfsreadlat.c | File | 896 B | 0644 |
|
| vfsreadlat.py | File | 1.3 KB | 0755 |
|
| vfsreadlat_example.txt | File | 3.53 KB | 0644 |
|