douyinWEB/scripts/_audit_neko_firewall2.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

94 lines
3.4 KiB
Python

# -*- coding: utf-8 -*-
"""Deep-check Docker/nft filters + UDP reachability for Neko WebRTC."""
from __future__ import annotations
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
HOST = "108.174.50.68"
PASS = "Xiao4669805"
REMOTE = r"""
set +e
echo '===== iptables filter all chains (relevant) ====='
iptables -S 2>/dev/null | head -120
echo
echo '===== iptables DOCKER / DOCKER-USER / FORWARD ====='
iptables -L DOCKER -n -v 2>/dev/null | head -40
iptables -L DOCKER-USER -n -v 2>/dev/null | head -40
iptables -L FORWARD -n -v 2>/dev/null | head -40
echo
echo '===== nft filter / raw snippets mentioning 52 ====='
nft list ruleset 2>/dev/null | grep -E '5200|5210|5220|5230|dport|policy|chain INPUT|chain FORWARD|DOCKER' | head -80
echo
echo '===== full nft (truncated) ====='
nft list ruleset 2>/dev/null | head -200
echo
echo '===== probe self via public IP from inside ====='
# TCP
timeout 3 bash -c 'echo >/dev/tcp/108.174.50.68/52300' && echo TCP52300_OK || echo TCP52300_FAIL
timeout 3 bash -c 'echo >/dev/tcp/108.174.50.68/443' && echo TCP443_OK || echo TCP443_FAIL
# UDP with nc if available
if command -v nc >/dev/null 2>&1; then
echo -n 'UDP52300_nc: '; echo -n $'\x00' | timeout 2 nc -u -w1 108.174.50.68 52300; echo exit:$?
echo -n 'UDP52000_nc: '; echo -n $'\x00' | timeout 2 nc -u -w1 108.174.50.68 52000; echo exit:$?
fi
# python udp bind test - see if packets arrive (start listener briefly on unused then check docker)
python3 - <<'PY'
import socket, select, time
# try connect-style: send to public IP and see ICMP
for port in (52300, 52000, 52050):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(1.5)
try:
s.connect(('108.174.50.68', port))
s.send(b'\x00\x01\x02')
try:
data = s.recv(64)
print(f'UDP{port} reply len={len(data)}')
except socket.timeout:
print(f'UDP{port} sent_ok no_reply (likely accepted by stack)')
except ConnectionRefusedError:
print(f'UDP{port} ConnectionRefused (closed/filtered)')
except OSError as e:
print(f'UDP{port} OSError {e}')
except Exception as e:
print(f'UDP{port} fail {e}')
finally:
s.close()
PY
echo
echo '===== conntrack / recent UDP hits ====='
conntrack -L -p udp 2>/dev/null | grep -E '5200|5230' | head -20 || echo 'no conntrack udp match'
echo
echo '===== provider panel hints ====='
ls /usr/local/aapanel /www/server/panel 2>/dev/null
ss -tlnp | grep -E ':8888|:7800|:10000|:2086|:2087' | head
# any firewall scripts
ls /etc/iptables* /etc/nftables.conf 2>/dev/null
systemctl is-active nftables iptables ufw 2>/dev/null
echo
echo '===== neko2 ports if started briefly? ====='
docker inspect douyinweb-neko-1 --format 'neko1 HostConfig.PortBindings={{json .HostConfig.PortBindings}}' 2>/dev/null | head -c 500; echo
docker inspect douyinweb-neko-1 --format 'NetworkMode={{.HostConfig.NetworkMode}}'
"""
def main() -> None:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, 22, "root", PASS, timeout=45, allow_agent=False, look_for_keys=False)
_i, o, e = c.exec_command(REMOTE, timeout=90)
print(o.read().decode("utf-8", "replace"))
err = e.read().decode("utf-8", "replace")
if err.strip():
print("STDERR:", err[:1500])
c.close()
if __name__ == "__main__":
main()