1
0
mirror of https://github.com/rofl0r/proxychains-ng synced 2026-05-15 01:52:34 +08:00

Compare commits

...

23 Commits

10 changed files with 120 additions and 38 deletions
+2 -2
View File
@@ -25,7 +25,7 @@ GENH = src/version.h
CFLAGS += -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe CFLAGS += -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe
NO_AS_NEEDED = -Wl,--no-as-needed NO_AS_NEEDED = -Wl,--no-as-needed
LIBDL = -ldl LIBDL = -ldl
LDFLAGS = -shared -fPIC $(NO_AS_NEEDED) $(LIBDL) -lpthread LDFLAGS = -fPIC $(NO_AS_NEEDED) $(LIBDL) -lpthread
INC = INC =
PIC = -fPIC PIC = -fPIC
AR = $(CROSS_COMPILE)ar AR = $(CROSS_COMPILE)ar
@@ -82,7 +82,7 @@ src/version.o: src/version.h
$(LDSO_PATHNAME): $(LOBJS) $(LDSO_PATHNAME): $(LOBJS)
$(CC) $(LDFLAGS) $(LD_SET_SONAME)$(LDSO_PATHNAME) $(USER_LDFLAGS) \ $(CC) $(LDFLAGS) $(LD_SET_SONAME)$(LDSO_PATHNAME) $(USER_LDFLAGS) \
-o $@ $(LOBJS) -shared -o $@ $(LOBJS)
$(ALL_TOOLS): $(OBJS) $(ALL_TOOLS): $(OBJS)
$(CC) src/main.o src/common.o $(USER_LDFLAGS) -o $(PXCHAINS) $(CC) src/main.o src/common.o $(USER_LDFLAGS) -o $(PXCHAINS)
+11 -1
View File
@@ -1,4 +1,4 @@
ProxyChains-NG ver 4.11 README ProxyChains-NG ver 4.12 README
============================= =============================
ProxyChains is a UNIX program, that hooks network-related libc functions ProxyChains is a UNIX program, that hooks network-related libc functions
@@ -52,6 +52,16 @@ ProxyChains-NG ver 4.11 README
Changelog: Changelog:
---------- ----------
Version 4.12
- fix several build issues
- for MAC
- with -pie
- with custom CC
- compatibility fix for some GUI apps (8870140)
- compatibility fix for some HTTP proxies (cf9a16d)
- fix several warnings for cleaner build on debian
- fix random_chain on OSX (0f6b226)
Version 4.11 Version 4.11
- preliminary IPv6 support - preliminary IPv6 support
- fixed bug in hostsreader - fixed bug in hostsreader
+1 -1
View File
@@ -1 +1 @@
4.11 4.12
Vendored
+27 -17
View File
@@ -1,6 +1,18 @@
#!/bin/sh #!/bin/sh
prefix=/usr/local prefix=/usr/local
OUR_CPPFLAGS=
# Get a temporary filename
i=0
set -C
while : ; do i=$(($i+1))
tmpc="./conf$$-$PPID-$i.c"
2>|/dev/null > "$tmpc" && break
test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
done
set +C
trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP
ismac() { ismac() {
uname -s | grep Darwin >/dev/null uname -s | grep Darwin >/dev/null
@@ -20,14 +32,12 @@ isopenbsd() {
check_compile() { check_compile() {
printf "checking %s ... " "$1" printf "checking %s ... " "$1"
local tmp=$(mktemp) printf "$3" > "$tmpc"
printf "$3" > "$tmp".c
local res=0 local res=0
$CC $CPPFLAGS $2 $CFLAGS -c "$tmp".c -o "$tmp".o >/dev/null 2>&1 \ $CC $OUR_CPPFLAGS $CPPFLAGS $2 $CFLAGS -c "$tmpc" -o /dev/null >/dev/null 2>&1 \
|| res=1 || res=1
rm -f "$tmp".c "$tmp".o
test x$res = x0 && \ test x$res = x0 && \
{ printf "yes\n" ; test x"$2" = x || CPPFLAGS="$CPPFLAGS $2" ; } \ { printf "yes\n" ; test x"$2" = x || OUR_CPPFLAGS="$OUR_CPPFLAGS $2" ; } \
|| printf "no\n" || printf "no\n"
return $res return $res
} }
@@ -35,20 +45,19 @@ check_compile() {
check_define() { check_define() {
printf "checking whether \$CC defines %s ... " "$1" printf "checking whether \$CC defines %s ... " "$1"
local res=1 local res=1
$CC $CPPFLAGS $CFLAGS -dM -E - </dev/null | grep "$1" >/dev/null && res=0 $CC $OUR_CPPFLAGS $CPPFLAGS $CFLAGS -dM -E - </dev/null | grep "$1" >/dev/null && res=0
test x$res = x0 && printf "yes\n" || printf "no\n" test x$res = x0 && printf "yes\n" || printf "no\n"
return $res return $res
} }
check_compile_run() { check_compile_run() {
printf "checking %s ... " "$1" printf "checking %s ... " "$1"
local tmp=$(mktemp) printf "$2" > "$tmpc"
printf "$2" > "$tmp".c
local res=0 local res=0
$CC $CPPFLAGS $CFLAGS "$tmp".c -o "$tmp".out >/dev/null 2>&1 \ $CC $OUR_CPPFLAGS $CPPFLAGS $CFLAGS "$tmpc" -o "$tmpc".out >/dev/null 2>&1 \
|| res=1 || res=1
test x$res = x0 && { "$tmp".out || res=1 ; } test x$res = x0 && { "$tmpc".out || res=1 ; }
rm -f "$tmp".c "$tmp".o "$tmp".out rm -f "$tmpc".out
test x$res = x0 && printf "yes\n" || printf "no\n" test x$res = x0 && printf "yes\n" || printf "no\n"
return $res return $res
} }
@@ -135,19 +144,20 @@ check_compile 'whether netinet/in.h defines __u6_addr.__u6_addr16' \
check_define __OpenBSD__ && \ check_define __OpenBSD__ && \
check_compile_run 'whether OpenBSDs fclose() (illegally) calls close()' \ check_compile_run 'whether OpenBSDs fclose() (illegally) calls close()' \
'#include <stdio.h>\n#include<stdlib.h>\nint close(int x){exit(0);}int main(){fclose(stdin);return 1;}' && \ '#include <stdio.h>\n#include<stdlib.h>\nint close(int x){exit(0);}int main(){fclose(stdin);return 1;}' && \
CPPFLAGS="$CPPFLAGS -DBROKEN_FCLOSE" OUR_CPPFLAGS="$OUR_CPPFLAGS -DBROKEN_FCLOSE"
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
[ -z "$LDFLAGS" ] || echo USER_LDFLAGS?=$LDFLAGS>>config.mak [ -z "$LDFLAGS" ] || echo "USER_LDFLAGS=$LDFLAGS">>config.mak
echo prefix=$prefix>>config.mak echo prefix=$prefix>>config.mak
echo exec_prefix=$exec_prefix>>config.mak echo exec_prefix=$exec_prefix>>config.mak
echo bindir=$bindir>>config.mak echo bindir=$bindir>>config.mak
echo libdir=$libdir>>config.mak echo libdir=$libdir>>config.mak
echo includedir=$includedir>>config.mak echo includedir=$includedir>>config.mak
echo sysconfdir=$sysconfdir>>config.mak echo sysconfdir=$sysconfdir>>config.mak
[ "$ignore_cve" = "no" ] && echo CPPFLAGS+= -DSUPER_SECURE>>config.mak [ "$ignore_cve" = "no" ] && echo "CPPFLAGS+= -DSUPER_SECURE">>config.mak
[ -z "$OUR_CPPFLAGS" ] || echo "CPPFLAGS+= $OUR_CPPFLAGS" >>config.mak
make_cmd=make make_cmd=make
if ismac ; then if ismac ; then
echo NO_AS_NEEDED=>>config.mak echo NO_AS_NEEDED=>>config.mak
+43 -6
View File
@@ -176,24 +176,61 @@ static int wait_data(int readfd) {
return 1; return 1;
} }
static int trywrite(int fd, void* buf, size_t bytes) {
ssize_t ret;
unsigned char *out = buf;
again:
ret = write(fd, out, bytes);
switch(ret) {
case -1:
if(errno == EINTR) goto again;
case 0:
return 0;
default:
if(ret == bytes || !bytes) return 1;
out += ret;
bytes -= ret;
goto again;
}
}
static int sendmessage(enum at_direction dir, struct at_msghdr *hdr, void* data) { static int sendmessage(enum at_direction dir, struct at_msghdr *hdr, void* data) {
static int* destfd[ATD_MAX] = { [ATD_SERVER] = &req_pipefd[1], [ATD_CLIENT] = &resp_pipefd[1] }; static int* destfd[ATD_MAX] = { [ATD_SERVER] = &req_pipefd[1], [ATD_CLIENT] = &resp_pipefd[1] };
int ret = write(*destfd[dir], hdr, sizeof *hdr) == sizeof *hdr; int ret = trywrite(*destfd[dir], hdr, sizeof *hdr);
if(ret && hdr->datalen) { if(ret && hdr->datalen) {
assert(hdr->datalen <= MSG_LEN_MAX); assert(hdr->datalen <= MSG_LEN_MAX);
ret = write(*destfd[dir], data, hdr->datalen) == hdr->datalen; ret = trywrite(*destfd[dir], data, hdr->datalen);
} }
return ret; return ret;
} }
static int tryread(int fd, void* buf, size_t bytes) {
ssize_t ret;
unsigned char *out = buf;
again:
ret = read(fd, out, bytes);
switch(ret) {
case -1:
if(errno == EINTR) goto again;
case 0:
return 0;
default:
if(ret == bytes || !bytes) return 1;
out += ret;
bytes -= ret;
goto again;
}
}
static int getmessage(enum at_direction dir, struct at_msghdr *hdr, void* data) { static int getmessage(enum at_direction dir, struct at_msghdr *hdr, void* data) {
static int* readfd[ATD_MAX] = { [ATD_SERVER] = &req_pipefd[0], [ATD_CLIENT] = &resp_pipefd[0] }; static int* readfd[ATD_MAX] = { [ATD_SERVER] = &req_pipefd[0], [ATD_CLIENT] = &resp_pipefd[0] };
int ret; ssize_t ret;
if((ret = wait_data(*readfd[dir]))) { if((ret = wait_data(*readfd[dir]))) {
ret = read(*readfd[dir], hdr, sizeof *hdr) == sizeof(*hdr); if(!tryread(*readfd[dir], hdr, sizeof *hdr))
return 0;
assert(hdr->datalen <= MSG_LEN_MAX); assert(hdr->datalen <= MSG_LEN_MAX);
if(ret && hdr->datalen) { if(hdr->datalen) {
ret = read(*readfd[dir], data, hdr->datalen) == hdr->datalen; ret = tryread(*readfd[dir], data, hdr->datalen);
} }
} }
return ret; return ret;
+9 -5
View File
@@ -236,13 +236,15 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
encode_base_64(src, dst, sizeof(dst)); encode_base_64(src, dst, sizeof(dst));
} else dst[0] = 0; } else dst[0] = 0;
uint16_t hs_port = ntohs(port);
len = snprintf((char *) buff, sizeof(buff), len = snprintf((char *) buff, sizeof(buff),
"CONNECT %s:%d HTTP/1.0\r\n%s%s%s\r\n", "CONNECT %s:%d HTTP/1.0\r\nHost: %s:%d\r\n%s%s%s\r\n",
dns_name, ntohs(port), dns_name, hs_port,
dns_name, hs_port,
ulen ? "Proxy-Authorization: Basic " : dst, ulen ? "Proxy-Authorization: Basic " : dst,
dst, ulen ? "\r\n" : dst); dst, ulen ? "\r\n" : dst);
if(len != send(sock, buff, len, 0)) if(len < 0 || len != send(sock, buff, len, 0))
goto err; goto err;
len = 0; len = 0;
@@ -269,7 +271,7 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
break; break;
case SOCKS4_TYPE:{ case SOCKS4_TYPE:{
if(v6) { if(v6) {
proxychains_write_log(LOG_PREFIX "error: SOCKS4 doesnt support ipv6 addresses\n"); proxychains_write_log(LOG_PREFIX "error: SOCKS4 doesn't support ipv6 addresses\n");
goto err; goto err;
} }
buff[0] = 4; // socks version buff[0] = 4; // socks version
@@ -464,7 +466,7 @@ static proxy_data *select_proxy(select_type how, proxy_data * pd, unsigned int p
case RANDOMLY: case RANDOMLY:
do { do {
k++; k++;
i = 0 + (unsigned int) (proxy_count * 1.0 * rand() / (RAND_MAX + 1.0)); i = rand() % proxy_count;
} while(pd[i].ps != PLAY_STATE && k < proxy_count * 100); } while(pd[i].ps != PLAY_STATE && k < proxy_count * 100);
break; break;
case FIFOLY: case FIFOLY:
@@ -698,8 +700,10 @@ int connect_proxy_chain(int sock, ip_type target_ip,
} }
proxychains_write_log(TP " OK\n"); proxychains_write_log(TP " OK\n");
int flags = fcntl(sock, F_GETFL, 0);
dup2(ns, sock); dup2(ns, sock);
close(ns); close(ns);
fcntl(sock, F_SETFL, flags);
return 0; return 0;
error: error:
if(ns != -1) if(ns != -1)
+6
View File
@@ -22,4 +22,10 @@ void DUMP_PROXY_CHAIN(proxy_data *pchain, unsigned int count) {
} }
} }
#else
// Do not allow this translation unit to end up empty
// for non-DEBUG builds, to satisfy ISO C standards.
typedef int __appease_iso_compilers__;
#endif #endif
+1 -1
View File
@@ -1,5 +1,5 @@
#include "ip_type.h" #include "ip_type.h"
const ip_type ip_type_invalid = { .addr.v4.as_int = -1 }; const ip_type ip_type_invalid = { .addr.v4.as_int = -1 };
const ip_type ip_type_localhost = { .addr.v4 = {127, 0, 0, 1} }; const ip_type ip_type_localhost = { .addr.v4.octet = {127, 0, 0, 1} };
+19 -4
View File
@@ -93,7 +93,7 @@ static void* load_sym(char* symname, void* proxyfunc) {
#define INIT() init_lib_wrapper(__FUNCTION__) #define INIT() init_lib_wrapper(__FUNCTION__)
#define SETUP_SYM(X) do { true_ ## X = load_sym( # X, X ); } while(0) #define SETUP_SYM(X) do { if (! true_ ## X ) true_ ## X = load_sym( # X, X ); } while(0)
#include "allocator_thread.h" #include "allocator_thread.h"
@@ -110,6 +110,9 @@ static void setup_hooks(void) {
SETUP_SYM(close); SETUP_SYM(close);
} }
static int close_fds[16];
static int close_fds_cnt = 0;
static void do_init(void) { static void do_init(void) {
srand(time(NULL)); srand(time(NULL));
core_initialize(); core_initialize();
@@ -123,6 +126,8 @@ static void do_init(void) {
setup_hooks(); setup_hooks();
while(close_fds_cnt) true_close(close_fds[--close_fds_cnt]);
init_l = 1; init_l = 1;
} }
@@ -229,7 +234,7 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
} else if(strstr(buff, "tcp_connect_time_out")) { } else if(strstr(buff, "tcp_connect_time_out")) {
sscanf(buff, "%s %d", user, &tcp_connect_time_out); sscanf(buff, "%s %d", user, &tcp_connect_time_out);
} else if(strstr(buff, "remote_dns_subnet")) { } else if(strstr(buff, "remote_dns_subnet")) {
sscanf(buff, "%s %d", user, &remote_dns_subnet); sscanf(buff, "%s %u", user, &remote_dns_subnet);
if(remote_dns_subnet >= 256) { if(remote_dns_subnet >= 256) {
fprintf(stderr, fprintf(stderr,
"remote_dns_subnet: invalid value. requires a number between 0 and 255.\n"); "remote_dns_subnet: invalid value. requires a number between 0 and 255.\n");
@@ -280,6 +285,10 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
char *pc; char *pc;
int len; int len;
pc = strchr(buff, '='); pc = strchr(buff, '=');
if(!pc) {
fprintf(stderr, "error: missing equals sign '=' in chain_len directive.\n");
exit(1);
}
len = atoi(++pc); len = atoi(++pc);
proxychains_max_chain = (len ? len : 1); proxychains_max_chain = (len ? len : 1);
} else if(strstr(buff, "quiet_mode")) { } else if(strstr(buff, "quiet_mode")) {
@@ -304,12 +313,18 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
/******* HOOK FUNCTIONS *******/ /******* HOOK FUNCTIONS *******/
int close(int fd) { int close(int fd) {
INIT(); if(!init_l) {
if(close_fds_cnt>=(sizeof close_fds/sizeof close_fds[0])) goto err;
close_fds[close_fds_cnt++] = fd;
errno = 0;
return 0;
}
/* prevent rude programs (like ssh) from closing our pipes */ /* prevent rude programs (like ssh) from closing our pipes */
if(fd != req_pipefd[0] && fd != req_pipefd[1] && if(fd != req_pipefd[0] && fd != req_pipefd[1] &&
fd != resp_pipefd[0] && fd != resp_pipefd[1]) { fd != resp_pipefd[0] && fd != resp_pipefd[1]) {
return true_close(fd); return true_close(fd);
} }
err:
errno = EBADF; errno = EBADF;
return -1; return -1;
} }
@@ -410,7 +425,7 @@ int getaddrinfo(const char *node, const char *service, const struct addrinfo *hi
void freeaddrinfo(struct addrinfo *res) { void freeaddrinfo(struct addrinfo *res) {
INIT(); INIT();
PDEBUG("freeaddrinfo %p \n", res); PDEBUG("freeaddrinfo %p \n", (void *) res);
if(!proxychains_resolver) if(!proxychains_resolver)
true_freeaddrinfo(res); true_freeaddrinfo(res);
+1 -1
View File
@@ -24,7 +24,7 @@
static int usage(char **argv) { static int usage(char **argv) {
printf("\nUsage:\t%s -q -f config_file program_name [arguments]\n" printf("\nUsage:\t%s -q -f config_file program_name [arguments]\n"
"\t-q makes proxychains quiet - this overrides the config setting\n" "\t-q makes proxychains quiet - this overrides the config setting\n"
"\t-f allows to manually specify a configfile to use\n" "\t-f allows one to manually specify a configfile to use\n"
"\tfor example : proxychains telnet somehost.com\n" "More help in README file\n\n", argv[0]); "\tfor example : proxychains telnet somehost.com\n" "More help in README file\n\n", argv[0]);
return EXIT_FAILURE; return EXIT_FAILURE;
} }