fix *all* trailing whitespace at once

This commit is contained in:
rofl0r 2012-01-27 17:55:37 +01:00
parent 73c4195ce3
commit 80817dbf6f
4 changed files with 130 additions and 130 deletions

View File

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

View File

@ -148,4 +148,4 @@ struct hostent* proxy_gethostbyname(const char *name);
# define PDEBUG(fmt, args...) # define PDEBUG(fmt, args...)
#endif #endif
#endif #endif

View File

@ -68,9 +68,9 @@ static void init_lib(void)
#endif #endif
/* read the config file */ /* read the config file */
get_chain_data(proxychains_pd, &proxychains_proxy_count, &proxychains_ct); get_chain_data(proxychains_pd, &proxychains_proxy_count, &proxychains_ct);
proxychains_write_log(LOG_PREFIX "DLL init\n"); proxychains_write_log(LOG_PREFIX "DLL init\n");
true_connect = (connect_t) dlsym(RTLD_NEXT, "connect"); true_connect = (connect_t) dlsym(RTLD_NEXT, "connect");
if (!true_connect) { if (!true_connect) {
@ -89,12 +89,12 @@ static void init_lib(void)
#endif #endif
abort(); abort();
} }
true_gethostbyname = (gethostbyname_t) true_gethostbyname = (gethostbyname_t)
dlsym(RTLD_NEXT, "gethostbyname"); dlsym(RTLD_NEXT, "gethostbyname");
if (!true_gethostbyname) { if (!true_gethostbyname) {
fprintf(stderr, "Cannot load symbol 'gethostbyname' %s\n", fprintf(stderr, "Cannot load symbol 'gethostbyname' %s\n",
dlerror()); dlerror());
exit(1); exit(1);
} else { } else {
@ -104,11 +104,11 @@ static void init_lib(void)
true_gethostbyname, gethostbyname); true_gethostbyname, gethostbyname);
#endif #endif
} }
true_getaddrinfo = (getaddrinfo_t) true_getaddrinfo = (getaddrinfo_t)
dlsym(RTLD_NEXT, "getaddrinfo"); dlsym(RTLD_NEXT, "getaddrinfo");
if (!true_getaddrinfo) { if (!true_getaddrinfo) {
fprintf(stderr, "Cannot load symbol 'getaddrinfo' %s\n", fprintf(stderr, "Cannot load symbol 'getaddrinfo' %s\n",
dlerror()); dlerror());
exit(1); exit(1);
} else { } else {
@ -118,11 +118,11 @@ static void init_lib(void)
true_getaddrinfo, getaddrinfo); true_getaddrinfo, getaddrinfo);
#endif #endif
} }
true_freeaddrinfo = (freeaddrinfo_t) true_freeaddrinfo = (freeaddrinfo_t)
dlsym(RTLD_NEXT, "freeaddrinfo"); dlsym(RTLD_NEXT, "freeaddrinfo");
if (!true_freeaddrinfo) { if (!true_freeaddrinfo) {
fprintf(stderr, "Cannot load symbol 'freeaddrinfo' %s\n", fprintf(stderr, "Cannot load symbol 'freeaddrinfo' %s\n",
dlerror()); dlerror());
exit(1); exit(1);
} else { } else {
@ -132,11 +132,11 @@ static void init_lib(void)
true_freeaddrinfo, freeaddrinfo); true_freeaddrinfo, freeaddrinfo);
#endif #endif
} }
true_gethostbyaddr = (gethostbyaddr_t) true_gethostbyaddr = (gethostbyaddr_t)
dlsym(RTLD_NEXT, "gethostbyaddr"); dlsym(RTLD_NEXT, "gethostbyaddr");
if (!true_gethostbyaddr) { if (!true_gethostbyaddr) {
fprintf(stderr, "Cannot load symbol 'gethostbyaddr' %s\n", fprintf(stderr, "Cannot load symbol 'gethostbyaddr' %s\n",
dlerror()); dlerror());
exit(1); exit(1);
} else { } else {
@ -146,11 +146,11 @@ static void init_lib(void)
true_gethostbyaddr, gethostbyaddr); true_gethostbyaddr, gethostbyaddr);
#endif #endif
} }
true_getnameinfo = (getnameinfo_t) true_getnameinfo = (getnameinfo_t)
dlsym(RTLD_NEXT, "getnameinfo"); dlsym(RTLD_NEXT, "getnameinfo");
if (!true_getnameinfo) { if (!true_getnameinfo) {
fprintf(stderr, "Cannot load symbol 'getnameinfo' %s\n", fprintf(stderr, "Cannot load symbol 'getnameinfo' %s\n",
dlerror()); dlerror());
exit(1); exit(1);
} else { } else {
@ -199,7 +199,7 @@ static inline void get_chain_data(
perror("Can't locate proxychains.conf"); perror("Can't locate proxychains.conf");
exit(1); exit(1);
} }
env = getenv(PROXYCHAINS_QUIET_MODE_ENV_VAR); env = getenv(PROXYCHAINS_QUIET_MODE_ENV_VAR);
if(env && *env == '1') proxychains_quiet_mode = 1; if(env && *env == '1') proxychains_quiet_mode = 1;
@ -207,25 +207,25 @@ static inline void get_chain_data(
if(buff[0] != '\n' && buff[strspn(buff," ")]!='#') { if(buff[0] != '\n' && buff[strspn(buff," ")]!='#') {
if(list) { if(list) {
memset(&pd[count], 0, sizeof(proxy_data)); memset(&pd[count], 0, sizeof(proxy_data));
pd[count].ps = PLAY_STATE; pd[count].ps = PLAY_STATE;
port_n = 0; port_n = 0;
sscanf(buff,"%s %s %d %s %s", type, host, &port_n, sscanf(buff,"%s %s %d %s %s", type, host, &port_n,
pd[count].user, pd[count].pass); pd[count].user, pd[count].pass);
pd[count].ip.as_int = (uint32_t) inet_addr(host); pd[count].ip.as_int = (uint32_t) inet_addr(host);
pd[count].port = htons((unsigned short)port_n); pd[count].port = htons((unsigned short)port_n);
if(!strcmp(type,"http")) { if(!strcmp(type,"http")) {
pd[count].pt = HTTP_TYPE; pd[count].pt = HTTP_TYPE;
} else if(!strcmp(type,"socks4")) { } else if(!strcmp(type,"socks4")) {
pd[count].pt = SOCKS4_TYPE; pd[count].pt = SOCKS4_TYPE;
} else if(!strcmp(type,"socks5")) { } else if(!strcmp(type,"socks5")) {
pd[count].pt = SOCKS5_TYPE; pd[count].pt = SOCKS5_TYPE;
} else } else
continue; continue;
if(pd[count].ip.as_int && port_n && if(pd[count].ip.as_int && port_n &&
pd[count].ip.as_int != (uint32_t) -1) pd[count].ip.as_int != (uint32_t) -1)
if(++count==MAX_CHAIN) if(++count==MAX_CHAIN)
@ -355,9 +355,9 @@ int connect (int sock, const struct sockaddr *addr, unsigned int len)
flags = fcntl(sock, F_GETFL, 0); flags = fcntl(sock, F_GETFL, 0);
if(flags & O_NONBLOCK) if(flags & O_NONBLOCK)
fcntl(sock, F_SETFL, !O_NONBLOCK); fcntl(sock, F_SETFL, !O_NONBLOCK);
dest_ip.as_int = SOCKADDR(*addr); dest_ip.as_int = SOCKADDR(*addr);
ret = connect_proxy_chain( ret = connect_proxy_chain(
sock, sock,
dest_ip, dest_ip,
@ -366,7 +366,7 @@ int connect (int sock, const struct sockaddr *addr, unsigned int len)
proxychains_proxy_count, proxychains_proxy_count,
proxychains_ct, proxychains_ct,
proxychains_max_chain ); proxychains_max_chain );
fcntl(sock, F_SETFL, flags); fcntl(sock, F_SETFL, flags);
if(ret != SUCCESS) if(ret != SUCCESS)
errno = ECONNREFUSED; errno = ECONNREFUSED;
@ -377,14 +377,14 @@ struct hostent *gethostbyname(const char *name)
{ {
if(!init_l) if(!init_l)
init_lib(); init_lib();
PDEBUG("gethostbyname: %s\n",name); PDEBUG("gethostbyname: %s\n",name);
if(proxychains_resolver) if(proxychains_resolver)
return proxy_gethostbyname(name); return proxy_gethostbyname(name);
else else
return true_gethostbyname(name); return true_gethostbyname(name);
return NULL; return NULL;
} }
@ -393,17 +393,17 @@ int getaddrinfo(const char *node, const char *service,
struct addrinfo **res) struct addrinfo **res)
{ {
int ret = 0; int ret = 0;
if(!init_l) if(!init_l)
init_lib(); init_lib();
PDEBUG("getaddrinfo: %s %s\n",node ,service); PDEBUG("getaddrinfo: %s %s\n",node ,service);
if(proxychains_resolver) if(proxychains_resolver)
ret = proxy_getaddrinfo(node, service, hints, res); ret = proxy_getaddrinfo(node, service, hints, res);
else else
ret = true_getaddrinfo(node, service, hints, res); ret = true_getaddrinfo(node, service, hints, res);
return ret; return ret;
} }
@ -411,9 +411,9 @@ void freeaddrinfo(struct addrinfo *res)
{ {
if(!init_l) if(!init_l)
init_lib(); init_lib();
PDEBUG("freeaddrinfo %p \n",res); PDEBUG("freeaddrinfo %p \n",res);
if(!proxychains_resolver) if(!proxychains_resolver)
true_freeaddrinfo(res); true_freeaddrinfo(res);
else { else {
@ -437,19 +437,19 @@ int getnameinfo (const struct sockaddr * sa,
#endif #endif
{ {
int ret = 0; int ret = 0;
if(!init_l) if(!init_l)
init_lib(); init_lib();
PDEBUG("getnameinfo: %s %s\n", host, serv); PDEBUG("getnameinfo: %s %s\n", host, serv);
if(!proxychains_resolver) { if(!proxychains_resolver) {
ret = true_getnameinfo(sa,salen,host,hostlen, ret = true_getnameinfo(sa,salen,host,hostlen,
serv,servlen,flags); serv,servlen,flags);
} else { } else {
if(hostlen) if(hostlen)
strncpy(host, inet_ntoa(SOCKADDR_2(*sa)),hostlen); strncpy(host, inet_ntoa(SOCKADDR_2(*sa)),hostlen);
if(servlen) if(servlen)
snprintf(serv, servlen,"%d",ntohs(SOCKPORT(*sa))); snprintf(serv, servlen,"%d",ntohs(SOCKPORT(*sa)));
} }
return ret; return ret;
@ -483,16 +483,16 @@ struct hostent *gethostbyaddr (const void *addr, socklen_t len, int type)
static char ipv4[4]; static char ipv4[4];
static char* list[2]; static char* list[2];
static struct hostent he; static struct hostent he;
if(!init_l) if(!init_l)
init_lib(); init_lib();
PDEBUG("TODO: proper gethostbyaddr hook\n"); PDEBUG("TODO: proper gethostbyaddr hook\n");
if(!proxychains_resolver) if(!proxychains_resolver)
return true_gethostbyaddr(addr,len,type); return true_gethostbyaddr(addr,len,type);
else { else {
PDEBUG("len %u\n", len); PDEBUG("len %u\n", len);
if(len != 4) return NULL; if(len != 4) return NULL;
he.h_name = buf; he.h_name = buf;
@ -508,4 +508,4 @@ struct hostent *gethostbyaddr (const void *addr, socklen_t len, int type)
} }
return NULL; return NULL;
} }

View File

@ -77,22 +77,22 @@ int main(int argc, char *argv[]) {
int quiet = 0; int quiet = 0;
size_t i; size_t i;
const char* prefix = NULL; const char* prefix = NULL;
for(i = 0; i < MAX_COMMANDLINE_FLAGS; i++) { for(i = 0; i < MAX_COMMANDLINE_FLAGS; i++) {
if(start_argv < argc && argv[start_argv][0] == '-') { if(start_argv < argc && argv[start_argv][0] == '-') {
if(argv[start_argv][1] == 'q') { if(argv[start_argv][1] == 'q') {
quiet = 1; quiet = 1;
start_argv++; start_argv++;
} else if(argv[start_argv][1] == 'f') { } else if(argv[start_argv][1] == 'f') {
if(start_argv + 1 < argc) if(start_argv + 1 < argc)
path = argv[start_argv + 1]; path = argv[start_argv + 1];
else else
return usage(argv); return usage(argv);
start_argv += 2; start_argv += 2;
} }
} else } else
break; break;
} }
@ -103,33 +103,33 @@ int main(int argc, char *argv[]) {
// priority 1: env var PROXYCHAINS_CONF_FILE // priority 1: env var PROXYCHAINS_CONF_FILE
path = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR); path = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
if(check_path(path)) goto have; if(check_path(path)) goto have;
// priority 2; proxychains conf in actual dir // priority 2; proxychains conf in actual dir
path = getcwd(buf, sizeof(buf)); path = getcwd(buf, sizeof(buf));
snprintf(pbuf, sizeof(pbuf), "%s/%s", path, PROXYCHAINS_CONF_FILE); snprintf(pbuf, sizeof(pbuf), "%s/%s", path, PROXYCHAINS_CONF_FILE);
path = pbuf; path = pbuf;
if(check_path(path)) goto have; if(check_path(path)) goto have;
// priority 3; $HOME/.proxychains/proxychains.conf // priority 3; $HOME/.proxychains/proxychains.conf
path = getenv("HOME"); path = getenv("HOME");
snprintf(pbuf, sizeof(pbuf), "%s/.proxychains/%s", path, PROXYCHAINS_CONF_FILE); snprintf(pbuf, sizeof(pbuf), "%s/.proxychains/%s", path, PROXYCHAINS_CONF_FILE);
path = pbuf; path = pbuf;
if(check_path(path)) goto have; if(check_path(path)) goto have;
// priority 4: /etc/proxychains.conf // priority 4: /etc/proxychains.conf
path = "/etc/proxychains.conf"; path = "/etc/proxychains.conf";
if(check_path(path)) goto have; if(check_path(path)) goto have;
perror("couldnt find configuration file"); perror("couldnt find configuration file");
return 1; return 1;
} }
have: have:
if(!quiet) fprintf(stderr, LOG_PREFIX "config file found: %s\n", path); if(!quiet) fprintf(stderr, LOG_PREFIX "config file found: %s\n", path);
/* Set PROXYCHAINS_CONF_FILE to get proxychains lib to use new config file. */ /* Set PROXYCHAINS_CONF_FILE to get proxychains lib to use new config file. */
setenv(PROXYCHAINS_CONF_FILE_ENV_VAR, path, 1); setenv(PROXYCHAINS_CONF_FILE_ENV_VAR, path, 1);
if(quiet) setenv(PROXYCHAINS_QUIET_MODE_ENV_VAR, "1", 1); if(quiet) setenv(PROXYCHAINS_QUIET_MODE_ENV_VAR, "1", 1);
@ -151,7 +151,7 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if(!quiet) fprintf(stderr, LOG_PREFIX "preloading %s/%s\n", prefix, dll_name); if(!quiet) fprintf(stderr, LOG_PREFIX "preloading %s/%s\n", prefix, dll_name);
snprintf(buf, sizeof(buf), "LD_PRELOAD=%s/%s", prefix, dll_name); snprintf(buf, sizeof(buf), "LD_PRELOAD=%s/%s", prefix, dll_name);
putenv(buf); putenv(buf);