diff --git a/CHANGES b/CHANGES index 77d7764..9f034b3 100755 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,13 @@ +Changes to proxytunnel version 1.0.7 -- Sat Nov 24 12:32:02 CET 2001 + +- Applied patch from "Andrew Griffiths" to fix + possible string format attacks. -- Maniac +- Some code cleanup and reformatting -- Maniac +- Added '-q' / '--quiet' flag to suppress status messages, Proxytunnel + can not be completely quiet and transparant. (Not when also providing + the '-v' flag naturally) -- Maniac +- Changed ipbuf size to 16, which should be enough. -- Maniac + Changes to proxytunnel version 1.0.6 -- Thu Nov 22 10:38:10 CET 2001 - Added support for compiling on Solaris, uncomment some lines in the diff --git a/CREDITS b/CREDITS index e828656..6874672 100644 --- a/CREDITS +++ b/CREDITS @@ -8,6 +8,7 @@ people. Ralph Loader - Broken DNS w/ DynDNS patch Martin Senft - Solaris patches + Andrew Griffiths" - String format fixes Furthermore we would like to thank the wonderfull people at SourceForge diff --git a/cmdline.c b/cmdline.c index 7555b28..a92403b 100755 --- a/cmdline.c +++ b/cmdline.c @@ -57,6 +57,7 @@ cmdline_parser_print_help (void) -D INT --destport=INT Destination portnumber to built the tunnel to\n\ -n --dottedquad Convert destination hostname to dotted quad\n\ -v --verbose Turn on verbosity (default=off)\n\ + -q --quiet Suppress messages (default=off)\n\ ", PACKAGE); } @@ -76,33 +77,36 @@ gengetopt_strdup (char * s) return n; } - -int -cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) +int cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_info ) { int c; /* Character of the parsed option. */ int missing_required_options = 0; - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->user_given = 0 ; - args_info->pass_given = 0 ; - args_info->proxyhost_given = 0 ; - args_info->proxyport_given = 0 ; - args_info->desthost_given = 0 ; - args_info->destport_given = 0 ; + args_info->help_given = 0; + args_info->version_given = 0; + args_info->user_given = 0; + args_info->pass_given = 0; + args_info->proxyhost_given = 0; + args_info->proxyport_given = 0; + args_info->desthost_given = 0; + args_info->destport_given = 0; args_info->dottedquad_given = 0; - args_info->verbose_given = 0 ; + args_info->verbose_given = 0; args_info->inetd_given = 0; -#define clear_args() { \ - args_info->user_arg = NULL; \ - args_info->pass_arg = NULL; \ - args_info->proxyhost_arg = NULL; \ - args_info->desthost_arg = NULL; \ - args_info->dottedquad_flag = 0;\ - args_info->verbose_flag = 0;\ - args_info->inetd_flag = 0;\ -} + args_info->quiet_given = 0; + +/* No... we can't make this a function... -- Maniac */ +#define clear_args() \ +{ \ + args_info->user_arg = NULL; \ + args_info->pass_arg = NULL; \ + args_info->proxyhost_arg = NULL; \ + args_info->desthost_arg = NULL; \ + args_info->dottedquad_flag = 0; \ + args_info->verbose_flag = 0; \ + args_info->inetd_flag = 0; \ + args_info->quiet_flag = 0; \ +} clear_args(); @@ -131,12 +135,13 @@ cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_i { "dottedquad", 0, NULL, 'n' }, { "verbose", 0, NULL, 'v' }, { "inetd", 0, NULL, 'i' }, + { "quiet", 0, NULL, 'q' }, { NULL, 0, NULL, 0 } }; - c = getopt_long (argc, argv, "hViu:s:g:G:d:D:nv", long_options, &option_index); + c = getopt_long (argc, argv, "hViu:s:g:G:d:D:nvq", long_options, &option_index); #else - c = getopt( argc, argv, "hViu:s:g:G:d:D:nv" ); + c = getopt( argc, argv, "hViu:s:g:G:d:D:nvq" ); #endif if (c == -1) break; /* Exit from `while (1)' loop. */ @@ -231,6 +236,10 @@ cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_i args_info->verbose_flag = !(args_info->verbose_flag); break; + case 'q': /* Suppress messages -- Quiet mode */ + args_info->quiet_flag = !(args_info->quiet_flag); + break; + case 0: /* Long option with no short option */ case '?': /* Invalid option. */ diff --git a/cmdline.h b/cmdline.h index 540a442..06db0dd 100755 --- a/cmdline.h +++ b/cmdline.h @@ -24,32 +24,34 @@ #define _cmdline_h struct gengetopt_args_info { - char * user_arg; /* Username to send to HTTPS proxy for authentication. */ - char * pass_arg; /* Password to send to HTTPS proxy for authentication. */ - char * proxyhost_arg; /* HTTPS Proxy host to connect to. */ - int proxyport_arg; /* HTTPS Proxy host portnumber to connect to. */ - char * desthost_arg; /* Destination host to built the tunnel to. */ - int destport_arg; /* Destination host portnumber to built the tunnel to. */ + char * user_arg; /* Username to send to HTTPS proxy for auth. */ + char * pass_arg; /* Password to send to HTTPS proxy for auth. */ + char * proxyhost_arg; /* HTTPS Proxy host to connect to. */ + int proxyport_arg; /* HTTPS Proxy host portnumber to connect to. */ + char * desthost_arg; /* Destination host to built the tunnel to. */ + int destport_arg; /* Dest host portnumber to built the tunnel to. */ int dottedquad_flag; /* Resolve hostname to dottedquad notation. */ - int verbose_flag; /* Turn on verbosity (default=off). */ - int inetd_flag; /* Turn on inetd (default=off). */ + int verbose_flag; /* Turn on verbosity (default=off). */ + int inetd_flag; /* Turn on inetd (default=off). */ + int quiet_flag; /* Turn on quiet mode (default=off). */ - int help_given ; /* Whether help was given. */ - int version_given ; /* Whether version was given. */ - int user_given ; /* Whether user was given. */ - int pass_given ; /* Whether pass was given. */ - int proxyhost_given ; /* Whether proxyhost was given. */ - int proxyport_given ; /* Whether proxyport was given. */ - int desthost_given ; /* Whether desthost was given. */ - int destport_given ; /* Whether destport was given. */ + int help_given; /* Whether help was given. */ + int version_given; /* Whether version was given. */ + int user_given; /* Whether user was given. */ + int pass_given; /* Whether pass was given. */ + int proxyhost_given; /* Whether proxyhost was given. */ + int proxyport_given; /* Whether proxyport was given. */ + int desthost_given; /* Whether desthost was given. */ + int destport_given; /* Whether destport was given. */ int dottedquad_given; /* Whether dottedquad was given. */ - int verbose_given ; /* Whether verbose was given. */ - int inetd_given ; /* Whether inetd was given. */ + int verbose_given; /* Whether verbose was given. */ + int inetd_given; /* Whether inetd was given. */ + int quiet_given; /* Whether quiet mode was given. */ } ; -int cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info); +int cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_info ); -void cmdline_parser_print_help(void); -void cmdline_parser_print_version(void); +void cmdline_parser_print_help( void ); +void cmdline_parser_print_version( void ); #endif /* _cmdline_h */ diff --git a/config.h b/config.h index d55c2da..273f5ba 100755 --- a/config.h +++ b/config.h @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define VERSION "1.0.6" +#define VERSION "1.0.7" #define PACKAGE "Proxytunnel" #define PURPOSE "Build generic tunnels through HTTPS proxys" #define AUTHORS "Jos Visser (Muppet) , Mark Janssen (Maniac) " diff --git a/proxytunnel b/proxytunnel index f750324..9c8897f 100755 Binary files a/proxytunnel and b/proxytunnel differ diff --git a/proxytunnel.c b/proxytunnel.c index 1762f90..b194c1b 100755 --- a/proxytunnel.c +++ b/proxytunnel.c @@ -37,20 +37,6 @@ static const char base64digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -#define BAD -1 -static const char base64val[] = { - BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, - BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, - BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD, 62, BAD,BAD,BAD, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,BAD,BAD, BAD,BAD,BAD,BAD, - BAD, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,BAD, BAD,BAD,BAD,BAD, - BAD, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,BAD, BAD,BAD,BAD,BAD -}; -/* bounds-check input */ -#define DECODE64(c) (isascii(c) ? base64val[c] : BAD) - /* * Some variables */ @@ -64,7 +50,7 @@ int write_fd=1; /* The file destriptor to write to */ struct gengetopt_args_info args_info; #define SIZE 80 -char basicauth[SIZE]; /* Buffer to hold the proxy's basic authentication screen */ +char basicauth[SIZE]; /* Buffer to hold the proxy's basic auth */ #define SIZE2 65536 char buf[SIZE2]; /* Data transfer buffer */ @@ -73,7 +59,7 @@ char buf[SIZE2]; /* Data transfer buffer */ * Small MAX macro */ #ifndef MAX -#define MAX(x,y) (((x)>(y))?(x):(y)) +#define MAX( x, y ) ( ( (x)>(y) ) ? (x) : (y) ) #endif @@ -142,7 +128,8 @@ void tunnel_connect() { /* * Create the socket */ - if ((sd=socket(AF_INET,SOCK_STREAM,0))<0) { + if( ( sd = socket( AF_INET, SOCK_STREAM, 0 ) ) < 0 ) + { perror("Can not create socket"); exit(1); } @@ -150,109 +137,131 @@ void tunnel_connect() { /* * Lookup the IP address of the proxy */ - if (!(he=gethostbyname(args_info.proxyhost_arg))) { + if( ! ( he = gethostbyname( args_info.proxyhost_arg ) ) ) + { perror("Proxy host not found"); exit(1); } - if (args_info.verbose_flag) - fprintf(stderr,"%s is %d.%d.%d.%d\n",args_info.proxyhost_arg, - he->h_addr[0], he->h_addr[1], he->h_addr[2], he->h_addr[3]); + if( args_info.verbose_flag ) + { + fprintf( stderr, "%s is %d.%d.%d.%d\n", + args_info.proxyhost_arg, + he->h_addr[0] & 255, + he->h_addr[1] & 255, + he->h_addr[2] & 255, + he->h_addr[3] & 255 ); + } /* * Set up the structure to connect to the proxy port of the proxy host */ - memset (&sa, '\0', sizeof(sa)); - sa.sin_family=AF_INET; - memcpy(&sa.sin_addr.s_addr,he->h_addr,4); - sa.sin_port= htons(args_info.proxyport_arg); + memset( &sa, '\0', sizeof( sa ) ); + sa.sin_family = AF_INET; + memcpy( &sa.sin_addr.s_addr, he->h_addr, 4); + sa.sin_port = htons( args_info.proxyport_arg ); /* * Connect the socket */ - if (connect(sd,(struct sockaddr*) &sa,sizeof(sa))<0) { + if( connect( sd, (struct sockaddr*) &sa, sizeof( sa ) ) < 0 ) + { perror("connect() failed"); exit(1); } - fprintf(stderr,"Connected to %s:%d\n",args_info.proxyhost_arg,args_info.proxyport_arg); + if( ! args_info.quiet_flag ) + { + fprintf( stderr, "Connected to %s:%d\n", + args_info.proxyhost_arg, + args_info.proxyport_arg ); + } } /* * Create the HTTP basic authentication cookie for use by the proxy. Result * is stored in basicauth. */ -void make_basicauth() { - int len=strlen(args_info.user_arg)+strlen(args_info.pass_arg)+2; - char *p=(char *)malloc(len); +void make_basicauth() +{ + int len = strlen( args_info.user_arg ) + \ + strlen( args_info.pass_arg ) + 2; + char *p = (char *) malloc( len ); /* * Set up the cookie in clear text */ - sprintf(p,"%s:%s",args_info.user_arg,args_info.pass_arg); + sprintf( p, "%s:%s", args_info.user_arg, args_info.pass_arg ); /* * Base64 encode the clear text cookie to create the HTTP base64 * authentication cookie */ - base64( basicauth, p, strlen(p)); - fprintf(stderr,"Proxy basic authentication is %s\n",basicauth); + base64( basicauth, p, strlen( p ) ); - if (args_info.verbose_flag) - fprintf(stderr,"Proxy basic authentication is %s\n",basicauth); + if( args_info.verbose_flag ) + { + fprintf( stderr, "Proxy basic auth is %s\n", basicauth ); + } - free(p); + free( p ); } /* * Read one line of data from the tunnel. Line is terminated by a * newline character. Result is stored in buf. */ -void readline() { - char *p=buf; - char c=0; - int i=0; +void readline() +{ + char *p = buf; + char c = 0; + int i = 0; /* * Read one character at a time into buf, until a newline is * encountered. */ - while (c!=10 && i