2011-02-25 09:40:11 +00:00
|
|
|
/***************************************************************************
|
|
|
|
main.c - description
|
2011-09-03 23:45:16 +00:00
|
|
|
|
2011-02-25 09:40:11 +00:00
|
|
|
begin : Tue May 14 2002
|
2011-09-03 23:45:16 +00:00
|
|
|
copyright : netcreature (C) 2002
|
|
|
|
email : netcreature@users.sourceforge.net
|
2011-02-25 09:40:11 +00:00
|
|
|
***************************************************************************/
|
|
|
|
/* GPL */
|
|
|
|
/***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
2011-09-03 23:45:16 +00:00
|
|
|
#include <string.h>
|
2011-02-25 09:40:11 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2011-02-25 12:21:34 +00:00
|
|
|
extern char *optarg;
|
2011-09-03 23:45:16 +00:00
|
|
|
extern int optind, opterr, optopt;
|
2011-02-25 12:21:34 +00:00
|
|
|
|
2011-09-03 23:45:16 +00:00
|
|
|
#define PROXYCHAINS_CONF_FILE "proxychains.conf"
|
2011-02-25 12:21:34 +00:00
|
|
|
|
2011-09-03 23:45:16 +00:00
|
|
|
static void usage(char** argv) {
|
|
|
|
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]);
|
2011-02-25 12:21:34 +00:00
|
|
|
}
|
|
|
|
|
2011-09-03 23:45:16 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
char *path = NULL;
|
|
|
|
char buf[256];
|
|
|
|
char pbuf[256];
|
|
|
|
int opt;
|
2011-02-25 12:21:34 +00:00
|
|
|
|
2011-09-03 23:45:16 +00:00
|
|
|
while ((opt = getopt(argc, argv, "fh:")) != -1) {
|
|
|
|
switch (opt) {
|
|
|
|
case 'h':
|
|
|
|
usage(argv);
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
path = (char *)optarg;
|
|
|
|
break;
|
|
|
|
default: /* '?' */
|
|
|
|
usage(argv);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
2011-02-25 12:21:34 +00:00
|
|
|
|
2011-09-03 23:45:16 +00:00
|
|
|
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) {
|
|
|
|
perror("couldnt find configuration file");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
have:
|
2011-02-25 12:21:34 +00:00
|
|
|
|
2011-09-04 00:03:47 +00:00
|
|
|
printf("using config file: %s\n", path);
|
|
|
|
//printf("argv = %s\n", argv[1]);
|
2011-02-25 12:21:34 +00:00
|
|
|
|
2011-09-03 23:45:16 +00:00
|
|
|
/* Set PROXYCHAINS_CONF_FILE to get proxychains lib to use new config file. */
|
|
|
|
setenv("PROXYCHAINS_CONF_FILE", 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....");
|
2011-02-25 12:21:34 +00:00
|
|
|
|
2011-09-03 23:45:16 +00:00
|
|
|
return EXIT_SUCCESS;
|
2011-02-25 09:40:11 +00:00
|
|
|
}
|