6 Commits

9 changed files with 132 additions and 75 deletions
+1
View File
@@ -4,6 +4,7 @@
*.lo
.deps/
.libs/
.*
# Autoconf stuff
libtool
+1 -1
View File
@@ -7,7 +7,7 @@ main.c, remote-dns, thread safety, bugfixes, build system, cleanups
rofl0r.
https://github.com/rofl0r/proxychains
localnet, bugfixes
localnet, bugfixes, macos x support
adam hamsik.
https://github.com/haad/proxychains
+15
View File
@@ -1,6 +1,21 @@
ProxyChains version history (public releases)
====================
ver 4.1
* Mac OS X support, create install script.
* thread-safe fixes by @rofl0r
-------------------------------------------------------------------------
ver 4.0
changed:
* Add a lot of fixes
* localnet-patch
* remote-dns
* thread-safe
-------------------------------------------------------------------------
ver 3.1
changed:
+3 -3
View File
@@ -17,8 +17,8 @@ SRCS = $(sort $(wildcard src/*.c))
OBJS = $(SRCS:.c=.o)
LOBJS = src/core.o src/common.o src/libproxychains.o
CCFLAGS = -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE -Werror
LDFLAGS = -shared -fPIC -ldl -lpthread
CCFLAGS = -Wall -O2 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE -Werror
LDFLAGS = -shared -fPIC -lpthread
INC =
PIC = -fPIC
AR = $(CROSS_COMPILE)ar
@@ -68,4 +68,4 @@ $(LDSO_PATHNAME): $(LOBJS)
$(ALL_TOOLS): $(OBJS)
$(CC) src/main.o src/common.o -o $(PXCHAINS)
.PHONY: all clean install install-config
.PHONY: all clean install install-config
Vendored
+25 -1
View File
@@ -1,6 +1,7 @@
#!/bin/sh
prefix=/usr/local
develflg=0
usage() {
echo "supported arguments"
@@ -10,6 +11,7 @@ usage() {
echo "--libdir=/path default: $prefix/lib"
echo "--includedir=/path default: $prefix/include"
echo "--sysconfdir=/path default: $prefix/etc"
echo "--devel default:no (set development mode)"
echo "--help : show this text"
exit 1
}
@@ -29,6 +31,7 @@ parsearg() {
--libdir=*) libdir=`spliteq $1`;;
--includedir=*) includedir=`spliteq $1`;;
--sysconfdir=*) sysconfdir=`spliteq $1`;;
--devel) develflg=1;;
--help) usage;;
esac
}
@@ -37,6 +40,14 @@ ismac() {
uname -s | grep Darwin
}
isbsd() {
uname -s | grep BSD
}
islinux() {
uname -s | grep Linux
}
while true ; do
case $1 in
-*) parsearg "$1"; shift;;
@@ -68,6 +79,10 @@ if [ -z "$CC" ] ; then
CC=cc
fi
if [ $develflg -eq 1 ]; then
CFLAGS="-Wextra -Wunused -Wuninitialized -Wconversion -fno-common -g -O0"
fi
echo CC?=$CC>config.mak
[ -z "$CPPFLAGS" ] || echo CPPFLAGS?=$CPPFLAGS>>config.mak
[ -z "$CFLAGS" ] || echo USER_CFLAGS?=$CFLAGS>>config.mak
@@ -81,9 +96,18 @@ if ismac ; then
echo LDSO_SUFFIX=dylib>>config.mak
echo MAC_CFLAGS+=-DIS_MAC=1 -arch x86_64 -arch i386 >>config.mak
echo MAC_LDFLAGS+=-arch x86_64 -arch i386 >>config.mak
echo LD_SET_SONAME=-Wl,-install_name,>>config.mak
echo LD_SET_SONAME=-ldl -Wl,-install_name,>>config.mak
echo INSTALL_FLAGS=-m>>config.mak
fi
if islinux ; then
echo LD_SET_SONAME=-ldl
fi
if isbsd ; then
echo INSTALL_FLAGS=-m>>config.mak
echo LD_SET_SONAME=-Wl,-rpath,$libdir -install_name,>>config.mak
fi
echo done, now run make \&\& make install
+5 -1
View File
@@ -3,6 +3,10 @@
#define PROXYCHAINS_CONF_FILE "proxychains.conf"
#define LOG_PREFIX "[proxychains] "
#define PROXYCHAINS_VERSION_MAJOR 4
#define PROXYCHAINS_VERSION_MINOR 1
#define PROXYCHAINS_VERSION_BUGFIX 0
#include <stddef.h>
char *get_config_path(char* default_path, char* pbuf, size_t bufsize);
char *get_config_path(char* default_path, char* pbuf, size_t bufsize);
+58 -50
View File
@@ -15,6 +15,7 @@
* *
***************************************************************************/
#include <sys/types.h>
#include <sys/cdefs.h>
#include <stdio.h>
#include <unistd.h>
@@ -34,10 +35,15 @@
#include <sys/time.h>
#include <stdarg.h>
#include <assert.h>
#ifdef THREAD_SAFE
#include <pthread.h>
pthread_mutex_t internal_ips_lock;
#endif
#ifdef __APPLE__
pthread_mutex_t internal_getsrvbyname_lock;
#endif /* __APPLE__ */
#endif /* THREAD_SAFE */
#include "core.h"
#include "common.h"
@@ -62,7 +68,7 @@ uint32_t dalias_hash(char *s0) {
uint32_t index_from_internal_ip(ip_type internalip) {
ip_type tmp = internalip;
uint32_t ret;
ret = tmp.octet[3] + (tmp.octet[2] << 8) + (tmp.octet[1] << 16);
ret = (uint32_t) (tmp.octet[3] + (tmp.octet[2] << 8) + (tmp.octet[1] << 16));
ret -= 1;
return ret;
}
@@ -106,7 +112,7 @@ static int poll_retry(struct pollfd *fds, nfds_t nfsd, int timeout)
//printf("Retry %d\n", time_remain);
ret = poll(fds, nfsd, time_remain);
gettimeofday(&tv, NULL);
time_elapsed = ((tv.tv_sec - start_time.tv_sec) * 1000 + (tv.tv_usec - start_time.tv_usec) / 1000);
time_elapsed = ((int)(tv.tv_sec - start_time.tv_sec) * 1000 + (int)(tv.tv_usec - start_time.tv_usec) / 1000);
//printf("Time elapsed %d\n", time_elapsed);
time_remain = timeout - time_elapsed;
} while(ret == -1 && errno == EINTR && time_remain > 0);
@@ -118,7 +124,9 @@ static int poll_retry(struct pollfd *fds, nfds_t nfsd, int timeout)
static void encode_base_64(char *src, char *dest, int max_len) {
int n, l, i;
int n, i;
size_t l;
l = strlen(src);
max_len = (max_len - 1) / 4;
for(i = 0; i < max_len; i++, src += 3, l -= 3) {
@@ -164,11 +172,11 @@ void proxychains_write_log(char *str, ...) {
}
}
static int write_n_bytes(int fd, char *buff, size_t size) {
int i = 0;
static size_t write_n_bytes(int fd, char *buff, size_t size) {
size_t i = 0;
size_t wrote = 0;
for(;;) {
i = write(fd, &buff[wrote], size - wrote);
i = (size_t) write(fd, &buff[wrote], size - wrote);
if(i <= 0)
return i;
wrote += i;
@@ -177,7 +185,7 @@ static int write_n_bytes(int fd, char *buff, size_t size) {
}
}
static int read_n_bytes(int fd, char *buff, size_t size) {
static size_t read_n_bytes(int fd, char *buff, size_t size) {
int ready;
size_t i;
struct pollfd pfd[1];
@@ -188,9 +196,9 @@ static int read_n_bytes(int fd, char *buff, size_t size) {
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))
return -1;
return 0;
}
return (int) size;
return size;
}
static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len) {
@@ -203,7 +211,7 @@ static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len) {
fcntl(sock, F_SETFL, O_NONBLOCK);
ret = true_connect(sock, addr, len);
PDEBUG("\nconnect ret=%d\n", ret);
if(ret == -1 && errno == EINPROGRESS) {
ret = poll_retry(pfd, 1, tcp_connect_time_out);
PDEBUG("\npoll ret=%d\n", ret);
@@ -253,7 +261,7 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
if(!dns_len)
goto err;
}
PDEBUG("host dns %s\n", dns_name ? dns_name : "<NULL>");
size_t ulen = strlen(user);
@@ -264,7 +272,7 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
goto err;
}
int len;
size_t len;
unsigned char buff[BUFF_SIZE];
char ip_buf[16];
//memset (buff, 0, sizeof(buff));
@@ -298,7 +306,7 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
len = strlen((char *) buff);
if(len != send(sock, buff, len, 0))
if(len != (size_t) send(sock, buff, len, 0))
goto err;
len = 0;
@@ -392,15 +400,15 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
int c;
*cur++ = 1; // version
c = ulen & 0xFF;
*cur++ = c;
memcpy(cur, user, c);
*cur++ = (char)c;
memcpy(cur, user, (size_t)c);
cur += c;
c = passlen & 0xFF;
*cur++ = c;
memcpy(cur, pass, c);
*cur++ = (char)c;
memcpy(cur, pass, (size_t)c);
cur += c;
if((cur - out) != write_n_bytes(sock, out, cur - out))
if((size_t)(cur - out) != write_n_bytes(sock, out, (size_t) (cur - out)))
goto err;
@@ -413,7 +421,7 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
return BLOCKED;
}
}
int buff_iter = 0;
size_t buff_iter = 0;
buff[buff_iter++] = 5; // version
buff[buff_iter++] = 1; // connect
buff[buff_iter++] = 0; // reserved
@@ -514,7 +522,7 @@ static proxy_data *select_proxy(select_type how, proxy_data * pd, unsigned int p
return NULL;
switch (how) {
case RANDOMLY:
srand(time(NULL));
srand((unsigned int)time(NULL));
do {
k++;
i = 0 + (unsigned int) (proxy_count * 1.0 * rand() / (RAND_MAX + 1.0));
@@ -552,8 +560,7 @@ static void release_busy(proxy_data * pd, unsigned int proxy_count) {
}
static unsigned int calc_alive(proxy_data * pd, unsigned int proxy_count) {
unsigned int i;
int alive_count = 0;
unsigned int i, alive_count = 0;
release_busy(pd, proxy_count);
for(i = 0; i < proxy_count; i++)
if(pd[i].ps == PLAY_STATE)
@@ -616,7 +623,7 @@ int connect_proxy_chain(int sock, ip_type target_ip,
switch (ct) {
case DYNAMIC_TYPE:
alive_count = calc_alive(pd, proxy_count);
calc_alive(pd, proxy_count);
offset = 0;
do {
if(!(p1 = select_proxy(FIFOLY, pd, proxy_count, &offset)))
@@ -640,7 +647,7 @@ int connect_proxy_chain(int sock, ip_type target_ip,
break;
case STRICT_TYPE:
alive_count = calc_alive(pd, proxy_count);
calc_alive(pd, proxy_count);
offset = 0;
if(!(p1 = select_proxy(FIFOLY, pd, proxy_count, &offset))) {
PDEBUG("select_proxy failed\n");
@@ -819,7 +826,7 @@ void proxy_freeaddrinfo(struct addrinfo *res) {
free(res);
}
void proxy_getserverbyname(const char * service, struct servent *se_buf,
void proxy_getservbyname(const char * service, struct servent *se_buf,
char * buf, size_t buf_len, struct servent **se_result)
{
@@ -829,22 +836,22 @@ void proxy_getserverbyname(const char * service, struct servent *se_buf,
#ifdef __APPLE__
struct servent *se;
#ifdef THREAD_SAFE
MUTEX_LOCK(&internal_getsrvbyname_lock);
#endif
if(service)
if(service) {
se = getservbyname(service, NULL);
if (!se)
memcpy(se_buf, se, buf_len);
*se_result = se_buf;
#ifdef THREAD_SAFE
if ( se != NULL ) {
memcpy(se_buf, se, buf_len);
*se_result = se_buf;
} else {
*se_result = NULL;
}
}
MUTEX_UNLOCK(&internal_getsrvbyname_lock);
#endif
#endif
#endif /* __APPLE__ */
}
int proxy_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
struct gethostbyname_data ghdata;
struct addrinfo_data *space;
@@ -857,21 +864,24 @@ int proxy_getaddrinfo(const char *node, const char *service, const struct addrin
// printf("proxy_getaddrinfo node %s service %s\n",node,service);
space = calloc(1, sizeof(struct addrinfo_data));
if(!space) goto err1;
if(!space)
return 1;
if(node && !inet_aton(node, &((struct sockaddr_in *) &space->sockaddr_space)->sin_addr)) {
hp = proxy_gethostbyname(node, &ghdata);
if(hp)
if(hp) {
memcpy(&((struct sockaddr_in *) &space->sockaddr_space)->sin_addr,
*(hp->h_addr_list), sizeof(in_addr_t));
else
goto err2;
} else {
free(space);
return 1;
}
}
if(service)
proxy_getserverbyname(service, &se_buf, buf, sizeof(buf), &se);
proxy_getservbyname(service, &se_buf, buf, sizeof(buf), &se);
port = se ? se->s_port : htons(atoi(service ? service : "0"));
((struct sockaddr_in *) &space->sockaddr_space)->sin_port = port;
((struct sockaddr_in *) &space->sockaddr_space)->sin_port = (in_port_t)port;
*res = p = &space->addrinfo_space;
assert((size_t)p == (size_t) space);
@@ -889,14 +899,12 @@ int proxy_getaddrinfo(const char *node, const char *service, const struct addrin
p->ai_flags = hints->ai_flags;
p->ai_protocol = hints->ai_protocol;
} else {
#ifdef BSD
p->ai_flags = (AI_V4MAPPED | AI_ADDRCONFIG);
#else
p->ai_flags = (AI_ADDRCONFIG);
#endif
}
goto out;
err2:
free(space);
err1:
return 1;
out:
return 0;
}
+16 -16
View File
@@ -41,11 +41,9 @@ extern internal_ip_lookup_table internal_ips;
#ifdef THREAD_SAFE
#include <pthread.h>
pthread_mutex_t internal_ips_lock;
#ifdef __APPLE__
pthread_mutex_t internal_getsrvbyname_lock;
#endif
extern pthread_mutex_t internal_ips_lock;
extern pthread_mutex_t internal_getsrvbyname_lock;
# define MUTEX_LOCK(x) pthread_mutex_lock(x)
# define MUTEX_UNLOCK(x) pthread_mutex_unlock(x)
@@ -104,21 +102,24 @@ typedef struct {
char pass[256];
} proxy_data;
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 );
int connect_proxy_chain (int, ip_type, unsigned short, proxy_data *, unsigned int,
chain_type, unsigned int);
void proxychains_write_log(char *str, ...);
void proxychains_write_log(char *, ...);
typedef int (*connect_t)(int, const struct sockaddr *, socklen_t);
typedef struct hostent* (*gethostbyname_t)(const char *);
typedef int (*freeaddrinfo_t)(struct addrinfo *);
#if (defined __linux__) || (defined __APPLE__)
typedef struct hostent *(*gethostbyaddr_t) (const void *, socklen_t, int);
#else
typedef struct hostent *(*gethostbyaddr_t) (const char *, socklen_t, int);
#endif
typedef int (*getaddrinfo_t)(const char *, const char *, const struct addrinfo *,
typedef int (*getaddrinfo_t)(const char *, const char *, const struct addrinfo *,
struct addrinfo **);
typedef int (*getnameinfo_t) (const struct sockaddr *, socklen_t, char *,
typedef int (*getnameinfo_t) (const struct sockaddr *, socklen_t, char *,
socklen_t, char *, socklen_t, int);
@@ -136,11 +137,10 @@ struct gethostbyname_data {
char addr_name[1024 * 8];
};
struct hostent* proxy_gethostbyname(const char *name, struct gethostbyname_data *data);
int proxy_getaddrinfo(const char *node, const char *service,
const struct addrinfo *hints, struct addrinfo **res);
void proxy_freeaddrinfo(struct addrinfo *res);
struct hostent* proxy_gethostbyname(const char *, struct gethostbyname_data *);
void proxy_getservbyname(const char *, struct servent *, char *, size_t, struct servent **);
int proxy_getaddrinfo(const char *, const char *, const struct addrinfo *, struct addrinfo **);
void proxy_freeaddrinfo(struct addrinfo *);
#ifdef DEBUG
# define PDEBUG(fmt, args...) do { fprintf(stderr,"DEBUG:"fmt, ## args); fflush(stderr); } while(0)
+8 -3
View File
@@ -164,7 +164,8 @@ open_config_file() {
/* get configuration from config file */
static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct) {
int count = 0, port_n = 0, list = 0;
unsigned int count = 0;
int port_n = 0, list = 0;
char buff[1024], type[1024], host[1024], user[1024];
char *env;
char local_in_addr_port[32];
@@ -266,7 +267,7 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
}
if(local_in_port[0]) {
localnet_addr[num_localnet_addr].port =
(short) atoi(local_in_port);
(unsigned short) atoi(local_in_port);
} else {
localnet_addr[num_localnet_addr].port = 0;
}
@@ -279,7 +280,7 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
int len;
pc = strchr(buff, '=');
len = atoi(++pc);
proxychains_max_chain = (len ? len : 1);
proxychains_max_chain = (unsigned int) (len ? len : 1);
} else if(strstr(buff, "quiet_mode")) {
proxychains_quiet_mode = 1;
} else if(strstr(buff, "proxy_dns")) {
@@ -424,7 +425,11 @@ int getnameinfo(const struct sockaddr *sa,
return ret;
}
#if (defined __linux__) || (defined __APPLE__)
struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type) {
#else
struct hostent *gethostbyaddr(const char *addr, socklen_t len, int type) {
#endif
static char buf[16];
static char ipv4[4];
static char *list[2];