Skip to content

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

fixed issues with socks5 UDP connection with proxy server, updated Readme

Sourav Kalal3f1d1ed405c6
diff --git a/README.md b/README.md
index ce450e2..f701ce1 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@
</p>
-ProxyBridge is a lightweight, open-source alternative to Proxifier that provides transparent proxy routing for Windows applications. It redirects TCP and UDP traffic from specific processes through SOCKS5 or HTTP proxies, with the ability to route, block, or allow traffic on a per-application basis. Working at the kernel level using WinDivert, ProxyBridge is compatible with proxy-unaware applications without requiring any configuration changes.
+ProxyBridge is a lightweight, open-source alternative to Proxifier that provides transparent proxy routing for Windows applications. It redirects TCP and UDP traffic from specific processes through SOCKS5 or HTTP proxies, with the ability to route, block, or allow traffic on a per-application basis. Unlike Proxifier which only logs UDP connections without proxy support, ProxyBridge fully supports both TCP and UDP proxy routing. Working at the kernel level using WinDivert, ProxyBridge is compatible with proxy-unaware applications without requiring any configuration changes.
## Features
@@ -35,6 +35,7 @@ ProxyBridge is a lightweight, open-source alternative to Proxifier that provides
- [Rule Examples](#rule-examples)
- [Use Cases](#use-cases)
- [Current Limitations](#current-limitations)
+- [Things to Note](#things-to-note)
- [How It Works](#how-it-works)
- [Build from Source](#build-from-source)
- [License](#license)
@@ -271,6 +272,22 @@ Commands:
- IPv4 only (IPv6 not supported)
+## Things to Note
+
+- **DNS Traffic Handling**: DNS traffic on TCP and UDP port 53 is handled separately from proxy rules. Even if you configure rules for port 53, they will be ignored. Instead, DNS routing is controlled by the **DNS via Proxy** option in the Proxy menu (enabled by default). When enabled, all DNS queries are routed through the proxy; when disabled, DNS queries use direct connection.
+
+- **Automatic Direct Routing**: Certain IP addresses automatically use direct connection regardless of proxy rules. This includes:
+ - Localhost addresses (127.*.*.*)
+ - Broadcast and multicast addresses
+ - These IPs are used by various processes (curl, Firefox, NVIDIA drivers, Windows services) and system components. Note that Windows loopback traffic uses its own method that bypasses the network interface card (NIC), which currently doesn't support proxy routing due to technical limitations with WinDivert at the network layer.
+
+- **UDP Proxy Requirements**: UDP traffic only works when a SOCKS5 proxy is configured. If an HTTP proxy server is configured, ProxyBridge will ignore UDP proxy rules and route UDP traffic as direct connection instead. This limitation does not affect UDP rules with BLOCK or DIRECT actions.
+
+ **Important UDP Considerations**:
+ - Configuring a SOCKS5 proxy does not guarantee UDP will work. Most SOCKS5 proxies do not support UDP traffic, including SSH SOCKS5 proxies.
+ - The SOCKS5 proxy must support UDP ASSOCIATE command. If ProxyBridge fails to establish a UDP association with the SOCKS5 proxy, packets will fail to connect.
+ - Many UDP applications use HTTP/3 and DTLS protocols. Even if your SOCKS5 proxy supports UDP ASSOCIATE, ensure it can handle DTLS and HTTP/3 UDP traffic, as they require separate handling beyond raw UDP packets.
+ - **Testing UDP/HTTP3/DTLS Support**: If you need to test UDP, HTTP/3, and DTLS support with a SOCKS5 proxy, try [Nexus Proxy](https://github.com/InterceptSuite/nexus-proxy) - a proxy application created specifically to test ProxyBridge with advanced UDP protocols.
## How It Works
diff --git a/img/proxy-rule2.png b/img/proxy-rule2.png
index ea9cf54..ce556fa 100644
Binary files a/img/proxy-rule2.png and b/img/proxy-rule2.png differ
diff --git a/src/ProxyBridge.c b/src/ProxyBridge.c
index e6b64fa..b42a8d1 100644
--- a/src/ProxyBridge.c
+++ b/src/ProxyBridge.c
@@ -1357,16 +1357,47 @@ static DWORD WINAPI udp_relay_server(LPVOID arg)
FD_ZERO(&read_fds);
FD_SET(udp_relay_socket, &read_fds);
- // Only monitor SOCKS5 socket if connection is established
+ // monitor both TCP control connection and UDP send socket
+ if (udp_associate_connected && socks5_udp_socket != INVALID_SOCKET)
+ FD_SET(socks5_udp_socket, &read_fds);
+
if (udp_associate_connected && socks5_udp_send_socket != INVALID_SOCKET)
FD_SET(socks5_udp_send_socket, &read_fds);
struct timeval timeout = {1, 0};
- int max_fd = (udp_relay_socket > socks5_udp_send_socket) ? udp_relay_socket : socks5_udp_send_socket;
+ SOCKET max_fd = udp_relay_socket;
+ if (socks5_udp_socket > max_fd) max_fd = socks5_udp_socket;
+ if (socks5_udp_send_socket > max_fd) max_fd = socks5_udp_send_socket;
+
if (select(max_fd + 1, &read_fds, NULL, NULL, &timeout) <= 0)
continue;
+ // check SOCKS5 server disconnected
+ if (udp_associate_connected && socks5_udp_socket != INVALID_SOCKET && FD_ISSET(socks5_udp_socket, &read_fds))
+ {
+ char test_buf[1];
+ int result = recv(socks5_udp_socket, test_buf, sizeof(test_buf), MSG_PEEK);
+ if (result == 0 || (result == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK))
+ {
+ log_message("[UDP RELAY] TCP control connection closed - SOCKS5 proxy disconnected");
+
+ // close all connections
+ if (socks5_udp_socket != INVALID_SOCKET)
+ {
+ closesocket(socks5_udp_socket);
+ socks5_udp_socket = INVALID_SOCKET;
+ }
+ if (socks5_udp_send_socket != INVALID_SOCKET)
+ {
+ closesocket(socks5_udp_send_socket);
+ socks5_udp_send_socket = INVALID_SOCKET;
+ }
+ udp_associate_connected = FALSE;
+ continue;
+ }
+ }
+
// Check if packet is from local application
if (FD_ISSET(udp_relay_socket, &read_fds))
{
@@ -1414,8 +1445,19 @@ static DWORD WINAPI udp_relay_server(LPVOID arg)
if (sent == SOCKET_ERROR) {
int err = WSAGetLastError();
- log_message("[UDP RELAY ERROR] Failed to send to SOCKS5 proxy: %d", err);
- // Connection might be broken, mark for retry
+ log_message("[UDP RELAY ERROR] Failed to send to SOCKS5 proxy: %d - closing connection", err);
+
+ // connection is broken close all sockets and retry
+ if (socks5_udp_socket != INVALID_SOCKET)
+ {
+ closesocket(socks5_udp_socket);
+ socks5_udp_socket = INVALID_SOCKET;
+ }
+ if (socks5_udp_send_socket != INVALID_SOCKET)
+ {
+ closesocket(socks5_udp_send_socket);
+ socks5_udp_send_socket = INVALID_SOCKET;
+ }
udp_associate_connected = FALSE;
}
}
@@ -1433,6 +1475,24 @@ static DWORD WINAPI udp_relay_server(LPVOID arg)
recv_len = recvfrom(socks5_udp_send_socket, (char*)recv_buf, sizeof(recv_buf), 0,
(struct sockaddr *)&from_addr, &from_len);
+ if (recv_len == SOCKET_ERROR)
+ {
+ int err = WSAGetLastError();
+ log_message("[UDP RELAY ERROR] Failed to receive from SOCKS5 proxy: %d - closing connection", err);
+ if (socks5_udp_socket != INVALID_SOCKET)
+ {
+ closesocket(socks5_udp_socket);
+ socks5_udp_socket = INVALID_SOCKET;
+ }
+ if (socks5_udp_send_socket != INVALID_SOCKET)
+ {
+ closesocket(socks5_udp_send_socket);
+ socks5_udp_send_socket = INVALID_SOCKET;
+ }
+ udp_associate_connected = FALSE;
+ continue;
+ }
+
if (recv_len > 0)
{
// Packet from SOCKS5 proxy - decapsulate and forward to original sender