mirror of
https://github.com/haad/proxychains
synced 2026-06-08 14:30:41 +00:00
Compare commits
35 Commits
rofl0r-master
...
testing
| Author | SHA1 | Date | |
|---|---|---|---|
| 5294214150 | |||
| 385b349a8e | |||
| 2320f6608a | |||
| 251fd7cd4a | |||
| b0d9d1da41 | |||
| a7831a8f53 | |||
| c9b8ce35b2 | |||
| 63c3a4b0d2 | |||
| 4d40a4790f | |||
| 50820ce80d | |||
| b6746997d2 | |||
| 6dda28a2c8 | |||
| fb3d8e04a1 | |||
| 0938a940c5 | |||
| 788ffd9d26 | |||
| 99dcfe085e | |||
| 89e8bfddf4 | |||
| adb13c7e79 | |||
| 2250ef66a8 | |||
| e991cabb94 | |||
| d28cf03c61 | |||
| 952a039801 | |||
| 8d9bb5545c | |||
| f512779539 | |||
| f53119773a | |||
| 2f9a9cf0b0 | |||
| cdec339f11 | |||
| fe8672eab6 | |||
| d9341a8c74 | |||
| af5163bccf | |||
| 1471c5756f | |||
| 15d4d5a669 | |||
| 865dc76c08 | |||
| 9a29a4c0d1 | |||
| ca599cbc86 |
@@ -5,19 +5,19 @@
|
||||
# Do not make changes here.
|
||||
#
|
||||
|
||||
exec_prefix = /usr/local
|
||||
bindir = $(exec_prefix)/bin
|
||||
|
||||
prefix = /usr/local/
|
||||
prefix = /usr/local
|
||||
includedir = $(prefix)/include
|
||||
libdir = $(prefix)/lib
|
||||
sysconfdir=$(prefix)/etc
|
||||
confdir = $(prefix)/etc
|
||||
|
||||
exec_prefix = $(prefix)
|
||||
bindir = $(exec_prefix)/bin
|
||||
|
||||
SRCS = $(sort $(wildcard src/*.c))
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
LOBJS = src/core.o src/libproxychains.o
|
||||
|
||||
CFLAGS += -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE
|
||||
CCFLAGS = -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE -Werror
|
||||
LDFLAGS = -shared -fPIC -ldl -lpthread
|
||||
INC =
|
||||
PIC = -fPIC
|
||||
@@ -38,18 +38,20 @@ PXCHAINS = proxychains4
|
||||
ALL_TOOLS = $(PXCHAINS)
|
||||
|
||||
|
||||
CFLAGS+=$(USER_CFLAGS) $(MAC_CFLAGS)
|
||||
CFLAGS_MAIN=-DLIB_DIR=\"$(libdir)\" -DSYSCONFDIR=\"$(sysconfdir)\" -DDLL_NAME=\"$(LDSO_PATHNAME)\"
|
||||
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 -d $(DESTDIR)/$(bindir)/ $(DESTDIR)/$(libdir)/ $(DESTDIR)/$(sysconfdir)
|
||||
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)/$(sysconfdir)/
|
||||
install $(INSTALL_FLAGS) 644 src/proxychains.conf $(DESTDIR)/$(confdir)
|
||||
|
||||
clean:
|
||||
rm -f $(ALL_LIBS)
|
||||
@@ -57,7 +59,7 @@ clean:
|
||||
rm -f $(OBJS)
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) $(CFLAGS_MAIN) $(INC) $(PIC) -c -o $@ $<
|
||||
$(CC) $(CCFLAGS) $(CFLAGS_MAIN) $(INC) $(PIC) -c -o $@ $<
|
||||
|
||||
$(LDSO_PATHNAME): $(LOBJS)
|
||||
$(CC) $(LDFLAGS) $(LD_SET_SONAME)$(LDSO_PATHNAME) -o $@ $(LOBJS)
|
||||
@@ -65,5 +67,4 @@ $(LDSO_PATHNAME): $(LOBJS)
|
||||
$(ALL_TOOLS): $(OBJS)
|
||||
$(CC) src/main.o -o $(PXCHAINS)
|
||||
|
||||
|
||||
.PHONY: all clean install
|
||||
|
||||
@@ -66,7 +66,8 @@ 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>>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
|
||||
|
||||
+27
-45
@@ -14,6 +14,7 @@
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@@ -25,7 +26,6 @@
|
||||
#include <sys/utsname.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -33,10 +33,6 @@
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdarg.h>
|
||||
#ifdef THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
pthread_mutex_t internal_ips_lock;
|
||||
#endif
|
||||
|
||||
#include "core.h"
|
||||
#include "common.h"
|
||||
@@ -48,7 +44,6 @@ extern unsigned int remote_dns_subnet;
|
||||
|
||||
internal_ip_lookup_table internal_ips = { 0, 0, NULL };
|
||||
|
||||
|
||||
uint32_t dalias_hash(char *s0) {
|
||||
unsigned char *s = (void *) s0;
|
||||
uint_fast32_t h = 0;
|
||||
@@ -89,33 +84,10 @@ in_addr_t make_internal_ip(uint32_t index) {
|
||||
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 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;
|
||||
int time_elapsed = 0;
|
||||
@@ -268,6 +240,8 @@ static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len) {
|
||||
|
||||
|
||||
#define INVALID_INDEX 0xFFFFFFFFU
|
||||
#define HTTP_AUTH_MAX ((0xFF * 2) + 1 + 1)
|
||||
|
||||
static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, char *user, char *pass) {
|
||||
char *dns_name = NULL;
|
||||
size_t dns_len = 0;
|
||||
@@ -304,7 +278,7 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
||||
switch (pt) {
|
||||
case HTTP_TYPE:{
|
||||
if(!dns_len) {
|
||||
pc_stringfromipv4(&ip.octet[0], ip_buf);
|
||||
inet_ntop(AF_INET, &ip.octet[0], ip_buf, sizeof(ip_buf));
|
||||
dns_name = ip_buf;
|
||||
}
|
||||
|
||||
@@ -312,7 +286,6 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
||||
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)];
|
||||
@@ -516,8 +489,8 @@ static int start_chain(int *fd, proxy_data * pd, char *begin_mark) {
|
||||
*fd = socket(PF_INET, SOCK_STREAM, 0);
|
||||
if(*fd == -1)
|
||||
goto error;
|
||||
|
||||
pc_stringfromipv4(&pd->ip.octet[0], ip_buf);
|
||||
|
||||
inet_ntop(AF_INET, &pd->ip.octet[0], ip_buf, sizeof(ip_buf));
|
||||
proxychains_write_log(LOG_PREFIX "%s " TP " %s:%d ",
|
||||
begin_mark, ip_buf, htons(pd->port));
|
||||
pd->ps = PLAY_STATE;
|
||||
@@ -539,8 +512,10 @@ static int start_chain(int *fd, proxy_data * pd, char *begin_mark) {
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
|
||||
|
||||
static proxy_data *select_proxy(select_type how, proxy_data * pd, unsigned int proxy_count, unsigned int *offset) {
|
||||
unsigned int i = 0, k = 0;
|
||||
|
||||
if(*offset >= proxy_count)
|
||||
return NULL;
|
||||
switch (how) {
|
||||
@@ -592,7 +567,6 @@ static unsigned int calc_alive(proxy_data * pd, unsigned int proxy_count) {
|
||||
return alive_count;
|
||||
}
|
||||
|
||||
|
||||
static int chain_step(int ns, proxy_data * pfrom, proxy_data * pto) {
|
||||
int retcode = -1;
|
||||
char *hostname;
|
||||
@@ -606,7 +580,7 @@ static int chain_step(int ns, proxy_data * pfrom, proxy_data * pto) {
|
||||
goto usenumericip;
|
||||
} else {
|
||||
usenumericip:
|
||||
pc_stringfromipv4(&pto->ip.octet[0], ip_buf);
|
||||
inet_ntop(AF_INET, &pto->ip.octet[0], ip_buf, sizeof(ip_buf));
|
||||
hostname = ip_buf;
|
||||
}
|
||||
|
||||
@@ -721,7 +695,6 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
||||
p3->port = target_port;
|
||||
if(SUCCESS != chain_step(ns, p1, p3))
|
||||
goto error;
|
||||
|
||||
}
|
||||
|
||||
proxychains_write_log(TP " OK\n");
|
||||
@@ -752,20 +725,18 @@ static in_addr_t resolved_addr;
|
||||
static char *resolved_addr_p[2];
|
||||
static char addr_name[1024 * 8];
|
||||
static const ip_type local_host = { {127, 0, 0, 1} };
|
||||
|
||||
struct hostent *proxy_gethostbyname(const char *name) {
|
||||
char buff[256];
|
||||
uint32_t i, hash;
|
||||
// yep, new_mem never gets freed. once you passed a fake ip to the client, you can't "retreat" it
|
||||
void *new_mem;
|
||||
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));
|
||||
@@ -783,7 +754,6 @@ struct hostent *proxy_gethostbyname(const char *name) {
|
||||
if(!strcmp(hp->h_name, name))
|
||||
return hp;
|
||||
|
||||
|
||||
hash = dalias_hash((char *) name);
|
||||
|
||||
MUTEX_LOCK(&internal_ips_lock);
|
||||
@@ -798,6 +768,7 @@ struct hostent *proxy_gethostbyname(const char *name) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// grow list if needed.
|
||||
if(internal_ips.capa < internal_ips.counter + 1) {
|
||||
PDEBUG("realloc\n");
|
||||
@@ -825,6 +796,7 @@ struct hostent *proxy_gethostbyname(const char *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);
|
||||
@@ -848,6 +820,7 @@ struct hostent *proxy_gethostbyname(const char *name) {
|
||||
int proxy_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
|
||||
struct servent *se = NULL;
|
||||
struct hostent *hp = NULL;
|
||||
|
||||
struct sockaddr *sockaddr_space = NULL;
|
||||
struct addrinfo *addrinfo_space = NULL;
|
||||
|
||||
@@ -862,6 +835,7 @@ int proxy_getaddrinfo(const char *node, const char *service, const struct addrin
|
||||
memset(addrinfo_space, 0, sizeof(*addrinfo_space));
|
||||
if(node && !inet_aton(node, &((struct sockaddr_in *) sockaddr_space)->sin_addr)) {
|
||||
hp = proxy_gethostbyname(node);
|
||||
|
||||
if(hp)
|
||||
memcpy(&((struct sockaddr_in *) sockaddr_space)->sin_addr,
|
||||
*(hp->h_addr_list), sizeof(in_addr_t));
|
||||
@@ -883,10 +857,18 @@ int proxy_getaddrinfo(const char *node, const char *service, const struct addrin
|
||||
(*res)->ai_canonname = addr_name;
|
||||
(*res)->ai_next = NULL;
|
||||
(*res)->ai_family = sockaddr_space->sa_family = AF_INET;
|
||||
(*res)->ai_socktype = hints->ai_socktype;
|
||||
(*res)->ai_flags = hints->ai_flags;
|
||||
(*res)->ai_protocol = hints->ai_protocol;
|
||||
(*res)->ai_addrlen = sizeof(*sockaddr_space);
|
||||
|
||||
if (hints != NULL) {
|
||||
(*res)->ai_socktype = hints->ai_socktype;
|
||||
(*res)->ai_flags = hints->ai_flags;
|
||||
(*res)->ai_protocol = hints->ai_protocol;
|
||||
} else {
|
||||
(*res)->ai_socktype = 0;
|
||||
(*res)->ai_flags = 0;
|
||||
(*res)->ai_protocol = 0;
|
||||
}
|
||||
|
||||
goto out;
|
||||
err3:
|
||||
free(sockaddr_space);
|
||||
|
||||
+2
-3
@@ -37,9 +37,10 @@ typedef struct {
|
||||
} internal_ip_lookup_table;
|
||||
|
||||
extern internal_ip_lookup_table internal_ips;
|
||||
|
||||
#ifdef THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
extern pthread_mutex_t internal_ips_lock;
|
||||
pthread_mutex_t internal_ips_lock;
|
||||
# define MUTEX_LOCK(x) pthread_mutex_lock(x)
|
||||
# define MUTEX_UNLOCK(x) pthread_mutex_unlock(x)
|
||||
# define MUTEX_INIT(x,y) pthread_mutex_init(x, y)
|
||||
@@ -133,8 +134,6 @@ int proxy_getaddrinfo(const char *node, const char *service,
|
||||
struct addrinfo **res);
|
||||
|
||||
|
||||
void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes);
|
||||
|
||||
#ifdef DEBUG
|
||||
# define PDEBUG(fmt, args...) fprintf(stderr,"DEBUG:"fmt, ## args)
|
||||
#else
|
||||
|
||||
+29
-23
@@ -18,20 +18,20 @@
|
||||
#undef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <fcntl.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
|
||||
#include "core.h"
|
||||
#include "common.h"
|
||||
@@ -45,17 +45,20 @@
|
||||
|
||||
int tcp_read_time_out;
|
||||
int tcp_connect_time_out;
|
||||
chain_type proxychains_ct;
|
||||
proxy_data proxychains_pd[MAX_CHAIN];
|
||||
unsigned int proxychains_proxy_count = 0;
|
||||
int proxychains_got_chain_data = 0;
|
||||
unsigned int proxychains_max_chain = 1;
|
||||
int proxychains_quiet_mode = 0;
|
||||
int proxychains_resolver = 0;
|
||||
localaddr_arg localnet_addr[MAX_LOCALNET];
|
||||
size_t num_localnet_addr = 0;
|
||||
|
||||
unsigned int proxychains_proxy_count = 0;
|
||||
unsigned int proxychains_max_chain = 1;
|
||||
unsigned int remote_dns_subnet = 224;
|
||||
|
||||
localaddr_arg localnet_addr[MAX_LOCALNET];
|
||||
chain_type proxychains_ct;
|
||||
proxy_data proxychains_pd[MAX_CHAIN];
|
||||
|
||||
size_t num_localnet_addr = 0;
|
||||
|
||||
#ifdef THREAD_SAFE
|
||||
pthread_once_t init_once = PTHREAD_ONCE_INIT;
|
||||
#endif
|
||||
@@ -66,7 +69,7 @@ static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, ch
|
||||
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);
|
||||
@@ -87,7 +90,7 @@ static void do_init(void) {
|
||||
char* symname;
|
||||
void* proxyfunc;
|
||||
} override_symbols[] = {
|
||||
#define SYM_ENTRY(X) { .funcptr = &true_ ## X, .symname = # X, .proxyfunc = X,}
|
||||
#define SYM_ENTRY(X) { .funcptr = &true_ ## X, .symname = # X, .proxyfunc = X,}
|
||||
SYM_ENTRY(connect),
|
||||
SYM_ENTRY(gethostbyname),
|
||||
SYM_ENTRY(getaddrinfo),
|
||||
@@ -123,10 +126,10 @@ static void init_lib_wrapper(const char* caller) {
|
||||
#endif
|
||||
}
|
||||
|
||||
/* if we use gcc >= 3, we can instruct the dynamic loader
|
||||
/* 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
|
||||
* race condition if 2 threads call it before init_l is set
|
||||
* and PTHREAD support was disabled */
|
||||
#if __GNUC__ > 2
|
||||
__attribute__((constructor))
|
||||
@@ -178,7 +181,7 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
|
||||
if(list) {
|
||||
if(count >= MAX_CHAIN)
|
||||
break;
|
||||
|
||||
|
||||
memset(&pd[count], 0, sizeof(proxy_data));
|
||||
|
||||
pd[count].ps = PLAY_STATE;
|
||||
@@ -293,6 +296,7 @@ int connect(int sock, const struct sockaddr *addr, unsigned int len) {
|
||||
unsigned short port;
|
||||
size_t i;
|
||||
int remote_dns_connect = 0;
|
||||
|
||||
INIT();
|
||||
optlen = sizeof(socktype);
|
||||
getsockopt(sock, SOL_SOCKET, SO_TYPE, &socktype, &optlen);
|
||||
@@ -375,8 +379,10 @@ void freeaddrinfo(struct addrinfo *res) {
|
||||
if(!proxychains_resolver)
|
||||
true_freeaddrinfo(res);
|
||||
else {
|
||||
free(res->ai_addr);
|
||||
free(res);
|
||||
if (res != NULL) {
|
||||
free(res->ai_addr);
|
||||
free(res);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -395,14 +401,14 @@ int getnameinfo(const struct sockaddr *sa,
|
||||
int ret = 0;
|
||||
|
||||
INIT();
|
||||
|
||||
|
||||
PDEBUG("getnameinfo: %s %s\n", host, serv);
|
||||
|
||||
if(!proxychains_resolver) {
|
||||
ret = true_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
|
||||
} else {
|
||||
if(hostlen) {
|
||||
pc_stringfromipv4((unsigned char*) &(SOCKADDR_2(*sa)), ip_buf);
|
||||
inet_ntop(AF_INET, (unsigned char*) &(SOCKADDR_2(*sa)), ip_buf, sizeof(ip_buf));
|
||||
strncpy(host, ip_buf, hostlen);
|
||||
}
|
||||
if(servlen)
|
||||
@@ -436,7 +442,7 @@ struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type) {
|
||||
he.h_addrtype = AF_INET;
|
||||
he.h_aliases = NULL;
|
||||
he.h_length = 4;
|
||||
pc_stringfromipv4((unsigned char *) addr, buf);
|
||||
inet_ntop(AF_INET, addr, buf, sizeof(buf));
|
||||
return &he;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
+25
-16
@@ -18,12 +18,16 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#undef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 700
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include "common.h"
|
||||
@@ -72,11 +76,12 @@ static void set_own_dir(const char *argv0) {
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *path = NULL;
|
||||
char buf[256];
|
||||
char pbuf[256];
|
||||
char buf[PATH_MAX];
|
||||
char pbuf[PATH_MAX];
|
||||
int start_argv = 1;
|
||||
int quiet = 0;
|
||||
size_t i;
|
||||
|
||||
const char *prefix = NULL;
|
||||
|
||||
for(i = 0; i < MAX_COMMANDLINE_FLAGS; i++) {
|
||||
@@ -104,6 +109,7 @@ int main(int argc, char *argv[]) {
|
||||
if(!path) {
|
||||
// priority 1: env var PROXYCHAINS_CONF_FILE
|
||||
path = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
|
||||
|
||||
if(check_path(path))
|
||||
goto have;
|
||||
|
||||
@@ -111,6 +117,7 @@ int main(int argc, char *argv[]) {
|
||||
path = getcwd(buf, sizeof(buf));
|
||||
snprintf(pbuf, sizeof(pbuf), "%s/%s", path, PROXYCHAINS_CONF_FILE);
|
||||
path = pbuf;
|
||||
|
||||
if(check_path(path))
|
||||
goto have;
|
||||
|
||||
@@ -121,16 +128,19 @@ int main(int argc, char *argv[]) {
|
||||
if(check_path(path))
|
||||
goto have;
|
||||
|
||||
// priority 4: $SYSCONFDIR/proxychains.conf
|
||||
path = SYSCONFDIR "/" PROXYCHAINS_CONF_FILE;
|
||||
/* Check for default config file in two locations {install_prefix}/etc /etc */
|
||||
// priority 4: $INSTALL_PREFIX/etc/proxychains.conf
|
||||
snprintf(pbuf, sizeof(pbuf), "%s/etc/%s", INSTALL_PREFIX, PROXYCHAINS_CONF_FILE);
|
||||
path = pbuf;
|
||||
if(check_path(path))
|
||||
goto have;
|
||||
|
||||
// priority 5: /etc/proxychains.conf
|
||||
path = "/etc/" PROXYCHAINS_CONF_FILE;
|
||||
snprintf(pbuf, sizeof(pbuf), "/etc/%s", PROXYCHAINS_CONF_FILE);
|
||||
path = pbuf;
|
||||
if(check_path(path))
|
||||
goto have;
|
||||
perror("couldnt find configuration file");
|
||||
perror("Couldn't find configuration file");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -145,9 +155,7 @@ int main(int argc, char *argv[]) {
|
||||
if(quiet)
|
||||
setenv(PROXYCHAINS_QUIET_MODE_ENV_VAR, "1", 1);
|
||||
|
||||
|
||||
// search DLL
|
||||
|
||||
set_own_dir(argv[0]);
|
||||
|
||||
while(dll_dirs[i]) {
|
||||
@@ -163,16 +171,17 @@ int main(int argc, char *argv[]) {
|
||||
fprintf(stderr, "couldnt locate %s\n", dll_name);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(!quiet)
|
||||
fprintf(stderr, LOG_PREFIX "preloading %s/%s\n", prefix, dll_name);
|
||||
|
||||
#ifndef IS_MAC
|
||||
snprintf(buf, sizeof(buf), "LD_PRELOAD=%s/%s", prefix, dll_name);
|
||||
putenv(buf);
|
||||
snprintf(buf, sizeof(buf), "%s/%s", prefix, dll_name);
|
||||
setenv("LD_PRELOAD", buf, 1);
|
||||
#else
|
||||
snprintf(buf, sizeof(buf), "DYLD_INSERT_LIBRARIES=%s/%s", prefix, dll_name);
|
||||
putenv(buf);
|
||||
putenv("DYLD_FORCE_FLAT_NAMESPACE=1");
|
||||
snprintf(buf, sizeof(buf), "%s/%s", prefix, dll_name);
|
||||
setenv("DYLD_INSERT_LIBRARIES", buf, 1);
|
||||
setenv("DYLD_FORCE_FLAT_NAMESPACE", "1", 1);
|
||||
#endif
|
||||
execvp(argv[start_argv], &argv[start_argv]);
|
||||
perror("proxychains can't load process....");
|
||||
|
||||
+93
-13
@@ -1,26 +1,106 @@
|
||||
#!/bin/sh
|
||||
echo "ProxyChains-3.1 (http://proxychains.sf.net)"
|
||||
echo "ProxyChains-4.0 (https://github.com/haad/proxychains)"
|
||||
|
||||
usage() {
|
||||
|
||||
echo " usage:"
|
||||
echo " $0 [h] [f config-file] <prog> [args]"
|
||||
echo " $0 [hq] [-f config-file] <prog> [args]"
|
||||
echo " -q make proxychains quiet"
|
||||
exit
|
||||
}
|
||||
|
||||
find_proxy_conf() {
|
||||
|
||||
show_proxy_env
|
||||
if [ -f "/usr/local/etc/proxychains.conf" ]; then
|
||||
export PROXYCHAINS_CONF_FILE="/usr/local/etc/proxychains.conf"
|
||||
else
|
||||
if [ -f "/etc/proxychains.conf" ];then
|
||||
PROXYCHAINS_CONF_FILE="/etc/proxychains.conf"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# XXX We should not overide possible user settings here. Just add libproxychains to it.
|
||||
#
|
||||
setup_proxy_env() {
|
||||
|
||||
if [ -z "$PROXYCHAINS_CONF_FILE" ]; then
|
||||
find_proxy_conf
|
||||
fi
|
||||
|
||||
if [ $(uname -s) = "Darwin" ]; then
|
||||
export DYLD_FORCE_FLAT_NAMESPACE=
|
||||
export DYLD_INSERT_LIBRARIES=libproxychains4.dylib
|
||||
else
|
||||
export LD_PRELOAD=libproxychains.so.4
|
||||
fi
|
||||
}
|
||||
|
||||
disable_proxy_env() {
|
||||
|
||||
if [ $(uname -s) = "Darwin" ]; then
|
||||
unset DYLD_FORCE_FLAT_NAMESPACE
|
||||
export DYLD_INSERT_LIBRARIES=$(echo $DYLD_INSERT_LIBRARIES | sed -e 's/libproxychains4.dylib//g')
|
||||
if [ -z $DYLD_INSERT_LIBRARIES ]; then
|
||||
unset DYLD_INSERT_LIBRARIES
|
||||
fi
|
||||
else
|
||||
export LD_PRELOAD=$(echo $DYLD_INSERT_LIBRARIES | sed -e 's/libproxychains.so.4//g')
|
||||
if [ -z $LD_PRELOAD ]; then
|
||||
unset LD_PRELOAD
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
show_proxy_env() {
|
||||
|
||||
echo "Proxified environment setup"
|
||||
echo "PROXYCHAINS_CONF_FILE = $PROXYCHAINS_CONF_FILE"
|
||||
|
||||
if [ $(uname -s) = "Darwin" ]; then
|
||||
echo "DYLD_FORCE_FLAT_NAMESPACE = $DYLD_FORCE_FLAT_NAMESPACE"
|
||||
echo "DYLD_INSERT_LIBRARIES = $DYLD_INSERT_LIBRARIES"
|
||||
else
|
||||
echo "LD_PRELOAD = $LD_PRELOAD"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ $# = 0 ] ; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ $1 = "-h" ]; then
|
||||
usage
|
||||
fi
|
||||
case "$1" in
|
||||
-h)
|
||||
usage
|
||||
;;
|
||||
-f)
|
||||
export PROXYCHAINS_CONF_FILE=$2;
|
||||
shift;
|
||||
shift;
|
||||
;;
|
||||
-q)
|
||||
export PROXYCHAINS_QUIET_MODE=1;
|
||||
shift;
|
||||
;;
|
||||
show)
|
||||
show_proxy_env
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$1" = "-f" ]; then
|
||||
export PROXYCHAINS_CONF_FILE=$2;
|
||||
shift;
|
||||
shift;
|
||||
fi
|
||||
|
||||
export LD_PRELOAD=libproxychains.so.3
|
||||
exec "$@"
|
||||
case "$1" in
|
||||
on)
|
||||
setup_proxy_env
|
||||
show_proxy_env
|
||||
;;
|
||||
off)
|
||||
disable_proxy_env
|
||||
show_proxy_env
|
||||
;;
|
||||
*)
|
||||
setup_proxy_env
|
||||
exec "$@"
|
||||
;;
|
||||
esac
|
||||
|
||||
+10
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user