mirror of
https://github.com/rofl0r/proxychains-ng.git
synced 2025-09-06 17:06:58 +00:00
fix *all* trailing whitespace at once
This commit is contained in:
150
src/core.c
150
src/core.c
@ -94,7 +94,7 @@ in_addr_t make_internal_ip(uint32_t index) {
|
||||
|
||||
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)
|
||||
{
|
||||
int ret;
|
||||
int time_remain = timeout;
|
||||
@ -113,7 +113,7 @@ static int poll_retry(struct pollfd *fds, nfds_t nfsd, int timeout)
|
||||
//printf("Time elapsed %d\n", time_elapsed);
|
||||
time_remain = timeout - time_elapsed;
|
||||
} while (ret == -1 && errno == EINTR && time_remain > 0);
|
||||
|
||||
|
||||
//if (ret == -1)
|
||||
//printf("Return %d %d %s\n", ret, errno, strerror(errno));
|
||||
return ret;
|
||||
@ -196,7 +196,7 @@ static int read_n_bytes(int fd,char *buff, size_t size)
|
||||
|
||||
pfd[0].fd=fd;
|
||||
pfd[0].events=POLLIN;
|
||||
for(i=0; i < size; i++) {
|
||||
for(i=0; i < size; i++) {
|
||||
pfd[0].revents = 0;
|
||||
ready = poll_retry(pfd, 1, tcp_read_time_out);
|
||||
if(ready != 1 || !(pfd[0].revents&POLLIN) || 1 != read(fd,&buff[i],1))
|
||||
@ -212,13 +212,13 @@ static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len)
|
||||
struct pollfd pfd[1];
|
||||
|
||||
pfd[0].fd=sock;
|
||||
pfd[0].events=POLLOUT;
|
||||
pfd[0].events=POLLOUT;
|
||||
fcntl(sock, F_SETFL, O_NONBLOCK);
|
||||
ret = true_connect(sock, addr, len);
|
||||
#ifdef DEBUG
|
||||
if(ret == -1) perror("true_connect");
|
||||
printf("\nconnect ret=%d\n",ret);
|
||||
|
||||
|
||||
fflush(stdout);
|
||||
#endif
|
||||
if(ret==-1 && errno==EINPROGRESS) {
|
||||
@ -242,7 +242,7 @@ static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len)
|
||||
} else {
|
||||
if (ret != 0)
|
||||
ret=-1;
|
||||
}
|
||||
}
|
||||
|
||||
fcntl(sock, F_SETFL, !O_NONBLOCK);
|
||||
return ret;
|
||||
@ -254,10 +254,10 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
|
||||
{
|
||||
#ifdef DEBUG
|
||||
PDEBUG("tunnel_to()\n");
|
||||
#endif
|
||||
#endif
|
||||
char* dns_name = NULL;
|
||||
size_t dns_len = 0;
|
||||
|
||||
|
||||
// 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.)
|
||||
@ -268,38 +268,38 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
|
||||
dns_len = strlen(dns_name);
|
||||
if(!dns_len) goto err;
|
||||
}
|
||||
|
||||
|
||||
size_t ulen = strlen(user);
|
||||
size_t passlen = strlen(pass);
|
||||
|
||||
|
||||
if(ulen > 0xFF || passlen > 0xFF || dns_len > 0xFF) {
|
||||
proxychains_write_log(LOG_PREFIX "error: maximum size of 255 for user/pass or domain name!\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
||||
int len;
|
||||
unsigned char buff[BUFF_SIZE];
|
||||
//memset (buff, 0, sizeof(buff));
|
||||
|
||||
|
||||
switch(pt) {
|
||||
case HTTP_TYPE: {
|
||||
if(!dns_len)
|
||||
dns_name = inet_ntoa( * (struct in_addr *) &ip.as_int);
|
||||
|
||||
|
||||
snprintf((char*)buff, sizeof(buff), "CONNECT %s:%d HTTP/1.0\r\n", dns_name, ntohs(port));
|
||||
|
||||
|
||||
if (user[0])
|
||||
{
|
||||
#define HTTP_AUTH_MAX ((0xFF * 2) + 1 + 1)
|
||||
// 2 * 0xff: username and pass, plus 1 for ':' and 1 for zero terminator.
|
||||
char src[HTTP_AUTH_MAX];
|
||||
char dst[(4 * HTTP_AUTH_MAX)];
|
||||
|
||||
|
||||
memcpy(src, user, ulen);
|
||||
memcpy(src + ulen, ":", 1);
|
||||
memcpy(src + ulen + 1, pass, passlen);
|
||||
src[ulen + 1 + passlen] = 0;
|
||||
|
||||
|
||||
encode_base_64(src, dst, sizeof(dst));
|
||||
strcat((char*)buff,"Proxy-Authorization: Basic ");
|
||||
strcat((char*)buff, dst);
|
||||
@ -307,12 +307,12 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
|
||||
}
|
||||
else
|
||||
strcat((char*)buff, "\r\n");
|
||||
|
||||
|
||||
len = strlen((char*)buff);
|
||||
|
||||
if(len != send(sock, buff, len, 0))
|
||||
goto err;
|
||||
|
||||
|
||||
len = 0 ;
|
||||
// read header byte by byte.
|
||||
while(len < BUFF_SIZE) {
|
||||
@ -338,7 +338,7 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
|
||||
return SUCCESS;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case SOCKS4_TYPE: {
|
||||
buff[0] = 4; // socks version
|
||||
buff[1] = 1; // connect command
|
||||
@ -356,19 +356,19 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
|
||||
else {
|
||||
buff[8] = 0;
|
||||
}
|
||||
|
||||
|
||||
// do socksv4a dns resolution on the server
|
||||
if(dns_len) {
|
||||
memcpy(&buff[8 + len], dns_name, dns_len + 1);
|
||||
len += dns_len + 1;
|
||||
}
|
||||
|
||||
|
||||
if((len + 8) != write_n_bytes(sock, (char*) buff, (8+len)))
|
||||
goto err;
|
||||
|
||||
if(8 != read_n_bytes(sock, (char*)buff, 8))
|
||||
goto err;
|
||||
|
||||
|
||||
if (buff[0] != 0 || buff[1] != 90)
|
||||
return BLOCKED;
|
||||
|
||||
@ -394,14 +394,14 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
|
||||
|
||||
if(2 != read_n_bytes(sock, (char*) buff, 2))
|
||||
goto err;
|
||||
|
||||
|
||||
if (buff[0] != 5 || (buff[1] != 0 && buff[1] != 2)) {
|
||||
if(buff[0] == 5 && buff[1] == 0xFF)
|
||||
return BLOCKED;
|
||||
else
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
||||
if (buff[1] == 2) {
|
||||
// authentication
|
||||
char in[2];
|
||||
@ -416,11 +416,11 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
|
||||
*cur++ = c;
|
||||
memcpy(cur, pass, c);
|
||||
cur += c;
|
||||
|
||||
|
||||
if((cur-out) != write_n_bytes(sock, out, cur-out))
|
||||
goto err;
|
||||
|
||||
|
||||
|
||||
|
||||
if(2 != read_n_bytes(sock,in,2))
|
||||
goto err;
|
||||
if(in[0] != 1 || in[1] != 0) {
|
||||
@ -434,7 +434,7 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
|
||||
buff[buff_iter++] = 5; // version
|
||||
buff[buff_iter++] = 1; // connect
|
||||
buff[buff_iter++] = 0; // reserved
|
||||
|
||||
|
||||
if(!dns_len) {
|
||||
buff[buff_iter++] = 1; // ip v4
|
||||
memcpy(buff + buff_iter, &ip, 4); // dest host
|
||||
@ -445,14 +445,14 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
|
||||
memcpy(buff + buff_iter, dns_name, dns_len);
|
||||
buff_iter += dns_len;
|
||||
}
|
||||
|
||||
|
||||
memcpy(buff + buff_iter, &port, 2); // dest port
|
||||
buff_iter += 2;
|
||||
|
||||
|
||||
|
||||
if(buff_iter != write_n_bytes(sock, (char*)buff, buff_iter))
|
||||
goto err;
|
||||
|
||||
|
||||
if(4 != read_n_bytes(sock, (char*)buff, 4))
|
||||
goto err;
|
||||
|
||||
@ -460,7 +460,7 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
|
||||
goto err;
|
||||
|
||||
switch (buff[3]) {
|
||||
|
||||
|
||||
case 1: len = 4; break;
|
||||
case 4: len = 16; break;
|
||||
case 3: len = 0;
|
||||
@ -491,11 +491,11 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,ch
|
||||
static int start_chain(int *fd, proxy_data *pd, char* begin_mark)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
|
||||
|
||||
*fd=socket(PF_INET,SOCK_STREAM,0);
|
||||
if(*fd==-1)
|
||||
goto error;
|
||||
|
||||
|
||||
proxychains_write_log(LOG_PREFIX "%s "TP" %s:%d ",
|
||||
begin_mark,
|
||||
inet_ntoa(*(struct in_addr*)&pd->ip),
|
||||
@ -519,7 +519,7 @@ error:
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
|
||||
static proxy_data * select_proxy(select_type how,
|
||||
static proxy_data * select_proxy(select_type how,
|
||||
proxy_data *pd, unsigned int proxy_count, unsigned int *offset)
|
||||
{
|
||||
unsigned int i=0, k=0;
|
||||
@ -593,12 +593,12 @@ static int chain_step(int ns, proxy_data *pfrom, proxy_data *pto)
|
||||
usenumericip:
|
||||
hostname = inet_ntoa(*(struct in_addr*)&pto->ip);
|
||||
}
|
||||
|
||||
proxychains_write_log(TP" %s:%d ",
|
||||
|
||||
proxychains_write_log(TP" %s:%d ",
|
||||
hostname,
|
||||
htons(pto->port));
|
||||
retcode =
|
||||
tunnel_to(ns, pto->ip, pto->port, pfrom->pt, pfrom->user,
|
||||
retcode =
|
||||
tunnel_to(ns, pto->ip, pto->port, pfrom->pt, pfrom->user,
|
||||
pfrom->pass);
|
||||
switch(retcode) {
|
||||
case SUCCESS:
|
||||
@ -618,8 +618,8 @@ static int chain_step(int ns, proxy_data *pfrom, proxy_data *pto)
|
||||
return retcode;
|
||||
}
|
||||
|
||||
int connect_proxy_chain( int sock, ip_type target_ip,
|
||||
unsigned short target_port, proxy_data *pd,
|
||||
int connect_proxy_chain( int sock, ip_type target_ip,
|
||||
unsigned short target_port, proxy_data *pd,
|
||||
unsigned int proxy_count, chain_type ct, unsigned int max_chain )
|
||||
{
|
||||
proxy_data p4;
|
||||
@ -628,12 +628,12 @@ int connect_proxy_chain( int sock, ip_type target_ip,
|
||||
unsigned int offset=0;
|
||||
unsigned int alive_count=0;
|
||||
unsigned int curr_len=0;
|
||||
|
||||
|
||||
p3=&p4;
|
||||
#ifdef DEBUG
|
||||
PDEBUG("connect_proxy_chain\n");
|
||||
#endif
|
||||
|
||||
|
||||
again:
|
||||
|
||||
switch(ct) {
|
||||
@ -695,7 +695,7 @@ again:
|
||||
if(SUCCESS!=chain_step(ns, p1, p3))
|
||||
goto error;
|
||||
break;
|
||||
|
||||
|
||||
case RANDOM_TYPE:
|
||||
alive_count=calc_alive(pd,proxy_count);
|
||||
if(alive_count<max_chain)
|
||||
@ -713,7 +713,7 @@ again:
|
||||
PDEBUG("GOTO AGAIN 2\n");
|
||||
#endif
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
p1 = p2;
|
||||
}
|
||||
//proxychains_write_log(TP);
|
||||
@ -721,7 +721,7 @@ again:
|
||||
p3->port = target_port;
|
||||
if(SUCCESS!=chain_step(ns,p1,p3))
|
||||
goto error;
|
||||
|
||||
|
||||
}
|
||||
|
||||
proxychains_write_log(TP" OK\n");
|
||||
@ -733,7 +733,7 @@ error:
|
||||
close(ns);
|
||||
errno = ECONNREFUSED; // for nmap ;)
|
||||
return -1;
|
||||
|
||||
|
||||
error_more:
|
||||
proxychains_write_log("\n!!!need more proxies!!!\n");
|
||||
error_strict:
|
||||
@ -762,36 +762,36 @@ struct hostent* proxy_gethostbyname(const char *name)
|
||||
size_t l;
|
||||
|
||||
struct hostent* hp;
|
||||
|
||||
|
||||
resolved_addr_p[0] = (char*) &resolved_addr;
|
||||
resolved_addr_p[1] = NULL;
|
||||
|
||||
|
||||
hostent_space.h_addr_list = resolved_addr_p;
|
||||
|
||||
resolved_addr = 0;
|
||||
|
||||
|
||||
gethostname(buff,sizeof(buff));
|
||||
|
||||
|
||||
if(!strcmp(buff, name)) {
|
||||
resolved_addr = inet_addr(buff);
|
||||
if (resolved_addr == (in_addr_t) (-1))
|
||||
resolved_addr = (in_addr_t) (local_host.as_int);
|
||||
return &hostent_space;
|
||||
}
|
||||
|
||||
|
||||
memset(buff, 0, sizeof(buff));
|
||||
|
||||
|
||||
while ((hp=gethostent()))
|
||||
if (!strcmp(hp->h_name,name))
|
||||
return hp;
|
||||
|
||||
|
||||
if (!strcmp(hp->h_name,name))
|
||||
return hp;
|
||||
|
||||
|
||||
hash = dalias_hash((char*) name);
|
||||
|
||||
|
||||
#ifdef THREAD_SAFE
|
||||
pthread_mutex_lock(&internal_ips_lock);
|
||||
#endif
|
||||
|
||||
|
||||
// see if we already have this dns entry saved.
|
||||
if(internal_ips.counter) {
|
||||
for( i = 0; i < internal_ips.counter; i++) {
|
||||
@ -802,7 +802,7 @@ struct hostent* proxy_gethostbyname(const char *name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// grow list if needed.
|
||||
if(internal_ips.capa < internal_ips.counter + 1) {
|
||||
PDEBUG("realloc\n");
|
||||
@ -816,34 +816,34 @@ struct hostent* proxy_gethostbyname(const char *name)
|
||||
goto err_plus_unlock;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
resolved_addr = make_internal_ip(internal_ips.counter);
|
||||
if(resolved_addr == (in_addr_t) -1) goto err_plus_unlock;
|
||||
|
||||
l = strlen(name);
|
||||
new_mem = malloc(sizeof(string_hash_tuple) + l + 1);
|
||||
if(!new_mem)
|
||||
if(!new_mem)
|
||||
goto oom;
|
||||
|
||||
|
||||
PDEBUG("creating new entry %d for ip of %s\n", (int) internal_ips.counter, name);
|
||||
|
||||
|
||||
internal_ips.list[internal_ips.counter] = new_mem;
|
||||
internal_ips.list[internal_ips.counter]->hash = hash;
|
||||
internal_ips.list[internal_ips.counter]->string = (char*) new_mem + sizeof(string_hash_tuple);
|
||||
|
||||
|
||||
memcpy(internal_ips.list[internal_ips.counter]->string, name, l + 1);
|
||||
|
||||
|
||||
internal_ips.counter += 1;
|
||||
|
||||
|
||||
have_ip:
|
||||
|
||||
|
||||
#ifdef THREAD_SAFE
|
||||
pthread_mutex_unlock(&internal_ips_lock);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
strncpy(addr_name, name, sizeof(addr_name));
|
||||
|
||||
|
||||
hostent_space.h_name = addr_name;
|
||||
hostent_space.h_length = sizeof (in_addr_t);
|
||||
return &hostent_space;
|
||||
@ -862,7 +862,7 @@ int proxy_getaddrinfo(const char *node, const char *service,
|
||||
struct hostent *hp = NULL;
|
||||
struct sockaddr* sockaddr_space = NULL;
|
||||
struct addrinfo* addrinfo_space = NULL;
|
||||
|
||||
|
||||
// printf("proxy_getaddrinfo node %s service %s\n",node,service);
|
||||
addrinfo_space = malloc(sizeof(struct addrinfo));
|
||||
if(!addrinfo_space)
|
||||
@ -875,7 +875,7 @@ int proxy_getaddrinfo(const char *node, const char *service,
|
||||
if (node &&
|
||||
!inet_aton(node,&((struct sockaddr_in*)sockaddr_space)->sin_addr)) {
|
||||
hp = proxy_gethostbyname(node);
|
||||
if (hp)
|
||||
if (hp)
|
||||
memcpy(&((struct sockaddr_in*)sockaddr_space)->sin_addr,
|
||||
*(hp->h_addr_list),
|
||||
sizeof(in_addr_t));
|
||||
@ -884,11 +884,11 @@ int proxy_getaddrinfo(const char *node, const char *service,
|
||||
}
|
||||
if (service)
|
||||
se = getservbyname(service, NULL);
|
||||
|
||||
|
||||
if (!se) {
|
||||
((struct sockaddr_in*)sockaddr_space)->sin_port =
|
||||
((struct sockaddr_in*)sockaddr_space)->sin_port =
|
||||
htons(atoi(service?:"0"));
|
||||
} else
|
||||
} else
|
||||
((struct sockaddr_in*)sockaddr_space)->sin_port = se->s_port;
|
||||
|
||||
*res = addrinfo_space;
|
||||
|
Reference in New Issue
Block a user