diff --git a/src/common.h b/src/common.h new file mode 100644 index 000000000..8e34773 --- /dev/null +++ b/src/common.h @@ -0,0 +1,2 @@ +#define PROXYCHAINS_CONF_FILE_ENV_VAR "PROXYCHAINS_CONF_FILE" +#define PROXYCHAINS_CONF_FILE "proxychains.conf" diff --git a/src/core.h b/src/core.h index e8d0d4e..581f7ce 100644 --- a/src/core.h +++ b/src/core.h @@ -18,6 +18,7 @@ #define __CORE_HEADER #define BUFF_SIZE 8*1024 // used to read responses from proxies. #define MAX_LOCALNET 1024 + /*error codes*/ typedef enum { diff --git a/src/libproxychains.c b/src/libproxychains.c index 8ce6588..fb75364 100644 --- a/src/libproxychains.c +++ b/src/libproxychains.c @@ -34,6 +34,7 @@ #include "core.h" +#include "common.h" #define satosin(x) ((struct sockaddr_in *) &(x)) #define SOCKADDR(x) (satosin(x)->sin_addr.s_addr) @@ -61,7 +62,7 @@ static void init_lib(void); static void init_lib(void) { - proxychains_write_log("ProxyChains-3.2 (http://github.com/rofl0r/proxychains)\n"); + proxychains_write_log("[proxychains v3.2] DLL init\n"); get_chain_data(proxychains_pd, &proxychains_proxy_count, &proxychains_ct); true_connect = (connect_t) dlsym(RTLD_NEXT, "connect"); @@ -156,12 +157,6 @@ static void init_lib(void) 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, @@ -188,7 +183,7 @@ static inline void get_chain_data( * Get path to configuration file from env this file has priority * if it's defined. */ - env = getenv(PROXYCHAINS_CONF_FILE); + env = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR); snprintf(buff,256,"%s/.proxychains/proxychains.conf",getenv("HOME")); diff --git a/src/main.c b/src/main.c index c1bbcd6..2f913f9 100644 --- a/src/main.c +++ b/src/main.c @@ -26,7 +26,7 @@ extern char *optarg; extern int optind, opterr, optopt; -#define PROXYCHAINS_CONF_FILE "proxychains.conf" +#include "common.h" static void usage(char** argv) { printf("\nUsage: %s [h] [f] config_file program_name [arguments]\n" @@ -34,6 +34,11 @@ static void usage(char** argv) { "More help in README file\n", argv[0]); } +int check_path(char* path) { + if(!path) return 0; + return access(path, R_OK) != -1; +} + int main(int argc, char *argv[]) { char *path = NULL; char buf[256]; @@ -54,34 +59,42 @@ int main(int argc, char *argv[]) { } } + /* check if path of config file has not been passed via command line */ if(!path) { - if(!(path = getenv("PROXYCHAINS_CONF_FILE"))) - path = getcwd(buf, sizeof(buf)); - else if(access(path, R_OK) != -1) goto have; - if(!path || - !snprintf(pbuf, sizeof(pbuf), "%s/%s", path, PROXYCHAINS_CONF_FILE) || - access(pbuf, R_OK) == -1 - ) - path = "/etc/proxychains.conf"; - else - path = pbuf; - } - if(access(path, R_OK) == -1) { + // 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; + + // priority 4: /etc/proxychains.conf + path = "/etc/proxychains.conf"; + if(check_path(path)) goto have; perror("couldnt find configuration file"); return 1; } + have: - printf("using config file: %s\n", path); - //printf("argv = %s\n", argv[1]); + printf("[proxychains config] %s\n", path); /* Set PROXYCHAINS_CONF_FILE to get proxychains lib to use new config file. */ - setenv("PROXYCHAINS_CONF_FILE", path, 1); + setenv(PROXYCHAINS_CONF_FILE_ENV_VAR, path, 1); snprintf(buf, sizeof(buf), "LD_PRELOAD=%s/libproxychains.so", LIB_DIR); putenv(buf); execvp(argv[1], &argv[1]); perror("proxychains can't load process...."); - return EXIT_SUCCESS; + return EXIT_FAILURE; }