Advertisement
albspirit86

intercept https

Dec 18th, 2014
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # squid proxy's IP address (which is attached to eth0)
  4. SQUID_SERVER=`ifconfig eth0 | sed -ne 's/.*inet addr:\([^ ]*\).*/\1/p'`
  5.  
  6. # interface connected to WAN
  7. INTERNET="eth0"
  8.  
  9. # interface connected to LAN
  10. LAN_IN="eth1"
  11.  
  12. # squid port
  13. SQUID_PORT="3128"
  14. SQUID_PORT_HTTPS="3127"
  15.  
  16. # clean old firewall
  17. iptables -F
  18. iptables -X
  19. iptables -t nat -F
  20. iptables -t nat -X
  21. iptables -t mangle -F
  22. iptables -t mangle -X
  23.  
  24. # load iptables modules for NAT masquerade and IP conntrack
  25. modprobe ip_conntrack
  26. modprobe ip_conntrack_ftp
  27.  
  28. # define necessary redirection for incoming http traffic (e.g., 80)
  29. iptables -t nat -A PREROUTING -i $LAN_IN -p tcp --dport 80 -j REDIRECT --to-port $SQUID_PORT
  30.  
  31. iptables -t nat -A PREROUTING -i $LAN_IN -p tcp --dport 443 -j REDIRECT --to-port $SQUID_PORT_HTTPS
  32.  
  33. # forward locally generated http traffic to Squid
  34. iptables -t nat -A OUTPUT -p tcp --dport 80 -m owner --uid-owner proxy -j ACCEPT
  35. iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to-ports $SQUID_PORT
  36.  
  37. iptables -t nat -A OUTPUT -p tcp --dport 443 -m owner --uid-owner proxy -j ACCEPT
  38. iptables -t nat -A OUTPUT -p tcp --dport 443 -j REDIRECT --to-ports $SQUID_PORT_HTTPS
  39.  
  40. # forward the rest of non-http traffic
  41. iptables --table nat --append POSTROUTING --out-interface $INTERNET -j MASQUERADE
  42. iptables --append FORWARD --in-interface $INTERNET -j ACCEPT
  43.  
  44. # enable IP forwarding for proxy
  45. echo 1 > /proc/sys/net/ipv4/ip_forward
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement