mirror of
https://github.com/2dust/v2rayN.git
synced 2026-03-30 12:07:40 +00:00
Xray browser header masquerading (#8981)
Some checks are pending
release Linux / build (Release) (push) Waiting to run
release Linux / deb (push) Blocked by required conditions
release Linux / rpm (push) Blocked by required conditions
release macOS / build (Release) (push) Waiting to run
release Windows desktop (Avalonia UI) / build (Release) (push) Waiting to run
release Windows / build (Release) (push) Waiting to run
Some checks are pending
release Linux / build (Release) (push) Waiting to run
release Linux / deb (push) Blocked by required conditions
release Linux / rpm (push) Blocked by required conditions
release macOS / build (Release) (push) Waiting to run
release Windows desktop (Avalonia UI) / build (Release) (push) Waiting to run
release Windows / build (Release) (push) Waiting to run
This commit is contained in:
parent
ad11a7e6a5
commit
7ddb46e74d
3 changed files with 17 additions and 12 deletions
|
|
@ -182,13 +182,14 @@ public class Global
|
||||||
@"https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/main/v2rayN/"
|
@"https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/main/v2rayN/"
|
||||||
];
|
];
|
||||||
|
|
||||||
public static readonly Dictionary<string, string> UserAgentTexts = new()
|
public static readonly Dictionary<string, string> TcpHttpUserAgentTexts = new()
|
||||||
{
|
{
|
||||||
{"chrome","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36" },
|
{"chrome","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36" },
|
||||||
{"firefox","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0" },
|
{"firefox","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0" },
|
||||||
{"safari","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15" },
|
{"safari","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15" },
|
||||||
{"edge","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.70" },
|
{"edge","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.70" },
|
||||||
{"none",""}
|
{"none",""},
|
||||||
|
{"golang",""}
|
||||||
};
|
};
|
||||||
|
|
||||||
public const string Hysteria2ProtocolShare = "hy2://";
|
public const string Hysteria2ProtocolShare = "hy2://";
|
||||||
|
|
@ -391,9 +392,8 @@ public class Global
|
||||||
[
|
[
|
||||||
"chrome",
|
"chrome",
|
||||||
"firefox",
|
"firefox",
|
||||||
"safari",
|
|
||||||
"edge",
|
"edge",
|
||||||
"none"
|
"golang"
|
||||||
];
|
];
|
||||||
|
|
||||||
public static readonly List<string> XhttpMode =
|
public static readonly List<string> XhttpMode =
|
||||||
|
|
|
||||||
|
|
@ -421,6 +421,8 @@ public class HttpupgradeSettings4Ray
|
||||||
public string? path { get; set; }
|
public string? path { get; set; }
|
||||||
|
|
||||||
public string? host { get; set; }
|
public string? host { get; set; }
|
||||||
|
|
||||||
|
public Headers4Ray headers { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class XhttpSettings4Ray
|
public class XhttpSettings4Ray
|
||||||
|
|
@ -456,6 +458,7 @@ public class GrpcSettings4Ray
|
||||||
public int? health_check_timeout { get; set; }
|
public int? health_check_timeout { get; set; }
|
||||||
public bool? permit_without_stream { get; set; }
|
public bool? permit_without_stream { get; set; }
|
||||||
public int? initial_windows_size { get; set; }
|
public int? initial_windows_size { get; set; }
|
||||||
|
public string? user_agent { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class HysteriaSettings4Ray
|
public class HysteriaSettings4Ray
|
||||||
|
|
|
||||||
|
|
@ -354,11 +354,7 @@ public partial class CoreConfigV2rayService
|
||||||
var host = _node.RequestHost.TrimEx();
|
var host = _node.RequestHost.TrimEx();
|
||||||
var path = _node.Path.TrimEx();
|
var path = _node.Path.TrimEx();
|
||||||
var sni = _node.Sni.TrimEx();
|
var sni = _node.Sni.TrimEx();
|
||||||
var useragent = "";
|
var useragent = _config.CoreBasicItem.DefUserAgent ?? string.Empty;
|
||||||
if (!_config.CoreBasicItem.DefUserAgent.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
useragent = Global.UserAgentTexts.GetValueOrDefault(_config.CoreBasicItem.DefUserAgent, _config.CoreBasicItem.DefUserAgent);
|
|
||||||
}
|
|
||||||
|
|
||||||
//if tls
|
//if tls
|
||||||
if (_node.StreamSecurity == Global.StreamSecurity)
|
if (_node.StreamSecurity == Global.StreamSecurity)
|
||||||
|
|
@ -496,13 +492,17 @@ public partial class CoreConfigV2rayService
|
||||||
case nameof(ETransport.httpupgrade):
|
case nameof(ETransport.httpupgrade):
|
||||||
HttpupgradeSettings4Ray httpupgradeSettings = new();
|
HttpupgradeSettings4Ray httpupgradeSettings = new();
|
||||||
|
|
||||||
|
if (host.IsNotEmpty())
|
||||||
|
{
|
||||||
|
httpupgradeSettings.host = host;
|
||||||
|
}
|
||||||
if (path.IsNotEmpty())
|
if (path.IsNotEmpty())
|
||||||
{
|
{
|
||||||
httpupgradeSettings.path = path;
|
httpupgradeSettings.path = path;
|
||||||
}
|
}
|
||||||
if (host.IsNotEmpty())
|
if (useragent.IsNotEmpty())
|
||||||
{
|
{
|
||||||
httpupgradeSettings.host = host;
|
httpupgradeSettings.headers.UserAgent = useragent;
|
||||||
}
|
}
|
||||||
streamSettings.httpupgradeSettings = httpupgradeSettings;
|
streamSettings.httpupgradeSettings = httpupgradeSettings;
|
||||||
|
|
||||||
|
|
@ -581,6 +581,7 @@ public partial class CoreConfigV2rayService
|
||||||
health_check_timeout = _config.GrpcItem.HealthCheckTimeout,
|
health_check_timeout = _config.GrpcItem.HealthCheckTimeout,
|
||||||
permit_without_stream = _config.GrpcItem.PermitWithoutStream,
|
permit_without_stream = _config.GrpcItem.PermitWithoutStream,
|
||||||
initial_windows_size = _config.GrpcItem.InitialWindowsSize,
|
initial_windows_size = _config.GrpcItem.InitialWindowsSize,
|
||||||
|
user_agent = useragent.NullIfEmpty(),
|
||||||
};
|
};
|
||||||
streamSettings.grpcSettings = grpcSettings;
|
streamSettings.grpcSettings = grpcSettings;
|
||||||
break;
|
break;
|
||||||
|
|
@ -655,10 +656,11 @@ public partial class CoreConfigV2rayService
|
||||||
|
|
||||||
//request Host
|
//request Host
|
||||||
var request = EmbedUtils.GetEmbedText(Global.V2raySampleHttpRequestFileName);
|
var request = EmbedUtils.GetEmbedText(Global.V2raySampleHttpRequestFileName);
|
||||||
|
var useragentValue = Global.TcpHttpUserAgentTexts.GetValueOrDefault(useragent, useragent);
|
||||||
var arrHost = host.Split(',');
|
var arrHost = host.Split(',');
|
||||||
var host2 = string.Join(",".AppendQuotes(), arrHost);
|
var host2 = string.Join(",".AppendQuotes(), arrHost);
|
||||||
request = request.Replace("$requestHost$", $"{host2.AppendQuotes()}");
|
request = request.Replace("$requestHost$", $"{host2.AppendQuotes()}");
|
||||||
request = request.Replace("$requestUserAgent$", $"{useragent.AppendQuotes()}");
|
request = request.Replace("$requestUserAgent$", $"{useragentValue.AppendQuotes()}");
|
||||||
//Path
|
//Path
|
||||||
var pathHttp = @"/";
|
var pathHttp = @"/";
|
||||||
if (path.IsNotEmpty())
|
if (path.IsNotEmpty())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue