mirror of
https://github.com/haad/proxychains
synced 2026-06-08 14:30:41 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1c020ced1e | |||
| 361889a2d2 | |||
| 025840930b | |||
| cca0cea44a | |||
| 462e34f447 | |||
| e5ad6e53c3 |
@@ -4,6 +4,7 @@
|
|||||||
*.lo
|
*.lo
|
||||||
.deps/
|
.deps/
|
||||||
.libs/
|
.libs/
|
||||||
|
.*
|
||||||
|
|
||||||
# Autoconf stuff
|
# Autoconf stuff
|
||||||
libtool
|
libtool
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ main.c, remote-dns, thread safety, bugfixes, build system, cleanups
|
|||||||
rofl0r.
|
rofl0r.
|
||||||
https://github.com/rofl0r/proxychains
|
https://github.com/rofl0r/proxychains
|
||||||
|
|
||||||
localnet, bugfixes
|
localnet, bugfixes, macos x support
|
||||||
adam hamsik.
|
adam hamsik.
|
||||||
https://github.com/haad/proxychains
|
https://github.com/haad/proxychains
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,21 @@
|
|||||||
ProxyChains version history (public releases)
|
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
|
ver 3.1
|
||||||
|
|
||||||
changed:
|
changed:
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ SRCS = $(sort $(wildcard src/*.c))
|
|||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
LOBJS = src/core.o src/common.o src/libproxychains.o
|
LOBJS = src/core.o src/common.o src/libproxychains.o
|
||||||
|
|
||||||
CCFLAGS = -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE -Werror
|
CCFLAGS = -Wall -O2 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE -Werror
|
||||||
LDFLAGS = -shared -fPIC -ldl -lpthread
|
LDFLAGS = -shared -fPIC -lpthread
|
||||||
INC =
|
INC =
|
||||||
PIC = -fPIC
|
PIC = -fPIC
|
||||||
AR = $(CROSS_COMPILE)ar
|
AR = $(CROSS_COMPILE)ar
|
||||||
@@ -68,4 +68,4 @@ $(LDSO_PATHNAME): $(LOBJS)
|
|||||||
$(ALL_TOOLS): $(OBJS)
|
$(ALL_TOOLS): $(OBJS)
|
||||||
$(CC) src/main.o src/common.o -o $(PXCHAINS)
|
$(CC) src/main.o src/common.o -o $(PXCHAINS)
|
||||||
|
|
||||||
.PHONY: all clean install install-config
|
.PHONY: all clean install install-config
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
prefix=/usr/local
|
prefix=/usr/local
|
||||||
|
develflg=0
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "supported arguments"
|
echo "supported arguments"
|
||||||
@@ -10,6 +11,7 @@ usage() {
|
|||||||
echo "--libdir=/path default: $prefix/lib"
|
echo "--libdir=/path default: $prefix/lib"
|
||||||
echo "--includedir=/path default: $prefix/include"
|
echo "--includedir=/path default: $prefix/include"
|
||||||
echo "--sysconfdir=/path default: $prefix/etc"
|
echo "--sysconfdir=/path default: $prefix/etc"
|
||||||
|
echo "--devel default:no (set development mode)"
|
||||||
echo "--help : show this text"
|
echo "--help : show this text"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@@ -29,6 +31,7 @@ parsearg() {
|
|||||||
--libdir=*) libdir=`spliteq $1`;;
|
--libdir=*) libdir=`spliteq $1`;;
|
||||||
--includedir=*) includedir=`spliteq $1`;;
|
--includedir=*) includedir=`spliteq $1`;;
|
||||||
--sysconfdir=*) sysconfdir=`spliteq $1`;;
|
--sysconfdir=*) sysconfdir=`spliteq $1`;;
|
||||||
|
--devel) develflg=1;;
|
||||||
--help) usage;;
|
--help) usage;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@@ -37,6 +40,14 @@ ismac() {
|
|||||||
uname -s | grep Darwin
|
uname -s | grep Darwin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isbsd() {
|
||||||
|
uname -s | grep BSD
|
||||||
|
}
|
||||||
|
|
||||||
|
islinux() {
|
||||||
|
uname -s | grep Linux
|
||||||
|
}
|
||||||
|
|
||||||
while true ; do
|
while true ; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-*) parsearg "$1"; shift;;
|
-*) parsearg "$1"; shift;;
|
||||||
@@ -68,6 +79,10 @@ if [ -z "$CC" ] ; then
|
|||||||
CC=cc
|
CC=cc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $develflg -eq 1 ]; then
|
||||||
|
CFLAGS="-Wextra -Wunused -Wuninitialized -Wconversion -fno-common -g -O0"
|
||||||
|
fi
|
||||||
|
|
||||||
echo CC?=$CC>config.mak
|
echo CC?=$CC>config.mak
|
||||||
[ -z "$CPPFLAGS" ] || echo CPPFLAGS?=$CPPFLAGS>>config.mak
|
[ -z "$CPPFLAGS" ] || echo CPPFLAGS?=$CPPFLAGS>>config.mak
|
||||||
[ -z "$CFLAGS" ] || echo USER_CFLAGS?=$CFLAGS>>config.mak
|
[ -z "$CFLAGS" ] || echo USER_CFLAGS?=$CFLAGS>>config.mak
|
||||||
@@ -81,9 +96,18 @@ if ismac ; then
|
|||||||
echo LDSO_SUFFIX=dylib>>config.mak
|
echo LDSO_SUFFIX=dylib>>config.mak
|
||||||
echo MAC_CFLAGS+=-DIS_MAC=1 -arch x86_64 -arch i386 >>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 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
|
echo INSTALL_FLAGS=-m>>config.mak
|
||||||
fi
|
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
|
echo done, now run make \&\& make install
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -3,6 +3,10 @@
|
|||||||
#define PROXYCHAINS_CONF_FILE "proxychains.conf"
|
#define PROXYCHAINS_CONF_FILE "proxychains.conf"
|
||||||
#define LOG_PREFIX "[proxychains] "
|
#define LOG_PREFIX "[proxychains] "
|
||||||
|
|
||||||
|
#define PROXYCHAINS_VERSION_MAJOR 4
|
||||||
|
#define PROXYCHAINS_VERSION_MINOR 1
|
||||||
|
#define PROXYCHAINS_VERSION_BUGFIX 0
|
||||||
|
|
||||||
#include <stddef.h>
|
#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
@@ -15,6 +15,7 @@
|
|||||||
* *
|
* *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -34,10 +35,15 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#ifdef THREAD_SAFE
|
#ifdef THREAD_SAFE
|
||||||
#include <pthread.h>
|
|
||||||
pthread_mutex_t internal_ips_lock;
|
pthread_mutex_t internal_ips_lock;
|
||||||
#endif
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
pthread_mutex_t internal_getsrvbyname_lock;
|
||||||
|
#endif /* __APPLE__ */
|
||||||
|
|
||||||
|
#endif /* THREAD_SAFE */
|
||||||
|
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@@ -62,7 +68,7 @@ uint32_t dalias_hash(char *s0) {
|
|||||||
uint32_t index_from_internal_ip(ip_type internalip) {
|
uint32_t index_from_internal_ip(ip_type internalip) {
|
||||||
ip_type tmp = internalip;
|
ip_type tmp = internalip;
|
||||||
uint32_t ret;
|
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;
|
ret -= 1;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -106,7 +112,7 @@ static int poll_retry(struct pollfd *fds, nfds_t nfsd, int timeout)
|
|||||||
//printf("Retry %d\n", time_remain);
|
//printf("Retry %d\n", time_remain);
|
||||||
ret = poll(fds, nfsd, time_remain);
|
ret = poll(fds, nfsd, time_remain);
|
||||||
gettimeofday(&tv, NULL);
|
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);
|
//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);
|
||||||
@@ -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) {
|
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);
|
l = strlen(src);
|
||||||
max_len = (max_len - 1) / 4;
|
max_len = (max_len - 1) / 4;
|
||||||
for(i = 0; i < max_len; i++, src += 3, l -= 3) {
|
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) {
|
static size_t write_n_bytes(int fd, char *buff, size_t size) {
|
||||||
int i = 0;
|
size_t i = 0;
|
||||||
size_t wrote = 0;
|
size_t wrote = 0;
|
||||||
for(;;) {
|
for(;;) {
|
||||||
i = write(fd, &buff[wrote], size - wrote);
|
i = (size_t) write(fd, &buff[wrote], size - wrote);
|
||||||
if(i <= 0)
|
if(i <= 0)
|
||||||
return i;
|
return i;
|
||||||
wrote += 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;
|
int ready;
|
||||||
size_t i;
|
size_t i;
|
||||||
struct pollfd pfd[1];
|
struct pollfd pfd[1];
|
||||||
@@ -188,9 +196,9 @@ static int read_n_bytes(int fd, char *buff, size_t size) {
|
|||||||
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))
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
return (int) size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len) {
|
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);
|
fcntl(sock, F_SETFL, O_NONBLOCK);
|
||||||
ret = true_connect(sock, addr, len);
|
ret = true_connect(sock, addr, len);
|
||||||
PDEBUG("\nconnect ret=%d\n", ret);
|
PDEBUG("\nconnect ret=%d\n", ret);
|
||||||
|
|
||||||
if(ret == -1 && errno == EINPROGRESS) {
|
if(ret == -1 && errno == EINPROGRESS) {
|
||||||
ret = poll_retry(pfd, 1, tcp_connect_time_out);
|
ret = poll_retry(pfd, 1, tcp_connect_time_out);
|
||||||
PDEBUG("\npoll ret=%d\n", ret);
|
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)
|
if(!dns_len)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
PDEBUG("host dns %s\n", dns_name ? dns_name : "<NULL>");
|
PDEBUG("host dns %s\n", dns_name ? dns_name : "<NULL>");
|
||||||
|
|
||||||
size_t ulen = strlen(user);
|
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;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int len;
|
size_t len;
|
||||||
unsigned char buff[BUFF_SIZE];
|
unsigned char buff[BUFF_SIZE];
|
||||||
char ip_buf[16];
|
char ip_buf[16];
|
||||||
//memset (buff, 0, sizeof(buff));
|
//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);
|
len = strlen((char *) buff);
|
||||||
|
|
||||||
if(len != send(sock, buff, len, 0))
|
if(len != (size_t) send(sock, buff, len, 0))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
len = 0;
|
len = 0;
|
||||||
@@ -392,15 +400,15 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
|||||||
int c;
|
int c;
|
||||||
*cur++ = 1; // version
|
*cur++ = 1; // version
|
||||||
c = ulen & 0xFF;
|
c = ulen & 0xFF;
|
||||||
*cur++ = c;
|
*cur++ = (char)c;
|
||||||
memcpy(cur, user, c);
|
memcpy(cur, user, (size_t)c);
|
||||||
cur += c;
|
cur += c;
|
||||||
c = passlen & 0xFF;
|
c = passlen & 0xFF;
|
||||||
*cur++ = c;
|
*cur++ = (char)c;
|
||||||
memcpy(cur, pass, c);
|
memcpy(cur, pass, (size_t)c);
|
||||||
cur += 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;
|
goto err;
|
||||||
|
|
||||||
|
|
||||||
@@ -413,7 +421,7 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
|||||||
return BLOCKED;
|
return BLOCKED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int buff_iter = 0;
|
size_t buff_iter = 0;
|
||||||
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
|
||||||
@@ -514,7 +522,7 @@ static proxy_data *select_proxy(select_type how, proxy_data * pd, unsigned int p
|
|||||||
return NULL;
|
return NULL;
|
||||||
switch (how) {
|
switch (how) {
|
||||||
case RANDOMLY:
|
case RANDOMLY:
|
||||||
srand(time(NULL));
|
srand((unsigned int)time(NULL));
|
||||||
do {
|
do {
|
||||||
k++;
|
k++;
|
||||||
i = 0 + (unsigned int) (proxy_count * 1.0 * rand() / (RAND_MAX + 1.0));
|
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) {
|
static unsigned int calc_alive(proxy_data * pd, unsigned int proxy_count) {
|
||||||
unsigned int i;
|
unsigned int i, alive_count = 0;
|
||||||
int alive_count = 0;
|
|
||||||
release_busy(pd, proxy_count);
|
release_busy(pd, proxy_count);
|
||||||
for(i = 0; i < proxy_count; i++)
|
for(i = 0; i < proxy_count; i++)
|
||||||
if(pd[i].ps == PLAY_STATE)
|
if(pd[i].ps == PLAY_STATE)
|
||||||
@@ -616,7 +623,7 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
|||||||
|
|
||||||
switch (ct) {
|
switch (ct) {
|
||||||
case DYNAMIC_TYPE:
|
case DYNAMIC_TYPE:
|
||||||
alive_count = calc_alive(pd, proxy_count);
|
calc_alive(pd, proxy_count);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
do {
|
do {
|
||||||
if(!(p1 = select_proxy(FIFOLY, pd, proxy_count, &offset)))
|
if(!(p1 = select_proxy(FIFOLY, pd, proxy_count, &offset)))
|
||||||
@@ -640,7 +647,7 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case STRICT_TYPE:
|
case STRICT_TYPE:
|
||||||
alive_count = calc_alive(pd, proxy_count);
|
calc_alive(pd, proxy_count);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
if(!(p1 = select_proxy(FIFOLY, pd, proxy_count, &offset))) {
|
if(!(p1 = select_proxy(FIFOLY, pd, proxy_count, &offset))) {
|
||||||
PDEBUG("select_proxy failed\n");
|
PDEBUG("select_proxy failed\n");
|
||||||
@@ -819,7 +826,7 @@ void proxy_freeaddrinfo(struct addrinfo *res) {
|
|||||||
free(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)
|
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__
|
#ifdef __APPLE__
|
||||||
struct servent *se;
|
struct servent *se;
|
||||||
#ifdef THREAD_SAFE
|
|
||||||
MUTEX_LOCK(&internal_getsrvbyname_lock);
|
MUTEX_LOCK(&internal_getsrvbyname_lock);
|
||||||
#endif
|
if(service) {
|
||||||
if(service)
|
|
||||||
se = getservbyname(service, NULL);
|
se = getservbyname(service, NULL);
|
||||||
if (!se)
|
|
||||||
memcpy(se_buf, se, buf_len);
|
if ( se != NULL ) {
|
||||||
*se_result = se_buf;
|
memcpy(se_buf, se, buf_len);
|
||||||
#ifdef THREAD_SAFE
|
*se_result = se_buf;
|
||||||
|
} else {
|
||||||
|
*se_result = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
MUTEX_UNLOCK(&internal_getsrvbyname_lock);
|
MUTEX_UNLOCK(&internal_getsrvbyname_lock);
|
||||||
#endif
|
#endif /* __APPLE__ */
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int proxy_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
|
int proxy_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
|
||||||
struct gethostbyname_data ghdata;
|
struct gethostbyname_data ghdata;
|
||||||
struct addrinfo_data *space;
|
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);
|
// printf("proxy_getaddrinfo node %s service %s\n",node,service);
|
||||||
space = calloc(1, sizeof(struct addrinfo_data));
|
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)) {
|
if(node && !inet_aton(node, &((struct sockaddr_in *) &space->sockaddr_space)->sin_addr)) {
|
||||||
hp = proxy_gethostbyname(node, &ghdata);
|
hp = proxy_gethostbyname(node, &ghdata);
|
||||||
if(hp)
|
if(hp) {
|
||||||
memcpy(&((struct sockaddr_in *) &space->sockaddr_space)->sin_addr,
|
memcpy(&((struct sockaddr_in *) &space->sockaddr_space)->sin_addr,
|
||||||
*(hp->h_addr_list), sizeof(in_addr_t));
|
*(hp->h_addr_list), sizeof(in_addr_t));
|
||||||
else
|
} else {
|
||||||
goto err2;
|
free(space);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(service)
|
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"));
|
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;
|
*res = p = &space->addrinfo_space;
|
||||||
assert((size_t)p == (size_t) 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_flags = hints->ai_flags;
|
||||||
p->ai_protocol = hints->ai_protocol;
|
p->ai_protocol = hints->ai_protocol;
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef BSD
|
||||||
p->ai_flags = (AI_V4MAPPED | AI_ADDRCONFIG);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-16
@@ -41,11 +41,9 @@ extern internal_ip_lookup_table internal_ips;
|
|||||||
|
|
||||||
#ifdef THREAD_SAFE
|
#ifdef THREAD_SAFE
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
pthread_mutex_t internal_ips_lock;
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
extern pthread_mutex_t internal_ips_lock;
|
||||||
pthread_mutex_t internal_getsrvbyname_lock;
|
extern pthread_mutex_t internal_getsrvbyname_lock;
|
||||||
#endif
|
|
||||||
|
|
||||||
# define MUTEX_LOCK(x) pthread_mutex_lock(x)
|
# define MUTEX_LOCK(x) pthread_mutex_lock(x)
|
||||||
# define MUTEX_UNLOCK(x) pthread_mutex_unlock(x)
|
# define MUTEX_UNLOCK(x) pthread_mutex_unlock(x)
|
||||||
@@ -104,21 +102,24 @@ typedef struct {
|
|||||||
char pass[256];
|
char pass[256];
|
||||||
} proxy_data;
|
} proxy_data;
|
||||||
|
|
||||||
int connect_proxy_chain (int sock, ip_type target_ip, unsigned short target_port,
|
int connect_proxy_chain (int, ip_type, unsigned short, proxy_data *, unsigned int,
|
||||||
proxy_data * pd, unsigned int proxy_count, chain_type ct,
|
chain_type, unsigned int);
|
||||||
unsigned int max_chain );
|
|
||||||
|
|
||||||
void proxychains_write_log(char *str, ...);
|
void proxychains_write_log(char *, ...);
|
||||||
|
|
||||||
typedef int (*connect_t)(int, const struct sockaddr *, socklen_t);
|
typedef int (*connect_t)(int, const struct sockaddr *, socklen_t);
|
||||||
typedef struct hostent* (*gethostbyname_t)(const char *);
|
typedef struct hostent* (*gethostbyname_t)(const char *);
|
||||||
typedef int (*freeaddrinfo_t)(struct addrinfo *);
|
typedef int (*freeaddrinfo_t)(struct addrinfo *);
|
||||||
|
|
||||||
|
#if (defined __linux__) || (defined __APPLE__)
|
||||||
typedef struct hostent *(*gethostbyaddr_t) (const void *, socklen_t, int);
|
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 **);
|
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);
|
socklen_t, char *, socklen_t, int);
|
||||||
|
|
||||||
|
|
||||||
@@ -136,11 +137,10 @@ struct gethostbyname_data {
|
|||||||
char addr_name[1024 * 8];
|
char addr_name[1024 * 8];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct hostent* proxy_gethostbyname(const char *name, struct gethostbyname_data *data);
|
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 *node, const char *service,
|
int proxy_getaddrinfo(const char *, const char *, const struct addrinfo *, struct addrinfo **);
|
||||||
const struct addrinfo *hints, struct addrinfo **res);
|
void proxy_freeaddrinfo(struct addrinfo *);
|
||||||
void proxy_freeaddrinfo(struct addrinfo *res);
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
# define PDEBUG(fmt, args...) do { fprintf(stderr,"DEBUG:"fmt, ## args); fflush(stderr); } while(0)
|
# define PDEBUG(fmt, args...) do { fprintf(stderr,"DEBUG:"fmt, ## args); fflush(stderr); } while(0)
|
||||||
|
|||||||
@@ -164,7 +164,8 @@ open_config_file() {
|
|||||||
|
|
||||||
/* get configuration from config file */
|
/* get configuration from config file */
|
||||||
static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct) {
|
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 buff[1024], type[1024], host[1024], user[1024];
|
||||||
char *env;
|
char *env;
|
||||||
char local_in_addr_port[32];
|
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]) {
|
if(local_in_port[0]) {
|
||||||
localnet_addr[num_localnet_addr].port =
|
localnet_addr[num_localnet_addr].port =
|
||||||
(short) atoi(local_in_port);
|
(unsigned short) atoi(local_in_port);
|
||||||
} else {
|
} else {
|
||||||
localnet_addr[num_localnet_addr].port = 0;
|
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;
|
int len;
|
||||||
pc = strchr(buff, '=');
|
pc = strchr(buff, '=');
|
||||||
len = atoi(++pc);
|
len = atoi(++pc);
|
||||||
proxychains_max_chain = (len ? len : 1);
|
proxychains_max_chain = (unsigned int) (len ? len : 1);
|
||||||
} else if(strstr(buff, "quiet_mode")) {
|
} else if(strstr(buff, "quiet_mode")) {
|
||||||
proxychains_quiet_mode = 1;
|
proxychains_quiet_mode = 1;
|
||||||
} else if(strstr(buff, "proxy_dns")) {
|
} else if(strstr(buff, "proxy_dns")) {
|
||||||
@@ -424,7 +425,11 @@ int getnameinfo(const struct sockaddr *sa,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (defined __linux__) || (defined __APPLE__)
|
||||||
struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type) {
|
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 buf[16];
|
||||||
static char ipv4[4];
|
static char ipv4[4];
|
||||||
static char *list[2];
|
static char *list[2];
|
||||||
|
|||||||
Reference in New Issue
Block a user