feat: hy2 host rewrite
This commit is contained in:
9 files changed
+56
-5
No files matched your search
@@ -63,6 +63,7 @@ Part of the [proxy-suite options reference](./index.md).
|
||||
- hysteria
|
||||
- [masquerade](#services-proxy-suite-inbounds-listeners-name-hysteria-masquerade)
|
||||
- [portHopping](#services-proxy-suite-inbounds-listeners-name-hysteria-porthopping)
|
||||
- [rewriteHost](#services-proxy-suite-inbounds-listeners-name-hysteria-rewritehost)
|
||||
- salamander
|
||||
- [enable](#services-proxy-suite-inbounds-listeners-name-hysteria-salamander-enable)
|
||||
- [password](#services-proxy-suite-inbounds-listeners-name-hysteria-salamander-password)
|
||||
@@ -657,6 +658,17 @@ ephemeral range (32768 and up on Linux)\.
|
||||
**Default:** `null`\
|
||||
**Example:** `"20000-30000"`
|
||||
|
||||
<a id="services-proxy-suite-inbounds-listeners-name-hysteria-rewritehost"></a>
|
||||
## services\.proxy-suite\.inbounds\.listeners\.\<name>\.hysteria\.rewriteHost
|
||||
|
||||
Ask ` masquerade ` for its own name, whatever name the client asked for\. ` false `
|
||||
passes the client’s on, for a ` masquerade ` that is this host’s own web server: a
|
||||
probe then gets the site it named, as it would over TCP, instead of the same one
|
||||
for every name\. Another operator’s site would answer those names with an error\.
|
||||
|
||||
**Type:** boolean\
|
||||
**Default:** `true`
|
||||
|
||||
<a id="services-proxy-suite-inbounds-listeners-name-hysteria-salamander-enable"></a>
|
||||
## services\.proxy-suite\.inbounds\.listeners\.\<name>\.hysteria\.salamander\.enable
|
||||
|
||||
|
||||
@@ -593,6 +593,17 @@ let
|
||||
`null`: answer 404.
|
||||
'' "https://www.example.com";
|
||||
|
||||
hysteria.rewriteHost = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Ask `masquerade` for its own name, whatever name the client asked for. `false`
|
||||
passes the client's on, for a `masquerade` that is this host's own web server: a
|
||||
probe then gets the site it named, as it would over TCP, instead of the same one
|
||||
for every name. Another operator's site would answer those names with an error.
|
||||
'';
|
||||
};
|
||||
|
||||
hysteria.salamander = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
|
||||
@@ -856,6 +856,9 @@ let
|
||||
(mkAssertion (
|
||||
!proxyInboundsEnabled || l.hysteria.masquerade == null || l.type == "hysteria2"
|
||||
) "${prefix}: hysteria.masquerade is for hysteria2 listeners only")
|
||||
(mkAssertion (
|
||||
!proxyInboundsEnabled || l.hysteria.rewriteHost || l.hysteria.masquerade != null
|
||||
) "${prefix}: hysteria.rewriteHost = false needs hysteria.masquerade")
|
||||
(mkAssertion (
|
||||
!proxyInboundsEnabled
|
||||
|| (!l.hysteria.salamander.enable && l.hysteria.portHopping == null)
|
||||
|
||||
@@ -1383,6 +1383,7 @@ let
|
||||
(lib.head (builtins.filter (l: l.tag == "hy2-in") firewallSpec.listeners)).hysteria.masquerade
|
||||
== "https://www.example.com"
|
||||
))
|
||||
(ok (lib.head (builtins.filter (l: l.tag == "hy2-in") firewallSpec.listeners)).hysteria.rewriteHost)
|
||||
(ok (noFirewallFixture.config.networking.firewall.allowedTCPPorts == [ ]))
|
||||
|
||||
# The unit exists, and only waits on the client stack when it relays.
|
||||
|
||||
@@ -238,6 +238,7 @@ INBOUND_ADD_FLAGS = {
|
||||
"--fingerprint": "browser fingerprint in share links (fp)",
|
||||
"--order": "position in links and subscriptions",
|
||||
"--masquerade": "hysteria2: site shown to anything else",
|
||||
"--keep-host": "hysteria2: pass --masquerade the name asked for (this host's own web server)",
|
||||
"--salamander": "hysteria2: Salamander obfuscation",
|
||||
"--user": "a user it accepts",
|
||||
}
|
||||
|
||||
@@ -343,6 +343,7 @@ LISTENER_SCHEMA = {
|
||||
"fallbacks": "fallbacks",
|
||||
"hysteria": {
|
||||
"masquerade": _nullable(_nonspace),
|
||||
"rewriteHost": _is_bool,
|
||||
"salamander": {
|
||||
"enable": _is_bool,
|
||||
"password": _nullable(_nonspace),
|
||||
@@ -666,6 +667,8 @@ def listener_problems(listener: dict, runtime: dict, share_links: bool, shared:
|
||||
"hysteria2 takes no reality or transport")
|
||||
need(hysteria.get("masquerade") is None or kind == "hysteria2",
|
||||
"hysteria.masquerade is for hysteria2 listeners only")
|
||||
need(hysteria.get("rewriteHost", True) or hysteria.get("masquerade") is not None,
|
||||
"hysteria.rewriteHost = false needs hysteria.masquerade")
|
||||
# XRay dials both for anyone, past routing: not this host or its LAN (a local decoy is
|
||||
# declared). Names are not resolved, so port 443 keeps one that resolves inside to TLS.
|
||||
if reality["enable"]:
|
||||
@@ -1298,6 +1301,8 @@ def listener_from_flags(kind: str, args: argparse.Namespace) -> dict:
|
||||
hysteria: dict = {}
|
||||
if args.masquerade:
|
||||
hysteria["masquerade"] = args.masquerade
|
||||
if args.keep_host:
|
||||
hysteria["rewriteHost"] = False
|
||||
if args.salamander:
|
||||
hysteria["salamander"] = {"enable": True}
|
||||
if hysteria:
|
||||
@@ -1458,6 +1463,7 @@ def main(argv: list[str] | None = None) -> int:
|
||||
("--sni", str), ("--reality", str), ("--reality-dest", str), ("--short-id", str),
|
||||
("--masquerade", str)):
|
||||
add.add_argument(flag, type=kind)
|
||||
add.add_argument("--keep-host", action="store_true")
|
||||
add.add_argument("--salamander", action="store_true")
|
||||
add.add_argument("--user", action="append", default=[])
|
||||
|
||||
|
||||
@@ -128,9 +128,10 @@ def _xray_stream(listener: dict, tag: str) -> dict:
|
||||
if listener["type"] == "hysteria2":
|
||||
# QUIC: the transport is hysteria's own, always under TLS.
|
||||
settings = {"version": 2}
|
||||
masquerade = (listener.get("hysteria") or {}).get("masquerade")
|
||||
hysteria = listener.get("hysteria") or {}
|
||||
masquerade = hysteria.get("masquerade")
|
||||
if masquerade:
|
||||
settings["masquerade"] = {"type": "proxy", "url": masquerade, "rewriteHost": True}
|
||||
settings["masquerade"] = {"type": "proxy", "url": masquerade, "rewriteHost": hysteria.get("rewriteHost", True)}
|
||||
stream = {
|
||||
"network": "hysteria",
|
||||
"hysteriaSettings": settings,
|
||||
|
||||
@@ -465,7 +465,11 @@ class RoundTripTests(unittest.TestCase):
|
||||
self.assertEqual(stream["network"], "hysteria")
|
||||
self.assertEqual(stream["security"], "tls")
|
||||
self.assertEqual(stream["tlsSettings"]["alpn"], ["h3"])
|
||||
self.assertEqual(stream["hysteriaSettings"]["masquerade"]["url"], "https://www.example.com")
|
||||
self.assertEqual(stream["hysteriaSettings"]["masquerade"],
|
||||
{"type": "proxy", "url": "https://www.example.com", "rewriteHost": True})
|
||||
# This host's own web server: the name the client asked for goes on to it.
|
||||
own = render_xray_inbound(dict(spec, hysteria={"masquerade": "https://www.example.com", "rewriteHost": False}))
|
||||
self.assertFalse(own["streamSettings"]["hysteriaSettings"]["masquerade"]["rewriteHost"])
|
||||
link = build_share_link(spec, "vpn.example.com")
|
||||
self.assertTrue(link.startswith("hysteria2://p%40ss%2Fword@vpn.example.com:8443?"), link)
|
||||
self.assertEqual(link_params(link)["alpn"], "h3")
|
||||
|
||||
@@ -19,7 +19,8 @@ LISTENER_DEFAULTS = {
|
||||
"address": "::",
|
||||
"fallbacks": [],
|
||||
"flow": None,
|
||||
"hysteria": {"masquerade": None, "portHopping": None, "salamander": {"enable": False, "password": None, "passwordFile": None}},
|
||||
"hysteria": {"masquerade": None, "portHopping": None, "rewriteHost": True,
|
||||
"salamander": {"enable": False, "password": None, "passwordFile": None}},
|
||||
"method": "2022-blake3-aes-128-gcm",
|
||||
"order": 1000,
|
||||
"port": 443,
|
||||
@@ -278,7 +279,7 @@ class RuntimeTest(unittest.TestCase):
|
||||
port=20001, listen=None, via=None, share_port=None, share_address=None, fingerprint="firefox", order=None, method=None,
|
||||
flow="vision", transport=None, path=None, host=None, mode=None, service_name=None, tls=None, alpn=None,
|
||||
sni=None, reality="www.example.com,example.com", reality_dest=None, short_id=None, masquerade=None,
|
||||
salamander=False, user=["bob"],
|
||||
keep_host=False, salamander=False, user=["bob"],
|
||||
)
|
||||
entry = rt.listener_from_flags("vless", args)
|
||||
self.assertEqual(entry["reality"]["dest"], "www.example.com:443")
|
||||
@@ -345,6 +346,11 @@ class RuntimeTest(unittest.TestCase):
|
||||
# A name may resolve inside (localtest.me is 127.0.0.1): a web port only.
|
||||
({"type": "hysteria2", "port": 20001, "tls": {"certificate": "main"},
|
||||
"hysteria": {"masquerade": "http://localtest.me:9090/"}}, "masquerade .* port 80 or 443"),
|
||||
# Nothing to pass the name to: XRay answers 404.
|
||||
({"type": "hysteria2", "port": 20001, "tls": {"certificate": "main"},
|
||||
"hysteria": {"rewriteHost": False}}, "rewriteHost = false needs hysteria.masquerade"),
|
||||
({"type": "hysteria2", "port": 20001, "tls": {"certificate": "main"},
|
||||
"hysteria": {"masquerade": "https://www.example.com", "rewriteHost": "no"}}, "rewriteHost: invalid value"),
|
||||
# Values XRay refuses, with the declared listeners along with them.
|
||||
({"type": "vless", "port": 20001, "reality": {"enable": True, "serverNames": ["a.com"], "shortIds": ["abc"]}},
|
||||
"shortIds: invalid"),
|
||||
@@ -556,6 +562,12 @@ class RuntimeTest(unittest.TestCase):
|
||||
self.assertIn("already exists", err)
|
||||
status, out, _ = self.run_main("show", "hy")
|
||||
self.assertTrue(json.loads(out)["hysteria"]["salamander"]["enable"])
|
||||
self.assertNotIn("rewriteHost", json.loads(out)["hysteria"])
|
||||
status, out, _ = self.run_main("add", "hy-own", "hysteria2", "--port", "20007", "--tls", "main",
|
||||
"--masquerade", "https://www.example.com", "--keep-host", "--user", "alice")
|
||||
self.assertEqual(status, 0, out)
|
||||
status, out, _ = self.run_main("show", "hy-own")
|
||||
self.assertEqual(json.loads(out)["hysteria"], {"masquerade": "https://www.example.com", "rewriteHost": False})
|
||||
|
||||
def test_check_names_the_awg_unit_when_its_peers_change(self):
|
||||
users = os.path.join(self.tmp.name, "users.json")
|
||||
|
||||
Reference in new issue
Block a user