Skip to content

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

feat(windows): IPv4 CIDR in Target Hosts, 32 proxy servers, CLI and Help link fixes

AnoF-Cyber9078eca1aa7a
diff --git a/Windows/README.md b/Windows/README.md
index 31036a7..d019dbb 100644
--- a/Windows/README.md
+++ b/Windows/README.md
@@ -109,6 +109,7 @@ ProxyBridge supports multiple proxy server configurations simultaneously. Each p
- Wildcard IP range: `192.168.*.*`
- Multiple IPs: `127.0.0.1; 192.168.1.1`
- IP range: `10.10.1.1-10.10.255.255`
+ - IPv4 CIDR: `10.0.0.0/8`, `192.168.1.128/25`
- IPv6 exact: `::1`, `2001:db8::1`
- IPv6 CIDR: `2001:db8::/32`, `fe80::/10`
- IPv6 range: `2001:db8::1-2001:db8::ff`
@@ -251,13 +252,13 @@ saved per profile. It only changes what is listed: rules are applied to the same
#### Profile Format
-The CLI reads `.pbprofile` files exported directly from the GUI (**File → Export Profile**). These are JSON files containing proxy server configurations and routing rules. See the [Profile JSON Format](#exporting-and-importing-rules) section above for the schema.
+The CLI reads `.pbprofile` files exported directly from the GUI (**Profile → Export Profile**). These are JSON files containing proxy server configurations and routing rules. See the [Profile JSON Format](#exporting-and-importing-rules) section above for the schema.
**Key profile fields read by the CLI:**
| Field | Description |
|---|---|
-| `ProxyConfigs[]` | Array of proxy servers (SOCKS5 or HTTP, up to 16) |
+| `ProxyConfigs[]` | Array of proxy servers (SOCKS5 or HTTP, up to 32) |
| `ProxyRules[]` | Array of routing rules (up to 256) |
| `ProxyRules[].LocalhostViaProxy` | Per rule: also proxy `127.x.x.x` / `::1` traffic that matches this rule (default `false`) |
| `IsTrafficLoggingEnabled` | Enable/disable connection logging |
@@ -299,7 +300,7 @@ ProxyBridge_CLI.exe --help
Options:
--profile <path> Path to .pbprofile file exported from the GUI
- Export from GUI: File > Export Profile
+ Export from GUI: Profile > Export Profile
--verbose <0-3> Logging verbosity
0 - Silent (default)
@@ -391,7 +392,7 @@ Commands:
- Many UDP applications use HTTP/3 and DTLS protocols - ensure your proxy handles these
- **Testing**: Try [Nexus Proxy](https://github.com/InterceptSuite/nexus-proxy) to test ProxyBridge UDP/HTTP3/DTLS support
-- **Multiple Proxy Configurations**: Up to 16 proxy server configurations can be active simultaneously. Rules can each be assigned to a specific proxy config. If the assigned config is not found, ProxyBridge falls back to the first available config. This allows routing different apps through different proxies without any application-side configuration.
+- **Multiple Proxy Configurations**: Up to 32 proxy server configurations can be active simultaneously. Rules can each be assigned to a specific proxy config. If the assigned config is not found, ProxyBridge falls back to the first available config. This allows routing different apps through different proxies without any application-side configuration.
## How It Works
diff --git a/Windows/cli/main.c b/Windows/cli/main.c
index 65f6657..78e242b 100644
--- a/Windows/cli/main.c
+++ b/Windows/cli/main.c
@@ -18,7 +18,7 @@
#define VERSION "4.2.0"
-#define MAX_PROXY_CONFIGS 16
+#define MAX_PROXY_CONFIGS 32
#define MAX_RULES 256
@@ -208,7 +208,7 @@ static void show_help(const char* prog)
printf(" %s [options]\n\n", prog);
printf("Options:\n");
printf(" --profile <path> Path to .pbprofile file\n");
- printf(" Export from the GUI: File > Export Profile\n\n");
+ printf(" Export from the GUI: Profile > Export Profile\n\n");
printf(" --verbose <0-3> Logging verbosity\n");
printf(" 0 - Silent (default)\n");
printf(" 1 - Log messages only\n");
diff --git a/Windows/gui/main.c b/Windows/gui/main.c
index e70a6a6..454deaf 100644
--- a/Windows/gui/main.c
+++ b/Windows/gui/main.c
@@ -1032,7 +1032,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
return 0;
}
case IDM_HELP_DOCS:
- ShellExecuteW(hwnd, L"open", L"https://interceptsuite.com/docs/proxybridge/", NULL, NULL, SW_SHOWNORMAL);
+ ShellExecuteW(hwnd, L"open", L"https://proxybridge.interceptsuite.com/docs/", NULL, NULL, SW_SHOWNORMAL);
return 0;
case IDM_HELP_UPDATE:
UpdStartCheck(hwnd, TRUE); // manual: also reports "up to date" / errors
diff --git a/Windows/src/ProxyBridge.h b/Windows/src/ProxyBridge.h
index e3d149f..00b46de 100644
--- a/Windows/src/ProxyBridge.h
+++ b/Windows/src/ProxyBridge.h
@@ -13,7 +13,7 @@
extern "C" {
#endif
-#define MAX_PROXY_CONFIGS 16
+#define MAX_PROXY_CONFIGS 32
typedef void (*LogCallback)(const char* message);
typedef void (*ConnectionCallback)(const char* process_name, DWORD pid, const char* dest_ip, UINT16 dest_port, const char* proxy_info);
diff --git a/Windows/src/pb_internal.h b/Windows/src/pb_internal.h
index f690630..5e3508f 100644
--- a/Windows/src/pb_internal.h
+++ b/Windows/src/pb_internal.h
@@ -5,6 +5,11 @@
// ProxyBridge.c (globals + lifecycle), pb_net.c, pb_rules.c, pb_conn.c.
// Defines, structs, extern globals and cross-module prototypes live here.
+// select() sets hold 64 sockets by default and FD_SET silently drops the rest. The UDP relay watches two sockets per
+// SOCKS5 proxy plus its own two, which is 66 with 32 proxies, so the sets must be bigger. Must come before winsock2.h.
+#ifndef FD_SETSIZE
+#define FD_SETSIZE 128
+#endif
#include <winsock2.h>
#include <windows.h>
#include "ProxyBridge.h"
@@ -17,6 +22,8 @@
#include <string.h>
#include "windivert.h"
+typedef char pb_fd_setsize_fits_all_proxies[(FD_SETSIZE >= 2 * MAX_PROXY_CONFIGS + 4) ? 1 : -1]; // compile error if MAX_PROXY_CONFIGS grows past it
+
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "advapi32.lib") // token elevation check for the firewall rule
diff --git a/Windows/src/pb_rules.c b/Windows/src/pb_rules.c
index bbca1cd..ad50e41 100644
--- a/Windows/src/pb_rules.c
+++ b/Windows/src/pb_rules.c
@@ -79,6 +79,21 @@ BOOL match_ip_pattern(const char *pattern, UINT32 ip)
if (pattern == NULL || strcmp(pattern, "*") == 0)
return TRUE;
+ // CIDR notation, e.g. "10.0.0.0/8" or "192.168.1.128/25": the first <prefix> bits must match.
+ // Strict on purpose: four numbers 0-255, a prefix of 0-32 and nothing after it, otherwise the entry matches nothing.
+ if (strchr(pattern, '/') != NULL)
+ {
+ int c1, c2, c3, c4, prefix, used = 0;
+ if (sscanf_s(pattern, "%d.%d.%d.%d/%d%n", &c1, &c2, &c3, &c4, &prefix, &used) != 5 || pattern[used] != '\0')
+ return FALSE;
+ if (c1 < 0 || c1 > 255 || c2 < 0 || c2 > 255 || c3 < 0 || c3 > 255 || c4 < 0 || c4 > 255 || prefix < 0 || prefix > 32)
+ return FALSE;
+ UINT32 ip_be = ((ip & 0xFF) << 24) | ((ip & 0xFF00) << 8) | ((ip & 0xFF0000) >> 8) | ((ip & 0xFF000000) >> 24);
+ UINT32 net_be = ((UINT32)c1 << 24) | ((UINT32)c2 << 16) | ((UINT32)c3 << 8) | (UINT32)c4;
+ UINT32 mask = prefix == 0 ? 0 : (0xFFFFFFFFu << (32 - prefix));
+ return (ip_be & mask) == (net_be & mask);
+ }
+
// check for IP range
char *dash = strchr(pattern, '-');
if (dash != NULL)
diff --git a/Windows/tests/test_engine.c b/Windows/tests/test_engine.c
index 9b41164..13ab949 100644
--- a/Windows/tests/test_engine.c
+++ b/Windows/tests/test_engine.c
@@ -108,5 +108,13 @@ int main(void)
ProxyBridge_EnableRule(x); CHECK(m4("zzz.exe", "8.8.8.8", 1) == RULE_ACTION_BLOCK);
ProxyBridge_DeleteRule(x); CHECK(m4("zzz.exe", "8.8.8.8", 1) == RULE_ACTION_DIRECT);
+ /* the GUI offers 32 proxy servers, so the engine must accept 32 (and refuse a 33rd, not overflow) */
+ { UINT32 ids[40]; int got = 0;
+ for (int i = 0; i < 40; i++) { ids[i] = ProxyBridge_AddProxyConfig(PROXY_TYPE_SOCKS5, "127.0.0.1", (UINT16)(2000 + i), NULL, NULL, TRUE); if (ids[i]) got++; }
+ CHECK(MAX_PROXY_CONFIGS == 32 && got == 32 && ids[31] != 0 && ids[32] == 0);
+ for (int i = 0; i < 40; i++) if (ids[i]) ProxyBridge_DeleteProxyConfig(ids[i]);
+ CHECK(ProxyBridge_AddProxyConfig(PROXY_TYPE_HTTP, "127.0.0.1", 3000, NULL, NULL, FALSE) != 0); /* room again after deleting */
+ }
+
return pbtest_done("test_engine");
}
diff --git a/Windows/tests/test_rules_match.c b/Windows/tests/test_rules_match.c
index 6c8ef5f..1b1f95b 100644
--- a/Windows/tests/test_rules_match.c
+++ b/Windows/tests/test_rules_match.c
@@ -26,6 +26,25 @@ int main(void)
CHECK(match_ip_list("", ip4("1.1.1.1")) && match_ip_list("*", ip4("1.1.1.1")));
CHECK(!match_ip_list(";", ip4("1.1.1.1"))); /* only separators: matches nothing (the GUI turns this into "*") */
+ /* IPv4 CIDR */
+ CHECK(match_ip_pattern("10.0.0.0/8", ip4("10.1.2.3")) && match_ip_pattern("10.0.0.0/8", ip4("10.255.255.255")) && match_ip_pattern("10.0.0.0/8", ip4("10.0.0.0")));
+ CHECK(!match_ip_pattern("10.0.0.0/8", ip4("11.0.0.1")) && !match_ip_pattern("10.0.0.0/8", ip4("9.255.255.255")));
+ CHECK(match_ip_pattern("192.168.1.128/25", ip4("192.168.1.200")) && match_ip_pattern("192.168.1.128/25", ip4("192.168.1.255")) &&
+ !match_ip_pattern("192.168.1.128/25", ip4("192.168.1.127")) && !match_ip_pattern("192.168.1.128/25", ip4("192.168.2.200"))); /* not on an octet boundary */
+ CHECK(match_ip_pattern("172.16.0.0/12", ip4("172.31.255.255")) && !match_ip_pattern("172.16.0.0/12", ip4("172.32.0.0")));
+ CHECK(match_ip_pattern("1.2.3.4/32", ip4("1.2.3.4")) && !match_ip_pattern("1.2.3.4/32", ip4("1.2.3.5"))); /* /32 = one address */
+ CHECK(match_ip_pattern("0.0.0.0/0", ip4("8.8.8.8")) && match_ip_pattern("0.0.0.0/0", ip4("255.255.255.255"))); /* /0 = everything */
+ CHECK(match_ip_pattern("10.1.2.3/8", ip4("10.99.0.1"))); /* host bits in the address are ignored */
+ CHECK(!match_ip_pattern("10.0.0.0/33", ip4("10.0.0.1")) && !match_ip_pattern("10.0.0.0/-1", ip4("10.0.0.1")) && !match_ip_pattern("10.0.0.0/", ip4("10.0.0.1")) &&
+ !match_ip_pattern("10.0.0.0/8x", ip4("10.0.0.1")) && !match_ip_pattern("10.0.0/8", ip4("10.0.0.1")) && !match_ip_pattern("300.0.0.0/8", ip4("10.0.0.1")) &&
+ !match_ip_pattern("10.*.*.*/8", ip4("10.0.0.1")) && !match_ip_pattern("/8", ip4("10.0.0.1"))); /* malformed: matches nothing */
+ CHECK(match_ip_list("10.0.0.0/8;192.168.0.0/16;172.16.0.0-172.31.255.255", ip4("192.168.44.1")) &&
+ match_ip_list("10.0.0.0/8;192.168.0.0/16;172.16.0.0-172.31.255.255", ip4("172.20.0.1")) &&
+ !match_ip_list("10.0.0.0/8;192.168.0.0/16;172.16.0.0-172.31.255.255", ip4("8.8.8.8"))); /* CIDR, range and list together */
+ { UINT32 c = ProxyBridge_AddRule("cidr.exe", "10.0.0.0/8", "*", "*", RULE_PROTOCOL_BOTH, RULE_ACTION_BLOCK, 0, FALSE);
+ CHECK(c != 0 && m4("cidr.exe", "10.200.1.1", 443) == RULE_ACTION_BLOCK && m4("cidr.exe", "11.0.0.1", 443) == RULE_ACTION_DIRECT); /* through a real rule */
+ ProxyBridge_DeleteRule(c); }
+
/* ================= IPv6 patterns ================= */
CHECK(v6("::1", "::1") && !v6("::1", "::2") && v6("*", "2001:db8::5"));
CHECK(v6("2001:db8::/32", "2001:db8:ffff::1") && !v6("2001:db8::/32", "2001:db9::1"));