Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic
C ccybersecurityhttp3httpproxylinuxlinux-proxymacosmacos-appmacos-proxyproxifierproxifier-alternativeproxyclienttcpthick-clientudpwindivertwindows
Moved local to pub repo -> updated methods, temp CLI
anof-cyberd10af6c26309
diff --git a/.gitignore b/.gitignoreindex 649c0a5..7532f42 100644--- a/.gitignore+++ b/.gitignore@@ -83,4 +83,4 @@ MacOS/ProxyBridge/build/MacOS/ProxyBridge/output/# Linux/**-Linux/*.so+Linux/output/**diff --git a/Linux/build.sh b/Linux/build.shnew file mode 100755index 0000000..cdc5e6d--- /dev/null+++ b/Linux/build.sh@@ -0,0 +1,23 @@+#!/bin/bash++cd "$(dirname "$0")"++rm -rf output+mkdir -p output++cd src+make clean+make+cd ..++cd cli+make clean+make+cd ..++mv src/libproxybridge.so output/+mv cli/proxybridge-cli output/++echo "Build complete!"+echo "Output files in: output/"+ls -lh output/diff --git a/Linux/cli/Makefile b/Linux/cli/Makefilenew file mode 100644index 0000000..c883b19--- /dev/null+++ b/Linux/cli/Makefile@@ -0,0 +1,36 @@+CC ?= gcc+CFLAGS := -O2 -Wall -Wextra -Werror -D_FORTIFY_SOURCE=2 -fstack-protector-strong+LDFLAGS := -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack+INCLUDES := -I../src+LIBS := -L../src -lproxybridge++TARGET = proxybridge-cli++.PHONY: all+all: $(TARGET)++$(TARGET): main.c+ $(CC) $(CFLAGS) $(INCLUDES) -o $@ $< $(LDFLAGS) $(LIBS)++.PHONY: clean+clean:+ rm -f $(TARGET)++.PHONY: run+run: $(TARGET)+ sudo LD_LIBRARY_PATH=../src ./$(TARGET)++.PHONY: help+help:+ @echo "ProxyBridge CLI Makefile"+ @echo ""+ @echo "Targets:"+ @echo " all - Build the CLI executable (default)"+ @echo " clean - Remove built executable"+ @echo " run - Build and run with sudo"+ @echo " help - Show this help message"+ @echo ""+ @echo "Usage:"+ @echo " 1. Build library first: cd ../src && make"+ @echo " 2. Build CLI: make"+ @echo " 3. Run: sudo LD_LIBRARY_PATH=../src ./proxybridge-cli"diff --git a/Linux/cli/main.c b/Linux/cli/main.cnew file mode 100644index 0000000..808f4e3--- /dev/null+++ b/Linux/cli/main.c@@ -0,0 +1,63 @@+#include <stdio.h>+#include <signal.h>+#include <errno.h>+#include <arpa/inet.h>+#include <proxybridge.h>++static volatile sig_atomic_t keep_running = 1;++static void sig_handler(int sig)+{+ (void)sig;+ keep_running = 0;+ ProxyBridge_Stop();+}++static void event_handler(const struct net_event *event)+{+ char daddr_str[INET_ADDRSTRLEN];+ struct in_addr addr;++ addr.s_addr = event->daddr;+ if (!inet_ntop(AF_INET, &addr, daddr_str, INET_ADDRSTRLEN))+ return;++ printf("%-16s --> %s:%-5d - %s\n",+ event->comm,+ daddr_str,+ event->dport,+ (event->protocol == PROTO_TCP) ? "TCP" : "UDP");+}++int main(void)+{+ int err;++ signal(SIGINT, sig_handler);+ signal(SIGTERM, sig_handler);++ err = ProxyBridge_Start();+ if (err) {+ fprintf(stderr, "Failed to start proxybridge: %d\n", err);+ return 1;+ }++ ProxyBridge_SetConnectionCallback(event_handler);++ printf("ProxyBridge started. Monitoring network connections...\n");+ printf("Press Ctrl+C to stop.\n");+ printf("%-16s %-21s %s\n", "PROCESS", "DESTINATION", "PROTOCOL");+ printf("%-16s %-21s %s\n", "-------", "-----------", "--------");++ while (keep_running) {+ err = ProxyBridge_Poll(100);+ if (err < 0 && err != -EINTR) {+ fprintf(stderr, "Error polling: %d\n", err);+ break;+ }+ }++ ProxyBridge_Stop();+ printf("\nProxyBridge stopped.\n");+ return 0;+}diff --git a/Linux/Makefile b/Linux/src/Makefilesimilarity index 81%rename from Linux/Makefilerename to Linux/src/Makefileindex e8800f6..8be17ab 100644--- a/Linux/Makefile+++ b/Linux/src/Makefile@@ -3,7 +3,7 @@ LLVM_STRIP ?= $(shell which llvm-strip-18 2>/dev/null || which llvm-strip 2>/devBPFTOOL ?= bpftoolLIBBPF_DIR = /usr/includeARCH := $(shell uname -m | sed 's/x86_64/x86/' | sed 's/aarch64/arm64/')-INCLUDES := -I$(LIBBPF_DIR) -I/usr/include/$(shell uname -m)-linux-gnu -Isrc+INCLUDES := -I$(LIBBPF_DIR) -I/usr/include/$(shell uname -m)-linux-gnu -I.CFLAGS := -O3 -Wall -Wextra -Werror -fPIC -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fstack-clash-protection -fcf-protection -Wformat -Wformat-security -pie -fPIELDFLAGS := -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wl,--as-neededLIB_NAME = libproxybridge.so@@ -14,19 +14,19 @@ all: $(LIB_NAME).PHONY: cleanclean:- rm -f src/*.o src/*.skel.h src/vmlinux.h $(LIB_NAME)+ rm -f *.o *.skel.h vmlinux.h $(LIB_NAME)-src/vmlinux.h:- $(BPFTOOL) btf dump file /sys/kernel/btf/vmlinux format c > src/vmlinux.h+vmlinux.h:+ $(BPFTOOL) btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h-src/%.bpf.o: src/%.bpf.c src/vmlinux.h- $(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(ARCH) $(INCLUDES) $(CLANG_BPF_SYS_INCLUDES) -c $< -o $@+%.bpf.o: %.bpf.c vmlinux.h+ $(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(ARCH) -D__KERNEL__ $(INCLUDES) $(CLANG_BPF_SYS_INCLUDES) -c $< -o $@$(LLVM_STRIP) -g $@-src/%.skel.h: src/%.bpf.o+%.skel.h: %.bpf.o$(BPFTOOL) gen skeleton $< > $@-$(LIB_NAME): src/proxybridge.c src/proxybridge.skel.h+$(LIB_NAME): proxybridge.c proxybridge.skel.h$(CC) $(CFLAGS) $(INCLUDES) $(LDFLAGS) -shared -o $@ $< -lbpf -lelf -lz.PHONY: install@@ -34,7 +34,7 @@ install: $(LIB_NAME)install -d $(DESTDIR)/usr/libinstall -m 755 $(LIB_NAME) $(DESTDIR)/usr/lib/install -d $(DESTDIR)/usr/include- install -m 644 src/proxybridge.h $(DESTDIR)/usr/include/+ install -m 644 proxybridge.h $(DESTDIR)/usr/include/.PHONY: install-depsinstall-deps:diff --git a/Linux/src/proxybridge.c b/Linux/src/proxybridge.cindex dae9672..8cddbcd 100644--- a/Linux/src/proxybridge.c+++ b/Linux/src/proxybridge.c@@ -10,8 +10,7 @@static struct proxybridge_bpf *skel = NULL;static struct ring_buffer *rb = NULL;-static event_callback_t user_callback = NULL;-static void *user_ctx = NULL;+static ConnectionCallback user_callback = NULL;static volatile sig_atomic_t should_stop = 0;static int handle_event(void *ctx, void *data, size_t data_sz)@@ -25,21 +24,18 @@ static int handle_event(void *ctx, void *data, size_t data_sz)return 0;if (user_callback)- user_callback(e, user_ctx);+ user_callback(e);return 0;}-int proxybridge_init(event_callback_t callback, void *ctx)+int ProxyBridge_Start(void){int err;if (skel)return -EBUSY;- user_callback = callback;- user_ctx = ctx;-libbpf_set_print(NULL);skel = proxybridge_bpf__open();@@ -64,12 +60,14 @@ int proxybridge_init(event_callback_t callback, void *ctx)return 0;cleanup:- proxybridge_cleanup();+ ProxyBridge_Stop();return err;}-void proxybridge_cleanup(void)+void ProxyBridge_Stop(void){+ should_stop = 1;+if (rb) {ring_buffer__free(rb);rb = NULL;@@ -79,10 +77,14 @@ void proxybridge_cleanup(void)skel = NULL;}user_callback = NULL;- user_ctx = NULL;}-int proxybridge_poll(int timeout_ms)+void ProxyBridge_SetConnectionCallback(ConnectionCallback callback)+{+ user_callback = callback;+}++int ProxyBridge_Poll(int timeout_ms){if (!rb)return -EINVAL;@@ -92,8 +94,3 @@ int proxybridge_poll(int timeout_ms)return ring_buffer__poll(rb, timeout_ms);}--void proxybridge_stop(void)-{- should_stop = 1;-}diff --git a/Linux/src/proxybridge.h b/Linux/src/proxybridge.hindex 881a9b9..398cd81 100644--- a/Linux/src/proxybridge.h+++ b/Linux/src/proxybridge.h@@ -1,25 +1,44 @@#ifndef __PROXYBRIDGE_H#define __PROXYBRIDGE_H+#ifdef __KERNEL__+#define PROXYBRIDGE_U32 __u32+#define PROXYBRIDGE_U16 __u16+#define PROXYBRIDGE_U8 __u8+#else+#include <stdint.h>+#define PROXYBRIDGE_U32 uint32_t+#define PROXYBRIDGE_U16 uint16_t+#define PROXYBRIDGE_U8 uint8_t+#endif+#define TASK_COMM_LEN 16#define PROTO_TCP 6#define PROTO_UDP 17struct net_event {- __u32 pid;- __u32 saddr;- __u32 daddr;- __u16 sport;- __u16 dport;- __u8 protocol;+ PROXYBRIDGE_U32 pid;+ PROXYBRIDGE_U32 saddr;+ PROXYBRIDGE_U32 daddr;+ PROXYBRIDGE_U16 sport;+ PROXYBRIDGE_U16 dport;+ PROXYBRIDGE_U8 protocol;char comm[TASK_COMM_LEN];};-typedef void (*event_callback_t)(const struct net_event *event, void *ctx);+typedef void (*ConnectionCallback)(const struct net_event *event);++#ifdef __cplusplus+extern "C" {+#endif++int ProxyBridge_Start(void);+void ProxyBridge_Stop(void);+void ProxyBridge_SetConnectionCallback(ConnectionCallback callback);+int ProxyBridge_Poll(int timeout_ms);-int proxybridge_init(event_callback_t callback, void *ctx);-void proxybridge_cleanup(void);-int proxybridge_poll(int timeout_ms);-void proxybridge_stop(void);+#ifdef __cplusplus+}+#endif#endif