-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathknockout_protocols.sh
More file actions
73 lines (61 loc) · 2.01 KB
/
Copy pathknockout_protocols.sh
File metadata and controls
73 lines (61 loc) · 2.01 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
#!/bin/bash
#
# Protocol Knockout Script
# Blocks external network (192.168.50.x), SSH, and .NET protocols
#
# Usage: sudo ./knockout_protocols.sh
#
set -e
echo "================================================================================"
echo "Protocol Knockout - Executing Firewall Rules"
echo "================================================================================"
echo ""
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "❌ This script must be run with sudo"
echo " Run: sudo ./knockout_protocols.sh"
exit 1
fi
echo "✓ Running with sudo privileges"
echo ""
# Enable pf firewall
echo "🔥 Enabling macOS packet filter (pf)..."
pfctl -e 2>/dev/null || echo " (pf already enabled)"
echo ""
# Create anchor if not exists
echo "📌 Setting up 'blockcode' firewall anchor..."
echo ""
# Block external network (192.168.50.x)
echo "🔨 Blocking external subnet 192.168.50.0/24..."
cat << 'EOF' | pfctl -a blockcode -f -
# Block entire external network
block drop from 192.168.50.0/24 to any
block drop from any to 192.168.50.0/24
# Block SSH (port 22)
block drop from any to any port 22
# Block .NET protocols
block drop from any to any port 5000
block drop from any to any port 5001
block drop from any to any port 8080
block drop from any to any port 8081
block drop from any to any port 50051
EOF
echo " ✓ Firewall rules applied"
echo ""
# Show active rules
echo "📋 Active firewall rules in 'blockcode' anchor:"
echo "--------------------------------------------------------------------------------"
pfctl -s rules -a blockcode
echo "--------------------------------------------------------------------------------"
echo ""
echo "✅ Protocol knockout complete!"
echo ""
echo "Blocked:"
echo " • External network: 192.168.50.0/24"
echo " • SSH: port 22"
echo " • .NET: ports 5000, 5001, 8080, 8081, 50051"
echo ""
echo "To remove these blocks, run:"
echo " sudo pfctl -a blockcode -F all"
echo ""
echo "================================================================================"