Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic
C ccybersecurityhttp3httpproxylinuxlinux-proxymacosmacos-appmacos-proxyproxifierproxifier-alternativeproxyclienttcpthick-clientudpwindivertwindows
#70 added local host proxy on off in GUI and CLI
Sourav Kalalfab69128b974
diff --git a/Windows/cli/Program.cs b/Windows/cli/Program.csindex 733a3d4..20a4073 100644--- a/Windows/cli/Program.cs+++ b/Windows/cli/Program.cs@@ -108,6 +108,11 @@ class Programdescription: "Route DNS queries through proxy (default: true)",getDefaultValue: () => true);+ var localhostViaProxyOption = new Option<bool>(+ name: "--localhost-via-proxy",+ description: "Route localhost traffic through proxy (default: false, most proxies block localhost for SSRF prevention, local traffic to remote proxy will cause issues)",+ getDefaultValue: () => false);+var verboseOption = new Option<int>(name: "--verbose",description: "Logging verbosity level\n" +@@ -125,6 +130,7 @@ class ProgramruleOption,ruleFileOption,dnsViaProxyOption,+ localhostViaProxyOption,verboseOption};@@ -135,10 +141,10 @@ class Programawait CheckAndUpdate();});- rootCommand.SetHandler(async (proxyUrl, rules, ruleFile, dnsViaProxy, verbose) =>+ rootCommand.SetHandler(async (proxyUrl, rules, ruleFile, dnsViaProxy, localhostViaProxy, verbose) =>{- await RunProxyBridge(proxyUrl, rules, ruleFile, dnsViaProxy, verbose);- }, proxyOption, ruleOption, ruleFileOption, dnsViaProxyOption, verboseOption);+ await RunProxyBridge(proxyUrl, rules, ruleFile, dnsViaProxy, localhostViaProxy, verbose);+ }, proxyOption, ruleOption, ruleFileOption, dnsViaProxyOption, localhostViaProxyOption, verboseOption);if (args.Contains("--help") || args.Contains("-h") || args.Contains("-?")){@@ -148,7 +154,7 @@ class Programreturn await rootCommand.InvokeAsync(args);}- private static async Task<int> RunProxyBridge(string proxyUrl, string[] rules, string? ruleFile, bool dnsViaProxy, int verboseLevel)+ private static async Task<int> RunProxyBridge(string proxyUrl, string[] rules, string? ruleFile, bool dnsViaProxy, bool localhostViaProxy, int verboseLevel){_verboseLevel = verboseLevel;ShowBanner();@@ -201,6 +207,7 @@ class ProgramConsole.WriteLine($"Proxy Auth: {proxyInfo.Username}:***");}Console.WriteLine($"DNS via Proxy: {(dnsViaProxy ? "Enabled" : "Disabled")}");+ Console.WriteLine($"Localhost via Proxy: {(localhostViaProxy ? "Enabled" : "Disabled (Security: most proxies block localhost)")}");if (!ProxyBridgeNative.ProxyBridge_SetProxyConfig(proxyInfo.Type,@@ -214,6 +221,7 @@ class Program}ProxyBridgeNative.ProxyBridge_SetDnsViaProxy(dnsViaProxy);+ ProxyBridgeNative.ProxyBridge_SetLocalhostViaProxy(localhostViaProxy);if (parsedRules.Count > 0){diff --git a/Windows/cli/ProxyBridgeNative.cs b/Windows/cli/ProxyBridgeNative.csindex fc29a02..071ffd1 100644--- a/Windows/cli/ProxyBridgeNative.cs+++ b/Windows/cli/ProxyBridgeNative.cs@@ -87,6 +87,9 @@ public static class ProxyBridgeNative[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]public static extern void ProxyBridge_SetDnsViaProxy([MarshalAs(UnmanagedType.Bool)] bool enable);+ [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]+ public static extern void ProxyBridge_SetLocalhostViaProxy([MarshalAs(UnmanagedType.Bool)] bool enable);+[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)][return: MarshalAs(UnmanagedType.Bool)]public static extern bool ProxyBridge_Start();diff --git a/Windows/gui/Interop/ProxyBridgeNative.cs b/Windows/gui/Interop/ProxyBridgeNative.csindex 4451f82..b9ba05f 100644--- a/Windows/gui/Interop/ProxyBridgeNative.cs+++ b/Windows/gui/Interop/ProxyBridgeNative.cs@@ -111,6 +111,9 @@ public static class ProxyBridgeNative[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]public static extern void ProxyBridge_SetDnsViaProxy([MarshalAs(UnmanagedType.Bool)] bool enable);+ [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]+ public static extern void ProxyBridge_SetLocalhostViaProxy([MarshalAs(UnmanagedType.Bool)] bool enable);+[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)][return: MarshalAs(UnmanagedType.Bool)]public static extern bool ProxyBridge_Start();diff --git a/Windows/gui/Resources/Resources.Designer.cs b/Windows/gui/Resources/Resources.Designer.csindex 95d49cb..f428fd7 100644--- a/Windows/gui/Resources/Resources.Designer.cs+++ b/Windows/gui/Resources/Resources.Designer.cs@@ -92,6 +92,12 @@ namespace ProxyBridge.GUI.Resources {}}+ internal static string MenuLocalhostViaProxy {+ get {+ return ResourceManager.GetString("MenuLocalhostViaProxy", resourceCulture);+ }+ }+internal static string MenuEnableTrafficLogging {get {return ResourceManager.GetString("MenuEnableTrafficLogging", resourceCulture);diff --git a/Windows/gui/Resources/Resources.resx b/Windows/gui/Resources/Resources.resxindex 0b64c18..3615a04 100644--- a/Windows/gui/Resources/Resources.resx+++ b/Windows/gui/Resources/Resources.resx@@ -26,6 +26,9 @@<data name="MenuDnsViaProxy" xml:space="preserve"><value>DNS via Proxy</value></data>+ <data name="MenuLocalhostViaProxy" xml:space="preserve">+ <value>Localhost via Proxy</value>+ </data><data name="MenuEnableTrafficLogging" xml:space="preserve"><value>Enable Traffic Logging</value></data>diff --git a/Windows/gui/Resources/Resources.zh.resx b/Windows/gui/Resources/Resources.zh.resxindex 981fd88..8551641 100644--- a/Windows/gui/Resources/Resources.zh.resx+++ b/Windows/gui/Resources/Resources.zh.resx@@ -26,6 +26,9 @@<data name="MenuDnsViaProxy" xml:space="preserve"><value>DNS通过代理</value></data>+ <data name="MenuLocalhostViaProxy" xml:space="preserve">+ <value>本地主机通过代理</value>+ </data><data name="MenuEnableTrafficLogging" xml:space="preserve"><value>启用流量日志</value></data>diff --git a/Windows/gui/Services/ConfigManager.cs b/Windows/gui/Services/ConfigManager.csindex b1b5055..e1d5acc 100644--- a/Windows/gui/Services/ConfigManager.cs+++ b/Windows/gui/Services/ConfigManager.cs@@ -15,6 +15,7 @@ public class AppConfigpublic string ProxyUsername { get; set; } = "";public string ProxyPassword { get; set; } = "";public bool DnsViaProxy { get; set; } = true;+ public bool LocalhostViaProxy { get; set; } = false; // Default: disabledpublic bool IsTrafficLoggingEnabled { get; set; } = true;public string Language { get; set; } = "en";public bool CloseToTray { get; set; } = true;diff --git a/Windows/gui/Services/Loc.cs b/Windows/gui/Services/Loc.csindex 43854fc..e2508a1 100644--- a/Windows/gui/Services/Loc.cs+++ b/Windows/gui/Services/Loc.cs@@ -41,6 +41,7 @@ public class Loc : INotifyPropertyChangedpublic string MenuProxySettings => Resources.Resources.MenuProxySettings;public string MenuProxyRules => Resources.Resources.MenuProxyRules;public string MenuDnsViaProxy => Resources.Resources.MenuDnsViaProxy;+ public string MenuLocalhostViaProxy => Resources.Resources.MenuLocalhostViaProxy;public string MenuEnableTrafficLogging => Resources.Resources.MenuEnableTrafficLogging;public string MenuSettings => Resources.Resources.MenuSettings;public string MenuCloseToTray => Resources.Resources.MenuCloseToTray;diff --git a/Windows/gui/Services/ProxyBridgeService.cs b/Windows/gui/Services/ProxyBridgeService.csindex be93ae3..fa34ce5 100644--- a/Windows/gui/Services/ProxyBridgeService.cs+++ b/Windows/gui/Services/ProxyBridgeService.cs@@ -128,6 +128,11 @@ public class ProxyBridgeService : IDisposableProxyBridgeNative.ProxyBridge_SetDnsViaProxy(enable);}+ public void SetLocalhostViaProxy(bool enable)+ {+ ProxyBridgeNative.ProxyBridge_SetLocalhostViaProxy(enable);+ }+public static void SetTrafficLoggingEnabled(bool enable){ProxyBridgeNative.ProxyBridge_SetTrafficLoggingEnabled(enable);diff --git a/Windows/gui/ViewModels/MainWindowViewModel.cs b/Windows/gui/ViewModels/MainWindowViewModel.csindex 84688d6..58393f0 100644--- a/Windows/gui/ViewModels/MainWindowViewModel.cs+++ b/Windows/gui/ViewModels/MainWindowViewModel.cs@@ -122,6 +122,7 @@ public class MainWindowViewModel : ViewModelBase_activityLogTimer.Start();_proxyService.SetDnsViaProxy(_dnsViaProxy);+ _proxyService.SetLocalhostViaProxy(_localhostViaProxy);if (!string.IsNullOrEmpty(_currentProxyIp) &&!string.IsNullOrEmpty(_currentProxyPort) &&ushort.TryParse(_currentProxyPort, out ushort portNum))@@ -288,6 +289,20 @@ public class MainWindowViewModel : ViewModelBase}}+ private bool _localhostViaProxy = false; // Default: disabled for security+ public bool LocalhostViaProxy+ {+ get => _localhostViaProxy;+ set+ {+ if (SetProperty(ref _localhostViaProxy, value))+ {+ _proxyService?.SetLocalhostViaProxy(value);+ SaveConfigurationInternal();+ }+ }+ }+private bool _isTrafficLoggingEnabled = true;public bool IsTrafficLoggingEnabled{@@ -362,6 +377,7 @@ public class MainWindowViewModel : ViewModelBasepublic ICommand ShowAboutCommand { get; }public ICommand CheckForUpdatesCommand { get; }public ICommand ToggleDnsViaProxyCommand { get; }+ public ICommand ToggleLocalhostViaProxyCommand { get; }public ICommand ToggleTrafficLoggingCommand { get; }public ICommand ToggleCloseToTrayCommand { get; }public ICommand ToggleStartWithWindowsCommand { get; }@@ -501,6 +517,11 @@ public class MainWindowViewModel : ViewModelBaseDnsViaProxy = !DnsViaProxy;});+ ToggleLocalhostViaProxyCommand = new RelayCommand(() =>+ {+ LocalhostViaProxy = !LocalhostViaProxy;+ });+ToggleTrafficLoggingCommand = new RelayCommand(() =>{IsTrafficLoggingEnabled = !IsTrafficLoggingEnabled;@@ -707,6 +728,7 @@ public class MainWindowViewModel : ViewModelBase_currentProxyPassword = config.ProxyPassword ?? "";DnsViaProxy = config.DnsViaProxy;+ LocalhostViaProxy = config.LocalhostViaProxy;CloseToTray = config.CloseToTray;IsTrafficLoggingEnabled = config.IsTrafficLoggingEnabled;@@ -763,6 +785,7 @@ public class MainWindowViewModel : ViewModelBaseProxyUsername = _currentProxyUsername,ProxyPassword = _currentProxyPassword,DnsViaProxy = _dnsViaProxy,+ LocalhostViaProxy = _localhostViaProxy,IsTrafficLoggingEnabled = _isTrafficLoggingEnabled,Language = _currentLanguage,CloseToTray = _closeToTray,diff --git a/Windows/gui/Views/MainWindow.axaml b/Windows/gui/Views/MainWindow.axamlindex 76094b8..48b1694 100644--- a/Windows/gui/Views/MainWindow.axaml+++ b/Windows/gui/Views/MainWindow.axaml@@ -221,6 +221,14 @@Margin="0"/></MenuItem.Icon></MenuItem>+ <MenuItem Header="{Binding Loc.MenuLocalhostViaProxy}"+ Command="{Binding ToggleLocalhostViaProxyCommand}">+ <MenuItem.Icon>+ <CheckBox IsChecked="{Binding LocalhostViaProxy}"+ IsHitTestVisible="False"+ Margin="0"/>+ </MenuItem.Icon>+ </MenuItem></MenuItem><MenuItem Header="{Binding Loc.MenuSettings}"><MenuItem Header="{Binding Loc.MenuCloseToTray}"