Home
If you are
using Squid as an anonymous proxy then you might like this perl script. It was
made to change the User-Agent string in the squid.conf configuration file
before squid was restarted or reconfigured.
The idea is to set a random user agent string every time squid is restarted. For example, in the script we could have the words "Stargate" and "Carter" and the user agent could turn out to be "Stargate/1.0 (Carter)" or "Carter/1.0 (Stargate)" randomly. This is _not_ a security tool, just something to keep those webalizer tools busy and the site admins confused. Instead of sending a bunch of boring Mozilla/5.0 strings as the user-agent you could send the words of your choice.
If your User-Agent was seen by remote servers as: "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.6) Gecko/20061201 Firefox/2.0.0.6 (Ubuntu-feisty)" You would now be seen as the anonymous User-Agent string: "Stargate/1.0 (Carter)" or even "Carter/1.0 (Stargate)"
Download the squid_ua_random.pl script here or take a look at the same code below in the scrollable window.
Step 1: Make sure the line that reads "my $infile = "/etc/squid/squid.conf";" actually points to your squid.conf file.
Step 2: Take a look at the line "my @digits = qw/name1 name2 name3 name4 name5/;". This is the line you will enter all of the words that will be randomly picked to be your user agent. As place holders the words name1, name2, etc are here. You can have as many words as you want as long as they are space separated and on a single line.
Step 3: Now, just execute this script before starting squid _OR_ before you execute a "squid -k reconfigure". You might also setup a cron job to execute this script and reconfigure squid every hour on the hour.
#!/usr/bin/perl -w # ### Calomel.org Squid User-Agent Randomizer ### squid_ua_random.pl # my $infile = "/etc/squid/squid.conf"; open F,$infile or die "Could not open $infile ($!)"; undef $/; # Tell perl to slurp whole file in one piece. $txt =; close F; my $useragent = &ruseragent; $txt =~ s/^(header_replace User-Agent ).*/$1$useragent/m; open F,">$infile.$^T.$$" or die "Could not create $infile.$^T.$$ ($!)"; print F $txt; close F; rename "$infile.$^T.$$", $infile or die "Error renaming $infile.$^T.$$ to $infile ($!)"; sub rdig{ my @digits = qw/name1 name2 name3 name4 name5/; srand(time ^ $$ ^ unpack "%32L*", `ps -ael | gzip`); $digits[int(rand(@digits))]; } sub ruseragent{ join '',&rdig,"/1.0 (",&rdig,")"; }
How do I test if the User-Agent is being changed by squid correctly?
You can test the browser headers at Xhaus's header test page.
Questions, comments, or suggestions? Contact Calomel.org