Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic
C ccybersecurityhttp3httpproxylinuxlinux-proxymacosmacos-appmacos-proxyproxifierproxifier-alternativeproxyclienttcpthick-clientudpwindivertwindows
strip
Sourav Kalal18a06fe2eaa5
diff --git a/Linux/cli/main.c b/Linux/cli/main.cindex 6781f14..45a540a 100644--- a/Linux/cli/main.c+++ b/Linux/cli/main.c@@ -33,7 +33,7 @@ static void connection_callback(const char* process_name, uint32_t pid, const ch{if (verbose_level == 2 || verbose_level == 3){- printf("[CONN] %s (PID:%u) -> %s:%u via %s\n",+ printf("[CONN] %s (PID:%u) -> %s:%u via %s\n",process_name, pid, dest_ip, dest_port, proxy_info);}}@@ -43,14 +43,14 @@ static void signal_handler(int sig)if (sig == SIGSEGV || sig == SIGABRT || sig == SIGBUS){printf("\n\n=== CLI CRASH DETECTED ===\n");- printf("Signal: %d (%s)\n", sig,- sig == SIGSEGV ? "SEGFAULT" :+ printf("Signal: %d (%s)\n", sig,+ sig == SIGSEGV ? "SEGFAULT" :sig == SIGABRT ? "ABORT" : "BUS ERROR");printf("Calling emergency cleanup...\n");ProxyBridge_Stop();_exit(1);}-+if (keep_running){printf("\n\nStopping ProxyBridge...\n");@@ -80,14 +80,14 @@ static void show_help(const char* prog)show_banner();printf("USAGE:\n");printf(" %s [OPTIONS]\n\n", prog);-+printf("OPTIONS:\n");printf(" --proxy <url> Proxy server URL with optional authentication\n");printf(" Format: type://ip:port or type://ip:port:username:password\n");printf(" Examples: socks5://127.0.0.1:1080\n");printf(" http://proxy.com:8080:myuser:mypass\n");printf(" Default: socks5://127.0.0.1:4444\n\n");-+printf(" --rule <rule> Traffic routing rule (can be specified multiple times)\n");printf(" Format: process:hosts:ports:protocol:action\n");printf(" process - Process name(s): curl, cur*, *, or multiple separated by ;\n");@@ -100,37 +100,37 @@ static void show_help(const char* prog)printf(" curl;wget:*:*:TCP:PROXY\n");printf(" *:*:53:UDP:PROXY\n");printf(" firefox:*:80;443:TCP:DIRECT\n\n");-+printf(" --dns-via-proxy <bool> Route DNS queries through proxy\n");printf(" Values: true, false, 1, 0\n");printf(" Default: true\n\n");-+printf(" --verbose <level> Logging verbosity level\n");printf(" 0 - No logs (default)\n");printf(" 1 - Show log messages only\n");printf(" 2 - Show connection events only\n");printf(" 3 - Show both logs and connections\n\n");-+printf(" --cleanup Cleanup resources (iptables, etc.) from crashed instance\n");printf(" Use if ProxyBridge crashed without proper cleanup\n\n");-+printf(" --help, -h Show this help message\n\n");-+printf("EXAMPLES:\n");printf(" # Basic usage with default proxy\n");printf(" sudo %s --rule curl:*:*:TCP:PROXY\n\n", prog);-+printf(" # Multiple rules with custom proxy\n");printf(" sudo %s --proxy socks5://192.168.1.10:1080 \\\n", prog);printf(" --rule curl:*:*:TCP:PROXY \\\n");printf(" --rule wget:*:*:TCP:PROXY \\\n");printf(" --verbose 2\n\n");-+printf(" # Route DNS through proxy with multiple apps\n");printf(" sudo %s --proxy socks5://127.0.0.1:1080 \\\n", prog);printf(" --rule \"curl;wget;firefox:*:*:BOTH:PROXY\" \\\n");printf(" --dns-via-proxy true --verbose 3\n\n");-+printf("NOTE:\n");printf(" ProxyBridge requires root privileges to use nfqueue.\n");printf(" Run with 'sudo' or as root user.\n\n");@@ -142,7 +142,7 @@ static RuleProtocol parse_protocol(const char* str)for (size_t i = 0; str[i] && i < 15; i++)upper[i] = toupper(str[i]);upper[strlen(str) < 15 ? strlen(str) : 15] = '\0';-+if (strcmp(upper, "TCP") == 0)return RULE_PROTOCOL_TCP;else if (strcmp(upper, "UDP") == 0)@@ -162,7 +162,7 @@ static RuleAction parse_action(const char* str)for (size_t i = 0; str[i] && i < 15; i++)upper[i] = toupper(str[i]);upper[strlen(str) < 15 ? strlen(str) : 15] = '\0';-+if (strcmp(upper, "PROXY") == 0)return RULE_ACTION_PROXY;else if (strcmp(upper, "DIRECT") == 0)@@ -190,31 +190,31 @@ static bool parse_rule(const char* rule_str, ProxyRule* rule)char buffer[MAX_RULE_STR];strncpy(buffer, rule_str, sizeof(buffer) - 1);buffer[sizeof(buffer) - 1] = '\0';-+char* parts[5] = {NULL, NULL, NULL, NULL, NULL};int part_idx = 0;char* token = strtok(buffer, ":");-+while (token != NULL && part_idx < 5){parts[part_idx++] = token;token = strtok(NULL, ":");}-+if (part_idx != 5){fprintf(stderr, "ERROR: Invalid rule format '%s'\n", rule_str);fprintf(stderr, "Expected format: process:hosts:ports:protocol:action\n");return false;}-+default_if_empty(rule->process_name, parts[0], "*", sizeof(rule->process_name));default_if_empty(rule->target_hosts, parts[1], "*", sizeof(rule->target_hosts));default_if_empty(rule->target_ports, parts[2], "*", sizeof(rule->target_ports));-+rule->protocol = parse_protocol(parts[3]);rule->action = parse_action(parts[4]);-+return true;}@@ -223,10 +223,10 @@ static bool parse_proxy_url(const char* url, ProxyType* type, char* host, uint16char buffer[512];strncpy(buffer, url, sizeof(buffer) - 1);buffer[sizeof(buffer) - 1] = '\0';-+username[0] = '\0';password[0] = '\0';-+// parse type://char* scheme_end = strstr(buffer, "://");if (scheme_end == NULL)@@ -234,16 +234,16 @@ static bool parse_proxy_url(const char* url, ProxyType* type, char* host, uint16fprintf(stderr, "ERROR: Invalid proxy URL format. Expected type://host:port\n");return false;}-+*scheme_end = '\0';char* scheme = buffer;char* rest = scheme_end + 3;-+char upper_scheme[16];for (size_t i = 0; scheme[i] && i < 15; i++)upper_scheme[i] = toupper(scheme[i]);upper_scheme[strlen(scheme) < 15 ? strlen(scheme) : 15] = '\0';-+if (strcmp(upper_scheme, "SOCKS5") == 0)*type = PROXY_TYPE_SOCKS5;else if (strcmp(upper_scheme, "HTTP") == 0)@@ -253,7 +253,7 @@ static bool parse_proxy_url(const char* url, ProxyType* type, char* host, uint16fprintf(stderr, "ERROR: Invalid proxy type '%s'. Use 'socks5' or 'http'\n", scheme);return false;}-+// parse host:port[:user:pass]char* parts[4];int num_parts = 0;@@ -263,23 +263,23 @@ static bool parse_proxy_url(const char* url, ProxyType* type, char* host, uint16parts[num_parts++] = token;token = strtok(NULL, ":");}-+if (num_parts < 2){fprintf(stderr, "ERROR: Invalid proxy URL. Missing host or port\n");return false;}-+strncpy(host, parts[0], 255);host[255] = '\0';-+*port = atoi(parts[1]);if (*port == 0){fprintf(stderr, "ERROR: Invalid proxy port '%s'\n", parts[1]);return false;}-+if (num_parts >= 4){strncpy(username, parts[2], 255);@@ -287,7 +287,7 @@ static bool parse_proxy_url(const char* url, ProxyType* type, char* host, uint16strncpy(password, parts[3], 255);password[255] = '\0';}-+return true;}@@ -309,12 +309,12 @@ int main(int argc, char *argv[])return 0;}}-+char proxy_url[512] = "socks5://127.0.0.1:4444";ProxyRule rules[MAX_RULES];int num_rules = 0;bool dns_via_proxy = true;-+// parse argsfor (int i = 1; i < argc; i++){@@ -368,9 +368,9 @@ int main(int argc, char *argv[])return 1;}}-+show_banner();-+// need rootif (!is_root()){@@ -378,54 +378,54 @@ int main(int argc, char *argv[])printf("Please run this application with sudo or as root.\n\n");return 1;}-+// parse proxy configProxyType proxy_type;char proxy_host[256];uint16_t proxy_port;char proxy_username[256];char proxy_password[256];-+if (!parse_proxy_url(proxy_url, &proxy_type, proxy_host, &proxy_port, proxy_username, proxy_password))return 1;-+// setup callbacks based on verbose// 0=nothing 1=logs 2=connections 3=both-+if (verbose_level == 1 || verbose_level == 3)ProxyBridge_SetLogCallback(log_callback);elseProxyBridge_SetLogCallback(NULL); // Explicitly disable-+if (verbose_level == 2 || verbose_level == 3)ProxyBridge_SetConnectionCallback(connection_callback);elseProxyBridge_SetConnectionCallback(NULL); // Explicitly disable-+// turn on traffic logging when neededProxyBridge_SetTrafficLoggingEnabled(verbose_level > 0);-+// show config- printf("Proxy: %s://%s:%u\n",+ printf("Proxy: %s://%s:%u\n",proxy_type == PROXY_TYPE_HTTP ? "http" : "socks5",proxy_host, proxy_port);-+if (proxy_username[0] != '\0')printf("Proxy Auth: %s:***\n", proxy_username);-+printf("DNS via Proxy: %s\n", dns_via_proxy ? "Enabled" : "Disabled");-+// setup proxy- if (!ProxyBridge_SetProxyConfig(proxy_type, proxy_host, proxy_port,+ if (!ProxyBridge_SetProxyConfig(proxy_type, proxy_host, proxy_port,proxy_username[0] ? proxy_username : "",proxy_password[0] ? proxy_password : "")){fprintf(stderr, "ERROR: Failed to set proxy configuration\n");return 1;}-+ProxyBridge_SetDnsViaProxy(dns_via_proxy);-+// add rulesif (num_rules > 0){@@ -436,17 +436,17 @@ int main(int argc, char *argv[])rules[i].protocol == RULE_PROTOCOL_UDP ? "UDP" : "BOTH";const char* action_str = rules[i].action == RULE_ACTION_PROXY ? "PROXY" :rules[i].action == RULE_ACTION_DIRECT ? "DIRECT" : "BLOCK";-+uint32_t rule_id = ProxyBridge_AddRule(rules[i].process_name,rules[i].target_hosts,rules[i].target_ports,rules[i].protocol,rules[i].action);-+if (rule_id > 0){- printf(" [%u] %s:%s:%s:%s -> %s\n",+ printf(" [%u] %s:%s:%s:%s -> %s\n",rule_id,rules[i].process_name,rules[i].target_hosts,@@ -465,32 +465,32 @@ int main(int argc, char *argv[])printf("\033[33mWARNING: No rules specified. No traffic will be proxied.\033[0m\n");printf("Use --rule to add proxy rules. See --help for examples.\n");}-+// start proxybridgeif (!ProxyBridge_Start()){fprintf(stderr, "ERROR: Failed to start ProxyBridge\n");return 1;}-+keep_running = true;printf("\nProxyBridge started. Press Ctrl+C to stop...\n\n");-+signal(SIGINT, signal_handler);signal(SIGTERM, signal_handler);signal(SIGSEGV, signal_handler); // Catch segfaultsignal(SIGABRT, signal_handler); // Catch abortsignal(SIGBUS, signal_handler); // Catch bus error-+// main loopwhile (keep_running){sleep(1);}-+// cleanupProxyBridge_Stop();printf("ProxyBridge stopped.\n");-+return 0;}diff --git a/Linux/gui/gui_config.c b/Linux/gui/gui_config.cindex 0abf955..4030967 100644--- a/Linux/gui/gui_config.c+++ b/Linux/gui/gui_config.c@@ -59,7 +59,7 @@ void load_config() {while (fgets(line, sizeof(line), f)) {// trim newlineline[strcspn(line, "\r\n")] = 0;-+if (strlen(line) == 0 || line[0] == '#') continue;if (strcmp(line, "[SETTINGS]") == 0) { section = 1; continue; }@@ -69,7 +69,7 @@ void load_config() {char *val = strchr(line, '=');if (!val) continue;*val = 0; val++;-+if (strcmp(line, "ip") == 0) strncpy(g_proxy_ip, val, sizeof(g_proxy_ip) - 1);else if (strcmp(line, "port") == 0) g_proxy_port = atoi(val);else if (strcmp(line, "type") == 0) g_proxy_type = atoi(val);@@ -84,7 +84,7 @@ void load_config() {char *p = line;char *token;int idx = 0;-+while ((token = strsep(&p, "|")) != NULL) {switch(idx) {case 0: rule->id = atoi(token); break;@@ -97,7 +97,7 @@ void load_config() {}idx++;}-+if (idx >= 4) {g_rules_list = g_list_append(g_rules_list, rule);} else {diff --git a/Linux/gui/gui_logs.c b/Linux/gui/gui_logs.cindex 3ff4c68..8fc8d2f 100644--- a/Linux/gui/gui_logs.c+++ b/Linux/gui/gui_logs.c@@ -3,7 +3,7 @@// filter logs based on searchstatic void filter_text_view(GtkTextBuffer *buffer, const char *text) {if (!buffer) return;-+GtkTextIter start, end;gtk_text_buffer_get_bounds(buffer, &start, &end);gtk_text_buffer_remove_tag_by_name(buffer, "hidden", &start, &end);@@ -15,23 +15,23 @@ static void filter_text_view(GtkTextBuffer *buffer, const char *text) {GtkTextIter line_end = line_start;if (!gtk_text_iter_ends_line(&line_end))gtk_text_iter_forward_to_line_end(&line_end);-+char *line_text = gtk_text_buffer_get_text(buffer, &line_start, &line_end, FALSE);-+// search case insensitivechar *lower_line = g_utf8_strdown(line_text, -1);char *lower_search = g_utf8_strdown(text, -1);- if (!strstr(lower_line, lower_search)) {- GtkTextIter next_line = line_end;+ if (!strstr(lower_line, lower_search)) {+ GtkTextIter next_line = line_end;gtk_text_iter_forward_char(&next_line); // include newlinegtk_text_buffer_apply_tag_by_name(buffer, "hidden", &line_start, &next_line);}-+g_free(lower_line);g_free(lower_search);g_free(line_text);-+gtk_text_iter_forward_line(&line_start);}}@@ -71,7 +71,7 @@ static gboolean update_log_gui(gpointer user_data) {GtkTextIter end;gtk_text_buffer_get_end_iter(log_buffer, &end);-+char *time_str = get_current_time_str();char full_msg[1200];snprintf(full_msg, sizeof(full_msg), "%s %s\n", time_str, data->message);@@ -94,11 +94,11 @@ static gboolean update_connection_gui_append(gpointer user_data) {if (conn_buffer) {GtkTextIter end;gtk_text_buffer_get_end_iter(conn_buffer, &end);-+char line_buffer[1024];- snprintf(line_buffer, sizeof(line_buffer), "%s %s (PID:%u) -> %s:%u via %s\n",+ snprintf(line_buffer, sizeof(line_buffer), "%s %s (PID:%u) -> %s:%u via %s\n",data->timestamp, data->process_name, data->pid, data->dest_ip, data->dest_port, data->proxy_info);-+gtk_text_buffer_insert(conn_buffer, &end, line_buffer, -1);trim_buffer_lines(conn_buffer, 100);