Repository navigation
Expand file tree
/
Copy pathBPFBlue.sh
More file actions
143 lines (124 loc) · 6.34 KB
/
Copy pathBPFBlue.sh
File metadata and controls
143 lines (124 loc) · 6.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
# eBPF passive security monitoring tool
# Copyright (C) 2023 Shadowpgp
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ "$#" -eq 0 ]; then
echo """
▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄ ▄▄ ▄▄ ▄▄▄▄▄▄▄
█ ▄ █ █ █ ▄ █ █ █ █ █ █ █
█ █▄█ █ ▄ █ ▄▄▄█ █▄█ █ █ █ █ █ █ ▄▄▄█
█ █ █▄█ █ █▄▄▄█ █ █ █ █▄█ █ █▄▄▄
█ ▄ ██ ▄▄▄█ ▄▄▄█ ▄ ██ █▄▄▄█ █ ▄▄▄█
█ █▄█ █ █ █ █ █ █▄█ █ █ █ █▄▄▄
█▄▄▄▄▄▄▄█▄▄▄█ █▄▄▄█ █▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█ V1.1
Created by @shadowpgp aka fcn
"""
echo "BPF passive security monitoring script"
echo "Usage: $0 [probe]"
echo ""
echo "Available probes:"
echo " execve trace syscall execve (execution of a program)"
echo " network trace network enter and exit events"
echo " sniff sniff network traffic (Warning: this is a heavy process)"
echo " open trace syscall open (opening of a file)"
echo " clone trace syscall clone (creation of a new process)"
echo " socket trace syscall socket (creation of a network socket)"
echo " bind trace syscall bind (binding of a network socket to a local address)"
echo " listen trace syscall listen (listening for incoming connections on a network socket)"
echo " connect trace syscall connect (connecting to a remote address)"
echo " event trace kernel events (listen to the kernel ring 0)"
echo ""
echo "This script uses eBPF and bpftrace to passively monitor the behavior of system calls on a Linux system."
echo "The script can be used to gain insights into system activity, detect malicious activity, or monitor system performance."
echo ""
echo "Example: $0 execve"
exit 0
fi
# Syscall execve
execve_command="sudo bpftrace -e 'tracepoint:syscalls:sys_enter_execve { printf(\" Execve syscall traced : Command - %s, Filename - %s, PID - %d\\n\", comm, str(args->filename), pid); }'"
# Network analysis
network_analysis="sudo bpftrace -e 'tracepoint:syscalls:sys_enter_socket { printf(\"Entering Sock : Program name - %s, PID - %d\\n\", comm, pid); } tracepoint:syscalls:sys_exit_socket { printf(\"Exiting Sock : Program name - %s, PID - %d\\n\", comm, pid); }'"
# Network sniffing
network_sniffing="sudo tcpdump -vvv -i any"
# Syscall open
open_command="sudo bpftrace -e 'tracepoint:syscalls:sys_enter_open { printf(\" Open syscall traced : Filename - %s, PID - %d\\n\", str(args->filename), pid); }'"
# Syscall clone
clone_command="sudo bpftrace -e 'tracepoint:syscalls:sys_enter_clone { printf(\" Clone syscall traced : Command - %s, PID - %d\\n\", comm, pid); }'"
# Syscall socket
socket_command="sudo bpftrace -e 'tracepoint:syscalls:sys_enter_socket { printf(\" Socket syscall traced : Domain - %d, PID - %d\\n\", args->domain, pid); }'"
# Syscall bind
bind_command="sudo bpftrace -e 'tracepoint:syscalls:sys_enter_bind { printf(\" Bind syscall traced : Socket - %s, PID - %d\\n\", comm, pid); }'"
# Syscall listen
listen_command="sudo bpftrace -e 'tracepoint:syscalls:sys_enter_listen { printf(\" Listen syscall traced : Socket - %s, PID - %d\\n\", comm, pid); }'"
# Syscall connect
connect_command="sudo bpftrace -e 'tracepoint:syscalls:sys_enter_connect { printf(\" Connect syscall traced : Socket - %s, PID - %d\\n\", comm, pid); }'"
# Clone syscall
clone_process="sudo bpftrace -e 'kprobe:sys_clone { printf(\"Clone syscall traced : Flags - %x, PID - %d\\n\", arg1, pid); }'"
# Event trace
event_command="sudo bpftrace -e 'tracepoint:sched:sched_switch { printf(\"Event : %s %s\\n\", args->prev_comm, args->next_comm); }'"
probe="$1"
case "$probe" in
"execve")
command=$execve_command
;;
"network")
command=$network_analysis
;;
"sniff")
command=$network_sniffing
;;
"open")
command=$open_command
;;
"clone")
command=$clone_command
;;
"socket")
command=$socket_command
;;
"bind")
command=$bind_command
;;
"listen")
command=$listen_command
;;
"connect")
command=$connect_command
;;
"clone")
command=$clone_process
;;
"event")
command=$event_command
;;
*)
echo "Invalid probe. Use -h or --help to see the available probes."
exit 1
;;
esac
echo """
▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄ ▄▄ ▄▄ ▄▄▄▄▄▄▄
█ ▄ █ █ █ ▄ █ █ █ █ █ █ █
█ █▄█ █ ▄ █ ▄▄▄█ █▄█ █ █ █ █ █ █ ▄▄▄█
█ █ █▄█ █ █▄▄▄█ █ █ █ █▄█ █ █▄▄▄
█ ▄ ██ ▄▄▄█ ▄▄▄█ ▄ ██ █▄▄▄█ █ ▄▄▄█
█ █▄█ █ █ █ █ █ █▄█ █ █ █ █▄▄▄
█▄▄▄▄▄▄▄█▄▄▄█ █▄▄▄█ █▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█ V1.1
Created by @shadowpgp aka fcn
"""
echo "BPF passive security monitoring script"
echo "Executing probe: $probe"
echo "Running command: $command"
eval "$command"