Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic
C ccybersecurityhttp3httpproxylinuxlinux-proxymacosmacos-appmacos-proxyproxifierproxifier-alternativeproxyclienttcpthick-clientudpwindivertwindows
4.0.8-beta #33 - Added domain-based proxy rules
AnoF-Cyberf968d8e804ea
diff --git a/Windows/cli/main.c b/Windows/cli/main.cindex cd888f3..7c4e789 100644--- a/Windows/cli/main.c+++ b/Windows/cli/main.c@@ -16,7 +16,7 @@#pragma comment(lib, "advapi32.lib")-#define VERSION "4.0.0"+#define VERSION "4.0.8-Beta"#define MAX_PROXY_CONFIGS 16#define MAX_RULES 256@@ -24,7 +24,8 @@typedef uint32_t (*pfnAddProxyConfig)(int type, const char* ip, uint16_t port,const char* user, const char* pass);typedef uint32_t (*pfnAddRule)(const char* process, const char* hosts,- const char* ports, int protocol, int action,+ const char* ports, const char* domains,+ int protocol, int action,uint32_t config_id);typedef int (*pfnDisableRule)(uint32_t rule_id);typedef void (*pfnSetLogCallback)(void (*cb)(const char*));@@ -60,6 +61,7 @@ typedef struct {char process_name[256];char target_hosts[512];char target_ports[256];+ char target_domains[512]; // "*", "google.com", "*.google.com;*.gstatic.com"int protocol; // 0=TCP, 1=UDP, 2=BOTHint action; // 0=PROXY, 1=DIRECT, 2=BLOCKint is_enabled;@@ -369,6 +371,7 @@ static bool load_profile(const char* path, PBProfile* prof)jstr(buf, "ProcessName", r->process_name, sizeof(r->process_name));jstr(buf, "TargetHosts", r->target_hosts, sizeof(r->target_hosts));jstr(buf, "TargetPorts", r->target_ports, sizeof(r->target_ports));+ jstr(buf, "TargetDomains", r->target_domains, sizeof(r->target_domains));char ps[16] = {0};jstr(buf, "Protocol", ps, sizeof(ps));@@ -919,11 +922,12 @@ int main(int argc, char* argv[])dll_cfg_id = id_map[0].dll_id; // fallback: first config}- const char* proc = r->process_name[0] ? r->process_name : "*";- const char* hosts = r->target_hosts[0] ? r->target_hosts : "*";- const char* ports = r->target_ports[0] ? r->target_ports : "*";+ const char* proc = r->process_name[0] ? r->process_name : "*";+ const char* hosts = r->target_hosts[0] ? r->target_hosts : "*";+ const char* ports = r->target_ports[0] ? r->target_ports : "*";+ const char* domains = r->target_domains[0] ? r->target_domains : "*";- uint32_t rid = g_AddRule(proc, hosts, ports,+ uint32_t rid = g_AddRule(proc, hosts, ports, domains,r->protocol, r->action, dll_cfg_id);if (rid == 0){@@ -938,8 +942,8 @@ int main(int argc, char* argv[])int p = r->protocol < 3 ? r->protocol : 0;int a = r->action < 3 ? r->action : 0;- printf(" [%d] %-28s %-22s %-14s %s %s%s\n",- i + 1, proc, hosts, ports,+ printf(" [%d] %-28s %-22s %-14s %-20s %s %s%s\n",+ i + 1, proc, hosts, ports, domains,PROTO[p], ACTION[a],r->is_enabled ? "" : " [disabled]");ok++;diff --git a/Windows/gui/Interop/ProxyBridgeNative.cs b/Windows/gui/Interop/ProxyBridgeNative.csindex a25b34b..7d7af51 100644--- a/Windows/gui/Interop/ProxyBridgeNative.cs+++ b/Windows/gui/Interop/ProxyBridgeNative.cs@@ -58,6 +58,7 @@ public static class ProxyBridgeNative[MarshalAs(UnmanagedType.LPUTF8Str)] string processName,[MarshalAs(UnmanagedType.LPStr)] string targetHosts,[MarshalAs(UnmanagedType.LPStr)] string targetPorts,+ [MarshalAs(UnmanagedType.LPStr)] string targetDomains,RuleProtocol protocol,RuleAction action,uint proxyConfigId);@@ -81,6 +82,7 @@ public static class ProxyBridgeNative[MarshalAs(UnmanagedType.LPUTF8Str)] string processName,[MarshalAs(UnmanagedType.LPStr)] string targetHosts,[MarshalAs(UnmanagedType.LPStr)] string targetPorts,+ [MarshalAs(UnmanagedType.LPStr)] string targetDomains,RuleProtocol protocol,RuleAction action,uint proxyConfigId);diff --git a/Windows/gui/ProxyBridge.GUI.csproj b/Windows/gui/ProxyBridge.GUI.csprojindex 89c2a84..036b588 100644--- a/Windows/gui/ProxyBridge.GUI.csproj+++ b/Windows/gui/ProxyBridge.GUI.csproj@@ -7,9 +7,9 @@<ApplicationManifest>app.manifest</ApplicationManifest><AssemblyName>ProxyBridge</AssemblyName><RootNamespace>ProxyBridge.GUI</RootNamespace>- <Version>4.0.0</Version>- <AssemblyVersion>4.0.0</AssemblyVersion>- <FileVersion>4.0.0</FileVersion>+ <Version>4.0.8-Beta</Version>+ <AssemblyVersion>4.0.8</AssemblyVersion>+ <FileVersion>4.0.8</FileVersion><ApplicationIcon>Assets\logo.ico</ApplicationIcon><Company>InterceptSuite</Company><Product>ProxyBridge</Product>diff --git a/Windows/gui/Resources/Resources.Designer.cs b/Windows/gui/Resources/Resources.Designer.csindex 75cdab5..fdf0989 100644--- a/Windows/gui/Resources/Resources.Designer.cs+++ b/Windows/gui/Resources/Resources.Designer.cs@@ -443,6 +443,8 @@ namespace ProxyBridge.GUI.Resources {internal static string ExampleApplications => ResourceManager.GetString("ExampleApplications", resourceCulture);internal static string ExampleTargetHosts => ResourceManager.GetString("ExampleTargetHosts", resourceCulture);internal static string ExampleTargetPorts => ResourceManager.GetString("ExampleTargetPorts", resourceCulture);+ internal static string LabelTargetDomains => ResourceManager.GetString("LabelTargetDomains", resourceCulture);+ internal static string ExampleTargetDomains => ResourceManager.GetString("ExampleTargetDomains", resourceCulture);internal static string ProtocolTCP => ResourceManager.GetString("ProtocolTCP", resourceCulture);internal static string ProtocolUDP => ResourceManager.GetString("ProtocolUDP", resourceCulture);internal static string ProtocolBoth => ResourceManager.GetString("ProtocolBoth", resourceCulture);diff --git a/Windows/gui/Resources/Resources.resx b/Windows/gui/Resources/Resources.resxindex fc8e62e..013e2ea 100644--- a/Windows/gui/Resources/Resources.resx+++ b/Windows/gui/Resources/Resources.resx@@ -243,6 +243,9 @@<data name="LabelTargetPorts" xml:space="preserve"><value>Target Ports</value></data>+ <data name="LabelTargetDomains" xml:space="preserve">+ <value>Target Domains</value>+ </data><data name="LabelProtocol" xml:space="preserve"><value>Protocol</value></data>@@ -264,6 +267,9 @@<data name="ExampleTargetPorts" xml:space="preserve"><value>Example: 80; 8000-9000; 3128</value></data>+ <data name="ExampleTargetDomains" xml:space="preserve">+ <value>Example: google.com; *.google.com; *.gstatic.com (requires unencrypted DNS)</value>+ </data><data name="ProtocolTCP" xml:space="preserve"><value>TCP</value></data>diff --git a/Windows/gui/Resources/Resources.zh.resx b/Windows/gui/Resources/Resources.zh.resxindex 26d5ad8..9cfd826 100644--- a/Windows/gui/Resources/Resources.zh.resx+++ b/Windows/gui/Resources/Resources.zh.resx@@ -244,6 +244,9 @@<data name="LabelTargetPorts" xml:space="preserve"><value>目标端口</value></data>+ <data name="LabelTargetDomains" xml:space="preserve">+ <value>目标域名</value>+ </data><data name="LabelProtocol" xml:space="preserve"><value>协议</value></data>@@ -265,6 +268,9 @@<data name="ExampleTargetPorts" xml:space="preserve"><value>示例: 80; 8000-9000; 3128</value></data>+ <data name="ExampleTargetDomains" xml:space="preserve">+ <value>示例: google.com; *.google.com; *.gstatic.com (需要未加密的 DNS)</value>+ </data><data name="ProtocolTCP" xml:space="preserve"><value>TCP</value></data>diff --git a/Windows/gui/Services/Loc.cs b/Windows/gui/Services/Loc.csindex f3ab9c3..e7e0f0a 100644--- a/Windows/gui/Services/Loc.cs+++ b/Windows/gui/Services/Loc.cs@@ -123,6 +123,7 @@ public class Loc : INotifyPropertyChangedpublic string ProcessLabel => Resources.Resources.LabelProcess;public string TargetHostsLabel => Resources.Resources.LabelTargetHosts;public string TargetPortsLabel => Resources.Resources.LabelTargetPorts;+ public string TargetDomainsLabel => Resources.Resources.LabelTargetDomains;public string ProtocolLabel => Resources.Resources.LabelProtocol;public string ActionLabel => Resources.Resources.LabelAction;public string ApplicationsLabel => Resources.Resources.LabelApplications;@@ -130,6 +131,7 @@ public class Loc : INotifyPropertyChangedpublic string ExampleApplications => Resources.Resources.ExampleApplications;public string ExampleTargetHosts => Resources.Resources.ExampleTargetHosts;public string ExampleTargetPorts => Resources.Resources.ExampleTargetPorts;+ public string ExampleTargetDomains => Resources.Resources.ExampleTargetDomains;public string ProtocolTCP => Resources.Resources.ProtocolTCP;public string ProtocolUDP => Resources.Resources.ProtocolUDP;public string ProtocolBoth => Resources.Resources.ProtocolBoth;diff --git a/Windows/gui/Services/ProfileManager.cs b/Windows/gui/Services/ProfileManager.csindex 7792b9c..765ca50 100644--- a/Windows/gui/Services/ProfileManager.cs+++ b/Windows/gui/Services/ProfileManager.cs@@ -32,6 +32,7 @@ public class ProxyRuleConfigpublic string ProcessName { get; set; } = "";public string TargetHosts { get; set; } = "*";public string TargetPorts { get; set; } = "*";+ public string TargetDomains { get; set; } = "*";public string Protocol { get; set; } = "TCP";public string Action { get; set; } = "PROXY";public bool IsEnabled { get; set; } = true;diff --git a/Windows/gui/Services/ProxyBridgeService.cs b/Windows/gui/Services/ProxyBridgeService.csindex 3662721..e33e0f6 100644--- a/Windows/gui/Services/ProxyBridgeService.cs+++ b/Windows/gui/Services/ProxyBridgeService.cs@@ -84,7 +84,7 @@ public class ProxyBridgeService : IDisposablereturn buffer.ToString();}- public uint AddRule(string processName, string targetHosts, string targetPorts, string protocol, string action, uint proxyConfigId = 0)+ public uint AddRule(string processName, string targetHosts, string targetPorts, string targetDomains, string protocol, string action, uint proxyConfigId = 0){ProxyBridgeNative.RuleAction ruleAction;if (string.Equals(action, "DIRECT", StringComparison.OrdinalIgnoreCase))@@ -103,7 +103,7 @@ public class ProxyBridgeService : IDisposableelseruleProtocol = ProxyBridgeNative.RuleProtocol.TCP;- return ProxyBridgeNative.ProxyBridge_AddRule(processName, targetHosts, targetPorts, ruleProtocol, ruleAction, proxyConfigId);+ return ProxyBridgeNative.ProxyBridge_AddRule(processName, targetHosts, targetPorts, targetDomains ?? "*", ruleProtocol, ruleAction, proxyConfigId);}public bool EnableRule(uint ruleId)@@ -121,7 +121,7 @@ public class ProxyBridgeService : IDisposablereturn ProxyBridgeNative.ProxyBridge_DeleteRule(ruleId);}- public bool EditRule(uint ruleId, string processName, string targetHosts, string targetPorts, string protocol, string action, uint proxyConfigId = 0)+ public bool EditRule(uint ruleId, string processName, string targetHosts, string targetPorts, string targetDomains, string protocol, string action, uint proxyConfigId = 0){ProxyBridgeNative.RuleAction ruleAction;if (string.Equals(action, "DIRECT", StringComparison.OrdinalIgnoreCase))@@ -140,7 +140,7 @@ public class ProxyBridgeService : IDisposableelseruleProtocol = ProxyBridgeNative.RuleProtocol.TCP;- return ProxyBridgeNative.ProxyBridge_EditRule(ruleId, processName, targetHosts, targetPorts, ruleProtocol, ruleAction, proxyConfigId);+ return ProxyBridgeNative.ProxyBridge_EditRule(ruleId, processName, targetHosts, targetPorts, targetDomains ?? "*", ruleProtocol, ruleAction, proxyConfigId);}public uint GetRulePosition(uint ruleId)diff --git a/Windows/gui/ViewModels/AboutViewModel.cs b/Windows/gui/ViewModels/AboutViewModel.csindex bf71576..b85f932 100644--- a/Windows/gui/ViewModels/AboutViewModel.cs+++ b/Windows/gui/ViewModels/AboutViewModel.cs@@ -16,9 +16,15 @@ public class AboutViewModelpublic AboutViewModel(Action onClose){- var version = Assembly.GetExecutingAssembly().GetName().Version;- Version = version != null- ? $"Version {version.Major}.{version.Minor}.{version.Build}"+ // AssemblyVersion (AssemblyName.Version) is strictly numeric — .NET drops any+ // "-Beta" suffix before it gets there. The csproj's <Version> (which does keep+ // suffixes like "4.0.8-Beta") is embedded as AssemblyInformationalVersionAttribute,+ // so read that instead to show the real product version, beta tag included.+ var infoVersion = Assembly.GetExecutingAssembly()+ .GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;++ Version = !string.IsNullOrWhiteSpace(infoVersion)+ ? $"Version {infoVersion}": "Version 1.0.0";CloseCommand = new RelayCommand(onClose);diff --git a/Windows/gui/ViewModels/MainWindowViewModel.cs b/Windows/gui/ViewModels/MainWindowViewModel.csindex f4a97fa..8796759 100644--- a/Windows/gui/ViewModels/MainWindowViewModel.cs+++ b/Windows/gui/ViewModels/MainWindowViewModel.cs@@ -152,7 +152,7 @@ public class MainWindowViewModel : ViewModelBaserule.ProxyConfigId = nativeProxyId;uint ruleId = _proxyService.AddRule(- rule.ProcessName, rule.TargetHosts, rule.TargetPorts,+ rule.ProcessName, rule.TargetHosts, rule.TargetPorts, rule.TargetDomains,rule.Protocol, rule.Action, nativeProxyId);if (ruleId > 0)@@ -447,7 +447,7 @@ public class MainWindowViewModel : ViewModelBaseif (_proxyService != null){uint ruleId = _proxyService.AddRule(- rule.ProcessName, rule.TargetHosts, rule.TargetPorts,+ rule.ProcessName, rule.TargetHosts, rule.TargetPorts, rule.TargetDomains,rule.Protocol, rule.Action, rule.ProxyConfigId);if (ruleId > 0){@@ -583,7 +583,7 @@ public class MainWindowViewModel : ViewModelBaseif (_proxyService != null){- var ruleId = _proxyService.AddRule(NewProcessName, "*", "*", "TCP", NewProxyAction);+ var ruleId = _proxyService.AddRule(NewProcessName, "*", "*", "*", "TCP", NewProxyAction);if (ruleId > 0){rule.RuleId = ruleId;@@ -1109,6 +1109,7 @@ public class MainWindowViewModel : ViewModelBaseProcessName = rc.ProcessName,TargetHosts = ValidationHelper.DefaultIfEmpty(rc.TargetHosts),TargetPorts = ValidationHelper.DefaultIfEmpty(rc.TargetPorts),+ TargetDomains = ValidationHelper.DefaultIfEmpty(rc.TargetDomains),Protocol = ValidationHelper.DefaultIfEmpty(rc.Protocol, "TCP"),Action = ValidationHelper.DefaultIfEmpty(rc.Action, "PROXY"),IsEnabled = rc.IsEnabled,@@ -1207,6 +1208,7 @@ public class MainWindowViewModel : ViewModelBaseProcessName = rc.ProcessName,TargetHosts = ValidationHelper.DefaultIfEmpty(rc.TargetHosts),TargetPorts = ValidationHelper.DefaultIfEmpty(rc.TargetPorts),+ TargetDomains = ValidationHelper.DefaultIfEmpty(rc.TargetDomains),Protocol = ValidationHelper.DefaultIfEmpty(rc.Protocol, "TCP"),Action = ValidationHelper.DefaultIfEmpty(rc.Action, "PROXY"),IsEnabled = rc.IsEnabled,@@ -1217,7 +1219,7 @@ public class MainWindowViewModel : ViewModelBaseif (_proxyService != null){uint ruleId = _proxyService.AddRule(- rule.ProcessName, rule.TargetHosts, rule.TargetPorts,+ rule.ProcessName, rule.TargetHosts, rule.TargetPorts, rule.TargetDomains,rule.Protocol, rule.Action, nativeProxyId);if (ruleId > 0){@@ -1284,6 +1286,7 @@ public class MainWindowViewModel : ViewModelBaseProcessName = r.ProcessName,TargetHosts = r.TargetHosts,TargetPorts = r.TargetPorts,+ TargetDomains = r.TargetDomains,Protocol = r.Protocol,Action = r.Action,IsEnabled = r.IsEnabled,@@ -1318,6 +1321,7 @@ public class ProxyRule : ViewModelBaseprivate string _processName = "*";private string _targetHosts = "*";private string _targetPorts = "*";+ private string _targetDomains = "*";private string _protocol = "TCP";private string _action = "PROXY";private bool _isEnabled = true;@@ -1355,6 +1359,12 @@ public class ProxyRule : ViewModelBaseset => SetProperty(ref _targetPorts, value);}+ public string TargetDomains+ {+ get => _targetDomains;+ set => SetProperty(ref _targetDomains, value);+ }+public string Protocol{get => _protocol;diff --git a/Windows/gui/ViewModels/ProxyRulesViewModel.cs b/Windows/gui/ViewModels/ProxyRulesViewModel.csindex 7f2529b..8234262 100644--- a/Windows/gui/ViewModels/ProxyRulesViewModel.cs+++ b/Windows/gui/ViewModels/ProxyRulesViewModel.cs@@ -24,6 +24,7 @@ public class ProxyRulesViewModel : ViewModelBaseprivate string _newProcessName = "*";private string _newTargetHosts = "*";private string _newTargetPorts = "*";+ private string _newTargetDomains = "*";private string _newProtocol = "TCP"; // TCP, UDP, or BOTHprivate RuleActionItem? _selectedRuleAction;private string _processNameError = "";@@ -64,6 +65,12 @@ public class ProxyRulesViewModel : ViewModelBaseset => SetProperty(ref _newTargetPorts, value);}+ public string NewTargetDomains+ {+ get => _newTargetDomains;+ set => SetProperty(ref _newTargetDomains, value);+ }+public string NewProtocol{get => _newProtocol;@@ -120,6 +127,7 @@ public class ProxyRulesViewModel : ViewModelBaseNewProcessName = "*";NewTargetHosts = "*";NewTargetPorts = "*";+ NewTargetDomains = "*";NewProtocol = "TCP";SelectedRuleAction = AvailableActions.FirstOrDefault();ProcessNameError = "";@@ -156,6 +164,7 @@ public class ProxyRulesViewModel : ViewModelBaseNewProcessName = ValidationHelper.DefaultIfEmpty(NewProcessName);NewTargetHosts = ValidationHelper.DefaultIfEmpty(NewTargetHosts);NewTargetPorts = ValidationHelper.DefaultIfEmpty(NewTargetPorts);+ NewTargetDomains = ValidationHelper.DefaultIfEmpty(NewTargetDomains);if (!_processNameRegex.IsMatch(NewProcessName)){@@ -179,13 +188,14 @@ public class ProxyRulesViewModel : ViewModelBasestring action = SelectedRuleAction?.Action ?? "PROXY";uint pcId = SelectedRuleAction?.ProxyConfigId ?? 0;- if (_proxyService.EditRule(_currentEditingRuleId, NewProcessName, NewTargetHosts, NewTargetPorts, NewProtocol, action, pcId))+ if (_proxyService.EditRule(_currentEditingRuleId, NewProcessName, NewTargetHosts, NewTargetPorts, NewTargetDomains, NewProtocol, action, pcId)){if (existRule != null){existRule.ProcessName = NewProcessName;existRule.TargetHosts = NewTargetHosts;existRule.TargetPorts = NewTargetPorts;+ existRule.TargetDomains = NewTargetDomains;existRule.Protocol = NewProtocol;existRule.Action = action;existRule.ProxyConfigId = pcId;@@ -206,6 +216,7 @@ public class ProxyRulesViewModel : ViewModelBaseProcessName = NewProcessName,TargetHosts = NewTargetHosts,TargetPorts = NewTargetPorts,+ TargetDomains = NewTargetDomains,Protocol = NewProtocol,Action = action,IsEnabled = true,@@ -301,6 +312,7 @@ public class ProxyRulesViewModel : ViewModelBaseNewProcessName = rule.ProcessName;NewTargetHosts = rule.TargetHosts;NewTargetPorts = rule.TargetPorts;+ NewTargetDomains = rule.TargetDomains;NewProtocol = rule.Protocol;SelectedRuleAction = AvailableActions.FirstOrDefault(a =>a.Action == rule.Action && (a.Action != "PROXY" || a.ProxyConfigId == rule.ProxyConfigId))diff --git a/Windows/gui/Views/ProxyRulesWindow.axaml b/Windows/gui/Views/ProxyRulesWindow.axamlindex 7b70a0d..b88696a 100644--- a/Windows/gui/Views/ProxyRulesWindow.axaml+++ b/Windows/gui/Views/ProxyRulesWindow.axaml@@ -76,7 +76,7 @@BorderBrush="#FF3F3F46"BorderThickness="0,1,0,1"Padding="20,12">- <Grid ColumnDefinitions="60,80,140,60,200,150,120,80,*">+ <Grid ColumnDefinitions="60,80,140,60,200,150,120,150,80,*"><TextBlock Grid.Column="0"Text="Select"FontSize="13"@@ -120,12 +120,18 @@Foreground="#FFB0B0B0"Margin="0,0,10,0"/><TextBlock Grid.Column="7"- Text="{Binding Loc.ProtocolLabel}"+ Text="{Binding Loc.TargetDomainsLabel}"FontSize="13"FontWeight="SemiBold"Foreground="#FFB0B0B0"Margin="0,0,10,0"/><TextBlock Grid.Column="8"+ Text="{Binding Loc.ProtocolLabel}"+ FontSize="13"+ FontWeight="SemiBold"+ Foreground="#FFB0B0B0"+ Margin="0,0,10,0"/>+ <TextBlock Grid.Column="9"Text="{Binding Loc.ActionLabel}"FontSize="13"FontWeight="SemiBold"@@ -146,7 +152,7 @@Padding="20,16"PointerPressed="Rule_PointerPressed"DragDrop.AllowDrop="True">- <Grid ColumnDefinitions="60,80,140,60,200,150,120,80,*">+ <Grid ColumnDefinitions="60,80,140,60,200,150,120,150,80,*"><CheckBox Grid.Column="0"IsChecked="{Binding IsSelected}"VerticalAlignment="Center"@@ -203,12 +209,19 @@TextTrimming="CharacterEllipsis"Margin="0,0,10,0"/><TextBlock Grid.Column="7"- Text="{Binding Protocol}"+ Text="{Binding TargetDomains}"FontSize="13"Foreground="#FF999999"VerticalAlignment="Center"+ TextTrimming="CharacterEllipsis"Margin="0,0,10,0"/><TextBlock Grid.Column="8"+ Text="{Binding Protocol}"+ FontSize="13"+ Foreground="#FF999999"+ VerticalAlignment="Center"+ Margin="0,0,10,0"/>+ <TextBlock Grid.Column="9"Text="{Binding ActionDisplay}"FontSize="14"FontWeight="SemiBold"@@ -274,6 +287,18 @@Margin="0,4,0,0"/></StackPanel>+ <!-- Target Domains Section -->+ <StackPanel Spacing="6">+ <TextBlock Text="{Binding Loc.TargetDomainsLabel}" Classes="label"/>+ <TextBox Text="{Binding NewTargetDomains}"+ Watermark="Any"/>+ <TextBlock Text="{Binding Loc.ExampleTargetDomains}"+ FontSize="11"+ Foreground="#FF999999"+ TextWrapping="Wrap"+ Margin="0,4,0,0"/>+ </StackPanel>+<!-- Protocol Section --><StackPanel Spacing="6"><TextBlock Text="{Binding Loc.ProtocolLabel}" Classes="label"/>diff --git a/Windows/installer/ProxyBridge.nsi b/Windows/installer/ProxyBridge.nsiindex 2055b36..3e68692 100644--- a/Windows/installer/ProxyBridge.nsi+++ b/Windows/installer/ProxyBridge.nsi@@ -1,5 +1,5 @@!define PRODUCT_NAME "ProxyBridge"-!define PRODUCT_VERSION "4.0.0"+!define PRODUCT_VERSION "4.0.8-Beta"!define PRODUCT_PUBLISHER "InterceptSuite"!define PRODUCT_WEB_SITE "https://github.com/InterceptSuite/ProxyBridge"!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"@@ -8,7 +8,7 @@Unicode True; Version Information-VIProductVersion "4.0.6.0"+VIProductVersion "4.0.8.0"VIAddVersionKey "ProductName" "${PRODUCT_NAME}"VIAddVersionKey "ProductVersion" "${PRODUCT_VERSION}"VIAddVersionKey "CompanyName" "${PRODUCT_PUBLISHER}"diff --git a/Windows/src/ProxyBridge.c b/Windows/src/ProxyBridge.cindex b8184c1..0209bc4 100644--- a/Windows/src/ProxyBridge.c+++ b/Windows/src/ProxyBridge.c@@ -17,7 +17,7 @@#define LOCAL_PROXY_PORT 34010#define LOCAL_UDP_RELAY_PORT 34011 // its running UDP port still make sure to not run on same port as TCP, opening same port and tcp and udp cause issue and handling port at relay server response injection#define MAX_PROCESS_NAME 1024-#define VERSION "4.0.0"+#define VERSION "4.0.8-Beta"#define PID_CACHE_SIZE 1024#define PID_CACHE_TTL_MS 30000// Single packet-processor thread eliminates TCP packet reordering.@@ -41,6 +41,7 @@ typedef struct PROCESS_RULE {char process_name[MAX_PROCESS_NAME];char *target_hosts; // Dynamic: IP filter "*", "192.168.*.*", "10.0.0.1;172.16.0.0"char *target_ports; // Dynamic: Port filter "*", "80", "80;443", "8000-9000"+ char *target_domains; // Dynamic: Domain filter "*", "google.com", "*.google.com;*.gstatic.com" ("" or "*" = no domain restriction)RuleProtocol protocol; // TCP, UDP, or BOTHRuleAction action;UINT32 proxy_config_id; // Which proxy config to route this rule through (0 = first available)@@ -170,6 +171,9 @@ static HANDLE udp_relay_thread = NULL;static HANDLE cleanup_thread = NULL;static PID_CACHE_ENTRY *pid_cache[PID_CACHE_SIZE] = {NULL};static volatile BOOL g_has_active_rules = FALSE;+// Set when at least one enabled rule carries a domain filter. Gates the DNS-cache+// lookup in match_rule so setups without domain rules pay zero extra cost.+static volatile BOOL g_has_domain_rules = FALSE;static SOCKET udp_relay_socket = INVALID_SOCKET;static SOCKET udp_relay_socket6 = INVALID_SOCKET;static volatile BOOL running = FALSE;@@ -358,6 +362,10 @@ static BOOL match_ip_list(const char *ip_list, UINT32 ip);static BOOL match_port_list(const char *port_list, UINT16 port);static BOOL match_process_pattern(const char *pattern, const char *process_name);static BOOL match_process_list(const char *process_list, const char *process_name);+static BOOL match_domain_pattern(const char *pattern, const char *domain);+static BOOL match_domain_list(const char *domain_list, const char *domain);+static BOOL rule_has_domain_filter(const PROCESS_RULE *rule);+static BOOL match_domain_filter(const PROCESS_RULE *rule, const char *domain);static int http_connect(SOCKET s, UINT32 dest_ip, UINT16 dest_port, const PROXY_CONFIG *cfg);static DWORD WINAPI local_proxy_server(LPVOID arg);static DWORD WINAPI connection_handler(LPVOID arg);@@ -1786,6 +1794,89 @@ static BOOL match_process_list(const char *process_list, const char *process_namreturn matched;}+// Match a single domain pattern against a resolved hostname (case-insensitive).+// "*" -> matches anything (no restriction)+// "google.com" -> exact match only+// "*.google.com" -> any subdomain AND the apex "google.com" itself+// "*google*" -> generic wildcard (handled by wildcard_match)+static BOOL match_domain_pattern(const char *pattern, const char *domain)+{+ if (pattern == NULL || pattern[0] == '\0' || strcmp(pattern, "*") == 0)+ return TRUE;+ if (domain == NULL || domain[0] == '\0')+ return FALSE;++ // "*.example.com" should also match the bare apex "example.com" (Proxifier/Clash convention).+ if (pattern[0] == '*' && pattern[1] == '.' && pattern[2] != '\0')+ {+ if (_stricmp(pattern + 2, domain) == 0)+ return TRUE;+ }++ if (strchr(pattern, '*') != NULL)+ return wildcard_match(pattern, domain);++ return _stricmp(pattern, domain) == 0;+}++// Match a resolved hostname against a semicolon/comma separated domain list.+// Empty list or "*" means no restriction (matches anything, including unknown domain).+static BOOL match_domain_list(const char *domain_list, const char *domain)+{+ if (domain_list == NULL || domain_list[0] == '\0' || strcmp(domain_list, "*") == 0)+ return TRUE;+ if (domain == NULL || domain[0] == '\0')+ return FALSE;++ size_t len = strnlen_s(domain_list, MAX_LIST_SIZE) + 1;+ char *list_copy = (char *)malloc(len);+ if (list_copy == NULL)+ return FALSE;++ strncpy_s(list_copy, len, domain_list, _TRUNCATE);+ BOOL matched = FALSE;+ char *context = NULL;+ char *token = strtok_s(list_copy, ",;", &context);+ while (token != NULL)+ {+ while (*token == ' ' || *token == '\t')+ token++;+ char *end = token + strnlen_s(token, MAX_LIST_SIZE);+ while (end > token && (end[-1] == ' ' || end[-1] == '\t'))+ *(--end) = '\0';++ if (token[0] != '\0' && match_domain_pattern(token, domain))+ {+ matched = TRUE;+ break;+ }+ token = strtok_s(NULL, ",;", &context);+ }+ free(list_copy);+ return matched;+}++// TRUE if the rule actually restricts by domain (non-empty and not "*").+static BOOL rule_has_domain_filter(const PROCESS_RULE *rule)+{+ return rule->target_domains != NULL &&+ rule->target_domains[0] != '\0' &&+ strcmp(rule->target_domains, "*") != 0;+}++// Domain-filter gate used inside rule matching.+// - rule has no domain restriction -> always TRUE (preserves pre-domain behaviour)+// - rule restricts by domain, IP has no resolved hostname -> FALSE (cache-miss: don't match)+// - otherwise -> match the resolved hostname against the rule's domain list+static BOOL match_domain_filter(const PROCESS_RULE *rule, const char *domain)+{+ if (!rule_has_domain_filter(rule))+ return TRUE;+ if (domain == NULL || domain[0] == '\0')+ return FALSE;+ return match_domain_list(rule->target_domains, domain);+}+static BOOL is_broadcast_or_multicast(UINT32 ip){@@ -1821,6 +1912,13 @@ static RuleAction match_rule(const char *process_name, UINT32 dest_ip, UINT16 dePROCESS_RULE *rule = rules_list;PROCESS_RULE *wildcard_rule = NULL; // Save fully wildcard rule for last+ // Resolve the destination hostname once (only when domain rules exist) from the+ // DNS-snoop cache. Reused for every rule's domain filter below. Cache miss -> unknown.+ char domain[256];+ const char *dst_domain = NULL;+ if (g_has_domain_rules && dns_cache_lookup(dest_ip, domain, sizeof(domain)))+ dst_domain = domain;+while (rule != NULL){if (!rule->enabled)@@ -1853,12 +1951,14 @@ static RuleAction match_rule(const char *process_name, UINT32 dest_ip, UINT16 de// Check if wildcard has specific filtersBOOL has_ip_filter = (strcmp(rule->target_hosts, "*") != 0);BOOL has_port_filter = (strcmp(rule->target_ports, "*") != 0);+ BOOL has_domain_filter = rule_has_domain_filter(rule);- if (has_ip_filter || has_port_filter)+ if (has_ip_filter || has_port_filter || has_domain_filter){// Filtered wildcard - check if it matchesif (match_ip_list(rule->target_hosts, dest_ip) &&- match_port_list(rule->target_ports, dest_port))+ match_port_list(rule->target_ports, dest_port) &&+ match_domain_filter(rule, dst_domain)){// Matched! Return this rule's actionif (out_proxy_config_id != NULL) *out_proxy_config_id = rule->proxy_config_id;@@ -1881,9 +1981,10 @@ static RuleAction match_rule(const char *process_name, UINT32 dest_ip, UINT16 de// Check if process name matchesif (match_process_list(rule->process_name, process_name)){- // Process matched! Check IP and port filters+ // Process matched! Check IP, port and domain filtersif (match_ip_list(rule->target_hosts, dest_ip) &&- match_port_list(rule->target_ports, dest_port))+ match_port_list(rule->target_ports, dest_port) &&+ match_domain_filter(rule, dst_domain)){// All filters matched! Return this rule's actionif (out_proxy_config_id != NULL) *out_proxy_config_id = rule->proxy_config_id;@@ -1914,6 +2015,13 @@ static RuleAction match_rule_v6(const char *process_name, const UINT8 dest_ip6[1PROCESS_RULE *rule = rules_list;PROCESS_RULE *wildcard_rule = NULL;+ // Resolve the destination hostname once (only when domain rules exist) from the+ // IPv6 DNS-snoop cache. Reused for every rule's domain filter below.+ char domain[256];+ const char *dst_domain = NULL;+ if (g_has_domain_rules && dns_cache_lookup_v6(dest_ip6, domain, sizeof(domain)))+ dst_domain = domain;+while (rule != NULL){if (!rule->enabled)@@ -1934,11 +2042,13 @@ static RuleAction match_rule_v6(const char *process_name, const UINT8 dest_ip6[1{BOOL has_ip_filter = (strcmp(rule->target_hosts, "*") != 0);BOOL has_port_filter = (strcmp(rule->target_ports, "*") != 0);+ BOOL has_domain_filter = rule_has_domain_filter(rule);- if (has_ip_filter || has_port_filter)+ if (has_ip_filter || has_port_filter || has_domain_filter){if (match_ip_list_v6(rule->target_hosts, dest_ip6) &&- match_port_list(rule->target_ports, dest_port))+ match_port_list(rule->target_ports, dest_port) &&+ match_domain_filter(rule, dst_domain)){if (out_proxy_config_id != NULL) *out_proxy_config_id = rule->proxy_config_id;return rule->action;@@ -1956,7 +2066,8 @@ static RuleAction match_rule_v6(const char *process_name, const UINT8 dest_ip6[1if (match_process_list(rule->process_name, process_name)){if (match_ip_list_v6(rule->target_hosts, dest_ip6) &&- match_port_list(rule->target_ports, dest_port))+ match_port_list(rule->target_ports, dest_port) &&+ match_domain_filter(rule, dst_domain)){if (out_proxy_config_id != NULL) *out_proxy_config_id = rule->proxy_config_id;return rule->action;@@ -3972,7 +4083,7 @@ static void cleanup_stale_connections(void)ReleaseSRWLockExclusive(&lock);}-PROXYBRIDGE_API UINT32 ProxyBridge_AddRule(const char* process_name, const char* target_hosts, const char* target_ports, RuleProtocol protocol, RuleAction action, UINT32 proxy_config_id)+PROXYBRIDGE_API UINT32 ProxyBridge_AddRule(const char* process_name, const char* target_hosts, const char* target_ports, const char* target_domains, RuleProtocol protocol, RuleAction action, UINT32 proxy_config_id){if (process_name == NULL || process_name[0] == '\0')return 0;@@ -3985,6 +4096,9 @@ PROXYBRIDGE_API UINT32 ProxyBridge_AddRule(const char* process_name, const char*strncpy_s(rule->process_name, MAX_PROCESS_NAME, process_name, _TRUNCATE);rule->protocol = protocol;rule->proxy_config_id = proxy_config_id;+ rule->target_hosts = NULL;+ rule->target_ports = NULL;+ rule->target_domains = NULL;if (target_hosts != NULL && target_hosts[0] != '\0'){@@ -4035,6 +4149,33 @@ PROXYBRIDGE_API UINT32 ProxyBridge_AddRule(const char* process_name, const char*strcpy_s(rule->target_ports, 2, "*");}+ // target_domains: "" or NULL means no domain restriction (stored as "*")+ if (target_domains != NULL && target_domains[0] != '\0')+ {+ size_t len = strnlen_s(target_domains, MAX_LIST_SIZE) + 1;+ rule->target_domains = (char *)malloc(len);+ if (rule->target_domains == NULL)+ {+ free(rule->target_ports);+ free(rule->target_hosts);+ free(rule);+ return 0;+ }+ strncpy_s(rule->target_domains, len, target_domains, _TRUNCATE);+ }+ else+ {+ rule->target_domains = (char *)malloc(2);+ if (rule->target_domains == NULL)+ {+ free(rule->target_ports);+ free(rule->target_hosts);+ free(rule);+ return 0;+ }+ strcpy_s(rule->target_domains, 2, "*");+ }+rule->action = action;rule->enabled = TRUE;rule->next = NULL;@@ -4054,7 +4195,7 @@ PROXYBRIDGE_API UINT32 ProxyBridge_AddRule(const char* process_name, const char*}update_has_active_rules();- log_message("Added rule ID: %u for process '%s' (Protocol: %d, Action: %d, ProxyConfigId: %u)", rule->rule_id, process_name, protocol, action, proxy_config_id);+ log_message("Added rule ID: %u for process '%s' (Protocol: %d, Action: %d, ProxyConfigId: %u, Domains: %s)", rule->rule_id, process_name, protocol, action, proxy_config_id, rule->target_domains);return rule->rule_id;}@@ -4120,6 +4261,8 @@ PROXYBRIDGE_API BOOL ProxyBridge_DeleteRule(UINT32 rule_id)free(rule->target_hosts);if (rule->target_ports != NULL)free(rule->target_ports);+ if (rule->target_domains != NULL)+ free(rule->target_domains);free(rule);update_has_active_rules();@@ -4132,42 +4275,46 @@ PROXYBRIDGE_API BOOL ProxyBridge_DeleteRule(UINT32 rule_id)return FALSE;}-PROXYBRIDGE_API BOOL ProxyBridge_EditRule(UINT32 rule_id, const char* process_name, const char* target_hosts, const char* target_ports, RuleProtocol protocol, RuleAction action, UINT32 proxy_config_id)+PROXYBRIDGE_API BOOL ProxyBridge_EditRule(UINT32 rule_id, const char* process_name, const char* target_hosts, const char* target_ports, const char* target_domains, RuleProtocol protocol, RuleAction action, UINT32 proxy_config_id){if (rule_id == 0 || process_name == NULL || target_hosts == NULL || target_ports == NULL)return FALSE;+ // NULL/"" domains means "no restriction" -> stored as "*"+ const char *domains_in = (target_domains != NULL && target_domains[0] != '\0') ? target_domains : "*";+PROCESS_RULE *rule = rules_list;while (rule != NULL){if (rule->rule_id == rule_id){- strncpy_s(rule->process_name, MAX_PROCESS_NAME, process_name, _TRUNCATE);-- if (rule->target_hosts != NULL)- free(rule->target_hosts);- rule->target_hosts = _strdup(target_hosts);- if (rule->target_hosts == NULL)+ // Allocate all three replacements up front so a failure leaves the rule untouched.+ char *new_hosts = _strdup(target_hosts);+ char *new_ports = _strdup(target_ports);+ char *new_domains = _strdup(domains_in);+ if (new_hosts == NULL || new_ports == NULL || new_domains == NULL){+ free(new_hosts);+ free(new_ports);+ free(new_domains);return FALSE;}- if (rule->target_ports != NULL)- free(rule->target_ports);- rule->target_ports = _strdup(target_ports);- if (rule->target_ports == NULL)- {- free(rule->target_hosts);- rule->target_hosts = NULL;- return FALSE;- }+ strncpy_s(rule->process_name, MAX_PROCESS_NAME, process_name, _TRUNCATE);++ free(rule->target_hosts);+ free(rule->target_ports);+ free(rule->target_domains);+ rule->target_hosts = new_hosts;+ rule->target_ports = new_ports;+ rule->target_domains = new_domains;rule->protocol = protocol;rule->action = action;rule->proxy_config_id = proxy_config_id;update_has_active_rules();- log_message("Updated rule ID: %u (ProxyConfigId: %u)", rule_id, proxy_config_id);+ log_message("Updated rule ID: %u (ProxyConfigId: %u, Domains: %s)", rule_id, proxy_config_id, rule->target_domains);return TRUE;}rule = rule->next;@@ -4641,19 +4788,48 @@ static DWORD WINAPI cleanup_worker(LPVOID arg)return 0;}+// Flush the Windows DNS resolver cache so applications re-resolve hostnames on the+// wire, where our port-53 snoop can capture the IP->hostname mapping. Without this a+// domain that was resolved before a domain rule existed would have no cached mapping+// and the rule could not match. DnsFlushResolverCache is loaded dynamically so we+// avoid a hard dnsapi.lib dependency (keeps the MinGW/GCC build path unchanged).+static void flush_dns_resolver_cache(void)+{+ HMODULE dnsapi = LoadLibraryA("dnsapi.dll");+ if (dnsapi == NULL)+ return;+ typedef BOOL (WINAPI *DnsFlushFn)(void);+ DnsFlushFn fn = (DnsFlushFn)GetProcAddress(dnsapi, "DnsFlushResolverCache");+ if (fn != NULL)+ fn();+ FreeLibrary(dnsapi);+}+static void update_has_active_rules(void){- g_has_active_rules = FALSE;+ BOOL has_active = FALSE;+ BOOL has_domain = FALSE;PROCESS_RULE *rule = rules_list;while (rule != NULL){if (rule->enabled){- g_has_active_rules = TRUE;- break;+ has_active = TRUE;+ if (rule_has_domain_filter(rule))+ {+ has_domain = TRUE;+ break; // both flags are now known+ }}rule = rule->next;}+ g_has_active_rules = has_active;++ // Edge trigger: when domain rules first become active, flush the OS DNS cache so+ // subsequent connections re-resolve and populate our snoop cache.+ if (has_domain && !g_has_domain_rules && running)+ flush_dns_resolver_cache();+ g_has_domain_rules = has_domain;}PROXYBRIDGE_API BOOL ProxyBridge_Start(void)@@ -4667,6 +4843,11 @@ PROXYBRIDGE_API BOOL ProxyBridge_Start(void)InitializeSRWLock(&lock);dns_cache_init();+ // If domain rules were configured before start, flush the OS DNS cache so the very+ // first connections re-resolve on the wire and populate our IP->hostname snoop cache.+ if (g_has_domain_rules)+ flush_dns_resolver_cache();+running = TRUE;proxy_thread = CreateThread(NULL, 1, local_proxy_server, NULL, 0, NULL);@@ -4932,6 +5113,8 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)free(to_free->target_hosts);if (to_free->target_ports != NULL)free(to_free->target_ports);+ if (to_free->target_domains != NULL)+ free(to_free->target_domains);free(to_free);}diff --git a/Windows/src/ProxyBridge.h b/Windows/src/ProxyBridge.hindex 467e48e..9592e36 100644--- a/Windows/src/ProxyBridge.h+++ b/Windows/src/ProxyBridge.h@@ -43,11 +43,13 @@ PROXYBRIDGE_API BOOL ProxyBridge_DeleteProxyConfig(UINT32 config_id);PROXYBRIDGE_API int ProxyBridge_TestProxyConfig(UINT32 config_id, const char* target_host, UINT16 target_port, char* result_buffer, size_t buffer_size);// Rule management - proxy_config_id selects which proxy config the rule uses (0 = first available)-PROXYBRIDGE_API UINT32 ProxyBridge_AddRule(const char* process_name, const char* target_hosts, const char* target_ports, RuleProtocol protocol, RuleAction action, UINT32 proxy_config_id);+// target_domains: semicolon/comma separated domain patterns ("*", "google.com", "*.google.com"); NULL/"" = no domain restriction.+// Domain matching relies on DNS snooping of the app's own resolutions; unencrypted DNS only (DoH/DoT bypasses it).+PROXYBRIDGE_API UINT32 ProxyBridge_AddRule(const char* process_name, const char* target_hosts, const char* target_ports, const char* target_domains, RuleProtocol protocol, RuleAction action, UINT32 proxy_config_id);PROXYBRIDGE_API BOOL ProxyBridge_EnableRule(UINT32 rule_id);PROXYBRIDGE_API BOOL ProxyBridge_DisableRule(UINT32 rule_id);PROXYBRIDGE_API BOOL ProxyBridge_DeleteRule(UINT32 rule_id);-PROXYBRIDGE_API BOOL ProxyBridge_EditRule(UINT32 rule_id, const char* process_name, const char* target_hosts, const char* target_ports, RuleProtocol protocol, RuleAction action, UINT32 proxy_config_id);+PROXYBRIDGE_API BOOL ProxyBridge_EditRule(UINT32 rule_id, const char* process_name, const char* target_hosts, const char* target_ports, const char* target_domains, RuleProtocol protocol, RuleAction action, UINT32 proxy_config_id);PROXYBRIDGE_API BOOL ProxyBridge_MoveRuleToPosition(UINT32 rule_id, UINT32 new_position); // Move rule to specific position (1=first, 2=second, etc)PROXYBRIDGE_API UINT32 ProxyBridge_GetRulePosition(UINT32 rule_id); // Get current position of rule in list (1-based)PROXYBRIDGE_API void ProxyBridge_SetLocalhostViaProxy(BOOL enable);