mirror of
https://github.com/rofl0r/proxychains-ng.git
synced 2024-12-22 20:38:49 +00:00
remove dangerous uses of inet_ntoa
This commit is contained in:
parent
526fb8b410
commit
5b5cc604a6
40
src/core.c
40
src/core.c
@ -93,6 +93,30 @@ in_addr_t make_internal_ip(uint32_t index) {
|
|||||||
return (in_addr_t) ret.as_int;
|
return (in_addr_t) ret.as_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stolen from libulz (C) rofl0r
|
||||||
|
void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes) {
|
||||||
|
unsigned char *p;
|
||||||
|
char *o = outbuf_16_bytes;
|
||||||
|
unsigned char n;
|
||||||
|
for(p = ip_buf_4_bytes; p < ip_buf_4_bytes + 4; p++) {
|
||||||
|
n = *p;
|
||||||
|
if(*p >= 100) {
|
||||||
|
if(*p >= 200)
|
||||||
|
*(o++) = '2';
|
||||||
|
else
|
||||||
|
*(o++) = '1';
|
||||||
|
n %= 100;
|
||||||
|
}
|
||||||
|
if(*p >= 10) {
|
||||||
|
*(o++) = (n / 10) + '0';
|
||||||
|
n %= 10;
|
||||||
|
}
|
||||||
|
*(o++) = n + '0';
|
||||||
|
*(o++) = '.';
|
||||||
|
}
|
||||||
|
o[-1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
|
|
||||||
static int poll_retry(struct pollfd *fds, nfds_t nfsd, int timeout) {
|
static int poll_retry(struct pollfd *fds, nfds_t nfsd, int timeout) {
|
||||||
@ -277,12 +301,16 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
|||||||
|
|
||||||
int len;
|
int len;
|
||||||
unsigned char buff[BUFF_SIZE];
|
unsigned char buff[BUFF_SIZE];
|
||||||
|
char ip_buf[16];
|
||||||
|
|
||||||
//memset (buff, 0, sizeof(buff));
|
//memset (buff, 0, sizeof(buff));
|
||||||
|
|
||||||
switch (pt) {
|
switch (pt) {
|
||||||
case HTTP_TYPE:{
|
case HTTP_TYPE:{
|
||||||
if(!dns_len)
|
if(!dns_len) {
|
||||||
dns_name = inet_ntoa(*(struct in_addr *) &ip.as_int);
|
pc_stringfromipv4(&ip.octet[0], ip_buf);
|
||||||
|
dns_name = ip_buf;
|
||||||
|
}
|
||||||
|
|
||||||
snprintf((char *) buff, sizeof(buff), "CONNECT %s:%d HTTP/1.0\r\n", dns_name,
|
snprintf((char *) buff, sizeof(buff), "CONNECT %s:%d HTTP/1.0\r\n", dns_name,
|
||||||
ntohs(port));
|
ntohs(port));
|
||||||
@ -487,13 +515,15 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
|||||||
|
|
||||||
static int start_chain(int *fd, proxy_data * pd, char *begin_mark) {
|
static int start_chain(int *fd, proxy_data * pd, char *begin_mark) {
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
|
char ip_buf[16];
|
||||||
|
|
||||||
*fd = socket(PF_INET, SOCK_STREAM, 0);
|
*fd = socket(PF_INET, SOCK_STREAM, 0);
|
||||||
if(*fd == -1)
|
if(*fd == -1)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
pc_stringfromipv4(&pd->ip.octet[0], ip_buf);
|
||||||
proxychains_write_log(LOG_PREFIX "%s " TP " %s:%d ",
|
proxychains_write_log(LOG_PREFIX "%s " TP " %s:%d ",
|
||||||
begin_mark, inet_ntoa(*(struct in_addr *) &pd->ip), htons(pd->port));
|
begin_mark, ip_buf, htons(pd->port));
|
||||||
pd->ps = PLAY_STATE;
|
pd->ps = PLAY_STATE;
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
@ -570,6 +600,7 @@ static unsigned int calc_alive(proxy_data * pd, unsigned int proxy_count) {
|
|||||||
static int chain_step(int ns, proxy_data * pfrom, proxy_data * pto) {
|
static int chain_step(int ns, proxy_data * pfrom, proxy_data * pto) {
|
||||||
int retcode = -1;
|
int retcode = -1;
|
||||||
char *hostname;
|
char *hostname;
|
||||||
|
char ip_buf[16];
|
||||||
|
|
||||||
PDEBUG("chain_step()\n");
|
PDEBUG("chain_step()\n");
|
||||||
|
|
||||||
@ -579,7 +610,8 @@ static int chain_step(int ns, proxy_data * pfrom, proxy_data * pto) {
|
|||||||
goto usenumericip;
|
goto usenumericip;
|
||||||
} else {
|
} else {
|
||||||
usenumericip:
|
usenumericip:
|
||||||
hostname = inet_ntoa(*(struct in_addr *) &pto->ip);
|
pc_stringfromipv4(&pto->ip.octet[0], ip_buf);
|
||||||
|
hostname = ip_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
proxychains_write_log(TP " %s:%d ", hostname, htons(pto->port));
|
proxychains_write_log(TP " %s:%d ", hostname, htons(pto->port));
|
||||||
|
@ -142,6 +142,8 @@ int proxy_getaddrinfo(const char *node, const char *service,
|
|||||||
|
|
||||||
struct hostent* proxy_gethostbyname(const char *name);
|
struct hostent* proxy_gethostbyname(const char *name);
|
||||||
|
|
||||||
|
void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
# define PDEBUG(fmt, args...) fprintf(stderr,"DEBUG:"fmt, ## args)
|
# define PDEBUG(fmt, args...) fprintf(stderr,"DEBUG:"fmt, ## args)
|
||||||
#else
|
#else
|
||||||
|
@ -385,6 +385,7 @@ int getnameinfo(const struct sockaddr *sa,
|
|||||||
socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags)
|
socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
char ip_buf[16];
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if(!init_l)
|
if(!init_l)
|
||||||
@ -395,38 +396,16 @@ int getnameinfo(const struct sockaddr *sa,
|
|||||||
if(!proxychains_resolver) {
|
if(!proxychains_resolver) {
|
||||||
ret = true_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
|
ret = true_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
|
||||||
} else {
|
} else {
|
||||||
if(hostlen)
|
if(hostlen) {
|
||||||
strncpy(host, inet_ntoa(SOCKADDR_2(*sa)), hostlen);
|
pc_stringfromipv4((unsigned char*) &(SOCKADDR_2(*sa)), ip_buf);
|
||||||
|
strncpy(host, ip_buf, hostlen);
|
||||||
|
}
|
||||||
if(servlen)
|
if(servlen)
|
||||||
snprintf(serv, servlen, "%d", ntohs(SOCKPORT(*sa)));
|
snprintf(serv, servlen, "%d", ntohs(SOCKPORT(*sa)));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// stolen from libulz (C) rofl0r
|
|
||||||
static void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes) {
|
|
||||||
unsigned char *p;
|
|
||||||
char *o = outbuf_16_bytes;
|
|
||||||
unsigned char n;
|
|
||||||
for(p = ip_buf_4_bytes; p < ip_buf_4_bytes + 4; p++) {
|
|
||||||
n = *p;
|
|
||||||
if(*p >= 100) {
|
|
||||||
if(*p >= 200)
|
|
||||||
*(o++) = '2';
|
|
||||||
else
|
|
||||||
*(o++) = '1';
|
|
||||||
n %= 100;
|
|
||||||
}
|
|
||||||
if(*p >= 10) {
|
|
||||||
*(o++) = (n / 10) + '0';
|
|
||||||
n %= 10;
|
|
||||||
}
|
|
||||||
*(o++) = n + '0';
|
|
||||||
*(o++) = '.';
|
|
||||||
}
|
|
||||||
o[-1] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type) {
|
struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type) {
|
||||||
static char buf[16];
|
static char buf[16];
|
||||||
static char ipv4[4];
|
static char ipv4[4];
|
||||||
|
Loading…
Reference in New Issue
Block a user