1
0
mirror of https://github.com/rofl0r/proxychains-ng synced 2025-01-08 06:02:51 +08:00

remove send_udp_packet()

This commit is contained in:
hugoc 2024-02-01 17:53:11 +01:00
parent 436f402f1e
commit 5660aea02e
2 changed files with 39 additions and 214 deletions

View File

@ -944,213 +944,6 @@ int socksify_udp_packet(void* udp_data, size_t udp_data_len, udp_relay_chain cha
}
int send_udp_packet(int sockfd, udp_relay_chain chain, ip_type target_ip, unsigned short target_port, char frag, char * data, unsigned int data_len, int flags) {
PFUNC();
char send_buffer[65535];
size_t send_buffer_len = sizeof(send_buffer);
int rc;
rc = socksify_udp_packet(data, data_len, chain, target_ip, target_port,send_buffer, &send_buffer_len);
if(rc != SUCCESS){
PDEBUG("error socksify_udp_packet()\n");
return -1;
}
// Send the packet
// FIXME: should write_n_bytes be used here instead ? -> No, because we send data on an unconnected socket, so we need to use sendto with an address and not send.
// We thus cannot use write(), which cannot be given an address
// if(chain.head->bnd_addr.atyp == ATYP_DOM){
// PDEBUG("BND_ADDR of type DOMAINE (0x03) not supported yet\n");
// goto err;
// }
int v6 = chain.head->bnd_addr.is_v6 == ATYP_V6;
struct sockaddr_in addr = {
.sin_family = AF_INET,
.sin_port = chain.head->bnd_port,
.sin_addr.s_addr = (in_addr_t) chain.head->bnd_addr.addr.v4.as_int,
};
struct sockaddr_in6 addr6 = {
.sin6_family = AF_INET6,
.sin6_port = chain.head->bnd_port,
};
if(v6) memcpy(&addr6.sin6_addr.s6_addr, chain.head->bnd_addr.addr.v6, 16);
int sent = 0;
sent = true_sendto(sockfd, send_buffer, send_buffer_len, flags, (struct sockaddr *) (v6?(void*)&addr6:(void*)&addr), v6?sizeof(addr6):sizeof(addr) );
if (sent != send_buffer_len){
PDEBUG("true_sendto error\n");
return -1;
}
return data_len;
}
// int send_udp_packet(int sockfd, udp_relay_chain chain, ip_type target_ip, unsigned short target_port, char frag, char * data, unsigned int data_len) {
// if (chain.head == NULL ){
// PDEBUG("provided chain is empty\n");
// return -1;
// }
// char *dns_name = NULL;
// char hostnamebuf[MSG_LEN_MAX];
// size_t dns_len = 0;
// socks5_addr target_addr;
// // we use ip addresses with 224.* to lookup their dns name in our table, to allow remote DNS resolution
// // the range 224-255.* is reserved, and it won't go outside (unless the app does some other stuff with
// // the results returned from gethostbyname et al.)
// // the hardcoded number 224 can now be changed using the config option remote_dns_subnet to i.e. 127
// if(!target_ip.is_v6 && proxychains_resolver >= DNSLF_RDNS_START && target_ip.addr.v4.octet[0] == remote_dns_subnet) {
// target_addr.atyp = ATYP_DOM;
// dns_len = rdns_get_host_for_ip(target_ip.addr.v4, target_addr.addr.dom.name);
// PDEBUG("dnslen: %d\n", dns_len);
// if(!dns_len) goto err;
// else dns_name = target_addr.addr.dom.name;
// target_addr.addr.dom.len = dns_len & 0xFF;
// PDEBUG("dnslen in struct: %d\n", target_addr.addr.dom.len);
// } else {
// if(target_ip.is_v6){
// target_addr.atyp = ATYP_V6;
// memcpy(target_addr.addr.v6, target_ip.addr.v6, 16);
// } else {
// target_addr.atyp = ATYP_V4;
// memcpy(target_addr.addr.v4.octet, target_ip.addr.v4.octet, 4);
// }
// }
// PDEBUG("host dns %s\n", dns_name ? dns_name : "<NULL>");
// // Allocate a new buffer for the packet data and all the headers
// unsigned int headers_size = 0;
// udp_relay_node * tmp = chain.head;
// int len = 0;
// while(tmp->next != NULL){
// // switch ((tmp->next)->bnd_addr.atyp)
// // {
// // case ATYP_V4:
// // len = 4;
// // break;
// // case ATYP_V6:
// // len = 6;
// // break;
// // case ATYP_DOM:
// // len = (tmp->next)->bnd_addr.addr.dom.len + 1;
// // break;
// // default:
// // break;
// // }
// len = (tmp->next)->bnd_addr.is_v6?16:4;
// headers_size += len + 6;
// tmp = tmp->next;
// }
// switch (target_addr.atyp)
// {
// case ATYP_V4:
// len = 4;
// break;
// case ATYP_V6:
// len = 6;
// break;
// case ATYP_DOM:
// len = target_addr.addr.dom.len + 1;
// break;
// default:
// break;
// }
// headers_size += len + 6;
// char * buff = NULL;
// if (NULL == (buff = (char*)malloc(headers_size+data_len))){
// PDEBUG("error malloc buffer\n");
// return -1;
// }
// // Append each header to the buffer
// unsigned int written = 0;
// unsigned int offset = 0;
// tmp = chain.head;
// while (tmp->next != NULL)
// {
// socks5_addr tmpaddr;
// tmpaddr.atyp = (tmp->next)->bnd_addr.is_v6?ATYP_V6:ATYP_V4;
// memcpy(tmpaddr.addr.v6, (tmp->next)->bnd_addr.addr.v6, (tmp->next)->bnd_addr.is_v6?16:4);
// written = write_udp_header(tmpaddr, (tmp->next)->bnd_port, 0, buff+offset, headers_size + data_len - offset);
// if (written == -1){
// PDEBUG("error write_udp_header\n");
// goto err;
// }
// offset += written;
// tmp = tmp->next;
// }
// written = write_udp_header(target_addr, target_port, 0, buff + offset, headers_size + data_len - offset);
// if (written == -1){
// PDEBUG("error write_udp_header\n");
// goto err;
// }
// offset += written;
// // Append data to the buffer
// memcpy(buff + offset, data, data_len);
// // Send the packet
// // FIXME: should write_n_bytes be used here instead ?
// // if(chain.head->bnd_addr.atyp == ATYP_DOM){
// // PDEBUG("BND_ADDR of type DOMAINE (0x03) not supported yet\n");
// // goto err;
// // }
// int v6 = chain.head->bnd_addr.is_v6 == ATYP_V6;
// struct sockaddr_in addr = {
// .sin_family = AF_INET,
// .sin_port = chain.head->bnd_port,
// .sin_addr.s_addr = (in_addr_t) chain.head->bnd_addr.addr.v4.as_int,
// };
// struct sockaddr_in6 addr6 = {
// .sin6_family = AF_INET6,
// .sin6_port = chain.head->bnd_port,
// };
// if(v6) memcpy(&addr6.sin6_addr.s6_addr, chain.head->bnd_addr.addr.v6, 16);
// int sent = 0;
// sent = true_sendto(sockfd, buff, offset+data_len, 0, (struct sockaddr *) (v6?(void*)&addr6:(void*)&addr), v6?sizeof(addr6):sizeof(addr) );
// if (sent != offset+data_len){
// PDEBUG("true_sendto error\n");
// goto err;
// }
// return SUCCESS;
// err:
// free(buff);
// return -1;
// }
#define TP " ... "
#define DT "Dynamic chain"

View File

@ -1136,15 +1136,47 @@ HOOKFUNC(ssize_t, sendto, int sockfd, const void *buf, size_t len, int flags,
DUMP_RELAY_CHAINS_LIST(relay_chains);
memcpy(dest_ip.addr.v6, v6 ? (void*)p_addr_in6 : (void*)p_addr_in, v6?16:4);
//TODO: is it better to do 'return send_udp_packet' ?
int sent = 0;
sent = send_udp_packet(sockfd, *relay_chain, dest_ip, htons(port),0, buf, len, flags);
if (-1 == sent ){
PDEBUG("could not send udp packet\n");
errno = ECONNREFUSED;
char send_buffer[65535];
size_t send_buffer_len = sizeof(send_buffer);
int rc;
rc = socksify_udp_packet(buf, len, *relay_chain, dest_ip, htons(port), send_buffer, &send_buffer_len);
if(rc != SUCCESS){
PDEBUG("error socksify_udp_packet()\n");
return -1;
}
// Send the packet
// FIXME: should write_n_bytes be used here instead ? -> No, because we send data on an unconnected socket, so we need to use sendto with an address and not send.
// We thus cannot use write(), which cannot be given an address
// if(chain.head->bnd_addr.atyp == ATYP_DOM){
// PDEBUG("BND_ADDR of type DOMAINE (0x03) not supported yet\n");
// goto err;
// }
v6 = relay_chain->head->bnd_addr.is_v6;
struct sockaddr_in addr = {
.sin_family = AF_INET,
.sin_port = relay_chain->head->bnd_port,
.sin_addr.s_addr = (in_addr_t) relay_chain->head->bnd_addr.addr.v4.as_int,
};
struct sockaddr_in6 addr6 = {
.sin6_family = AF_INET6,
.sin6_port = relay_chain->head->bnd_port,
};
if(v6) memcpy(&addr6.sin6_addr.s6_addr, relay_chain->head->bnd_addr.addr.v6, 16);
int sent = 0;
sent = true_sendto(sockfd, send_buffer, send_buffer_len, flags, (struct sockaddr*)(v6?(void*)&addr6:(void*)&addr), v6?sizeof(addr6):sizeof(addr));
if(sent == -1){
PDEBUG("error true_sendto()\n");
return sent;
}
PDEBUG("Successful sendto() hook\n\n");
return sent;
}
@ -1989,7 +2021,7 @@ HOOKFUNC(ssize_t, send, int sockfd, const void *buf, size_t len, int flags){
}
// Retreive the peer address the socket is connected to, and check it is of AF_INET or AF_INET6 family
struct sockaddr_storage addr;
socklen_t addr_len = sizeof(addr);
if(SUCCESS != getpeername(sockfd, (struct sockaddr*)&addr, &addr_len )){