From 65ab050bc2e54490dc8560d1bbb17493c74b761f Mon Sep 17 00:00:00 2001 From: hc Date: Wed, 22 May 2024 17:52:59 +0200 Subject: [PATCH] add uv_close hook --- src/core.h | 3 +++ src/libproxychains.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/core.h b/src/core.h index e810de8..873b05d 100644 --- a/src/core.h +++ b/src/core.h @@ -20,6 +20,7 @@ #include #include #include +#include #ifndef __CORE_HEADER #define __CORE_HEADER @@ -151,6 +152,7 @@ void proxychains_write_log(char *str, ...); typedef int (*close_t)(int); typedef int (*close_range_t)(unsigned, unsigned, int); +typedef void (*uv_close_t)(uv_handle_t* , uv_close_cb); typedef int (*connect_t)(int, const struct sockaddr *, socklen_t); typedef struct hostent* (*gethostbyname_t)(const char *); typedef int (*freeaddrinfo_t)(struct addrinfo *); @@ -197,6 +199,7 @@ extern getpeername_t true_getpeername; extern read_t true_read; extern write_t true_write; extern close_t true_close; +extern uv_close_t true_uv_close; struct gethostbyname_data { struct hostent hostent_space; diff --git a/src/libproxychains.c b/src/libproxychains.c index fe15f80..9f7f8f6 100644 --- a/src/libproxychains.c +++ b/src/libproxychains.c @@ -37,6 +37,7 @@ #include #include +#include @@ -63,6 +64,7 @@ connect_t true___xnet_connect; close_t true_close; close_range_t true_close_range; +uv_close_t true_uv_close; connect_t true_connect; gethostbyname_t true_gethostbyname; getaddrinfo_t true_getaddrinfo; @@ -647,6 +649,41 @@ HOOKFUNC(int, close, int fd) { return -1; } +HOOKFUNC(void, uv_close, uv_handle_t* handle, uv_close_cb close_cb){ + PFUNC(); + + switch (handle->type) + { + case UV_UDP: + int fd = ((uv_udp_t*)handle)->io_watcher.fd; + + /***** UDP STUFF *******/ + //PDEBUG("checking if a relay chain is opened for fd %d\n", fd); + udp_relay_chain* relay_chain = NULL; + + PDEBUG("waiting for mutex\n"); + MUTEX_LOCK(&relay_chains_mutex); + PDEBUG("got mutex\n"); + relay_chain = get_relay_chain(relay_chains, fd); + if(NULL != relay_chain){ + PDEBUG("fd %d corresponds to chain %x, closing it\n", fd, relay_chain); + free_relay_chain_contents(relay_chain); + del_relay_chain(&relay_chains, relay_chain); + PDEBUG("chain %x corresponding to fd %d closed\n", relay_chain, fd); + DUMP_RELAY_CHAINS_LIST(relay_chains); + } + MUTEX_UNLOCK(&relay_chains_mutex); + /***** END UDP STUFF *******/ + break; + + default: + + break; + } + return true_uv_close(handle, close_cb); + +} + static int is_v4inv6(const struct in6_addr *a) { return !memcmp(a->s6_addr, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12); } @@ -2240,6 +2277,7 @@ static void setup_hooks(void) { #endif SETUP_SYM(close); SETUP_SYM_OPTIONAL(close_range); + SETUP_SYM_OPTIONAL(uv_close); } #ifdef MONTEREY_HOOKING