Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added getting proxy from env PROXYCHAINS_ONE_PROXY #276

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ Usage Example:
in this example it will resolve targethost.com through proxy(or chained proxies)
specified by proxychains.conf

Usage Example:
$ PROXYCHAINS_ONE_PROXY="socks4 127.0.0.1 9050" proxychains telnet targethost.com

in this example it will using only proxy from envirmoment variable PROXYCHAINS_ONE_PROXY
and ignore proxy list from config file

Known Problems:
---------------
- newer versions of nmap try to determine the network interface to use
Expand Down
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#define PROXYCHAINS_CONF_FILE_ENV_VAR "PROXYCHAINS_CONF_FILE"
#define PROXYCHAINS_QUIET_MODE_ENV_VAR "PROXYCHAINS_QUIET_MODE"
#define PROXYCHAINS_ONE_PROXY_ENV_VAR "PROXYCHAINS_ONE_PROXY"
#define PROXYCHAINS_CONF_FILE "proxychains.conf"
#define LOG_PREFIX "[proxychains] "
#ifndef SYSCONFDIR
Expand Down
92 changes: 53 additions & 39 deletions src/libproxychains.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pthread_once_t init_once = PTHREAD_ONCE_INIT;
static int init_l = 0;

static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct);
inline int populate_proxychain(proxy_data * pd, unsigned int *proxy_count, chain_type * ct, char * buff, int count);

static void* load_sym(char* symname, void* proxyfunc) {

Expand Down Expand Up @@ -259,9 +260,10 @@ static int proxy_from_string(const char *proxystring,

/* 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;
char buff[1024], type[1024], host[1024], user[1024];
int count = 0, list = 0;
char buff[1024], user[1024];
char *env;
char *env_one_proxy_line;
char local_in_addr_port[32];
char local_in_addr[32], local_in_port[32], local_netmask[32];
FILE *file = NULL;
Expand All @@ -275,57 +277,27 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
*ct = DYNAMIC_TYPE;

env = get_config_path(getenv(PROXYCHAINS_CONF_FILE_ENV_VAR), buff, sizeof(buff));
if( ( file = fopen(env, "r") ) == NULL )
{
if((file = fopen(env, "r")) == NULL) {
perror("couldnt read configuration file");
exit(1);
}

env_one_proxy_line = getenv(PROXYCHAINS_ONE_PROXY_ENV_VAR);
if (env_one_proxy_line)
count = populate_proxychain(pd, proxy_count, ct, env_one_proxy_line, count);

env = getenv(PROXYCHAINS_QUIET_MODE_ENV_VAR);
if(env && *env == '1')
proxychains_quiet_mode = 1;

while(fgets(buff, sizeof(buff), file)) {
if(buff[0] != '\n' && buff[strspn(buff, " ")] != '#') {
/* proxylist has to come last */
if(list) {
if(list && !env_one_proxy_line) {
if(count >= MAX_CHAIN)
break;

memset(&pd[count], 0, sizeof(proxy_data));

pd[count].ps = PLAY_STATE;
port_n = 0;

int ret = sscanf(buff, "%s %s %d %s %s", type, host, &port_n, pd[count].user, pd[count].pass);
if(ret < 3 || ret == EOF) {
if(!proxy_from_string(buff, type, host, &port_n, pd[count].user, pd[count].pass)) {
inv:
fprintf(stderr, "error: invalid item in proxylist section: %s", buff);
exit(1);
}
}

memset(&pd[count].ip, 0, sizeof(pd[count].ip));
pd[count].ip.is_v6 = !!strchr(host, ':');
pd[count].port = htons((unsigned short) port_n);
ip_type* host_ip = &pd[count].ip;
if(1 != inet_pton(host_ip->is_v6 ? AF_INET6 : AF_INET, host, host_ip->addr.v6)) {
fprintf(stderr, "proxy %s has invalid value or is not numeric\n", host);
exit(1);
}

if(!strcmp(type, "http")) {
pd[count].pt = HTTP_TYPE;
} else if(!strcmp(type, "socks4")) {
pd[count].pt = SOCKS4_TYPE;
} else if(!strcmp(type, "socks5")) {
pd[count].pt = SOCKS5_TYPE;
} else
goto inv;

if(port_n)
count++;
count = populate_proxychain(pd, proxy_count, ct, buff, count);
} else {
if(strstr(buff, "[ProxyList]")) {
list = 1;
Expand Down Expand Up @@ -419,6 +391,48 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
PDEBUG("proxy_dns: %s\n", proxychains_resolver ? "ON" : "OFF");
}

int populate_proxychain(proxy_data * pd, unsigned int *proxy_count, chain_type * ct, char * buff, int count) {
int port_n = 0;
char type[1024], host[1024];

memset(&pd[count], 0, sizeof(proxy_data));

pd[count].ps = PLAY_STATE;
port_n = 0;

int ret = sscanf(buff, "%s %s %d %s %s", type, host, &port_n, pd[count].user, pd[count].pass);
if(ret < 3 || ret == EOF) {
if(!proxy_from_string(buff, type, host, &port_n, pd[count].user, pd[count].pass)) {
inv:
fprintf(stderr, "error: invalid item in proxylist section: %s", buff);
exit(1);
}
}

memset(&pd[count].ip, 0, sizeof(pd[count].ip));
pd[count].ip.is_v6 = !!strchr(host, ':');
pd[count].port = htons((unsigned short) port_n);
ip_type* host_ip = &pd[count].ip;
if(1 != inet_pton(host_ip->is_v6 ? AF_INET6 : AF_INET, host, host_ip->addr.v6)) {
fprintf(stderr, "proxy %s has invalid value or is not numeric\n", host);
exit(1);
}

if(!strcmp(type, "http")) {
pd[count].pt = HTTP_TYPE;
} else if(!strcmp(type, "socks4")) {
pd[count].pt = SOCKS4_TYPE;
} else if(!strcmp(type, "socks5")) {
pd[count].pt = SOCKS5_TYPE;
} else
goto inv;

if(port_n)
count++;

return count;
}

/******* HOOK FUNCTIONS *******/

int close(int fd) {
Expand Down