Skip to content

Instantly share code, notes, and snippets.

@aenniw
Created February 2, 2023 15:55
Show Gist options
  • Save aenniw/f7cef6b9fc7c81d260c6b2a6252e8a00 to your computer and use it in GitHub Desktop.
Save aenniw/f7cef6b9fc7c81d260c6b2a6252e8a00 to your computer and use it in GitHub Desktop.
OSX Zscaler proxy disable
#!/bin/bash
ANCHOR=zsc_proxy
ANCHOR_FILE=/etc/pf.anchors/${ANCHOR}
ROOT_ANCHOR=/etc/pf.conf
if ! cat ${ROOT_ANCHOR} | grep -q '^anchor "'${ANCHOR}'"'; then
echo "Backup ${ROOT_ANCHOR}"
sudo cp "${ROOT_ANCHOR}" "${ROOT_ANCHOR}.backup"
echo "Add ${ANCHOR} anchor to ${ROOT_ANCHOR}"
echo -e '\nanchor "'${ANCHOR}'"\nload anchor "'${ANCHOR}'" from "'${ANCHOR_FILE}'"' | \
sudo tee -a ${ROOT_ANCHOR} > /dev/null
fi
echo "Generate ${ANCHOR} rules"
curl https://api.config.zscaler.com/zscaler.net/cenr/json 2>/dev/null | \
jq -r '."zscaler.net"[][][].range' | \
sed -r '/^\s*$/d' | sort | uniq | \
awk '{ print "block drop from any to " $0 }' | \
sudo tee ${ANCHOR_FILE} > /dev/null
echo "pass from any to api.config.zscaler.com" | \
sudo tee -a ${ANCHOR_FILE} > /dev/null
curl https://api.config.zscaler.com/zscaler.net/cenr/json 2>/dev/null | \
jq -r '."zscaler.net"[][][].vpn' | \
sed -r '/^\s*$/d' | sort | uniq | \
awk '{ print "pass from any to " $0 }' | \
sudo tee -a ${ANCHOR_FILE} > /dev/null
echo "Generated $(cat ${ANCHOR_FILE} | grep block | wc -l | tr -d ' ') block rules"
echo "Generated $(cat ${ANCHOR_FILE} | grep pass | wc -l | tr -d ' ') pass rules"
echo "Refresh rules"
sudo pfctl -ef ${ROOT_ANCHOR}
echo "Clean up ${ANCHOR} rules for reboot"
echo | sudo tee ${ANCHOR_FILE} > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment