mirror of
https://github.com/rofl0r/proxychains-ng
synced 2026-05-13 17:03:07 +08:00
Compare commits
8 Commits
+12
@@ -0,0 +1,12 @@
|
||||
*.o
|
||||
*.so
|
||||
*.la
|
||||
*.lo
|
||||
.deps/
|
||||
.libs/
|
||||
|
||||
# Autoconf stuff
|
||||
libtool
|
||||
config.*
|
||||
Makefile
|
||||
stamp-h
|
||||
@@ -1,5 +1,5 @@
|
||||
ProxyChains ver 3.1 README
|
||||
======================
|
||||
==========================
|
||||
|
||||
This is Unix version only.
|
||||
|
||||
@@ -40,9 +40,11 @@ Some cool features:
|
||||
|
||||
Configuration:
|
||||
proxychains looks for config file in following order:
|
||||
1) ./proxychains.conf
|
||||
2) $(HOME)/.proxychains/proxychains.conf
|
||||
3) /etc/proxychains.conf **
|
||||
1) file listed in environment variable ${PROXYCHAINS_CONF_FILE} or
|
||||
provided as a -f argument to proxychains script or binary.
|
||||
2) ./proxychains.conf
|
||||
3) $(HOME)/.proxychains/proxychains.conf
|
||||
4) /etc/proxychains.conf **
|
||||
|
||||
**see more in /etc/proxychains.conf
|
||||
|
||||
@@ -53,6 +55,13 @@ Usage Example:
|
||||
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
|
||||
|
||||
in this example it will use different configuration file then proxychains.conf
|
||||
to connect to targethost2.com host.
|
||||
|
||||
Usage Example:
|
||||
|
||||
bash$ proxyresolv targethost.com
|
||||
@@ -60,5 +69,3 @@ Usage Example:
|
||||
in this example it will resolve targethost.com through proxy(or chained proxies)
|
||||
specified by proxychains.conf
|
||||
|
||||
NOTE:
|
||||
to run suid/sgid programs(like ssh) through proxychains you have to be root
|
||||
|
||||
+43
-21
@@ -43,6 +43,33 @@ extern int proxychains_quiet_mode;
|
||||
|
||||
static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
static int poll_retry(struct pollfd *fds, nfds_t nfsd, int timeout)
|
||||
{
|
||||
int ret;
|
||||
int time_remain = timeout;
|
||||
int time_elapsed = 0;
|
||||
|
||||
struct timeval start_time;
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&start_time, NULL);
|
||||
|
||||
do
|
||||
{
|
||||
//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);
|
||||
//printf("Time elapsed %d\n", time_elapsed);
|
||||
time_remain = timeout - time_elapsed;
|
||||
}
|
||||
while (ret == -1 && errno == EINTR && time_remain > 0);
|
||||
//if (ret == -1)
|
||||
//printf("Return %d %d %s\n", ret, errno, strerror(errno));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static void encode_base_64(char* src,char* dest,int max_len)
|
||||
{
|
||||
int n,l,i;
|
||||
@@ -123,7 +150,7 @@ static int read_line(int fd, char *buff, size_t size)
|
||||
for(i=0;i<size-1;i++)
|
||||
{
|
||||
pfd[0].revents=0;
|
||||
ready=poll(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))
|
||||
return -1;
|
||||
else if(buff[i]=='\n')
|
||||
@@ -142,10 +169,9 @@ static int read_n_bytes(int fd,char *buff, size_t size)
|
||||
|
||||
pfd[0].fd=fd;
|
||||
pfd[0].events=POLLIN;
|
||||
for(i=0;i<size;i++)
|
||||
{
|
||||
for(i=0; i < size; i++) {
|
||||
pfd[0].revents=0;
|
||||
ready=poll(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))
|
||||
return -1;
|
||||
}
|
||||
@@ -162,31 +188,27 @@ static int timed_connect(int sock, const struct sockaddr *addr, unsigned int len
|
||||
fcntl(sock, F_SETFL, O_NONBLOCK);
|
||||
ret=true_connect(sock, addr, len);
|
||||
// printf("\nconnect ret=%d\n",ret);fflush(stdout);
|
||||
if(ret==-1 && errno==EINPROGRESS)
|
||||
{
|
||||
ret=poll(pfd,1,tcp_connect_time_out);
|
||||
// printf("\npoll ret=%d\n",ret);fflush(stdout);
|
||||
if(ret==1)
|
||||
{
|
||||
if(ret==-1 && errno==EINPROGRESS) {
|
||||
ret=poll_retry(pfd,1,tcp_connect_time_out);
|
||||
//printf("\npoll ret=%d\n",ret);fflush(stdout);
|
||||
if(ret == 1) {
|
||||
value_len=sizeof(int);
|
||||
getsockopt(sock,SOL_SOCKET,SO_ERROR,&value,&value_len) ;
|
||||
// printf("\nvalue=%d\n",value);fflush(stdout);
|
||||
//printf("\nvalue=%d\n",value);fflush(stdout);
|
||||
if(!value)
|
||||
ret=0;
|
||||
ret=0;
|
||||
else
|
||||
ret=-1;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
ret=-1;
|
||||
}
|
||||
else if (ret==0)
|
||||
;
|
||||
else
|
||||
}
|
||||
} else {
|
||||
if (ret != 0)
|
||||
ret=-1;
|
||||
|
||||
}
|
||||
|
||||
fcntl(sock, F_SETFL, !O_NONBLOCK);
|
||||
return ret;
|
||||
fcntl(sock, F_SETFL, !O_NONBLOCK);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int tunnel_to(int sock, unsigned int ip, unsigned short port, proxy_type pt,char *user,char *pass)
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#ifndef __CORE_HEADER
|
||||
#define __CORE_HEADER
|
||||
#define BUFF_SIZE 8*1024 // used to read responses from proxies.
|
||||
#define MAX_LOCALNET 1024
|
||||
/*error codes*/
|
||||
typedef enum
|
||||
{
|
||||
@@ -34,6 +35,12 @@ typedef enum {DYNAMIC_TYPE,STRICT_TYPE,RANDOM_TYPE} chain_type;
|
||||
typedef enum {PLAY_STATE,DOWN_STATE,BLOCKED_STATE,BUSY_STATE} proxy_state;
|
||||
typedef enum {RANDOMLY,FIFOLY} select_type;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct in_addr in_addr, netmask;
|
||||
unsigned short port;
|
||||
} localaddr_arg;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int ip;
|
||||
|
||||
@@ -52,12 +52,14 @@ int proxychains_max_chain = 1;
|
||||
int proxychains_quiet_mode = 0;
|
||||
int proxychains_resolver = 0;
|
||||
static int init_l = 0;
|
||||
static inline void get_chain_data(
|
||||
proxy_data *pd,
|
||||
unsigned int *proxy_count,
|
||||
chain_type *ct);
|
||||
localaddr_arg localnet_addr[MAX_LOCALNET];
|
||||
size_t num_localnet_addr = 0;
|
||||
|
||||
static void init_lib()
|
||||
static inline void get_chain_data(proxy_data *pd, unsigned int *proxy_count,
|
||||
chain_type *ct);
|
||||
static void init_lib(void);
|
||||
|
||||
static void init_lib(void)
|
||||
{
|
||||
// proxychains_write_log("ProxyChains-"VERSION
|
||||
// " (http://proxychains.sf.net)\n");
|
||||
@@ -136,16 +138,22 @@ static void init_lib()
|
||||
init_l = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX. Same thing is defined in proxychains main.c it
|
||||
* needs to be changed, too.
|
||||
*/
|
||||
#define PROXYCHAINS_CONF_FILE "PROXYCHAINS_CONF_FILE"
|
||||
|
||||
static inline void get_chain_data(
|
||||
proxy_data *pd,
|
||||
unsigned int *proxy_count,
|
||||
chain_type *ct)
|
||||
{
|
||||
|
||||
|
||||
int count=0,port_n=0,list=0;
|
||||
char buff[1024],type[1024],host[1024],user[1024];
|
||||
char *env;
|
||||
char local_in_addr_port[32];
|
||||
char local_in_addr[32], local_in_port[32], local_netmask[32];
|
||||
FILE* file;
|
||||
|
||||
if(proxychains_got_chain_data)
|
||||
@@ -156,8 +164,17 @@ static inline void get_chain_data(
|
||||
tcp_connect_time_out=10*1000;
|
||||
*ct=DYNAMIC_TYPE;
|
||||
|
||||
env = NULL;
|
||||
|
||||
/*
|
||||
* Get path to configuration file from env this file has priority
|
||||
* if it's defined.
|
||||
*/
|
||||
env = getenv(PROXYCHAINS_CONF_FILE);
|
||||
|
||||
snprintf(buff,256,"%s/.proxychains/proxychains.conf",getenv("HOME"));
|
||||
|
||||
if(!(file=fopen(env,"r")))
|
||||
if(!(file=fopen("./proxychains.conf","r")))
|
||||
if(!(file=fopen(buff,"r")))
|
||||
if(!(file=fopen("/etc/proxychains.conf","r")))
|
||||
@@ -200,7 +217,54 @@ static inline void get_chain_data(
|
||||
sscanf(buff,"%s %d",user,&tcp_read_time_out) ;
|
||||
}else if(strstr(buff,"tcp_connect_time_out")){
|
||||
sscanf(buff,"%s %d",user,&tcp_connect_time_out) ;
|
||||
}else if(strstr(buff,"chain_len")){
|
||||
}
|
||||
else if(strstr(buff,"localnet"))
|
||||
{
|
||||
if (sscanf(buff,"%s %21[^/]/%15s", user,
|
||||
local_in_addr_port, local_netmask) < 3) {
|
||||
fprintf(stderr, "localnet format error");
|
||||
exit(1);
|
||||
}
|
||||
/* clean previously used buffer */
|
||||
memset(local_in_port, 0,
|
||||
sizeof(local_in_port) / sizeof(local_in_port[0]));
|
||||
|
||||
if (sscanf(local_in_addr_port, "%15[^:]:%5s",
|
||||
local_in_addr, local_in_port) < 2) {
|
||||
PDEBUG("added localnet: netaddr=%s, port=%s\n",
|
||||
local_in_addr, local_netmask);
|
||||
} else {
|
||||
PDEBUG("added localnet: netaddr=%s, port=%s, netmask=%s\n",
|
||||
local_in_addr, local_in_port, local_netmask);
|
||||
}
|
||||
if (num_localnet_addr < MAX_LOCALNET)
|
||||
{
|
||||
int error;
|
||||
error = inet_pton(AF_INET, local_in_addr, &localnet_addr[num_localnet_addr].in_addr);
|
||||
if (error <= 0)
|
||||
{
|
||||
fprintf(stderr, "localnet address error\n");
|
||||
exit(1);
|
||||
}
|
||||
error = inet_pton(AF_INET, local_netmask, &localnet_addr[num_localnet_addr].netmask);
|
||||
if (error <= 0)
|
||||
{
|
||||
fprintf(stderr, "localnet netmask error\n");
|
||||
exit(1);
|
||||
}
|
||||
if (local_in_port[0]) {
|
||||
localnet_addr[num_localnet_addr].port = (short)atoi(local_in_port);
|
||||
} else {
|
||||
localnet_addr[num_localnet_addr].port = 0;
|
||||
}
|
||||
++num_localnet_addr;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "# of localnet exceed %d.\n", MAX_LOCALNET);
|
||||
}
|
||||
}
|
||||
else if(strstr(buff,"chain_len")){
|
||||
char *pc;int len;
|
||||
pc=strchr(buff,'=');
|
||||
len=atoi(++pc);
|
||||
@@ -223,6 +287,10 @@ static inline void get_chain_data(
|
||||
int connect (int sock, const struct sockaddr *addr, unsigned int len)
|
||||
{
|
||||
int socktype=0,optlen=0,flags=0,ret=0;
|
||||
char str[256];
|
||||
struct in_addr *p_addr_in;
|
||||
unsigned short port;
|
||||
size_t i;
|
||||
|
||||
if(!init_l)
|
||||
init_lib();
|
||||
@@ -230,6 +298,25 @@ int connect (int sock, const struct sockaddr *addr, unsigned int len)
|
||||
getsockopt(sock,SOL_SOCKET,SO_TYPE,&socktype,&optlen);
|
||||
if (! (SOCKFAMILY(*addr)==AF_INET && socktype==SOCK_STREAM))
|
||||
return true_connect(sock,addr,len);
|
||||
|
||||
p_addr_in = &((struct sockaddr_in *)addr)->sin_addr;
|
||||
port = ntohs(((struct sockaddr_in *)addr)->sin_port);
|
||||
|
||||
//PDEBUG("localnet: %s; ", inet_ntop(AF_INET,&in_addr_localnet, str, sizeof(str)));
|
||||
//PDEBUG("netmask: %s; " , inet_ntop(AF_INET, &in_addr_netmask, str, sizeof(str)));
|
||||
//PDEBUG("target: %s\n", inet_ntop(AF_INET, p_addr_in, str, sizeof(str)));
|
||||
//PDEBUG("port: %d\n", port);
|
||||
for (i = 0; i < num_localnet_addr; i++) {
|
||||
if ((localnet_addr[i].in_addr.s_addr & localnet_addr[i].netmask.s_addr)
|
||||
== (p_addr_in->s_addr & localnet_addr[i].netmask.s_addr))
|
||||
{
|
||||
if (localnet_addr[i].port && localnet_addr[i].port == port) {
|
||||
PDEBUG("accessing localnet using true_connect\n");
|
||||
return true_connect(sock,addr,len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
flags=fcntl(sock, F_GETFL, 0);
|
||||
if(flags & O_NONBLOCK)
|
||||
fcntl(sock, F_SETFL, !O_NONBLOCK);
|
||||
@@ -308,8 +395,8 @@ int getnameinfo (const struct sockaddr * sa,
|
||||
PDEBUG("getnameinfo: %s %s\n", host, serv);
|
||||
return ret;
|
||||
}
|
||||
struct hostent *gethostbyaddr (const void *addr, socklen_t len,
|
||||
int type)
|
||||
|
||||
struct hostent *gethostbyaddr (const void *addr, socklen_t len, int type)
|
||||
{
|
||||
PDEBUG("TODO: gethostbyaddr hook\n");
|
||||
if(!init_l)
|
||||
|
||||
+44
-7
@@ -1,6 +1,6 @@
|
||||
/***************************************************************************
|
||||
main.c - description
|
||||
-------------------
|
||||
q -------------------
|
||||
begin : Tue May 14 2002
|
||||
copyright : netcreature (C) 2002
|
||||
email : netcreature@users.sourceforge.net
|
||||
@@ -32,17 +32,54 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind, opterr, optopt
|
||||
|
||||
/*
|
||||
* XXX. Same thing is defined in proxychains main.c it
|
||||
* needs to be changed, too.
|
||||
*/
|
||||
#define PROXYCHAINS_CONF_FILE "PROXYCHAINS_CONF_FILE"
|
||||
|
||||
static usage(void)
|
||||
{
|
||||
|
||||
printf("\nUsage: %s [h] [f] config_file program_name [arguments]\n"
|
||||
"\t for example : proxychains telnet somehost.com\n"
|
||||
"More help in README file\n", argv[0], );
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if(argc<2)
|
||||
{
|
||||
printf("\nUsage: proxychains program_name [arguments]\n"
|
||||
"\t for example : proxychains telnet somehost.com\n"
|
||||
"More help in README file\n");
|
||||
return 0 ;
|
||||
char *path;
|
||||
|
||||
path = NULL;
|
||||
|
||||
while ((opt = getopt(argc, argv, "fh:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'h':
|
||||
usage();
|
||||
break;
|
||||
case 'f':
|
||||
path = (char *)optarg;
|
||||
break;
|
||||
default: /* '?' */
|
||||
usage();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
printf("Proxychains are going to use %s as config file.\n", path);
|
||||
printf("argv = %s\n", argv[1]);
|
||||
|
||||
/* Set PROXYCHAINS_CONF_FILE to get proxychains lib to
|
||||
use new config file. */
|
||||
setenv(PROXYCHAINS_CONF_FILE, path, 1);
|
||||
|
||||
/*XXX. proxychains might be installed in some different location */
|
||||
putenv("LD_PRELOAD=/usr/lib/libproxychains.so");
|
||||
execvp(argv[1],&argv[1]);
|
||||
perror("proxychains can't load process....");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
+20
-3
@@ -1,9 +1,26 @@
|
||||
#!/bin/sh
|
||||
echo "ProxyChains-3.1 (http://proxychains.sf.net)"
|
||||
if [ $# = 0 ] ; then
|
||||
|
||||
usage() {
|
||||
|
||||
echo " usage:"
|
||||
echo " proxychains <prog> [args]"
|
||||
echo " $0 [h] [f config-file] <prog> [args]"
|
||||
exit
|
||||
}
|
||||
|
||||
if [ $# = 0 ] ; then
|
||||
usage
|
||||
fi
|
||||
export LD_PRELOAD=libproxychains.so
|
||||
|
||||
if [ $1 = "-h" ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$1" = "-f" ]; then
|
||||
export PROXYCHAINS_CONF_FILE=$2;
|
||||
shift;
|
||||
shift;
|
||||
fi
|
||||
|
||||
export LD_PRELOAD=libproxychains.so.3
|
||||
exec "$@"
|
||||
|
||||
@@ -41,6 +41,16 @@ proxy_dns
|
||||
tcp_read_time_out 15000
|
||||
tcp_connect_time_out 8000
|
||||
|
||||
# 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
|
||||
|
||||
## Exclude connections to 192.168.100.0/24
|
||||
# localnet 192.168.100.0/255.255.255.0
|
||||
|
||||
## Exclude connections to ANYwhere with port 80
|
||||
# localnet 0.0.0.0:80/0.0.0.0
|
||||
|
||||
# ProxyList format
|
||||
# type host port [user pass]
|
||||
# (values separated by 'tab' or 'blank')
|
||||
|
||||
Reference in New Issue
Block a user