Skip to content

Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic

added TCP and UDP support in GUI, added DNS via Proxy in GUI

Sourav Kalalbe34ee41e9e0
diff --git a/gui/Interop/ProxyBridgeNative.cs b/gui/Interop/ProxyBridgeNative.cs
index 174bf32..81d9f2f 100644
--- a/gui/Interop/ProxyBridgeNative.cs
+++ b/gui/Interop/ProxyBridgeNative.cs
@@ -84,6 +84,9 @@ public static class ProxyBridgeNative
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void ProxyBridge_SetConnectionCallback(ConnectionCallback callback);
+ [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
+ public static extern void ProxyBridge_SetDnsViaProxy([MarshalAs(UnmanagedType.Bool)] bool enable);
+
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ProxyBridge_Start();
diff --git a/gui/Services/ProxyBridgeService.cs b/gui/Services/ProxyBridgeService.cs
index 47cfe60..3d26f7f 100644
--- a/gui/Services/ProxyBridgeService.cs
+++ b/gui/Services/ProxyBridgeService.cs
@@ -88,6 +88,11 @@ public class ProxyBridgeService : IDisposable
return ProxyBridgeNative.ProxyBridge_DisableRule(ruleId);
}
+ public void SetDnsViaProxy(bool enable)
+ {
+ ProxyBridgeNative.ProxyBridge_SetDnsViaProxy(enable);
+ }
+
public string TestConnection(string targetHost, ushort targetPort)
{
var buffer = new System.Text.StringBuilder(4096);
diff --git a/gui/ViewModels/MainWindowViewModel.cs b/gui/ViewModels/MainWindowViewModel.cs
index 3355d81..42f2bef 100644
--- a/gui/ViewModels/MainWindowViewModel.cs
+++ b/gui/ViewModels/MainWindowViewModel.cs
@@ -92,6 +92,8 @@ public class MainWindowViewModel : ViewModelBase
};
_connectionLogTimer.Start();
+ _proxyService.SetDnsViaProxy(true);
+
// Start the proxy bridge
if (_proxyService.Start())
{
@@ -204,10 +206,25 @@ public class MainWindowViewModel : ViewModelBase
public ObservableCollection<ProxyRule> ProxyRules { get; } = new();
+ private bool _dnsViaProxy = true; // Default TRUE
+ public bool DnsViaProxy
+ {
+ get => _dnsViaProxy;
+ set
+ {
+ if (SetProperty(ref _dnsViaProxy, value))
+ {
+ _proxyService?.SetDnsViaProxy(value);
+ ActivityLog += $"[{DateTime.Now:HH:mm:ss}] DNS via Proxy: {(value ? "Enabled" : "Disabled")}\n";
+ }
+ }
+ }
+
// Commands
public ICommand ShowProxySettingsCommand { get; }
public ICommand ShowProxyRulesCommand { get; }
public ICommand ShowAboutCommand { get; }
+ public ICommand ToggleDnsViaProxyCommand { get; }
public ICommand CloseDialogCommand { get; }
public ICommand ClearConnectionsLogCommand { get; }
public ICommand ClearActivityLogCommand { get; }
@@ -328,6 +345,11 @@ public class MainWindowViewModel : ViewModelBase
}
});
+ ToggleDnsViaProxyCommand = new RelayCommand(() =>
+ {
+ DnsViaProxy = !DnsViaProxy;
+ });
+
CloseDialogCommand = new RelayCommand(CloseDialogs);
ClearConnectionsLogCommand = new RelayCommand(() =>
diff --git a/gui/ViewModels/ProxyRulesViewModel.cs b/gui/ViewModels/ProxyRulesViewModel.cs
index 912c55b..e2cf924 100644
--- a/gui/ViewModels/ProxyRulesViewModel.cs
+++ b/gui/ViewModels/ProxyRulesViewModel.cs
@@ -12,7 +12,7 @@ public class ProxyRulesViewModel : ViewModelBase
private string _newProcessName = "*";
private string _newTargetHosts = "*";
private string _newTargetPorts = "*";
- private string _newProtocol = "TCP";
+ private string _newProtocol = "TCP"; // TCP, UDP, or BOTH
private string _newProxyAction = "PROXY";
private string _processNameError = "";
private Action<ProxyRule>? _onAddRule;
diff --git a/gui/Views/MainWindow.axaml b/gui/Views/MainWindow.axaml
index fce084a..04be551 100644
--- a/gui/Views/MainWindow.axaml
+++ b/gui/Views/MainWindow.axaml
@@ -203,6 +203,15 @@
<MenuItem Header="Proxy">
<MenuItem Header="Proxy Settings" Command="{Binding ShowProxySettingsCommand}"/>
<MenuItem Header="Proxy Rules" Command="{Binding ShowProxyRulesCommand}"/>
+ <Separator/>
+ <MenuItem Header="DNS via Proxy"
+ Command="{Binding ToggleDnsViaProxyCommand}">
+ <MenuItem.Icon>
+ <CheckBox IsChecked="{Binding DnsViaProxy}"
+ IsHitTestVisible="False"
+ Margin="0"/>
+ </MenuItem.Icon>
+ </MenuItem>
</MenuItem>
<MenuItem Header="About" Command="{Binding ShowAboutCommand}"/>
</Menu>
diff --git a/gui/Views/ProxyRulesWindow.axaml b/gui/Views/ProxyRulesWindow.axaml
index 5e8f754..904d4f2 100644
--- a/gui/Views/ProxyRulesWindow.axaml
+++ b/gui/Views/ProxyRulesWindow.axaml
@@ -276,9 +276,10 @@
<TextBlock Text="Protocol" Classes="label"/>
<ComboBox SelectedIndex="0"
HorizontalAlignment="Stretch"
- IsEnabled="False"
x:Name="ProtocolComboBox">
- <ComboBoxItem Content="TCP (UDP not yet supported)" Tag="TCP"/>
+ <ComboBoxItem Content="TCP" Tag="TCP"/>
+ <ComboBoxItem Content="UDP" Tag="UDP"/>
+ <ComboBoxItem Content="Both (TCP + UDP)" Tag="BOTH"/>
</ComboBox>
</StackPanel>
diff --git a/src/ProxyBridge.c b/src/ProxyBridge.c
index 280bd9e..e12f39d 100644
--- a/src/ProxyBridge.c
+++ b/src/ProxyBridge.c
@@ -14,7 +14,7 @@
#define MAXBUF 0xFFFF
#define LOCAL_PROXY_PORT 34010
-#define LOCAL_UDP_RELAY_PORT 34011
+#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 256
typedef struct PROCESS_RULE {
diff --git a/src/ProxyBridge.h b/src/ProxyBridge.h
index 30af4ca..c3e0af1 100644
--- a/src/ProxyBridge.h
+++ b/src/ProxyBridge.h
@@ -30,14 +30,14 @@ typedef enum {
typedef enum {
RULE_PROTOCOL_TCP = 0,
RULE_PROTOCOL_UDP = 1,
- RULE_PROTOCOL_BOTH = 2 // Future: Match both TCP and UDP
+ RULE_PROTOCOL_BOTH = 2
} RuleProtocol;
PROXYBRIDGE_API UINT32 ProxyBridge_AddRule(const char* process_name, const char* target_hosts, const char* target_ports, RuleProtocol protocol, RuleAction action);
PROXYBRIDGE_API BOOL ProxyBridge_EnableRule(UINT32 rule_id);
PROXYBRIDGE_API BOOL ProxyBridge_DisableRule(UINT32 rule_id);
PROXYBRIDGE_API BOOL ProxyBridge_SetProxyConfig(ProxyType type, const char* proxy_ip, UINT16 proxy_port, const char* username, const char* password);
-PROXYBRIDGE_API void ProxyBridge_SetDnsViaProxy(BOOL enable); // DNS routing: TRUE = via proxy (UDP via SOCKS5, TCP via HTTP/SOCKS5), FALSE = direct
+PROXYBRIDGE_API void ProxyBridge_SetDnsViaProxy(BOOL enable);
PROXYBRIDGE_API void ProxyBridge_SetLogCallback(LogCallback callback);
PROXYBRIDGE_API void ProxyBridge_SetConnectionCallback(ConnectionCallback callback);
PROXYBRIDGE_API BOOL ProxyBridge_Start(void);