33 Commits

Author SHA1 Message Date
Adam Hamsik 5294214150 Fix merge error. 2012-06-18 15:46:22 +02:00
Adam Hamsik 385b349a8e Add support for both i386 and amd64 in mac os x binary. 2012-06-18 15:45:45 +02:00
Adam Hamsik 2320f6608a Merge rofl0r changes to main stream. 2012-06-16 12:10:41 +02:00
Michel Oosterhof 251fd7cd4a Only enable loopback localnet by default, not private address range. 2012-06-16 12:04:28 +02:00
Michel Oosterhof b0d9d1da41 Enable localnet by default for loopback and private address ranges. 2012-06-16 12:04:23 +02:00
Michel Oosterhof a7831a8f53 Typo fix. 2012-06-16 12:02:51 +02:00
Jahrome 229eb7cc5a bugfix: localnet never used if no port specified. Fix typo. 2012-05-22 23:11:03 +02:00
Adam Hamsik c9b8ce35b2 Merge pull request #16 from jahrome/master
Hi ! Nice job with localnet, just what I was needing, here is just a small fix. Hope this helps.
2012-05-22 06:07:35 -07:00
Jahrome 63c3a4b0d2 bugfix: localnet never used if no port specified. Fix typo. 2012-05-22 14:25:53 +02:00
rofl0r 45f50ac754 cosmetic fix 2012-04-24 02:04:02 +02:00
rofl0r d72e668767 use sane defaults 2012-04-24 01:48:17 +02:00
rofl0r 561679fbcd remove dead code 2012-04-24 01:46:57 +02:00
rofl0r bc23ef8f46 fix debug message 2012-04-23 22:56:44 +02:00
rofl0r 88a54e872a use dynloader to call init() func when gcc is available, and lock it properly 2012-04-23 22:21:40 +02:00
rofl0r caed782652 macros 2012-04-23 22:21:40 +02:00
rofl0r f55c6bc4d5 fix PDEBUG macro 2012-04-23 22:21:40 +02:00
rofl0r 49293b180d some cleanup in core.h 2012-04-23 20:26:13 +02:00
rofl0r 3260ee812a debloat init_lib() 2012-04-23 19:51:14 +02:00
rofl0r 1000366f88 Makefile: create destination dirs in case they do not exist 2012-03-07 18:05:04 +01:00
rofl0r 598a41a671 Makefile: add support for DESTDIR 2012-03-07 18:02:37 +01:00
Jianing Yang 65471b750c bugfix: localnet conflicts with proxydns 2012-03-07 17:58:37 +01:00
Adam Hamsik 4d40a4790f Merge pull request #15 from jianingy/master
bugfix: localnet conflicts with proxydns
2012-03-04 23:21:43 -08:00
Jianing Yang 50820ce80d new: added DESTDIR option to Makefile so that packaging will be easier 2012-03-03 14:57:49 +08:00
Jianing Yang b6746997d2 bugfix: localnet conflicts with proxydns (fixed bytes-order) 2012-03-03 14:30:14 +08:00
Jianing Yang 6dda28a2c8 bugfix: localnet conflicts with proxydns 2012-03-03 14:24:05 +08:00
Adam Hamsik fb3d8e04a1 Change example config version to 4. 2012-03-02 12:57:05 +01:00
rofl0r 03b49f529e fix bogus use of ! in configure 2012-01-30 18:35:03 +01:00
rofl0r e99dd76941 complete sysconfdir support 2012-01-30 18:29:35 +01:00
rofl0r 0ee539f31c added support for --sysconfdir 2012-01-30 18:26:38 +01:00
rofl0r f4e4c8c2b1 remove unnecessary sprintf call 2012-01-29 02:34:04 +01:00
Adam Hamsik 0938a940c5 Create install destionation directories first with install -d. 2012-01-28 23:10:40 +01:00
rofl0r dbb172b510 use PROXYCHAINS_CONF_FILE consistently 2012-01-28 18:34:40 +01:00
rofl0r 48373ab7a5 fix forgotten etc 2012-01-28 18:33:40 +01:00
6 changed files with 132 additions and 120 deletions
+8 -6
View File
@@ -17,7 +17,7 @@ SRCS = $(sort $(wildcard src/*.c))
OBJS = $(SRCS:.c=.o)
LOBJS = src/core.o src/libproxychains.o
CCFLAGS = -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE -Werror
CCFLAGS = -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE -Werror
LDFLAGS = -shared -fPIC -ldl -lpthread
INC =
PIC = -fPIC
@@ -39,16 +39,19 @@ ALL_TOOLS = $(PXCHAINS)
CCFLAGS+=$(USER_CFLAGS) $(MAC_CFLAGS)
LDFLAGS+=$(USER_LDFLAGS) $(MAC_LDFLAGS)
CXXFLAGS+=$(CCFLAGS) $(USER_CFLAGS) $(MAC_CFLAGS)
CFLAGS_MAIN=-DLIB_DIR=\"$(libdir)\" -DINSTALL_PREFIX=\"$(prefix)\" -DDLL_NAME=\"$(LDSO_PATHNAME)\"
all: $(ALL_LIBS) $(ALL_TOOLS)
#install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(DESTDIR)$(LDSO_PATHNAME)
install:
install $(INSTALL_FLAGS) 755 $(ALL_TOOLS) $(bindir)/
install $(INSTALL_FLAGS) 644 $(ALL_LIBS) $(libdir)/
install $(INSTALL_FLAGS) 644 src/proxychains.conf $(prefix)/etc/
install:
install -d $(DESTDIR)/$(bindir) $(DESTDIR)/$(libdir) $(DESTDIR)/$(confdir) $(DESTDIR)/$(includedir)
install $(INSTALL_FLAGS) 755 $(ALL_TOOLS) $(DESTDIR)/$(bindir)/
install $(INSTALL_FLAGS) 644 $(ALL_LIBS) $(DESTDIR)/$(libdir)/
install $(INSTALL_FLAGS) 644 src/proxychains.conf $(DESTDIR)/$(confdir)
clean:
rm -f $(ALL_LIBS)
@@ -64,5 +67,4 @@ $(LDSO_PATHNAME): $(LOBJS)
$(ALL_TOOLS): $(OBJS)
$(CC) src/main.o -o $(PXCHAINS)
.PHONY: all clean install
Vendored
+13 -6
View File
@@ -11,11 +11,12 @@ spliteq() {
parsearg() {
case "$1" in
--prefix=*) prefix=$(spliteq "$1");;
--prefix=*) prefix=`spliteq $1`;;
--exec_prefix=*) exec_prefix=`spliteq $1`;;
--bindir=*) bindir=`spliteq $1`;;
--libdir=*) libdir=`spliteq $1`;;
--includedir=*) includedir=`spliteq $1`;;
--sysconfdir=*) sysconfdir=`spliteq $1`;;
esac
}
@@ -30,23 +31,27 @@ while true ; do
esac
done
if [ ! $exec_prefix ] ; then
if [ -z "$exec_prefix" ] ; then
exec_prefix=$prefix
fi
if [ ! $libdir ] ; then
if [ -z "$libdir" ] ; then
libdir=$prefix/lib
fi
if [ ! $includedir ] ; then
if [ -z "$includedir" ] ; then
includedir=$prefix/include
fi
if [ ! $bindir ] ; then
if [ -z "$sysconfdir" ] ; then
sysconfdir=$prefix/etc
fi
if [ -z "$bindir" ] ; then
bindir=$exec_prefix/bin
fi
if [ ! $CC ] ; then
if [ -z "$CC" ] ; then
CC=cc
fi
@@ -58,9 +63,11 @@ echo exec_prefix=$exec_prefix>>config.mak
echo bindir=$bindir>>config.mak
echo libdir=$libdir>>config.mak
echo includedir=$includedir>>config.mak
echo sysconfdir=$sysconfdir>>config.mak
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 INSTALL_FLAGS=-m>>config.mak
fi
+8 -23
View File
@@ -18,7 +18,7 @@
#ifndef __CORE_HEADER
#define __CORE_HEADER
#define BUFF_SIZE 8*1024 // used to read responses from proxies.
#define MAX_LOCALNET 1024
#define MAX_LOCALNET 64
typedef union {
unsigned char octet[4];
@@ -60,7 +60,6 @@ typedef enum {
BLOCKED // target's port blocked on last proxy in the chain
} ERR_CODE;
typedef enum {
HTTP_TYPE,
SOCKS4_TYPE,
@@ -99,26 +98,11 @@ typedef struct {
char pass[256];
} proxy_data;
typedef struct {
proxy_data *pd;
chain_type ct;
unsigned int proxy_count;
int sock;
struct sockaddr addr;
int flags;
} thread_arg;
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 sock, ip_type target_ip, unsigned short target_port,
proxy_data * pd, unsigned int proxy_count, chain_type ct,
unsigned int max_chain );
int proxychains_write_log(char *str,...);
struct hostent* proxy_gethostbyname(const char *name);
typedef int (*connect_t)(int, const struct sockaddr *, socklen_t);
connect_t true_connect;
@@ -137,22 +121,23 @@ freeaddrinfo_t true_freeaddrinfo;
typedef int (*getnameinfo_t) (const struct sockaddr *,
socklen_t, char *,
socklen_t, char *,
socklen_t, unsigned int);
socklen_t, int);
getnameinfo_t true_getnameinfo;
typedef struct hostent *(*gethostbyaddr_t) (const void *, socklen_t, int);
gethostbyaddr_t true_gethostbyaddr;
struct hostent* proxy_gethostbyname(const char *name);
int proxy_getaddrinfo(const char *node, const char *service,
const struct addrinfo *hints,
struct addrinfo **res);
struct hostent* proxy_gethostbyname(const char *name);
#ifdef DEBUG
# define PDEBUG(fmt, args...) fprintf(stderr,"DEBUG:"fmt, ## args)
#else
# define PDEBUG(fmt, args...)
# define PDEBUG(fmt, args...) do {} while (0)
#endif
#endif
+92 -83
View File
@@ -41,14 +41,13 @@
#define SOCKADDR_2(x) (satosin(x)->sin_addr)
#define SOCKPORT(x) (satosin(x)->sin_port)
#define SOCKFAMILY(x) (satosin(x)->sin_family)
#define MAX_CHAIN 30*1024
#define MAX_CHAIN 512
int tcp_read_time_out;
int tcp_connect_time_out;
int proxychains_got_chain_data = 0;
int proxychains_quiet_mode = 0;
int proxychains_resolver = 0;
static int init_l = 0;
unsigned int proxychains_proxy_count = 0;
unsigned int proxychains_max_chain = 1;
@@ -60,81 +59,87 @@ proxy_data proxychains_pd[MAX_CHAIN];
size_t num_localnet_addr = 0;
static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct);
static void init_lib(void);
#ifdef THREAD_SAFE
pthread_once_t init_once = PTHREAD_ONCE_INIT;
#endif
static int init_l = 0;
static void init_lib(void) {
static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct);
static void load_sym(void** funcptr, char* symname, void* proxyfunc) {
*funcptr = dlsym(RTLD_NEXT, symname);
if(!(*funcptr)) {
fprintf(stderr, "Cannot load symbol '%s' %s\n", symname, dlerror());
exit(1);
} else {
PDEBUG("loaded symbol '%s'" " real addr %p wrapped addr %p\n", symname, (*funcptr), proxyfunc);
}
if((*funcptr) == proxyfunc) {
PDEBUG("circular reference detected, aborting!\n");
abort();
}
}
#define INIT() init_lib_wrapper(__FUNCTION__)
static void do_init(void) {
static const struct override_info {
void* funcptr;
char* symname;
void* proxyfunc;
} override_symbols[] = {
#define SYM_ENTRY(X) { .funcptr = &true_ ## X, .symname = # X, .proxyfunc = X,}
SYM_ENTRY(connect),
SYM_ENTRY(gethostbyname),
SYM_ENTRY(getaddrinfo),
SYM_ENTRY(freeaddrinfo),
SYM_ENTRY(gethostbyaddr),
SYM_ENTRY(getnameinfo),
#undef SYM_ENTRY
};
unsigned i;
MUTEX_INIT(&internal_ips_lock, NULL);
/* read the config file */
get_chain_data(proxychains_pd, &proxychains_proxy_count, &proxychains_ct);
proxychains_write_log(LOG_PREFIX "DLL init\n");
true_connect = (connect_t) dlsym(RTLD_NEXT, "connect");
if(!true_connect) {
fprintf(stderr, "Cannot load symbol 'connect' %s\n", dlerror());
exit(1);
} else {
PDEBUG("loaded symbol 'connect'" " real addr %p wrapped addr %p\n", true_connect, connect);
}
if(connect == true_connect) {
PDEBUG("circular reference detected, aborting!\n");
abort();
}
true_gethostbyname = (gethostbyname_t)
dlsym(RTLD_NEXT, "gethostbyname");
if(!true_gethostbyname) {
fprintf(stderr, "Cannot load symbol 'gethostbyname' %s\n", dlerror());
exit(1);
} else {
PDEBUG("loaded symbol 'gethostbyname'"
" real addr %p wrapped addr %p\n", true_gethostbyname, gethostbyname);
}
true_getaddrinfo = (getaddrinfo_t)
dlsym(RTLD_NEXT, "getaddrinfo");
if(!true_getaddrinfo) {
fprintf(stderr, "Cannot load symbol 'getaddrinfo' %s\n", dlerror());
exit(1);
} else {
PDEBUG("loaded symbol 'getaddrinfo'" " real addr %p wrapped addr %p\n", true_getaddrinfo, getaddrinfo);
}
true_freeaddrinfo = (freeaddrinfo_t)
dlsym(RTLD_NEXT, "freeaddrinfo");
if(!true_freeaddrinfo) {
fprintf(stderr, "Cannot load symbol 'freeaddrinfo' %s\n", dlerror());
exit(1);
} else {
PDEBUG("loaded symbol 'freeaddrinfo'"
" real addr %p wrapped addr %p\n", true_freeaddrinfo, freeaddrinfo);
}
true_gethostbyaddr = (gethostbyaddr_t)
dlsym(RTLD_NEXT, "gethostbyaddr");
if(!true_gethostbyaddr) {
fprintf(stderr, "Cannot load symbol 'gethostbyaddr' %s\n", dlerror());
exit(1);
} else {
PDEBUG("loaded symbol 'gethostbyaddr'"
" real addr %p wrapped addr %p\n", true_gethostbyaddr, gethostbyaddr);
}
true_getnameinfo = (getnameinfo_t)
dlsym(RTLD_NEXT, "getnameinfo");
if(!true_getnameinfo) {
fprintf(stderr, "Cannot load symbol 'getnameinfo' %s\n", dlerror());
exit(1);
} else {
PDEBUG("loaded symbol 'getnameinfo'" " real addr %p wrapped addr %p\n", true_getnameinfo, getnameinfo);
for (i = 0; i < (sizeof(override_symbols) / sizeof(override_symbols[0])); i++) {
load_sym(override_symbols[i].funcptr, override_symbols[i].symname, override_symbols[i].proxyfunc);
}
init_l = 1;
}
static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct) {
static void init_lib_wrapper(const char* caller) {
#ifndef DEBUG
(void) caller;
#endif
#ifndef THREAD_SAFE
if(init_l) return;
PDEBUG("%s called from %s\n", __FUNCTION__, caller);
do_init();
#else
if(!init_l) PDEBUG("%s called from %s\n", __FUNCTION__, caller);
pthread_once(&init_once, do_init);
#endif
}
/* if we use gcc >= 3, we can instruct the dynamic loader
* to call init_lib at link time. otherwise it gets loaded
* lazily, which has the disadvantage that there's a potential
* race condition if 2 threads call it before init_l is set
* and PTHREAD support was disabled */
#if __GNUC__ > 2
__attribute__((constructor))
static void gcc_init(void) {
INIT();
}
#endif
/* 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;
char buff[1024], type[1024], host[1024], user[1024];
char *env;
@@ -172,7 +177,11 @@ static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, ch
while(fgets(buff, sizeof(buff), file)) {
if(buff[0] != '\n' && buff[strspn(buff, " ")] != '#') {
/* proxylist has to come last */
if(list) {
if(count >= MAX_CHAIN)
break;
memset(&pd[count], 0, sizeof(proxy_data));
pd[count].ps = PLAY_STATE;
@@ -193,8 +202,7 @@ static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, ch
continue;
if(pd[count].ip.as_int && port_n && pd[count].ip.as_int != (uint32_t) - 1)
if(++count == MAX_CHAIN)
break;
count++;
} else {
if(strstr(buff, "[ProxyList]")) {
list = 1;
@@ -224,7 +232,7 @@ static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, ch
memset(local_in_port, 0, sizeof(local_in_port) / sizeof(local_in_port[0]));
if(sscanf(local_in_addr_port, "%15[^:]:%5s", local_in_addr, local_in_port) < 2) {
PDEBUG("added localnet: netaddr=%s, port=%s\n",
PDEBUG("added localnet: netaddr=%s, netmask=%s\n",
local_in_addr, local_netmask);
} else {
PDEBUG("added localnet: netaddr=%s, port=%s, netmask=%s\n",
@@ -275,6 +283,8 @@ static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, ch
proxychains_got_chain_data = 1;
}
/******* HOOK FUNCTIONS *******/
int connect(int sock, const struct sockaddr *addr, unsigned int len) {
int socktype = 0, flags = 0, ret = 0;
socklen_t optlen = 0;
@@ -285,9 +295,9 @@ int connect(int sock, const struct sockaddr *addr, unsigned int len) {
struct in_addr *p_addr_in;
unsigned short port;
size_t i;
int remote_dns_connect = 0;
if(!init_l)
init_lib();
INIT();
optlen = sizeof(socktype);
getsockopt(sock, SOL_SOCKET, SO_TYPE, &socktype, &optlen);
if(!(SOCKFAMILY(*addr) == AF_INET && socktype == SOCK_STREAM))
@@ -302,10 +312,14 @@ int connect(int sock, const struct sockaddr *addr, unsigned int len) {
PDEBUG("target: %s\n", inet_ntop(AF_INET, p_addr_in, str, sizeof(str)));
PDEBUG("port: %d\n", port);
#endif
for(i = 0; i < num_localnet_addr; i++) {
// check if connect called from proxydns
remote_dns_connect = (ntohl(p_addr_in->s_addr) >> 24 == remote_dns_subnet);
for(i = 0; i < num_localnet_addr && !remote_dns_connect; i++) {
if((localnet_addr[i].in_addr.s_addr & localnet_addr[i].netmask.s_addr)
== (p_addr_in->s_addr & localnet_addr[i].netmask.s_addr)) {
if(localnet_addr[i].port || localnet_addr[i].port == port) {
if(!localnet_addr[i].port || localnet_addr[i].port == port) {
PDEBUG("accessing localnet using true_connect\n");
return true_connect(sock, addr, len);
}
@@ -330,8 +344,7 @@ int connect(int sock, const struct sockaddr *addr, unsigned int len) {
}
struct hostent *gethostbyname(const char *name) {
if(!init_l)
init_lib();
INIT();
PDEBUG("gethostbyname: %s\n", name);
@@ -346,8 +359,7 @@ struct hostent *gethostbyname(const char *name) {
int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
int ret = 0;
if(!init_l)
init_lib();
INIT();
PDEBUG("getaddrinfo: %s %s\n", node, service);
@@ -360,8 +372,7 @@ int getaddrinfo(const char *node, const char *service, const struct addrinfo *hi
}
void freeaddrinfo(struct addrinfo *res) {
if(!init_l)
init_lib();
INIT();
PDEBUG("freeaddrinfo %p \n", res);
@@ -389,8 +400,7 @@ int getnameinfo(const struct sockaddr *sa,
char ip_buf[16];
int ret = 0;
if(!init_l)
init_lib();
INIT();
PDEBUG("getnameinfo: %s %s\n", host, serv);
@@ -413,8 +423,7 @@ struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type) {
static char *list[2];
static struct hostent he;
if(!init_l)
init_lib();
INIT();
PDEBUG("TODO: proper gethostbyaddr hook\n");
+1 -1
View File
@@ -5,7 +5,7 @@ usage() {
echo " usage:"
echo " $0 [hq] [-f config-file] <prog> [args]"
echo " -q make proxychains quite"
echo " -q make proxychains quiet"
exit
}
+10 -1
View File
@@ -1,4 +1,4 @@
# proxychains.conf VER 3.1
# proxychains.conf VER 4
#
# HTTP, SOCKS4, SOCKS5 tunneling proxifier with DNS.
#
@@ -54,6 +54,15 @@ remote_dns_subnet 224
tcp_read_time_out 15000
tcp_connect_time_out 8000
# By default enable localnet for loopback address ranges
# RFC5735 Loopback address range
localnet 127.0.0.0/255.0.0.0
# RFC1918 Private Address Ranges
# localnet 10.0.0.0/255.0.0.0
# localnet 172.16.0.0/255.240.0.0
# localnet 192.168.0.0/255.255.0.0
# Example for localnet exclusion
## Exclude connections to 192.168.1.0/24 with port 80
# localnet 192.168.1.0:80/255.255.255.0