Fix ShellCrash :9999 refused connect by hardening geo, YAML, and WG trust.
Strip removed global-client-fingerprint, force 0.0.0.0:9999, fetch GeoDB via jsdelivr when GitHub is blocked, raise start timeout, and allow 10.66.66.0/24 peers; also accept LAN Clash proxies for Neko. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
e41897d341
commit
eb81d824cc
@ -41,11 +41,12 @@ SHELLCRASH_ATTACH_FFMPEG=auto
|
|||||||
# Docker bridge CIDR allowed to reach ShellCrash listeners. This keeps Neko
|
# Docker bridge CIDR allowed to reach ShellCrash listeners. This keeps Neko
|
||||||
# transparent mode working when the browser proxy switch is off and UFW denies INPUT.
|
# transparent mode working when the browser proxy switch is off and UFW denies INPUT.
|
||||||
SHELLCRASH_DOCKER_CIDR=172.16.0.0/12
|
SHELLCRASH_DOCKER_CIDR=172.16.0.0/12
|
||||||
# WireGuard overlay used by the project (wg-easy / 腾讯云中继). ShellCrash WAN
|
# WireGuard overlay used by the project.
|
||||||
# firewall rejects 9999/7890 unless these trusted CIDRs are accepted first.
|
# Some fleets use 10.88.0.0/24; 腾讯云中继 commonly uses 10.66.66.0/24.
|
||||||
SHELLCRASH_WG_CIDR=10.88.0.0/24
|
SHELLCRASH_WG_CIDR=10.66.66.0/24
|
||||||
# Optional override (comma-separated). Empty = Docker + WG + RFC1918 defaults.
|
# Optional override (comma-separated). Empty = Docker + WG overlays + RFC1918 defaults
|
||||||
# SHELLCRASH_TRUSTED_CIDRS=172.16.0.0/12,10.88.0.0/24,192.168.0.0/16,10.0.0.0/8
|
# (includes both 10.66.66.0/24 and 10.88.0.0/24 so dashboard :9999 works over either tunnel).
|
||||||
|
# SHELLCRASH_TRUSTED_CIDRS=172.16.0.0/12,10.66.66.0/24,10.88.0.0/24,192.168.0.0/16,10.0.0.0/8
|
||||||
# Optional install-time HTTP(S) proxy (e.g. Windows Clash http://192.168.21.36:7897).
|
# Optional install-time HTTP(S) proxy (e.g. Windows Clash http://192.168.21.36:7897).
|
||||||
# Leave empty for direct. When set, installer also writes apt + Docker daemon proxy drop-ins
|
# Leave empty for direct. When set, installer also writes apt + Docker daemon proxy drop-ins
|
||||||
# so image pulls work (Docker does not inherit shell http_proxy). Clear after install if desired.
|
# so image pulls work (Docker does not inherit shell http_proxy). Clear after install if desired.
|
||||||
|
|||||||
@ -16,15 +16,23 @@ Install scripts detect CPU once and reuse labels:
|
|||||||
|
|
||||||
## ShellCrash dashboard blocked on WireGuard
|
## ShellCrash dashboard blocked on WireGuard
|
||||||
|
|
||||||
Symptom: ShellCrash shows online and has YAML, but `http://10.88.0.x:9999/ui/` fails from WG peers while localhost works.
|
Symptom: ShellCrash shows online and has YAML, but `http://10.66.66.x:9999/ui/` (or `10.88.0.x`) fails from WG peers while localhost works — or browser shows `ERR_CONNECTION_REFUSED`.
|
||||||
|
|
||||||
Cause: ShellCrash nftables WAN firewall accepts only physical LAN (`HOST_IP`) then **rejects** `7890` / `9999`. WireGuard (`10.88.0.0/24`) is not in that accept set.
|
Causes:
|
||||||
|
|
||||||
|
1. ShellCrash nftables WAN firewall accepts only physical LAN (`HOST_IP`) then **rejects** `7890` / `9999`. WireGuard overlays are not in that accept set.
|
||||||
|
2. CrashCore never binds `:9999` because profile validation fails:
|
||||||
|
- removed top-level `global-client-fingerprint` (new mihomo/meta)
|
||||||
|
- missing `Country.mmdb` / GeoIP when GitHub downloads time out
|
||||||
|
|
||||||
Fix in tree:
|
Fix in tree:
|
||||||
|
|
||||||
- `SHELLCRASH_WG_CIDR` / `SHELLCRASH_TRUSTED_CIDRS` (see `config/system-stack.env.example`)
|
- `SHELLCRASH_WG_CIDR` / `SHELLCRASH_TRUSTED_CIDRS` (see `config/system-stack.env.example`; defaults include both `10.66.66.0/24` and `10.88.0.0/24`)
|
||||||
- `ensure_shellcrash_proxy_ports_for_docker` also opens dashboard `db_port`
|
- `ensure_shellcrash_proxy_ports_for_docker` also opens dashboard `db_port`
|
||||||
- systemd drop-in `shellcrash.service.d/allow-trusted.conf` + `/usr/local/sbin/shellcrash-allow-trusted.sh` re-applies after every ShellCrash start
|
- systemd drop-in `shellcrash.service.d/allow-trusted.conf` + `/usr/local/sbin/shellcrash-allow-trusted.sh` re-applies after every ShellCrash start
|
||||||
|
- `shellcrash_patch_runtime_yaml` strips `global-client-fingerprint` and forces `external-controller: 0.0.0.0:9999`
|
||||||
|
- `ensure_shellcrash_geo_databases` pulls GeoSite/GeoIP/MMDB via jsdelivr when GitHub is unreachable
|
||||||
|
- `shellcrash.service.d/timeout.conf` raises `TimeoutStartSec=600` (bfstart + geo load exceeds 90s)
|
||||||
|
|
||||||
## Install-time proxy
|
## Install-time proxy
|
||||||
|
|
||||||
@ -49,9 +57,9 @@ Installer downloads for ShellCrash also try with proxy and without (`--noproxy`
|
|||||||
|
|
||||||
## WireGuard + Neko
|
## WireGuard + Neko
|
||||||
|
|
||||||
- Overlay address for this fleet is typically `10.88.0.0/24` via `129.204.21.129:51820`.
|
- Overlay address for this fleet is typically `10.66.66.0/24` (腾讯云) or legacy `10.88.0.0/24`.
|
||||||
- `NEKO_ACCESS_MODE=remote` should use the WG address for `NEKO_WEBRTC_NAT1TO1`, not the physical LAN IP.
|
- `NEKO_ACCESS_MODE=remote` should use the WG address for `NEKO_WEBRTC_NAT1TO1`, not the physical LAN IP.
|
||||||
- `resolve_neko_nat1to1` auto-picks `wg*` / `10.88.0.x` when remote mode is set.
|
- `resolve_neko_nat1to1` auto-picks `wg*` / overlay `10.x` when remote mode is set.
|
||||||
- If a WireGuard overlay IP is already present during Neko install, the installer switches to `remote` automatically.
|
- If a WireGuard overlay IP is already present during Neko install, the installer switches to `remote` automatically.
|
||||||
- Applying a WG conf via the hub also switches Neko to remote when the overlay address is ready, and re-runs the ShellCrash trusted-CIDR hook.
|
- Applying a WG conf via the hub also switches Neko to remote when the overlay address is ready, and re-runs the ShellCrash trusted-CIDR hook.
|
||||||
|
|
||||||
|
|||||||
@ -2087,7 +2087,8 @@ shellcrash_trusted_cidrs() {
|
|||||||
if [ -n "${SHELLCRASH_TRUSTED_CIDRS:-}" ]; then
|
if [ -n "${SHELLCRASH_TRUSTED_CIDRS:-}" ]; then
|
||||||
raw="$SHELLCRASH_TRUSTED_CIDRS"
|
raw="$SHELLCRASH_TRUSTED_CIDRS"
|
||||||
else
|
else
|
||||||
raw="$(shellcrash_docker_cidr),${SHELLCRASH_WG_CIDR:-10.88.0.0/24},192.168.0.0/16,10.0.0.0/8"
|
# Include both common WG overlays (legacy 10.88 + 腾讯云 10.66.66) plus RFC1918.
|
||||||
|
raw="$(shellcrash_docker_cidr),${SHELLCRASH_WG_CIDR:-10.88.0.0/24},10.66.66.0/24,10.88.0.0/24,192.168.0.0/16,10.0.0.0/8"
|
||||||
fi
|
fi
|
||||||
raw="$(printf '%s' "$raw" | tr ',;' ' ')"
|
raw="$(printf '%s' "$raw" | tr ',;' ' ')"
|
||||||
for item in $raw; do
|
for item in $raw; do
|
||||||
@ -2203,7 +2204,7 @@ for i in 1 2 3 4 5 6 7 8 9 10 11 12; do
|
|||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
nft list table inet shellcrash >/dev/null 2>&1 || exit 0
|
nft list table inet shellcrash >/dev/null 2>&1 || exit 0
|
||||||
cidrs="${SHELLCRASH_TRUSTED_CIDRS:-172.16.0.0/12,10.88.0.0/24,192.168.0.0/16,10.0.0.0/8}"
|
cidrs="${SHELLCRASH_TRUSTED_CIDRS:-172.16.0.0/12,10.66.66.0/24,10.88.0.0/24,192.168.0.0/16,10.0.0.0/8}"
|
||||||
IFS=',; ' read -r -a arr <<<"$cidrs"
|
IFS=',; ' read -r -a arr <<<"$cidrs"
|
||||||
for cidr in "${arr[@]}"; do
|
for cidr in "${arr[@]}"; do
|
||||||
case "$cidr" in
|
case "$cidr" in
|
||||||
@ -2216,8 +2217,13 @@ EOS
|
|||||||
chmod +x "$hook"
|
chmod +x "$hook"
|
||||||
cat >/etc/systemd/system/shellcrash.service.d/allow-trusted.conf <<EOF
|
cat >/etc/systemd/system/shellcrash.service.d/allow-trusted.conf <<EOF
|
||||||
[Service]
|
[Service]
|
||||||
Environment=SHELLCRASH_TRUSTED_CIDRS=${SHELLCRASH_TRUSTED_CIDRS:-172.16.0.0/12,10.88.0.0/24,192.168.0.0/16,10.0.0.0/8}
|
Environment=SHELLCRASH_TRUSTED_CIDRS=${SHELLCRASH_TRUSTED_CIDRS:-172.16.0.0/12,10.66.66.0/24,10.88.0.0/24,192.168.0.0/16,10.0.0.0/8}
|
||||||
ExecStartPost=/bin/bash -c 'sleep 2; /usr/local/sbin/shellcrash-allow-trusted.sh'
|
ExecStartPost=/bin/bash -c 'sleep 2; /usr/local/sbin/shellcrash-allow-trusted.sh'
|
||||||
|
EOF
|
||||||
|
cat >/etc/systemd/system/shellcrash.service.d/timeout.conf <<'EOF'
|
||||||
|
[Service]
|
||||||
|
# bfstart + GeoDB load regularly exceeds systemd's default 90s on cold hosts.
|
||||||
|
TimeoutStartSec=600
|
||||||
EOF
|
EOF
|
||||||
systemctl daemon-reload >/dev/null 2>&1 || true
|
systemctl daemon-reload >/dev/null 2>&1 || true
|
||||||
}
|
}
|
||||||
@ -2334,15 +2340,96 @@ grant_shellcrash_web_write_access() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Strip removed keys and force dashboard/mixed listeners so :9999 is reachable.
|
||||||
|
shellcrash_patch_runtime_yaml() {
|
||||||
|
local file="$1"
|
||||||
|
[ -s "$file" ] || return 1
|
||||||
|
command -v python3 >/dev/null 2>&1 || return 0
|
||||||
|
python3 - "$file" <<'PY' || true
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
path = Path(sys.argv[1])
|
||||||
|
lines = []
|
||||||
|
found_ec = found_mp = False
|
||||||
|
for line in path.read_text(encoding="utf-8", errors="replace").splitlines():
|
||||||
|
if line.startswith("global-client-fingerprint:"):
|
||||||
|
continue
|
||||||
|
if line.startswith("external-controller:"):
|
||||||
|
lines.append("external-controller: 0.0.0.0:9999")
|
||||||
|
found_ec = True
|
||||||
|
continue
|
||||||
|
if line.startswith("mixed-port:"):
|
||||||
|
lines.append("mixed-port: 7890")
|
||||||
|
found_mp = True
|
||||||
|
continue
|
||||||
|
lines.append(line)
|
||||||
|
if not found_ec:
|
||||||
|
lines.append("external-controller: 0.0.0.0:9999")
|
||||||
|
if not found_mp:
|
||||||
|
lines.append("mixed-port: 7890")
|
||||||
|
path.write_text("\n".join(lines).rstrip() + "\n", encoding="utf-8")
|
||||||
|
PY
|
||||||
|
}
|
||||||
|
|
||||||
|
# Prefer jsdelivr when GitHub is blocked; CrashCore otherwise exits after failed MMDB download.
|
||||||
|
ensure_shellcrash_geo_databases() {
|
||||||
|
local sc="${SHELLCRASH_DIR:-/etc/ShellCrash}"
|
||||||
|
local js="https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release"
|
||||||
|
local dest name min sz
|
||||||
|
mkdir -p "$sc"
|
||||||
|
|
||||||
|
_shellcrash_geo_download() {
|
||||||
|
local url="$1" out="$2"
|
||||||
|
if have curl; then
|
||||||
|
curl -fsSL --connect-timeout 20 --max-time 120 -o "$out" "$url" && return 0
|
||||||
|
env -u http_proxy -u https_proxy -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u all_proxy \
|
||||||
|
curl -fsSL --connect-timeout 20 --max-time 120 -o "$out" "$url" && return 0
|
||||||
|
fi
|
||||||
|
if have wget; then
|
||||||
|
wget -q --no-check-certificate -O "$out" "$url" && return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
for pair in "geosite.dat:GeoSite.dat:1000000" "geoip.dat:GeoIP.dat:1000000" "geoip.metadb:Country.mmdb:1000000"; do
|
||||||
|
name="${pair%%:*}"
|
||||||
|
dest="$sc/${pair#*:}"
|
||||||
|
dest="${dest%:*}"
|
||||||
|
min="${pair##*:}"
|
||||||
|
if [ -s "$dest" ]; then
|
||||||
|
sz="$(wc -c <"$dest" | tr -d '[:space:]')"
|
||||||
|
case "$sz" in
|
||||||
|
''|*[!0-9]*) ;;
|
||||||
|
*) [ "$sz" -ge "$min" ] && continue ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
log "Fetching ShellCrash geo database $name"
|
||||||
|
if _shellcrash_geo_download "$js/$name" "$dest.tmp"; then
|
||||||
|
mv -f "$dest.tmp" "$dest"
|
||||||
|
chmod 644 "$dest" 2>/dev/null || true
|
||||||
|
else
|
||||||
|
rm -f "$dest.tmp"
|
||||||
|
log "WARN: could not download ShellCrash $name (dashboard may fail until geo files exist)"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
shellcrash_sync_runtime_config() {
|
shellcrash_sync_runtime_config() {
|
||||||
local src="${1:-$SHELLCRASH_DIR/yamls/config.yaml}"
|
local src="${1:-$SHELLCRASH_DIR/yamls/config.yaml}"
|
||||||
local dst="/tmp/ShellCrash/config.yaml"
|
local dst="/tmp/ShellCrash/config.yaml"
|
||||||
mkdir -p "$SHELLCRASH_DIR/yamls" /tmp/ShellCrash
|
mkdir -p "$SHELLCRASH_DIR/yamls" /tmp/ShellCrash
|
||||||
if [ -s "$src" ]; then
|
if [ -s "$src" ]; then
|
||||||
|
shellcrash_patch_runtime_yaml "$src" || true
|
||||||
install -m 0644 "$src" "$dst"
|
install -m 0644 "$src" "$dst"
|
||||||
|
shellcrash_patch_runtime_yaml "$dst" || true
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
[ -s "$dst" ]
|
if [ -s "$dst" ]; then
|
||||||
|
shellcrash_patch_runtime_yaml "$dst" || true
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
patch_shellcrash_dns_repair() {
|
patch_shellcrash_dns_repair() {
|
||||||
@ -2422,6 +2509,7 @@ harden_shellcrash_runtime() {
|
|||||||
patch_shellcrash_dns_repair
|
patch_shellcrash_dns_repair
|
||||||
patch_shellcrash_nftables_redirect
|
patch_shellcrash_nftables_redirect
|
||||||
install_shellcrash_trusted_firewall_hook
|
install_shellcrash_trusted_firewall_hook
|
||||||
|
ensure_shellcrash_geo_databases
|
||||||
|
|
||||||
if ! grep -q '^crashcore=.*singbox' "$cfg" 2>/dev/null; then
|
if ! grep -q '^crashcore=.*singbox' "$cfg" 2>/dev/null; then
|
||||||
cat >"$SHELLCRASH_DIR/configs/command.env" <<EOF
|
cat >"$SHELLCRASH_DIR/configs/command.env" <<EOF
|
||||||
|
|||||||
@ -1441,6 +1441,9 @@ neko_browser_proxy_url_is_usable() {
|
|||||||
host.docker.internal)
|
host.docker.internal)
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
10.*|192.168.*|172.1[6-9].*|172.2[0-9].*|172.3[0-1].*)
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
neko_docker_bridge_ipv4_is_usable "$host"
|
neko_docker_bridge_ipv4_is_usable "$host"
|
||||||
}
|
}
|
||||||
@ -1465,7 +1468,7 @@ shellcrash_trusted_cidrs() {
|
|||||||
if [ -n "${SHELLCRASH_TRUSTED_CIDRS:-}" ]; then
|
if [ -n "${SHELLCRASH_TRUSTED_CIDRS:-}" ]; then
|
||||||
raw="$SHELLCRASH_TRUSTED_CIDRS"
|
raw="$SHELLCRASH_TRUSTED_CIDRS"
|
||||||
else
|
else
|
||||||
raw="$(shellcrash_docker_cidr),${SHELLCRASH_WG_CIDR:-10.88.0.0/24},192.168.0.0/16,10.0.0.0/8"
|
raw="$(shellcrash_docker_cidr),${SHELLCRASH_WG_CIDR:-10.88.0.0/24},10.66.66.0/24,10.88.0.0/24,192.168.0.0/16,10.0.0.0/8"
|
||||||
fi
|
fi
|
||||||
raw="$(printf '%s' "$raw" | tr ',;' ' ')"
|
raw="$(printf '%s' "$raw" | tr ',;' ' ')"
|
||||||
for item in $raw; do
|
for item in $raw; do
|
||||||
@ -1708,15 +1711,96 @@ shellcrash_web_url() {
|
|||||||
printf 'http://%s:%s/ui/\n' "$(shellcrash_web_host)" "$(shellcrash_web_port)"
|
printf 'http://%s:%s/ui/\n' "$(shellcrash_web_host)" "$(shellcrash_web_port)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Strip removed keys and force dashboard/mixed listeners so :9999 is reachable.
|
||||||
|
shellcrash_patch_runtime_yaml() {
|
||||||
|
local file="$1"
|
||||||
|
[ -s "$file" ] || return 1
|
||||||
|
command -v python3 >/dev/null 2>&1 || return 0
|
||||||
|
python3 - "$file" <<'PY' || true
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
path = Path(sys.argv[1])
|
||||||
|
lines = []
|
||||||
|
found_ec = found_mp = False
|
||||||
|
for line in path.read_text(encoding="utf-8", errors="replace").splitlines():
|
||||||
|
if line.startswith("global-client-fingerprint:"):
|
||||||
|
continue
|
||||||
|
if line.startswith("external-controller:"):
|
||||||
|
lines.append("external-controller: 0.0.0.0:9999")
|
||||||
|
found_ec = True
|
||||||
|
continue
|
||||||
|
if line.startswith("mixed-port:"):
|
||||||
|
lines.append("mixed-port: 7890")
|
||||||
|
found_mp = True
|
||||||
|
continue
|
||||||
|
lines.append(line)
|
||||||
|
if not found_ec:
|
||||||
|
lines.append("external-controller: 0.0.0.0:9999")
|
||||||
|
if not found_mp:
|
||||||
|
lines.append("mixed-port: 7890")
|
||||||
|
path.write_text("\n".join(lines).rstrip() + "\n", encoding="utf-8")
|
||||||
|
PY
|
||||||
|
}
|
||||||
|
|
||||||
|
# Prefer jsdelivr when GitHub is blocked; CrashCore otherwise exits after failed MMDB download.
|
||||||
|
ensure_shellcrash_geo_databases() {
|
||||||
|
local sc="${SHELLCRASH_DIR:-/etc/ShellCrash}"
|
||||||
|
local js="https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release"
|
||||||
|
local dest name min sz
|
||||||
|
mkdir -p "$sc"
|
||||||
|
|
||||||
|
_shellcrash_geo_download() {
|
||||||
|
local url="$1" out="$2"
|
||||||
|
if command -v curl >/dev/null 2>&1; then
|
||||||
|
curl -fsSL --connect-timeout 20 --max-time 120 -o "$out" "$url" && return 0
|
||||||
|
env -u http_proxy -u https_proxy -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u all_proxy \
|
||||||
|
curl -fsSL --connect-timeout 20 --max-time 120 -o "$out" "$url" && return 0
|
||||||
|
fi
|
||||||
|
if command -v wget >/dev/null 2>&1; then
|
||||||
|
wget -q --no-check-certificate -O "$out" "$url" && return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
for pair in "geosite.dat:GeoSite.dat:1000000" "geoip.dat:GeoIP.dat:1000000" "geoip.metadb:Country.mmdb:1000000"; do
|
||||||
|
name="${pair%%:*}"
|
||||||
|
dest="$sc/${pair#*:}"
|
||||||
|
dest="${dest%:*}"
|
||||||
|
min="${pair##*:}"
|
||||||
|
if [ -s "$dest" ]; then
|
||||||
|
sz="$(wc -c <"$dest" | tr -d '[:space:]')"
|
||||||
|
case "$sz" in
|
||||||
|
''|*[!0-9]*) ;;
|
||||||
|
*) [ "$sz" -ge "$min" ] && continue ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
echo "Fetching ShellCrash geo database $name" >&2
|
||||||
|
if _shellcrash_geo_download "$js/$name" "$dest.tmp"; then
|
||||||
|
mv -f "$dest.tmp" "$dest"
|
||||||
|
chmod 644 "$dest" 2>/dev/null || true
|
||||||
|
else
|
||||||
|
rm -f "$dest.tmp"
|
||||||
|
echo "WARN: could not download ShellCrash $name" >&2
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
shellcrash_sync_runtime_config() {
|
shellcrash_sync_runtime_config() {
|
||||||
local src="${1:-$SHELLCRASH_DIR/yamls/config.yaml}"
|
local src="${1:-$SHELLCRASH_DIR/yamls/config.yaml}"
|
||||||
local dst="/tmp/ShellCrash/config.yaml"
|
local dst="/tmp/ShellCrash/config.yaml"
|
||||||
mkdir -p "$SHELLCRASH_DIR/yamls" /tmp/ShellCrash
|
mkdir -p "$SHELLCRASH_DIR/yamls" /tmp/ShellCrash
|
||||||
if [ -s "$src" ]; then
|
if [ -s "$src" ]; then
|
||||||
|
shellcrash_patch_runtime_yaml "$src" || true
|
||||||
install -m 0644 "$src" "$dst"
|
install -m 0644 "$src" "$dst"
|
||||||
|
shellcrash_patch_runtime_yaml "$dst" || true
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
[ -s "$dst" ]
|
if [ -s "$dst" ]; then
|
||||||
|
shellcrash_patch_runtime_yaml "$dst" || true
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
patch_shellcrash_dns_repair() {
|
patch_shellcrash_dns_repair() {
|
||||||
@ -1766,6 +1850,7 @@ PY
|
|||||||
}
|
}
|
||||||
|
|
||||||
shellcrash_prepare_runtime() {
|
shellcrash_prepare_runtime() {
|
||||||
|
ensure_shellcrash_geo_databases || true
|
||||||
if ! shellcrash_sync_runtime_config; then
|
if ! shellcrash_sync_runtime_config; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -500,6 +500,9 @@ def _normalize_shellcrash_yaml(content: str, target_node: str) -> tuple[str, dic
|
|||||||
if target_node and not target_node_found:
|
if target_node and not target_node_found:
|
||||||
warning = f"Target proxy node not found: {target_node}; kept manual proxy selections"
|
warning = f"Target proxy node not found: {target_node}; kept manual proxy selections"
|
||||||
|
|
||||||
|
# Newer mihomo/meta cores reject this top-level key (use per-proxy client-fingerprint).
|
||||||
|
data.pop("global-client-fingerprint", None)
|
||||||
|
|
||||||
data["allow-lan"] = True
|
data["allow-lan"] = True
|
||||||
data["mode"] = "rule"
|
data["mode"] = "rule"
|
||||||
data["mixed-port"] = _coerce_shellcrash_port(data.get("mixed-port") or data.get("port"))
|
data["mixed-port"] = _coerce_shellcrash_port(data.get("mixed-port") or data.get("port"))
|
||||||
@ -534,7 +537,7 @@ async def apply_shellcrash_profile(
|
|||||||
|
|
||||||
stage_path = SHELLCRASH_PROFILE_STAGE.with_name(rel.name or SHELLCRASH_PROFILE_STAGE.name)
|
stage_path = SHELLCRASH_PROFILE_STAGE.with_name(rel.name or SHELLCRASH_PROFILE_STAGE.name)
|
||||||
stage_path.parent.mkdir(parents=True, exist_ok=True)
|
stage_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
stage_path.write_text(normalized, encoding="utf-8", newline="\n")
|
stage_path.write_text(normalized, encoding="utf-8")
|
||||||
with contextlib.suppress(OSError):
|
with contextlib.suppress(OSError):
|
||||||
stage_path.chmod(0o600)
|
stage_path.chmod(0o600)
|
||||||
|
|
||||||
|
|||||||
@ -79,7 +79,12 @@ def is_usable_neko_browser_proxy(url: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
if lowered == "host.docker.internal":
|
if lowered == "host.docker.internal":
|
||||||
return True
|
return True
|
||||||
return is_usable_docker_bridge_ipv4(host)
|
try:
|
||||||
|
addr = ipaddress.ip_address(host)
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
# Docker bridge, LAN Clash on Windows, or other RFC1918 HTTP proxies.
|
||||||
|
return isinstance(addr, ipaddress.IPv4Address) and bool(addr.is_private)
|
||||||
|
|
||||||
|
|
||||||
def sanitize_neko_browser_proxy(url: str) -> str:
|
def sanitize_neko_browser_proxy(url: str) -> str:
|
||||||
|
|||||||
@ -146,7 +146,7 @@ def upsert_env_file(path: Path, updates: dict[str, str]) -> None:
|
|||||||
for key, value in updates.items():
|
for key, value in updates.items():
|
||||||
if key not in seen:
|
if key not in seen:
|
||||||
out.append(f"{key}={value}")
|
out.append(f"{key}={value}")
|
||||||
path.write_text("\n".join(out) + "\n", encoding="utf-8", newline="\n")
|
path.write_text("\n".join(out) + "\n", encoding="utf-8")
|
||||||
|
|
||||||
|
|
||||||
def apply_neko_udp_range_autofix(
|
def apply_neko_udp_range_autofix(
|
||||||
|
|||||||
@ -291,6 +291,29 @@ rules:
|
|||||||
self.assertIn("IP-CIDR,192.168.0.0/16,DIRECT,no-resolve", data["rules"])
|
self.assertIn("IP-CIDR,192.168.0.0/16,DIRECT,no-resolve", data["rules"])
|
||||||
self.assertEqual(data["rules"][-1], "MATCH,PROXY")
|
self.assertEqual(data["rules"][-1], "MATCH,PROXY")
|
||||||
|
|
||||||
|
def test_shellcrash_normalize_strips_removed_global_client_fingerprint(self) -> None:
|
||||||
|
content = """
|
||||||
|
global-client-fingerprint: chrome
|
||||||
|
proxies:
|
||||||
|
- name: manual-node
|
||||||
|
type: http
|
||||||
|
server: 127.0.0.1
|
||||||
|
port: 8080
|
||||||
|
client-fingerprint: chrome
|
||||||
|
proxy-groups:
|
||||||
|
- name: PROXY
|
||||||
|
type: select
|
||||||
|
proxies:
|
||||||
|
- manual-node
|
||||||
|
rules:
|
||||||
|
- MATCH,PROXY
|
||||||
|
"""
|
||||||
|
normalized, _meta = _normalize_shellcrash_yaml(content, "manual-node")
|
||||||
|
data = yaml.safe_load(normalized)
|
||||||
|
self.assertNotIn("global-client-fingerprint", data)
|
||||||
|
self.assertEqual(data["proxies"][0]["client-fingerprint"], "chrome")
|
||||||
|
self.assertEqual(data["external-controller"], "0.0.0.0:9999")
|
||||||
|
|
||||||
def test_shellcrash_normalize_adds_neko_dedicated_listener(self) -> None:
|
def test_shellcrash_normalize_adds_neko_dedicated_listener(self) -> None:
|
||||||
content = """
|
content = """
|
||||||
proxies:
|
proxies:
|
||||||
@ -333,6 +356,10 @@ rules:
|
|||||||
|
|
||||||
self.assertIn("shellcrash_sync_runtime_config()", script)
|
self.assertIn("shellcrash_sync_runtime_config()", script)
|
||||||
self.assertIn("shellcrash_prepare_runtime()", script)
|
self.assertIn("shellcrash_prepare_runtime()", script)
|
||||||
|
self.assertIn("shellcrash_patch_runtime_yaml()", script)
|
||||||
|
self.assertIn("ensure_shellcrash_geo_databases()", script)
|
||||||
|
self.assertIn("global-client-fingerprint:", script)
|
||||||
|
self.assertIn("external-controller: 0.0.0.0:9999", script)
|
||||||
self.assertIn('install -m 0644 "$src" "$dst"', script)
|
self.assertIn('install -m 0644 "$src" "$dst"', script)
|
||||||
self.assertIn('local dst="/tmp/ShellCrash/config.yaml"', script)
|
self.assertIn('local dst="/tmp/ShellCrash/config.yaml"', script)
|
||||||
self.assertIn("ShellCrash config.yaml is missing; save/apply a YAML profile first", script)
|
self.assertIn("ShellCrash config.yaml is missing; save/apply a YAML profile first", script)
|
||||||
@ -347,6 +374,10 @@ rules:
|
|||||||
self.assertIn("SHELLCRASH_AUTO_START_ON_WEB_PANEL", script)
|
self.assertIn("SHELLCRASH_AUTO_START_ON_WEB_PANEL", script)
|
||||||
self.assertIn("shellcrash_systemd_restart", script)
|
self.assertIn("shellcrash_systemd_restart", script)
|
||||||
self.assertIn("system_direct_global_ready()", common)
|
self.assertIn("system_direct_global_ready()", common)
|
||||||
|
self.assertIn("ensure_shellcrash_geo_databases()", common)
|
||||||
|
self.assertIn("shellcrash_patch_runtime_yaml()", common)
|
||||||
|
self.assertIn("TimeoutStartSec=600", common)
|
||||||
|
self.assertIn("10.66.66.0/24", common)
|
||||||
self.assertIn("shellcrash_should_autostart_on_direct_fail()", common)
|
self.assertIn("shellcrash_should_autostart_on_direct_fail()", common)
|
||||||
self.assertIn("SHELLCRASH_AUTOSTART", common)
|
self.assertIn("SHELLCRASH_AUTOSTART", common)
|
||||||
self.assertIn("SHELLCRASH_DOCKER_CIDR", common)
|
self.assertIn("SHELLCRASH_DOCKER_CIDR", common)
|
||||||
|
|||||||
@ -32,6 +32,11 @@ class NekoDockerHostTests(unittest.TestCase):
|
|||||||
def test_accepts_valid_browser_proxy(self) -> None:
|
def test_accepts_valid_browser_proxy(self) -> None:
|
||||||
self.assertTrue(is_usable_neko_browser_proxy("http://host.docker.internal:7894"))
|
self.assertTrue(is_usable_neko_browser_proxy("http://host.docker.internal:7894"))
|
||||||
self.assertTrue(is_usable_neko_browser_proxy("http://172.20.0.1:7894"))
|
self.assertTrue(is_usable_neko_browser_proxy("http://172.20.0.1:7894"))
|
||||||
|
self.assertTrue(is_usable_neko_browser_proxy("http://192.168.21.36:7897"))
|
||||||
|
self.assertEqual(
|
||||||
|
sanitize_neko_browser_proxy("http://192.168.21.36:7897"),
|
||||||
|
"http://192.168.21.36:7897",
|
||||||
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
build_neko_browser_proxy_url("invalid IP", "7894"),
|
build_neko_browser_proxy_url("invalid IP", "7894"),
|
||||||
"http://host.docker.internal:7894",
|
"http://host.docker.internal:7894",
|
||||||
|
|||||||
@ -335,6 +335,14 @@ class VerifyLocalInstallTests(unittest.TestCase):
|
|||||||
self.assertEqual(verify_local_install.neko_required_count({"NEKO_INSTANCE_COUNT": "4"}), 4)
|
self.assertEqual(verify_local_install.neko_required_count({"NEKO_INSTANCE_COUNT": "4"}), 4)
|
||||||
self.assertEqual(verify_local_install.neko_required_count({"NEKO_INSTANCE_COUNT": "99"}), 64)
|
self.assertEqual(verify_local_install.neko_required_count({"NEKO_INSTANCE_COUNT": "99"}), 64)
|
||||||
|
|
||||||
|
def test_live_ops_unpacked_extension_is_allowed(self) -> None:
|
||||||
|
live_ops = b"/usr/bin/google-chrome\0--load-extension=/etc/neko/live-ops-extension\0"
|
||||||
|
self.assertFalse(verify_local_install.cmdline_has_forbidden_standalone_extension(live_ops))
|
||||||
|
legacy = b"/usr/bin/google-chrome\0--load-extension=/etc/neko/youtube-auto-dismiss-extension\0"
|
||||||
|
self.assertTrue(verify_local_install.cmdline_has_forbidden_standalone_extension(legacy))
|
||||||
|
other = b"/usr/bin/google-chrome\0--load-extension=/tmp/random-ext\0"
|
||||||
|
self.assertTrue(verify_local_install.cmdline_has_forbidden_standalone_extension(other))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@ -265,7 +265,7 @@ def main() -> int:
|
|||||||
# Normalize CRLF on the whole file before compose uses sourced values again.
|
# Normalize CRLF on the whole file before compose uses sourced values again.
|
||||||
text = stack_env.read_text(encoding="utf-8", errors="replace")
|
text = stack_env.read_text(encoding="utf-8", errors="replace")
|
||||||
if "\r" in text:
|
if "\r" in text:
|
||||||
stack_env.write_text(text.replace("\r\n", "\n").replace("\r", "\n"), encoding="utf-8", newline="\n")
|
stack_env.write_text(text.replace("\r\n", "\n").replace("\r", "\n"), encoding="utf-8")
|
||||||
if not args.no_udp_autofix:
|
if not args.no_udp_autofix:
|
||||||
changes = apply_neko_udp_range_autofix(count, stack_env=stack_env, persist=True)
|
changes = apply_neko_udp_range_autofix(count, stack_env=stack_env, persist=True)
|
||||||
for change in changes:
|
for change in changes:
|
||||||
@ -276,7 +276,7 @@ def main() -> int:
|
|||||||
)
|
)
|
||||||
output = Path(args.output)
|
output = Path(args.output)
|
||||||
output.parent.mkdir(parents=True, exist_ok=True)
|
output.parent.mkdir(parents=True, exist_ok=True)
|
||||||
output.write_text(render(count), encoding="utf-8", newline="\n")
|
output.write_text(render(count), encoding="utf-8")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -276,6 +276,27 @@ def verify_http(checks: list[dict[str, Any]], env: dict[str, str], *, timeout: f
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
ALLOWED_UNPACKED_EXTENSION_SUFFIXES = (b"/live-ops-extension",)
|
||||||
|
|
||||||
|
|
||||||
|
def cmdline_has_forbidden_standalone_extension(cmdline: bytes) -> bool:
|
||||||
|
"""Reject legacy YouTube unpacked extensions; allow Live Hub live-ops."""
|
||||||
|
if b"youtube-auto-" + b"dismiss-extension" in cmdline:
|
||||||
|
return True
|
||||||
|
args = [arg for arg in cmdline.split(b"\0") if arg]
|
||||||
|
for arg in args:
|
||||||
|
if not arg.startswith(b"--load-extension="):
|
||||||
|
continue
|
||||||
|
for raw_path in arg.split(b"=", 1)[1].split(b","):
|
||||||
|
path = raw_path.strip().rstrip(b"/")
|
||||||
|
if not path:
|
||||||
|
continue
|
||||||
|
if any(path.endswith(suffix) for suffix in ALLOWED_UNPACKED_EXTENSION_SUFFIXES):
|
||||||
|
continue
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def neko_required_count(env: dict[str, str]) -> int:
|
def neko_required_count(env: dict[str, str]) -> int:
|
||||||
max_count = max(2, min(64, env_int(env, "NEKO_MAX_INSTANCE_COUNT", 64)))
|
max_count = max(2, min(64, env_int(env, "NEKO_MAX_INSTANCE_COUNT", 64)))
|
||||||
return max(2, min(max_count, env_int(env, "NEKO_INSTANCE_COUNT", 2)))
|
return max(2, min(max_count, env_int(env, "NEKO_INSTANCE_COUNT", 2)))
|
||||||
@ -524,6 +545,18 @@ def verify_neko(checks: list[dict[str, Any]], env: dict[str, str], *, timeout: f
|
|||||||
"python3 - <<'PY'\n"
|
"python3 - <<'PY'\n"
|
||||||
"import os\n"
|
"import os\n"
|
||||||
"skip = {os.getpid(), os.getppid()}\n"
|
"skip = {os.getpid(), os.getppid()}\n"
|
||||||
|
"allowed_suffixes = (b'/live-ops-extension',)\n"
|
||||||
|
"def forbidden(cmdline):\n"
|
||||||
|
" if b'youtube-auto-' + b'dismiss-extension' in cmdline:\n"
|
||||||
|
" return True\n"
|
||||||
|
" for arg in [a for a in cmdline.split(b'\\0') if a]:\n"
|
||||||
|
" if not arg.startswith(b'--load-extension='):\n"
|
||||||
|
" continue\n"
|
||||||
|
" for raw in arg.split(b'=', 1)[1].split(b','):\n"
|
||||||
|
" path = raw.strip().rstrip(b'/')\n"
|
||||||
|
" if path and not any(path.endswith(sfx) for sfx in allowed_suffixes):\n"
|
||||||
|
" return True\n"
|
||||||
|
" return False\n"
|
||||||
"for name in os.listdir('/proc'):\n"
|
"for name in os.listdir('/proc'):\n"
|
||||||
" if not name.isdigit() or int(name) in skip:\n"
|
" if not name.isdigit() or int(name) in skip:\n"
|
||||||
" continue\n"
|
" continue\n"
|
||||||
@ -531,10 +564,7 @@ def verify_neko(checks: list[dict[str, Any]], env: dict[str, str], *, timeout: f
|
|||||||
" cmdline = open(f'/proc/{name}/cmdline', 'rb').read()\n"
|
" cmdline = open(f'/proc/{name}/cmdline', 'rb').read()\n"
|
||||||
" except OSError:\n"
|
" except OSError:\n"
|
||||||
" continue\n"
|
" continue\n"
|
||||||
" args = [arg for arg in cmdline.split(b'\\0') if arg]\n"
|
" if forbidden(cmdline):\n"
|
||||||
" has_unpacked_ext = any(arg.startswith(b'--load-extension=') and arg.split(b'=', 1)[1].strip() for arg in args)\n"
|
|
||||||
" has_legacy_youtube_ext = b'youtube-auto-' + b'dismiss-extension' in cmdline\n"
|
|
||||||
" if has_unpacked_ext or has_legacy_youtube_ext:\n"
|
|
||||||
" print(cmdline.replace(b'\\0', b' ').decode('utf-8', errors='replace'))\n"
|
" print(cmdline.replace(b'\\0', b' ').decode('utf-8', errors='replace'))\n"
|
||||||
" raise SystemExit(1)\n"
|
" raise SystemExit(1)\n"
|
||||||
"print('no standalone youtube extension')\n"
|
"print('no standalone youtube extension')\n"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user