Skip to content

Commit

Permalink
allow to specify own Host Header in CONNECT method via -o on commandline
Browse files Browse the repository at this point in the history
(from thieso2's fork of proxytunnel)
  • Loading branch information
Daniel Jonka committed Feb 3, 2016
1 parent 5472415 commit fc46781
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
13 changes: 11 additions & 2 deletions cmdline.c
Expand Up @@ -133,6 +133,7 @@ int cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *ar
args_info->encryptremproxy_given = 0;
args_info->proctitle_given = 0;
args_info->enforcetls1_given = 0;
args_info->host_given = 0;

/* No... we can't make this a function... -- Maniac */
#define clear_args() \
Expand All @@ -159,6 +160,7 @@ int cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *ar
args_info->encryptremproxy_flag = 0; \
args_info->proctitle_arg = NULL; \
args_info->enforcetls1_flag = 0; \
args_info->host_arg = NULL; \
}

clear_args();
Expand Down Expand Up @@ -191,6 +193,7 @@ int cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *ar
{ "remproxy", 1, NULL, 'r' },
{ "remproxyauth", 1, NULL, 'R' },
{ "proctitle", 1, NULL, 'x' },
{ "host", 1, NULL, 'o' },
{ "tlsenforce", 1, NULL, 'L' },
{ "header", 1, NULL, 'H' },
{ "verbose", 0, NULL, 'v' },
Expand All @@ -204,9 +207,9 @@ int cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *ar
{ NULL, 0, NULL, 0 }
};

c = getopt_long (argc, argv, "hVia:u:s:t:F:p:P:r:R:d:H:x:nvNeEXqL", long_options, &option_index);
c = getopt_long (argc, argv, "hVia:u:s:t:F:p:P:r:R:d:H:x:nvNeEXqLo", long_options, &option_index);
#else
c = getopt( argc, argv, "hVia:u:s:t:F:p:P:r:R:d:H:x:nvNeEXqL" );
c = getopt( argc, argv, "hVia:u:s:t:F:p:P:r:R:d:H:x:nvNeEXqLo" );
#endif

if (c == -1)
Expand Down Expand Up @@ -271,6 +274,12 @@ int cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *ar
args_info->enforcetls1_flag = 1;
break;

case 'o':
args_info->host_given = 1;
message("Host-header override enabled\n");
args_info->host_arg = gengetopt_strdup (optarg);
break;

case 'u': /* Username to send to HTTPS proxy for authentication. */
if (args_info->user_given) {
fprintf (stderr, "%s: `--user' (`-u'), `--proxyauth' (`-P') or `--passfile' (`-F') option given more than once\n", PACKAGE);
Expand Down
2 changes: 2 additions & 0 deletions cmdline.h
Expand Up @@ -49,6 +49,7 @@ struct gengetopt_args_info {
int encryptremproxy_flag; /* Turn on local to remote proxy SSL encryption (def=off).*/
char *proctitle_arg; /* Override process title (default=off). */
int enforcetls1_flag; /* Override default and enforce TLSv1 */
char *host_arg; /* Optional Host Header */
int help_given; /* Whether help was given. */
int version_given; /* Whether version was given. */
int user_given; /* Whether user was given. */
Expand All @@ -73,6 +74,7 @@ struct gengetopt_args_info {
int encryptremproxy_given; /* Whether encrypt was given */
int proctitle_given; /* Whether to override process title */
int enforcetls1_given; /* Wheter to enforce TLSv1 */
int host_given; /* Wheter we override the Host Header */
};

int cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_info );
Expand Down
6 changes: 3 additions & 3 deletions http.c
Expand Up @@ -105,11 +105,11 @@ void proxy_protocol(PTSTREAM *pts) {
if (args_info.remproxy_given ) {
if( args_info.verbose_flag )
message( "\nTunneling to %s (remote proxy)\n", args_info.remproxy_arg );
sprintf( buf, "CONNECT %s HTTP/1.1\r\nHost: %s\r\n", args_info.remproxy_arg, args_info.remproxy_arg );
sprintf( buf, "CONNECT %s HTTP/1.1\r\nHost: %s\r\n", args_info.remproxy_arg, args_info.host_arg ? args_info.host_arg : args_info.remproxy_arg );
} else {
if( args_info.verbose_flag )
message( "\nTunneling to %s (destination)\n", args_info.dest_arg );
sprintf( buf, "CONNECT %s HTTP/1.1\r\nHost: %s\r\n", args_info.dest_arg, args_info.dest_arg );
sprintf( buf, "CONNECT %s HTTP/1.1\r\nHost: %s\r\n", args_info.dest_arg, args_info.host_arg ? args_info.host_arg : args_info.dest_arg );
}

if ( args_info.user_given && args_info.pass_given ) {
Expand Down Expand Up @@ -163,7 +163,7 @@ void proxy_protocol(PTSTREAM *pts) {

if( args_info.verbose_flag )
message( "\nTunneling to %s (destination)\n", args_info.dest_arg );
sprintf( buf, "CONNECT %s HTTP/1.1\r\nHost: %s\r\n", args_info.dest_arg, args_info.dest_arg);
sprintf( buf, "CONNECT %s HTTP/1.1\r\nHost: %s\r\n", args_info.dest_arg, args_info.host_arg ? args_info.host_arg : args_info.dest_arg);

if ( args_info.remuser_given && args_info.rempass_given )
strzcat( buf, "Proxy-Authorization: Basic %s\r\n", basicauth(args_info.remuser_arg, args_info.rempass_arg ));
Expand Down

0 comments on commit fc46781

Please sign in to comment.