1
0
mirror of https://github.com/rofl0r/proxychains-ng synced 2025-02-10 07:32:58 +08:00
This commit is contained in:
hugoc 2023-09-06 02:22:35 +02:00
parent 39ff28a2bc
commit 2c5ad9f81a
3 changed files with 91 additions and 0 deletions

View File

@ -423,6 +423,52 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
return SOCKET_ERROR; return SOCKET_ERROR;
} }
/* Given a socket connected to a SOCKS5 proxy server, performs a UDP_ASSOCIATE handshake and returns BND_ADDR and BND_PORT if successfull*/
static int udp_associate(int sock, ip_type dst_addr, unsigned short dst_port, ip_type *bnd_addr, unsigned short *bnd_port, char *user, char *pass){
//TODO hugoc
return SUCCESS;
}
/* Fills buf with the SOCKS5 udp request header for the target dst_addr:dst_port*/
static int udp_header(socks5_addr dst_addr, unsigned short dst_port , char frag, char * buf, size_t buflen) {
if (buflen <= 262) { //TODO: make something cleaner
return -1;
}
int buf_iter = 0;
buf[buf_iter++] = 0; // reserved
buf[buf_iter++] = 0; // reserved
buf[buf_iter++] = frag; // frag
buf[buf_iter++] = dst_addr.atyp; // atyp
int v6 = dst_addr.atyp == ATYP_V6;
switch (dst_addr.atyp){
case ATYP_V6:
case ATYP_V4:
memcpy(buf + buf_iter, dst_addr.addr.v6, v6?16:4);
buf_iter += v6?16:4;
break;
case ATYP_DOM:
buf[buf_iter++] = dst_addr.addr.dom.len;
memcpy(buf + buf_iter, dst_addr.addr.dom.name, dst_addr.addr.dom.len);
buf_iter += dst_addr.addr.dom.len;
break;
}
memcpy(buf + buf_iter, &dst_port, 2); // dest port
buf_iter += 2;
return buf_iter;
}
static int encapsulate_udp_packet(udp_relay_chain rcd, ip_type target_addr, unsigned short target_port, char frag) {
}
#define TP " ... " #define TP " ... "
#define DT "Dynamic chain" #define DT "Dynamic chain"
#define ST "Strict chain" #define ST "Strict chain"

View File

@ -64,6 +64,7 @@ typedef enum {
FIFOLY FIFOLY
} select_type; } select_type;
typedef struct { typedef struct {
sa_family_t family; sa_family_t family;
unsigned short port; unsigned short port;
@ -93,6 +94,43 @@ typedef struct {
char pass[256]; char pass[256];
} proxy_data; } proxy_data;
typedef enum {
ATYP_V4 = 0x01,
ATYP_V6 = 0x04,
ATYP_DOM = 0x03
} ATYP;
typedef struct{
ATYP atyp;
union {
ip_type4 v4;
unsigned char v6[16];
struct {
char len;
char name[255];
} dom;
} addr ;
} socks5_addr;
/* A structure to hold necessary information about an UDP relay server that has been set up
with a UDP_ASSOCIATE command issued on the tcp_sockfd */
typedef struct {
int tcp_sockfd; // the tcp socket on which the UDP_ASSOCIATE command has been issued. Closing this fd closes the udp relay.
socks5_addr bnd_addr; // the BND_ADDR returned by the udp relay server in the response to the UDP_ASSOCIATE command.
unsigned short bnd_port; // the BND_PORT returned by the udp relay server in the response to the UDP_ASSOCIATE command.
socks5_addr dst_addr; // ?? the DST_ADDR sent in the UDP_ASSOCIATE command.
unsigned short dst_port; // ?? the DST_PORT sent in the UDP_ASSOCIATE command.
} udp_relay_data;
/* A structure to hold the chain of udp relay servers assiociated with a client socket */
typedef struct {
int sockfd; // the client socket for which the chain of relays has been set up
udp_relay_data * ud; // an array of relay, ud[0] being the closest to the client and u[len(ud)-1] the closest to the targets
unsigned int relay_count;
} udp_relay_chain;
int connect_proxy_chain (int sock, ip_type target_ip, unsigned short target_port, int connect_proxy_chain (int sock, ip_type target_ip, unsigned short target_port,
proxy_data * pd, unsigned int proxy_count, chain_type ct, proxy_data * pd, unsigned int proxy_count, chain_type ct,
unsigned int max_chain ); unsigned int max_chain );
@ -147,6 +185,8 @@ void proxy_freeaddrinfo(struct addrinfo *res);
void core_initialize(void); void core_initialize(void);
void core_unload(void); void core_unload(void);
static int udp_associate(int sock, ip_type dst_addr, unsigned short dst_port, ip_type *bnd_addr, unsigned short *bnd_port, char *user, char *pass);
#include "debug.h" #include "debug.h"
#endif #endif

View File

@ -902,12 +902,15 @@ HOOKFUNC(ssize_t, sendto, int sockfd, const void *buf, size_t len, int flags,
addrlen = 0; addrlen = 0;
flags &= ~MSG_FASTOPEN; flags &= ~MSG_FASTOPEN;
} }
//TODO hugoc: case of SOCK_DGRAM with AF_INET or AF_INET6
return true_sendto(sockfd, buf, len, flags, dest_addr, addrlen); return true_sendto(sockfd, buf, len, flags, dest_addr, addrlen);
} }
HOOKFUNC(ssize_t, recv, int sockfd, void *buf, size_t len, int flags){ HOOKFUNC(ssize_t, recv, int sockfd, void *buf, size_t len, int flags){
INIT(); INIT();
PFUNC(); PFUNC();
//TODO hugoc
return true_recv(sockfd, buf, len, flags); return true_recv(sockfd, buf, len, flags);
} }
@ -915,12 +918,14 @@ HOOKFUNC(ssize_t, recvfrom, int sockfd, void *buf, size_t len, int flags,
struct sockaddr *src_addr, socklen_t *addrlen){ struct sockaddr *src_addr, socklen_t *addrlen){
INIT(); INIT();
PFUNC(); PFUNC();
//TODO hugoc
return true_recvfrom(sockfd, buf, len, flags, src_addr, addrlen); return true_recvfrom(sockfd, buf, len, flags, src_addr, addrlen);
} }
HOOKFUNC(ssize_t, send, int sockfd, const void *buf, size_t len, int flags){ HOOKFUNC(ssize_t, send, int sockfd, const void *buf, size_t len, int flags){
INIT(); INIT();
PFUNC(); PFUNC();
//TODO hugoc
return true_send(sockfd, buf, len, flags); return true_send(sockfd, buf, len, flags);
} }