From fc467818807723b63c70f29ccfd6386e8460d2bb Mon Sep 17 00:00:00 2001 From: Daniel Jonka Date: Wed, 3 Feb 2016 17:28:22 +0100 Subject: [PATCH] allow to specify own Host Header in CONNECT method via -o on commandline (from thieso2's fork of proxytunnel) --- cmdline.c | 13 +++++++++++-- cmdline.h | 2 ++ http.c | 6 +++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cmdline.c b/cmdline.c index 538df03..8b64aa9 100644 --- a/cmdline.c +++ b/cmdline.c @@ -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() \ @@ -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(); @@ -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' }, @@ -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) @@ -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); diff --git a/cmdline.h b/cmdline.h index 8c51e4c..01a92ad 100644 --- a/cmdline.h +++ b/cmdline.h @@ -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. */ @@ -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 ); diff --git a/http.c b/http.c index 3b7f6b9..eb9f88f 100644 --- a/http.c +++ b/http.c @@ -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 ) { @@ -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 ));