mirror of
https://github.com/haad/proxychains
synced 2026-06-08 14:30:41 +00:00
Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1c020ced1e | |||
| 361889a2d2 | |||
| 025840930b | |||
| cca0cea44a | |||
| 462e34f447 | |||
| e5ad6e53c3 | |||
| 5b7270d75b | |||
| e6b5f245f7 | |||
| 17dbc76577 | |||
| efa5738a6a | |||
| 8547764a82 | |||
| 40bb78b53f | |||
| a4f3dd0538 | |||
| 80e58726e2 | |||
| 3c7fcc7507 | |||
| ab3ca31871 | |||
| 6f56956715 | |||
| 037edbcb8e | |||
| 40edf758ee | |||
| 4b999cdae7 | |||
| 71e15e2edd | |||
| e5e87c8f22 | |||
| fafeaf5936 | |||
| fba5f5694c | |||
| 1a02b9f82f | |||
| 3004240462 | |||
| 364c785970 | |||
| 1fc7e38ee0 | |||
| eb0db7221a | |||
| 2c9c4d9da7 | |||
| d95ef42d48 | |||
| 7599bdfdfe | |||
| c1f0c68abd | |||
| 877e1844ea | |||
| 69ab0415ac | |||
| c14bf58cd7 |
@@ -4,8 +4,11 @@
|
||||
*.lo
|
||||
.deps/
|
||||
.libs/
|
||||
.*
|
||||
|
||||
# Autoconf stuff
|
||||
libtool
|
||||
config.*
|
||||
stamp-h
|
||||
proxychains4
|
||||
*.dylib
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
original code
|
||||
N3E7CR34TUR3.
|
||||
http://proxychains.sourceforge.net
|
||||
netcreature@users.sourceforge.net
|
||||
|
||||
web site: proxychains.sourceforge.net
|
||||
email: netcreature@users.sourceforge.net
|
||||
main.c, remote-dns, thread safety, bugfixes, build system, cleanups
|
||||
rofl0r.
|
||||
https://github.com/rofl0r/proxychains
|
||||
|
||||
localnet, bugfixes, macos x support
|
||||
adam hamsik.
|
||||
https://github.com/haad/proxychains
|
||||
|
||||
localnet-port, bugfixes
|
||||
jianing yang.
|
||||
https://github.com/jianingy/proxychains
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
ProxyChains ver 3.1 Installation
|
||||
=======================
|
||||
|
||||
If you have installed other ver of proxychains "make uninstall" before installing this distribution
|
||||
|
||||
unpack the .tar.gz , 'cd' to distribution directory and
|
||||
run following commands (as root)
|
||||
-------------------------------------
|
||||
./configure
|
||||
make
|
||||
make install
|
||||
-------------------------------------
|
||||
that's all
|
||||
@@ -15,10 +15,10 @@ bindir = $(exec_prefix)/bin
|
||||
|
||||
SRCS = $(sort $(wildcard src/*.c))
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
LOBJS = src/core.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
|
||||
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
|
||||
@@ -37,12 +37,10 @@ ALL_LIBS = $(SHARED_LIBS)
|
||||
PXCHAINS = proxychains4
|
||||
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)\"
|
||||
|
||||
CFLAGS_MAIN=-DLIB_DIR=\"$(libdir)\" -DINSTALL_PREFIX=\"$(prefix)\" -DDLL_NAME=\"$(LDSO_PATHNAME)\" -DSYSCONFDIR=\"$(confdir)\"
|
||||
|
||||
all: $(ALL_LIBS) $(ALL_TOOLS)
|
||||
|
||||
@@ -51,7 +49,10 @@ 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)
|
||||
|
||||
install-config:
|
||||
install -d $(DESTDIR)/$(confdir)
|
||||
install $(INSTALL_FLAGS) 644 src/proxychains.conf $(DESTDIR)/$(confdir)/
|
||||
|
||||
clean:
|
||||
rm -f $(ALL_LIBS)
|
||||
@@ -65,6 +66,6 @@ $(LDSO_PATHNAME): $(LOBJS)
|
||||
$(CC) $(LDFLAGS) $(LD_SET_SONAME)$(LDSO_PATHNAME) -o $@ $(LOBJS)
|
||||
|
||||
$(ALL_TOOLS): $(OBJS)
|
||||
$(CC) src/main.o -o $(PXCHAINS)
|
||||
$(CC) src/main.o src/common.o -o $(PXCHAINS)
|
||||
|
||||
.PHONY: all clean install
|
||||
.PHONY: all clean install install-config
|
||||
|
||||
@@ -1,23 +1,43 @@
|
||||
ProxyChains ver 4.0 README
|
||||
==========================
|
||||
|
||||
ProxyChains is a UNIX program, that hooks network-related libc functions
|
||||
in dynamically linked programs via a preloaded DLL and redirects the
|
||||
connections through SOCKS4a/5 or HTTP proxies.
|
||||
|
||||
*********** ATTENTION ***********
|
||||
|
||||
this program works only on dynamically linked programs.
|
||||
also both proxychains and the program to call must use
|
||||
the same dynamic linker (i.e. same libc)
|
||||
this program works only on dynamically linked programs.
|
||||
also both proxychains and the program to call must use
|
||||
the same dynamic linker (i.e. same libc)
|
||||
|
||||
*********************************
|
||||
|
||||
*** Known limitations of the current version: ***
|
||||
|
||||
This is Unix version only.
|
||||
when a process forks, does a DNS lookup in the child, and then uses
|
||||
the ip in the parent, the corresponding ip mapping will not be found.
|
||||
this is because the fork can't write back into the parents mapping table.
|
||||
IRSSI shows this behaviour, so you have to pass the resolved ip address
|
||||
to it. (you can use the proxyresolv script (requires "dig") to do so)
|
||||
|
||||
How to mess with sources - How to Install : read INSTALL !!!!!!
|
||||
this means that you can't currently use tor onion urls for irssi.
|
||||
to solve this issue, an external data store (file, pipe, ...) has to
|
||||
manage the dns <-> ip mapping. of course there has to be proper locking.
|
||||
shm_open, mkstemp, are possible candidates for a file based approach,
|
||||
the other option is to spawn some kind of server process that manages the
|
||||
map lookups. since connect() etc are hooked, this must not be a TCP server.
|
||||
|
||||
This program forces any tcp connection made by any given tcp client
|
||||
to follow through proxy (or proxy chain). It is a kind of proxifier.
|
||||
It acts like sockscap / permeo / eborder driver ( intercepts TCP calls )
|
||||
It is FREE.
|
||||
I am reluctant on doing this change, because the described behaviour
|
||||
seems pretty idiotic (doing a fork only for a DNS lookup), and irssi
|
||||
is currently the only known affected program.
|
||||
|
||||
*** Installation ***
|
||||
|
||||
# needs a working C compiler, preferably gcc
|
||||
./configure
|
||||
make
|
||||
sudo make install
|
||||
|
||||
Changelog:
|
||||
----------
|
||||
@@ -74,21 +94,21 @@ proxychains looks for config file in following order:
|
||||
|
||||
Usage Example:
|
||||
|
||||
bash$ proxychains telnet targethost.com
|
||||
$ proxychains telnet targethost.com
|
||||
|
||||
in this example it will run telnet through proxy(or chained proxies)
|
||||
specified by proxychains.conf
|
||||
|
||||
Usage Example:
|
||||
|
||||
bash$ proxychains -f /etc/proxychains-other.conf targethost2.com
|
||||
$ proxychains -f /etc/proxychains-other.conf targethost2.com
|
||||
|
||||
in this example it will use different configuration file then proxychains.conf
|
||||
to connect to targethost2.com host.
|
||||
|
||||
Usage Example:
|
||||
|
||||
bash$ proxyresolv targethost.com
|
||||
$ proxyresolv targethost.com
|
||||
|
||||
in this example it will resolve targethost.com through proxy(or chained proxies)
|
||||
specified by proxychains.conf
|
||||
|
||||
@@ -1,6 +1,20 @@
|
||||
#!/bin/sh
|
||||
|
||||
prefix=/usr/local
|
||||
develflg=0
|
||||
|
||||
usage() {
|
||||
echo "supported arguments"
|
||||
echo "--prefix=/path default: $prefix"
|
||||
echo "--exec_prefix=/path default: $prefix/bin"
|
||||
echo "--bindir=/path default: $prefix/bin"
|
||||
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
|
||||
}
|
||||
|
||||
spliteq() {
|
||||
arg=$1
|
||||
@@ -17,6 +31,8 @@ parsearg() {
|
||||
--libdir=*) libdir=`spliteq $1`;;
|
||||
--includedir=*) includedir=`spliteq $1`;;
|
||||
--sysconfdir=*) sysconfdir=`spliteq $1`;;
|
||||
--devel) develflg=1;;
|
||||
--help) usage;;
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -24,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;;
|
||||
@@ -55,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
|
||||
@@ -68,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
|
||||
|
||||
|
||||
+8
-8
@@ -1,14 +1,14 @@
|
||||
Begin3
|
||||
Title: ProxyChains
|
||||
Version: 3.0
|
||||
Entered-date:
|
||||
Description:
|
||||
Keywords:
|
||||
Title: ProxyChains
|
||||
Version: 4.0
|
||||
Entered-date:
|
||||
Description:
|
||||
Keywords:
|
||||
Author: <N37CR347UR3>
|
||||
Maintained-by: <NetCreature>
|
||||
Primary-site:
|
||||
Maintained-by: <haad@netbsd.org>
|
||||
Primary-site:
|
||||
Home-page: http://proxychains.sourceforge.net
|
||||
Original-site:
|
||||
Original-site:
|
||||
Platforms: Linux and other Unices
|
||||
Copying-policy: GNU Public License
|
||||
End
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#include "common.h"
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static int check_path(char *path) {
|
||||
if(!path)
|
||||
return 0;
|
||||
return access(path, R_OK) != -1;
|
||||
}
|
||||
|
||||
char *get_config_path(char* default_path, char* pbuf, size_t bufsize) {
|
||||
char buf[512];
|
||||
// top priority: user defined path
|
||||
char *path = default_path;
|
||||
if(check_path(path))
|
||||
return path;
|
||||
|
||||
// priority 1: env var PROXYCHAINS_CONF_FILE
|
||||
path = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
|
||||
if(check_path(path))
|
||||
return path;
|
||||
|
||||
// priority 2; proxychains conf in actual dir
|
||||
path = getcwd(buf, sizeof(buf));
|
||||
snprintf(pbuf, bufsize, "%s/%s", path, PROXYCHAINS_CONF_FILE);
|
||||
path = pbuf;
|
||||
if(check_path(path))
|
||||
return path;
|
||||
|
||||
// priority 3; $HOME/.proxychains/proxychains.conf
|
||||
path = getenv("HOME");
|
||||
snprintf(pbuf, bufsize, "%s/.proxychains/%s", path, PROXYCHAINS_CONF_FILE);
|
||||
path = pbuf;
|
||||
if(check_path(path))
|
||||
return path;
|
||||
|
||||
// priority 4: $SYSCONFDIR/proxychains.conf
|
||||
path = SYSCONFDIR "/" PROXYCHAINS_CONF_FILE;
|
||||
if(check_path(path))
|
||||
return path;
|
||||
|
||||
// priority 5: /etc/proxychains.conf
|
||||
path = "/etc/" PROXYCHAINS_CONF_FILE;
|
||||
if(check_path(path))
|
||||
return path;
|
||||
|
||||
perror("couldnt find configuration file");
|
||||
exit(1);
|
||||
}
|
||||
@@ -2,3 +2,11 @@
|
||||
#define PROXYCHAINS_QUIET_MODE_ENV_VAR "PROXYCHAINS_QUIET_MODE"
|
||||
#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);
|
||||
|
||||
+148
-119
@@ -15,6 +15,7 @@
|
||||
* *
|
||||
***************************************************************************/
|
||||
#include <sys/types.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@@ -33,6 +34,16 @@
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef THREAD_SAFE
|
||||
pthread_mutex_t internal_ips_lock;
|
||||
|
||||
#ifdef __APPLE__
|
||||
pthread_mutex_t internal_getsrvbyname_lock;
|
||||
#endif /* __APPLE__ */
|
||||
|
||||
#endif /* THREAD_SAFE */
|
||||
|
||||
#include "core.h"
|
||||
#include "common.h"
|
||||
@@ -57,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;
|
||||
}
|
||||
@@ -101,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);
|
||||
@@ -113,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) {
|
||||
@@ -147,28 +160,23 @@ static void encode_base_64(char *src, char *dest, int max_len) {
|
||||
*dest++ = 0;
|
||||
}
|
||||
|
||||
#define LOG_BUFF 1024*20
|
||||
|
||||
int proxychains_write_log(char *str, ...) {
|
||||
char buff[LOG_BUFF];
|
||||
void proxychains_write_log(char *str, ...) {
|
||||
char buff[1024*20];
|
||||
va_list arglist;
|
||||
FILE *log_file;
|
||||
log_file = stderr;
|
||||
if(!proxychains_quiet_mode) {
|
||||
va_start(arglist, str);
|
||||
vsprintf(buff, str, arglist);
|
||||
vsnprintf(buff, sizeof(buff), str, arglist);
|
||||
va_end(arglist);
|
||||
fprintf(log_file, "%s", buff);
|
||||
fflush(log_file);
|
||||
fprintf(stderr, "%s", buff);
|
||||
fflush(stderr);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -202,26 +210,15 @@ static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len) {
|
||||
pfd[0].events = POLLOUT;
|
||||
fcntl(sock, F_SETFL, O_NONBLOCK);
|
||||
ret = true_connect(sock, addr, len);
|
||||
#ifdef DEBUG
|
||||
if(ret == -1)
|
||||
perror("true_connect");
|
||||
printf("\nconnect ret=%d\n", ret);
|
||||
PDEBUG("\nconnect ret=%d\n", ret);
|
||||
|
||||
fflush(stdout);
|
||||
#endif
|
||||
if(ret == -1 && errno == EINPROGRESS) {
|
||||
ret = poll_retry(pfd, 1, tcp_connect_time_out);
|
||||
#ifdef DEBUG
|
||||
printf("\npoll ret=%d\n", ret);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
PDEBUG("\npoll ret=%d\n", ret);
|
||||
if(ret == 1) {
|
||||
value_len = sizeof(socklen_t);
|
||||
getsockopt(sock, SOL_SOCKET, SO_ERROR, &value, &value_len);
|
||||
#ifdef DEBUG
|
||||
printf("\nvalue=%d\n", value);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
PDEBUG("\nvalue=%d\n", value);
|
||||
if(!value)
|
||||
ret = 0;
|
||||
else
|
||||
@@ -230,6 +227,10 @@ static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len) {
|
||||
ret = -1;
|
||||
}
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
if(ret == -1)
|
||||
perror("true_connect");
|
||||
#endif
|
||||
if(ret != 0)
|
||||
ret = -1;
|
||||
}
|
||||
@@ -261,6 +262,8 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
||||
goto err;
|
||||
}
|
||||
|
||||
PDEBUG("host dns %s\n", dns_name ? dns_name : "<NULL>");
|
||||
|
||||
size_t ulen = strlen(user);
|
||||
size_t passlen = strlen(pass);
|
||||
|
||||
@@ -269,10 +272,9 @@ 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));
|
||||
|
||||
switch (pt) {
|
||||
@@ -304,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;
|
||||
@@ -398,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;
|
||||
|
||||
|
||||
@@ -419,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
|
||||
@@ -520,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));
|
||||
@@ -558,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)
|
||||
@@ -597,7 +598,7 @@ static int chain_step(int ns, proxy_data * pfrom, proxy_data * pto) {
|
||||
break;
|
||||
case SOCKET_ERROR:
|
||||
pto->ps = DOWN_STATE;
|
||||
proxychains_write_log("<--timeout\n");
|
||||
proxychains_write_log("<--socket error or timeout!\n");
|
||||
close(ns);
|
||||
break;
|
||||
}
|
||||
@@ -622,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)))
|
||||
@@ -646,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");
|
||||
@@ -711,7 +712,7 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
||||
proxychains_write_log("\n!!!need more proxies!!!\n");
|
||||
error_strict:
|
||||
PDEBUG("error\n");
|
||||
|
||||
|
||||
release_all(pd, proxy_count);
|
||||
if(ns != -1)
|
||||
close(ns);
|
||||
@@ -719,14 +720,9 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
||||
return -1;
|
||||
}
|
||||
|
||||
// TODO: all those buffers aren't threadsafe, but since no memory allocation happens there shouldnt be any segfaults
|
||||
static struct hostent hostent_space;
|
||||
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) {
|
||||
struct hostent *proxy_gethostbyname(const char *name, struct gethostbyname_data* data) {
|
||||
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
|
||||
@@ -734,18 +730,20 @@ struct hostent *proxy_gethostbyname(const char *name) {
|
||||
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;
|
||||
data->resolved_addr_p[0] = (char *) &data->resolved_addr;
|
||||
data->resolved_addr_p[1] = NULL;
|
||||
|
||||
data->hostent_space.h_addr_list = data->resolved_addr_p;
|
||||
|
||||
data->resolved_addr = 0;
|
||||
|
||||
gethostname(buff, sizeof(buff));
|
||||
|
||||
if(!strcmp(buff, name)) {
|
||||
resolved_addr = inet_addr(buff);
|
||||
if(resolved_addr == (in_addr_t) (-1))
|
||||
resolved_addr = (in_addr_t) (local_host.as_int);
|
||||
return &hostent_space;
|
||||
data->resolved_addr = inet_addr(buff);
|
||||
if(data->resolved_addr == (in_addr_t) (-1))
|
||||
data->resolved_addr = (in_addr_t) (local_host.as_int);
|
||||
return &data->hostent_space;
|
||||
}
|
||||
|
||||
memset(buff, 0, sizeof(buff));
|
||||
@@ -762,7 +760,7 @@ struct hostent *proxy_gethostbyname(const char *name) {
|
||||
if(internal_ips.counter) {
|
||||
for(i = 0; i < internal_ips.counter; i++) {
|
||||
if(internal_ips.list[i]->hash == hash && !strcmp(name, internal_ips.list[i]->string)) {
|
||||
resolved_addr = make_internal_ip(i);
|
||||
data->resolved_addr = make_internal_ip(i);
|
||||
PDEBUG("got cached ip for %s\n", name);
|
||||
goto have_ip;
|
||||
}
|
||||
@@ -783,8 +781,8 @@ struct hostent *proxy_gethostbyname(const char *name) {
|
||||
}
|
||||
}
|
||||
|
||||
resolved_addr = make_internal_ip(internal_ips.counter);
|
||||
if(resolved_addr == (in_addr_t) - 1)
|
||||
data->resolved_addr = make_internal_ip(internal_ips.counter);
|
||||
if(data->resolved_addr == (in_addr_t) - 1)
|
||||
goto err_plus_unlock;
|
||||
|
||||
l = strlen(name);
|
||||
@@ -807,75 +805,106 @@ struct hostent *proxy_gethostbyname(const char *name) {
|
||||
|
||||
MUTEX_UNLOCK(&internal_ips_lock);
|
||||
|
||||
strncpy(addr_name, name, sizeof(addr_name));
|
||||
strncpy(data->addr_name, name, sizeof(data->addr_name));
|
||||
|
||||
hostent_space.h_name = addr_name;
|
||||
hostent_space.h_length = sizeof(in_addr_t);
|
||||
return &hostent_space;
|
||||
data->hostent_space.h_name = data->addr_name;
|
||||
data->hostent_space.h_length = sizeof(in_addr_t);
|
||||
return &data->hostent_space;
|
||||
|
||||
err_plus_unlock:
|
||||
MUTEX_UNLOCK(&internal_ips_lock);
|
||||
return NULL;
|
||||
}
|
||||
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;
|
||||
struct addrinfo_data {
|
||||
struct addrinfo addrinfo_space;
|
||||
struct sockaddr sockaddr_space;
|
||||
char addr_name[256];
|
||||
};
|
||||
|
||||
// printf("proxy_getaddrinfo node %s service %s\n",node,service);
|
||||
addrinfo_space = malloc(sizeof(struct addrinfo));
|
||||
if(!addrinfo_space)
|
||||
goto err1;
|
||||
sockaddr_space = malloc(sizeof(struct sockaddr));
|
||||
if(!sockaddr_space)
|
||||
goto err2;
|
||||
memset(sockaddr_space, 0, sizeof(*sockaddr_space));
|
||||
memset(addrinfo_space, 0, sizeof(*addrinfo_space));
|
||||
if(node && !inet_aton(node, &((struct sockaddr_in *) sockaddr_space)->sin_addr)) {
|
||||
hp = proxy_gethostbyname(node);
|
||||
void proxy_freeaddrinfo(struct addrinfo *res) {
|
||||
free(res);
|
||||
}
|
||||
|
||||
if(hp)
|
||||
memcpy(&((struct sockaddr_in *) sockaddr_space)->sin_addr,
|
||||
*(hp->h_addr_list), sizeof(in_addr_t));
|
||||
else
|
||||
goto err3;
|
||||
}
|
||||
if(service)
|
||||
void proxy_getservbyname(const char * service, struct servent *se_buf,
|
||||
char * buf, size_t buf_len, struct servent **se_result)
|
||||
{
|
||||
|
||||
#ifdef __linux__
|
||||
getservbyname_r(service, NULL, se_buf, buf, buf_len, se_result);
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
struct servent *se;
|
||||
|
||||
MUTEX_LOCK(&internal_getsrvbyname_lock);
|
||||
if(service) {
|
||||
se = getservbyname(service, NULL);
|
||||
|
||||
if(!se) {
|
||||
((struct sockaddr_in *) sockaddr_space)->sin_port = htons(atoi(service ? : "0"));
|
||||
} else
|
||||
((struct sockaddr_in *) sockaddr_space)->sin_port = se->s_port;
|
||||
if ( se != NULL ) {
|
||||
memcpy(se_buf, se, buf_len);
|
||||
*se_result = se_buf;
|
||||
} else {
|
||||
*se_result = NULL;
|
||||
}
|
||||
}
|
||||
MUTEX_UNLOCK(&internal_getsrvbyname_lock);
|
||||
#endif /* __APPLE__ */
|
||||
}
|
||||
|
||||
*res = addrinfo_space;
|
||||
(*res)->ai_addr = sockaddr_space;
|
||||
int proxy_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
|
||||
struct gethostbyname_data ghdata;
|
||||
struct addrinfo_data *space;
|
||||
struct servent *se = NULL;
|
||||
struct hostent *hp = NULL;
|
||||
struct servent se_buf;
|
||||
struct addrinfo *p;
|
||||
char buf[1024];
|
||||
int port;
|
||||
|
||||
// printf("proxy_getaddrinfo node %s service %s\n",node,service);
|
||||
space = calloc(1, sizeof(struct addrinfo_data));
|
||||
if(!space)
|
||||
return 1;
|
||||
|
||||
if(node && !inet_aton(node, &((struct sockaddr_in *) &space->sockaddr_space)->sin_addr)) {
|
||||
hp = proxy_gethostbyname(node, &ghdata);
|
||||
if(hp) {
|
||||
memcpy(&((struct sockaddr_in *) &space->sockaddr_space)->sin_addr,
|
||||
*(hp->h_addr_list), sizeof(in_addr_t));
|
||||
} else {
|
||||
free(space);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if(service)
|
||||
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 = (in_port_t)port;
|
||||
|
||||
*res = p = &space->addrinfo_space;
|
||||
assert((size_t)p == (size_t) space);
|
||||
|
||||
p->ai_addr = &space->sockaddr_space;
|
||||
if(node)
|
||||
strcpy(addr_name, node);
|
||||
(*res)->ai_canonname = addr_name;
|
||||
(*res)->ai_next = NULL;
|
||||
(*res)->ai_family = sockaddr_space->sa_family = AF_INET;
|
||||
(*res)->ai_addrlen = sizeof(*sockaddr_space);
|
||||
strncpy(space->addr_name, node, sizeof(space->addr_name));
|
||||
p->ai_canonname = space->addr_name;
|
||||
p->ai_next = NULL;
|
||||
p->ai_family = space->sockaddr_space.sa_family = AF_INET;
|
||||
p->ai_addrlen = sizeof(space->sockaddr_space);
|
||||
|
||||
if (hints != NULL) {
|
||||
(*res)->ai_socktype = hints->ai_socktype;
|
||||
(*res)->ai_flags = hints->ai_flags;
|
||||
(*res)->ai_protocol = hints->ai_protocol;
|
||||
if(hints) {
|
||||
p->ai_socktype = hints->ai_socktype;
|
||||
p->ai_flags = hints->ai_flags;
|
||||
p->ai_protocol = hints->ai_protocol;
|
||||
} else {
|
||||
(*res)->ai_socktype = 0;
|
||||
(*res)->ai_flags = 0;
|
||||
(*res)->ai_protocol = 0;
|
||||
#ifdef BSD
|
||||
p->ai_flags = (AI_V4MAPPED | AI_ADDRCONFIG);
|
||||
#else
|
||||
p->ai_flags = (AI_ADDRCONFIG);
|
||||
#endif
|
||||
}
|
||||
|
||||
goto out;
|
||||
err3:
|
||||
free(sockaddr_space);
|
||||
err2:
|
||||
free(addrinfo_space);
|
||||
err1:
|
||||
return 1;
|
||||
out:
|
||||
return 0;
|
||||
}
|
||||
|
||||
+39
-31
@@ -4,10 +4,8 @@
|
||||
begin : Tue May 14 2002
|
||||
copyright : netcreature (C) 2002
|
||||
email : netcreature@users.sourceforge.net
|
||||
***************************************************************************/
|
||||
#include <stdint.h>
|
||||
/* GPL */
|
||||
/***************************************************************************
|
||||
***************************************************************************
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
@@ -15,6 +13,9 @@
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef __CORE_HEADER
|
||||
#define __CORE_HEADER
|
||||
#define BUFF_SIZE 8*1024 // used to read responses from proxies.
|
||||
@@ -40,7 +41,10 @@ extern internal_ip_lookup_table internal_ips;
|
||||
|
||||
#ifdef THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
pthread_mutex_t internal_ips_lock;
|
||||
|
||||
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)
|
||||
# define MUTEX_INIT(x,y) pthread_mutex_init(x, y)
|
||||
@@ -98,44 +102,48 @@ 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);
|
||||
|
||||
int proxychains_write_log(char *str,...);
|
||||
void proxychains_write_log(char *, ...);
|
||||
|
||||
typedef int (*connect_t)(int, const struct sockaddr *, socklen_t);
|
||||
connect_t true_connect;
|
||||
|
||||
typedef struct hostent* (*gethostbyname_t)(const char *);
|
||||
gethostbyname_t true_gethostbyname;
|
||||
|
||||
typedef int (*getaddrinfo_t)(const char *, const char *,
|
||||
const struct addrinfo *,
|
||||
struct addrinfo **);
|
||||
getaddrinfo_t true_getaddrinfo;
|
||||
|
||||
typedef int (*freeaddrinfo_t)(struct addrinfo *);
|
||||
freeaddrinfo_t true_freeaddrinfo;
|
||||
|
||||
typedef int (*getnameinfo_t) (const struct sockaddr *,
|
||||
socklen_t, char *,
|
||||
socklen_t, char *,
|
||||
socklen_t, int);
|
||||
getnameinfo_t true_getnameinfo;
|
||||
|
||||
#if (defined __linux__) || (defined __APPLE__)
|
||||
typedef struct hostent *(*gethostbyaddr_t) (const void *, socklen_t, int);
|
||||
gethostbyaddr_t true_gethostbyaddr;
|
||||
#else
|
||||
typedef struct hostent *(*gethostbyaddr_t) (const char *, socklen_t, int);
|
||||
#endif
|
||||
|
||||
struct hostent* proxy_gethostbyname(const char *name);
|
||||
typedef int (*getaddrinfo_t)(const char *, const char *, const struct addrinfo *,
|
||||
struct addrinfo **);
|
||||
typedef int (*getnameinfo_t) (const struct sockaddr *, socklen_t, char *,
|
||||
socklen_t, char *, socklen_t, int);
|
||||
|
||||
int proxy_getaddrinfo(const char *node, const char *service,
|
||||
const struct addrinfo *hints,
|
||||
struct addrinfo **res);
|
||||
|
||||
extern connect_t true_connect;
|
||||
extern gethostbyname_t true_gethostbyname;
|
||||
extern getaddrinfo_t true_getaddrinfo;
|
||||
extern freeaddrinfo_t true_freeaddrinfo;
|
||||
extern getnameinfo_t true_getnameinfo;
|
||||
extern gethostbyaddr_t true_gethostbyaddr;
|
||||
|
||||
struct gethostbyname_data {
|
||||
struct hostent hostent_space;
|
||||
in_addr_t resolved_addr;
|
||||
char *resolved_addr_p[2];
|
||||
char addr_name[1024 * 8];
|
||||
};
|
||||
|
||||
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...) fprintf(stderr,"DEBUG:"fmt, ## args)
|
||||
# define PDEBUG(fmt, args...) do { fprintf(stderr,"DEBUG:"fmt, ## args); fflush(stderr); } while(0)
|
||||
#else
|
||||
# define PDEBUG(fmt, args...) do {} while (0)
|
||||
#endif
|
||||
|
||||
+64
-52
@@ -19,6 +19,7 @@
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
@@ -43,6 +44,13 @@
|
||||
#define SOCKFAMILY(x) (satosin(x)->sin_family)
|
||||
#define MAX_CHAIN 512
|
||||
|
||||
connect_t true_connect;
|
||||
gethostbyname_t true_gethostbyname;
|
||||
getaddrinfo_t true_getaddrinfo;
|
||||
freeaddrinfo_t true_freeaddrinfo;
|
||||
getnameinfo_t true_getnameinfo;
|
||||
gethostbyaddr_t true_gethostbyaddr;
|
||||
|
||||
int tcp_read_time_out;
|
||||
int tcp_connect_time_out;
|
||||
int proxychains_got_chain_data = 0;
|
||||
@@ -66,49 +74,43 @@ static int init_l = 0;
|
||||
|
||||
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) {
|
||||
static void* load_sym(char* symname, void* proxyfunc) {
|
||||
|
||||
*funcptr = dlsym(RTLD_NEXT, symname);
|
||||
|
||||
if(!(*funcptr)) {
|
||||
void *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);
|
||||
PDEBUG("loaded symbol '%s'" " real addr %p wrapped addr %p\n", symname, funcptr, proxyfunc);
|
||||
}
|
||||
if((*funcptr) == proxyfunc) {
|
||||
if(funcptr == proxyfunc) {
|
||||
PDEBUG("circular reference detected, aborting!\n");
|
||||
abort();
|
||||
}
|
||||
return funcptr;
|
||||
}
|
||||
|
||||
#define INIT() init_lib_wrapper(__FUNCTION__)
|
||||
|
||||
#define SETUP_SYM(X) do { true_ ## X = load_sym( # X, X ); } while(0)
|
||||
|
||||
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);
|
||||
|
||||
#ifdef __APPLE__
|
||||
MUTEX_INIT(&internal_getsrvbyname_lock, NULL);
|
||||
#endif
|
||||
|
||||
/* read the config file */
|
||||
get_chain_data(proxychains_pd, &proxychains_proxy_count, &proxychains_ct);
|
||||
|
||||
proxychains_write_log(LOG_PREFIX "DLL init\n");
|
||||
|
||||
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);
|
||||
}
|
||||
SETUP_SYM(connect);
|
||||
SETUP_SYM(gethostbyname);
|
||||
SETUP_SYM(getaddrinfo);
|
||||
SETUP_SYM(freeaddrinfo);
|
||||
SETUP_SYM(gethostbyaddr);
|
||||
SETUP_SYM(getnameinfo);
|
||||
init_l = 1;
|
||||
}
|
||||
|
||||
@@ -138,14 +140,37 @@ static void gcc_init(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
FILE *
|
||||
open_config_file() {
|
||||
char home_conf[MAXPATHLEN], prefix_conf[MAXPATHLEN];
|
||||
FILE *file;
|
||||
|
||||
snprintf(home_conf, 256, "%s/.proxychains/proxychains.conf", getenv("HOME"));
|
||||
snprintf(prefix_conf, 256, "%s/etc/proxychains.conf", INSTALL_PREFIX);
|
||||
|
||||
if(!(file = fopen("./proxychains.conf", "r"))) {
|
||||
if(!(file = fopen(home_conf, "r"))) {
|
||||
if(!(file = fopen(prefix_conf, "r"))) {
|
||||
if(!(file = fopen("/etc/proxychains.conf", "r"))) {
|
||||
perror("Can't locate proxychains.conf");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 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];
|
||||
char local_in_addr[32], local_in_port[32], local_netmask[32];
|
||||
FILE *file;
|
||||
FILE *file = NULL;
|
||||
|
||||
if(proxychains_got_chain_data)
|
||||
return;
|
||||
@@ -154,22 +179,8 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
|
||||
tcp_read_time_out = 4 * 1000;
|
||||
tcp_connect_time_out = 10 * 1000;
|
||||
*ct = DYNAMIC_TYPE;
|
||||
|
||||
/*
|
||||
* Get path to configuration file from env this file has priority
|
||||
* if it's defined.
|
||||
*/
|
||||
env = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
|
||||
|
||||
snprintf(buff, 256, "%s/.proxychains/proxychains.conf", getenv("HOME"));
|
||||
|
||||
if(!env || (!(file = fopen(env, "r"))))
|
||||
if(!(file = fopen("./proxychains.conf", "r")))
|
||||
if(!(file = fopen(buff, "r")))
|
||||
if(!(file = fopen("/etc/proxychains.conf", "r"))) {
|
||||
perror("Can't locate proxychains.conf");
|
||||
exit(1);
|
||||
}
|
||||
env = get_config_path(getenv(PROXYCHAINS_CONF_FILE_ENV_VAR), buff, sizeof(buff));
|
||||
file = fopen(env, "r");
|
||||
|
||||
env = getenv(PROXYCHAINS_QUIET_MODE_ENV_VAR);
|
||||
if(env && *env == '1')
|
||||
@@ -256,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;
|
||||
}
|
||||
@@ -269,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")) {
|
||||
@@ -343,13 +354,14 @@ int connect(int sock, const struct sockaddr *addr, unsigned int len) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct gethostbyname_data ghbndata;
|
||||
struct hostent *gethostbyname(const char *name) {
|
||||
INIT();
|
||||
|
||||
PDEBUG("gethostbyname: %s\n", name);
|
||||
|
||||
if(proxychains_resolver)
|
||||
return proxy_gethostbyname(name);
|
||||
return proxy_gethostbyname(name, &ghbndata);
|
||||
else
|
||||
return true_gethostbyname(name);
|
||||
|
||||
@@ -378,12 +390,8 @@ void freeaddrinfo(struct addrinfo *res) {
|
||||
|
||||
if(!proxychains_resolver)
|
||||
true_freeaddrinfo(res);
|
||||
else {
|
||||
if (res != NULL) {
|
||||
free(res->ai_addr);
|
||||
free(res);
|
||||
}
|
||||
}
|
||||
else
|
||||
proxy_freeaddrinfo(res);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -417,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];
|
||||
|
||||
+3
-55
@@ -1,12 +1,4 @@
|
||||
/***************************************************************************
|
||||
main.c - description
|
||||
|
||||
begin : Tue May 14 2002
|
||||
copyright : netcreature (C) 2002
|
||||
email : netcreature@users.sourceforge.net
|
||||
***************************************************************************/
|
||||
/* GPL */
|
||||
/***************************************************************************
|
||||
/* (C) 2011, 2012 rofl0r
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
@@ -14,6 +6,7 @@
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#undef _POSIX_C_SOURCE
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#undef _XOPEN_SOURCE
|
||||
@@ -40,12 +33,6 @@ static int usage(char **argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int check_path(char *path) {
|
||||
if(!path)
|
||||
return 0;
|
||||
return access(path, R_OK) != -1;
|
||||
}
|
||||
|
||||
static const char *dll_name = DLL_NAME;
|
||||
|
||||
static char own_dir[256];
|
||||
@@ -106,46 +93,7 @@ int main(int argc, char *argv[]) {
|
||||
return usage(argv);
|
||||
|
||||
/* check if path of config file has not been passed via command line */
|
||||
if(!path) {
|
||||
// priority 1: env var PROXYCHAINS_CONF_FILE
|
||||
path = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
|
||||
|
||||
if(check_path(path))
|
||||
goto have;
|
||||
|
||||
// priority 2; proxychains conf in actual dir
|
||||
path = getcwd(buf, sizeof(buf));
|
||||
snprintf(pbuf, sizeof(pbuf), "%s/%s", path, PROXYCHAINS_CONF_FILE);
|
||||
path = pbuf;
|
||||
|
||||
if(check_path(path))
|
||||
goto have;
|
||||
|
||||
// priority 3; $HOME/.proxychains/proxychains.conf
|
||||
path = getenv("HOME");
|
||||
snprintf(pbuf, sizeof(pbuf), "%s/.proxychains/%s", path, PROXYCHAINS_CONF_FILE);
|
||||
path = pbuf;
|
||||
if(check_path(path))
|
||||
goto have;
|
||||
|
||||
/* 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
|
||||
snprintf(pbuf, sizeof(pbuf), "/etc/%s", PROXYCHAINS_CONF_FILE);
|
||||
path = pbuf;
|
||||
if(check_path(path))
|
||||
goto have;
|
||||
perror("Couldn't find configuration file");
|
||||
return 1;
|
||||
}
|
||||
|
||||
have:
|
||||
|
||||
path = get_config_path(path, pbuf, sizeof(pbuf));
|
||||
if(!quiet)
|
||||
fprintf(stderr, LOG_PREFIX "config file found: %s\n", path);
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifndef NI_MAXHOST
|
||||
#define NI_MAXHOST 1025
|
||||
#endif
|
||||
|
||||
int main(void) {
|
||||
struct addrinfo *result;
|
||||
struct addrinfo *res;
|
||||
int error;
|
||||
|
||||
/* resolve the domain name into a list of addresses */
|
||||
error = getaddrinfo("www.example.com", NULL, NULL, &result);
|
||||
if (error != 0)
|
||||
{
|
||||
fprintf(stderr, "error in getaddrinfo: %s\n", gai_strerror(error));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* loop over all returned results and do inverse lookup */
|
||||
for (res = result; res != NULL; res = res->ai_next)
|
||||
{
|
||||
char hostname[NI_MAXHOST] = "";
|
||||
|
||||
error = getnameinfo(res->ai_addr, res->ai_addrlen, hostname, NI_MAXHOST, NULL, 0, 0);
|
||||
if (error != 0)
|
||||
{
|
||||
fprintf(stderr, "error in getnameinfo: %s\n", gai_strerror(error));
|
||||
continue;
|
||||
}
|
||||
if (*hostname != '\0')
|
||||
printf("hostname: %s\n", hostname);
|
||||
}
|
||||
|
||||
freeaddrinfo(result);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user