Files
knowledge-base/snippets/niikn-podkop/podkop-probe.sh

27 lines
1.6 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# podkop-probe.sh (NIIKN OpenWrt 192.168.1.50) — проба обхода ИЗ-ЗА КЛИЕНТА.
# netns-«LAN-клиент» на br-lan: трафик идёт client→MikroTik(.1)→OpenWrt-tproxy, как у реального ПК —
# в отличие от роутерного curl (output-путь), который маскирует залип forward/tproxy.
# exit 0 = обход у клиентов работает; 1 = сломан (повод лечить); 2 = инфра (не повод лечить podkop).
NS=pkprobe; GW=192.168.1.1; DNS=192.168.1.50; CIP=192.168.1.242
cleanup(){ ip netns del $NS 2>/dev/null; ip link del veth-h 2>/dev/null; }
cleanup
ip link add veth-h type veth peer name veth-p 2>/dev/null || exit 2
ip netns add $NS 2>/dev/null || { cleanup; exit 2; }
ip link set veth-p netns $NS
ip link set veth-h master br-lan; ip link set veth-h up
ip netns exec $NS ip link set lo up
ip netns exec $NS ip link set veth-p up
ip netns exec $NS ip addr add $CIP/24 dev veth-p
ip netns exec $NS ip route add default via $GW
FIP=$(ip netns exec $NS nslookup web.telegram.org $DNS 2>/dev/null | awk '/^Address[ :]/{a=$NF} END{print a}')
case "$FIP" in
198.1[89].*) : ;; # домен заворачивается в туннель — ок
"") cleanup; exit 2 ;; # DNS молчит — инфра
*) cleanup; exit 1 ;; # не FakeIP — списки/FakeIP сломаны
esac
CODE=$(ip netns exec $NS curl -s -o /dev/null -w '%{http_code}' --resolve web.telegram.org:443:"$FIP" --max-time 8 https://web.telegram.org/ 2>/dev/null)
cleanup
[ "$CODE" = "200" ] || [ "$CODE" = "302" ] && exit 0
exit 1