I needed to access a website from behind an authenticated HTTP proxy via an automated script and I didn’t know the protocol. I managed to capture some packets from a lynx session which is set up to utilize the gateway and figured it out.
The proper request looks something like this:
telnet proxy.whatever.com 80
Trying 123.123.123.123…
Connected to proxy.whatever.com.
Escape character is ‘^]’.
GET http://www.google.com HTTP/1.0
Proxy-Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
The first ‘telnet…’ and the last two lines are of course what you would type in and the rest is the output from the other end of the telnet pipe.
The Proxy-Authorization header tells the proxy that the information immediately following the colon are the requester’s credentials. The Basic denotes the credential encoding type (I think) of base64. Finally, that long mash of letters, numbers, and symbols is the base64 encoding of your username and password glued together with a colon like the following
username:password
Finally, you tap enter twice (possibly once if you are on a windows machine) and presto, telnet should barf out your requested web page’s HTML if you’ve done everything correctly.
If you are wondering how you can encode your credentials, you can use the following perl code:
#!/usr/bin/perl
use MIME::Base64;
print encode_base64($ARGV[0].’:’.$ARGV[1]);
Just pass the script your username and password from the command line and it will print out your base64 encoded string, like this:
/tmp/base64.pl username password
dXNlcm5hbWU6cGFzc3dvcmQ=