1 /* (C) 2011, 2012 rofl0r
3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. *
8 ***************************************************************************/
10 #define _DEFAULT_SOURCE
16 #include <sys/types.h>
20 #define _DARWIN_C_SOURCE
26 static int usage(char **argv
) {
27 printf("\nUsage:\t%s -q -f config_file program_name [arguments]\n"
28 "\t-q makes proxychains quiet - this overrides the config setting\n"
29 "\t-f allows one to manually specify a configfile to use\n"
30 "\tfor example : proxychains telnet somehost.com\n" "More help in README file\n\n", argv
[0]);
34 static const char *dll_name
= DLL_NAME
;
36 static char own_dir
[256];
37 static const char *dll_dirs
[] = {
38 #ifndef SUPER_SECURE /* CVE-2015-3887 */
50 static void set_own_dir(const char *argv0
) {
51 size_t l
= strlen(argv0
);
52 while(l
&& argv0
[l
- 1] != '/')
54 if(l
== 0 || l
>= sizeof(own_dir
))
56 memcpy(own_dir
, "/dev/null/", 11);
58 memcpy(own_dir
, ".", 2);
61 memcpy(own_dir
, argv0
, l
- 1);
66 #define MAX_COMMANDLINE_FLAGS 2
68 int main(int argc
, char *argv
[]) {
75 const char *prefix
= NULL
;
77 if(argc
== 2 && !strcmp(argv
[1], "--help"))
80 for(i
= 0; i
< MAX_COMMANDLINE_FLAGS
; i
++) {
81 if(start_argv
< argc
&& argv
[start_argv
][0] == '-') {
82 if(argv
[start_argv
][1] == 'q') {
85 } else if(argv
[start_argv
][1] == 'f') {
87 if(start_argv
+ 1 < argc
)
88 path
= argv
[start_argv
+ 1];
98 if(start_argv
>= argc
)
101 /* check if path of config file has not been passed via command line */
102 path
= get_config_path(path
, pbuf
, sizeof(pbuf
));
105 fprintf(stderr
, LOG_PREFIX
"config file found: %s\n", path
);
107 /* Set PROXYCHAINS_CONF_FILE to get proxychains lib to use new config file. */
108 setenv(PROXYCHAINS_CONF_FILE_ENV_VAR
, path
, 1);
111 setenv(PROXYCHAINS_QUIET_MODE_ENV_VAR
, "1", 1);
117 dladdr(own_dir
, &dli
);
118 set_own_dir(dli
.dli_fname
);
123 snprintf(buf
, sizeof(buf
), "%s/%s", dll_dirs
[i
], dll_name
);
124 if(access(buf
, R_OK
) != -1) {
125 prefix
= dll_dirs
[i
];
132 fprintf(stderr
, "couldnt locate %s\n", dll_name
);
136 fprintf(stderr
, LOG_PREFIX
"preloading %s/%s\n", prefix
, dll_name
);
138 #if defined(IS_MAC) || defined(IS_OPENBSD)
139 #define LD_PRELOAD_SEP ":"
141 /* Dynlinkers for Linux and most BSDs seem to support space
142 as LD_PRELOAD separator, with colon added only recently.
143 We use the old syntax for maximum compat */
144 #define LD_PRELOAD_SEP " "
148 putenv("DYLD_FORCE_FLAT_NAMESPACE=1");
149 #define LD_PRELOAD_ENV "DYLD_INSERT_LIBRARIES"
151 #define LD_PRELOAD_ENV "LD_PRELOAD"
153 char *old_val
= getenv(LD_PRELOAD_ENV
);
154 snprintf(buf
, sizeof(buf
), LD_PRELOAD_ENV
"=%s/%s%s%s",
156 /* append previous LD_PRELOAD content, if existent */
157 old_val
? LD_PRELOAD_SEP
: "",
158 old_val
? old_val
: "");
160 execvp(argv
[start_argv
], &argv
[start_argv
]);
161 fprintf(stderr
, "proxychains: can't load process '%s'.", argv
[start_argv
]);
162 perror(" (hint: it's probably a typo)");