Advertisement
Sweetening

Egress Filtering

Mar 23rd, 2024
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Define your proxy server IP and port if you're using Squid or similar for application layer filtering
  4. PROXY_IP="192.168.1.100"
  5. PROXY_PORT="3128"
  6.  
  7. echo "Starting iptables configuration..."
  8.  
  9. # Flush existing iptables rules to start fresh
  10. iptables -F
  11. iptables -t nat -F
  12.  
  13. echo "Setting default policies..."
  14. # Set default policies to accept
  15. iptables -P INPUT ACCEPT
  16. iptables -P FORWARD ACCEPT
  17. iptables -P OUTPUT ACCEPT
  18.  
  19. echo "Configuring loopback access..."
  20. # Allow loopback access
  21. iptables -A INPUT -i lo -j ACCEPT
  22. iptables -A OUTPUT -o lo -j ACCEPT
  23.  
  24. echo "Allowing existing connections to continue..."
  25. # Allow existing connections to continue
  26. iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  27. iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  28.  
  29. echo "Redirecting HTTP/HTTPS traffic to Squid proxy for application layer filtering..."
  30. # Redirect HTTP/HTTPS traffic to Squid proxy
  31. iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to $PROXY_IP:$PROXY_PORT
  32. iptables -t nat -A OUTPUT -p tcp --dport 443 -j DNAT --to $PROXY_IP:$PROXY_PORT
  33. # Ensure Squid is configured to handle HTTPS by intercepting and decrypting traffic where necessary.
  34.  
  35. # NOTE: Configure Squid separately to block or allow specific websites.
  36. # This involves editing Squid's configuration files to define ACLs (Access Control Lists)
  37. # for allowed or blocked domains.
  38.  
  39. echo "Configuring transport layer filtering..."
  40. # Example: Block outgoing SMTP mail traffic (TCP port 25)
  41. # iptables -A OUTPUT -p tcp --dport 25 -j DROP
  42. # Add similar lines for other protocols you wish to block or allow.
  43.  
  44. echo "Configuring policy to drop all other outgoing traffic..."
  45. # Block all other outgoing traffic
  46. iptables -P OUTPUT DROP
  47.  
  48. # Log dropped output packets for debugging (optional)
  49. iptables -A OUTPUT -j LOG --log-prefix "Dropped by firewall: "
  50.  
  51. echo "Egress filtering configured. Please ensure Squid is properly configured for application layer filtering."
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement