Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic
C ccybersecurityhttp3httpproxylinuxlinux-proxymacosmacos-appmacos-proxyproxifierproxifier-alternativeproxyclienttcpthick-clientudpwindivertwindows
fixed #47 windows startup uac for admin permission - fixed garbage issue in C connection
Sourav Kalal14248d2562bc
diff --git a/Windows/gui/Services/SettingsService.cs b/Windows/gui/Services/SettingsService.csindex 6e51756..8f191ce 100644--- a/Windows/gui/Services/SettingsService.cs+++ b/Windows/gui/Services/SettingsService.cs@@ -2,7 +2,6 @@ using System;using System.IO;using System.Text.Json;using System.Text.Json.Serialization;-using Microsoft.Win32;namespace ProxyBridge.GUI.Services;@@ -58,36 +57,50 @@ public class SettingsServicepublic void SetStartupWithWindows(bool enable){- const string keyName = "ProxyBridge";- const string runKey = @"Software\Microsoft\Windows\CurrentVersion\Run";- const string approvedKey = @"Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run";+ const string taskName = "ProxyBridge";try{- using var key = Registry.CurrentUser.OpenSubKey(runKey, true);- if (key == null) return;+ var exePath = Environment.ProcessPath;+ if (exePath == null) return;if (enable){- var exePath = Environment.ProcessPath;- if (exePath != null)+ // Adding in registy in Software\Microsoft\Windows\CurrentVersion\Run is not possible or bad idea+ // app need admin permisison to run with registy not posible or uac at startup whicih is bad idea+ // Possible solution - Windows Service - Have no experience developing serice and its too much work for simple startup load+ // Solution 2 - Task schedule - implemented+ var arguments = $"/Create /F /TN \"{taskName}\" /TR \"\\\"{exePath}\\\" --minimized\" /SC ONLOGON /RL HIGHEST";++ var startInfo = new System.Diagnostics.ProcessStartInfo{- key.SetValue(keyName, $"\"{exePath}\" --minimized");-- using var approvedKeyHandle = Registry.CurrentUser.CreateSubKey(approvedKey, true);- if (approvedKeyHandle != null)- {- byte[] enabledData = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };- approvedKeyHandle.SetValue(keyName, enabledData, RegistryValueKind.Binary);- }- }+ FileName = "schtasks.exe",+ Arguments = arguments,+ UseShellExecute = false,+ CreateNoWindow = true,+ RedirectStandardOutput = true,+ RedirectStandardError = true+ };++ using var process = System.Diagnostics.Process.Start(startInfo);+ process?.WaitForExit();}else{- key.DeleteValue(keyName, false);+ var arguments = $"/Delete /F /TN \"{taskName}\"";++ var startInfo = new System.Diagnostics.ProcessStartInfo+ {+ FileName = "schtasks.exe",+ Arguments = arguments,+ UseShellExecute = false,+ CreateNoWindow = true,+ RedirectStandardOutput = true,+ RedirectStandardError = true+ };- using var approvedKeyHandle = Registry.CurrentUser.OpenSubKey(approvedKey, true);- approvedKeyHandle?.DeleteValue(keyName, false);+ using var process = System.Diagnostics.Process.Start(startInfo);+ process?.WaitForExit();}}catch@@ -97,13 +110,25 @@ public class SettingsServicepublic bool IsStartupEnabled(){- const string keyName = "ProxyBridge";- const string runKey = @"Software\Microsoft\Windows\CurrentVersion\Run";+ const string taskName = "ProxyBridge";try{- using var key = Registry.CurrentUser.OpenSubKey(runKey, false);- return key?.GetValue(keyName) != null;+ var startInfo = new System.Diagnostics.ProcessStartInfo+ {+ FileName = "schtasks.exe",+ Arguments = $"/Query /TN \"{taskName}\"",+ UseShellExecute = false,+ CreateNoWindow = true,+ RedirectStandardOutput = true,+ RedirectStandardError = true+ };++ using var process = System.Diagnostics.Process.Start(startInfo);+ if (process == null) return false;++ process.WaitForExit();+ return process.ExitCode == 0;}catch{diff --git a/Windows/src/ProxyBridge.c b/Windows/src/ProxyBridge.cindex e7b8ca3..303a808 100644--- a/Windows/src/ProxyBridge.c+++ b/Windows/src/ProxyBridge.c@@ -2480,6 +2480,12 @@ PROXYBRIDGE_API void ProxyBridge_SetTrafficLoggingEnabled(BOOL enable)}}+PROXYBRIDGE_API void ProxyBridge_ClearConnectionLogs(void)+{+ clear_logged_connections();+ log_message("Connection logs cleared");+}+// Check if connection already logged (deduplication)static BOOL is_connection_already_logged(DWORD pid, UINT32 dest_ip, UINT16 dest_port, RuleAction action){@@ -2504,10 +2510,48 @@ static BOOL is_connection_already_logged(DWORD pid, UINT32 dest_ip, UINT16 dest_return found;}++// Memory usage and cpu usage are limitation of the ProxyBridge arch+// Relay server takes huge amount of memory and cpu and add extra hops+// hops can cuase slight delay in network speed+// relay server are ippoved to process it as fast as possible with minimal impact on memory usage+static void add_logged_connection(DWORD pid, UINT32 dest_ip, UINT16 dest_port, RuleAction action){WaitForSingleObject(lock, INFINITE);+ int count = 0;+ LOGGED_CONNECTION *temp = logged_connections;+ while (temp != NULL)+ {+ count++;+ temp = temp->next;+ }++ if (count >= 100)+ {+ temp = logged_connections;+ for (int i = 0; i < 98 && temp != NULL; i++)+ {+ temp = temp->next;+ }++ if (temp != NULL && temp->next != NULL)+ {+ LOGGED_CONNECTION *to_free_list = temp->next;+ temp->next = NULL;++ ReleaseMutex(lock);+ while (to_free_list != NULL)+ {+ LOGGED_CONNECTION *next = to_free_list->next;+ free(to_free_list);+ to_free_list = next;+ }+ WaitForSingleObject(lock, INFINITE);+ }+ }+LOGGED_CONNECTION *logged = (LOGGED_CONNECTION *)malloc(sizeof(LOGGED_CONNECTION));if (logged != NULL){diff --git a/Windows/src/ProxyBridge.h b/Windows/src/ProxyBridge.hindex 893d99d..6f7f1c1 100644--- a/Windows/src/ProxyBridge.h+++ b/Windows/src/ProxyBridge.h@@ -43,6 +43,7 @@ PROXYBRIDGE_API void ProxyBridge_SetDnsViaProxy(BOOL enable);PROXYBRIDGE_API void ProxyBridge_SetLogCallback(LogCallback callback);PROXYBRIDGE_API void ProxyBridge_SetConnectionCallback(ConnectionCallback callback);PROXYBRIDGE_API void ProxyBridge_SetTrafficLoggingEnabled(BOOL enable);+PROXYBRIDGE_API void ProxyBridge_ClearConnectionLogs(void); // Clear connection history from memoryPROXYBRIDGE_API BOOL ProxyBridge_Start(void);PROXYBRIDGE_API BOOL ProxyBridge_Stop(void);PROXYBRIDGE_API int ProxyBridge_TestConnection(const char* target_host, UINT16 target_port, char* result_buffer, size_t buffer_size);