Since the Linux proxy server is between the browser and the internet, this is a very good position to alter the delivered content.
You can change images or ads or whatever. This can be done using the url_rewrite_program module.
Actually, you can do more than that, but we don’t want to be evil.
In our example, we will flip the images and surf the flipped images instead of the original.
sudo apt install imagemagick
Then we will write the script that will do the magic.
The script will be written in Perl.
You can find the script here
#!/usr/bin/perl $|=1; $count = 0; $pid = $$; while (<>) { chomp $_; if ($_ =~ /(.*\.jpg)/i) { $url = $1; system("/usr/bin/wget", "-q", "-O","/space/WebPages/images/$pid-$count.jpg", "$url"); system("/usr/bin/mogrify", "-flip","/space/WebPages/images/$pid-$count.jpg"); print "http://127.0.0.1/images/$pid-$count.jpg\n"; } elsif ($_ =~ /(.*\.gif)/i) { $url = $1; system("/usr/bin/wget", "-q", "-O","/space/WebPages/images/$pid-$count.gif", "$url"); system("/usr/bin/mogrify", "-flip","/space/WebPages/images/$pid-$count.gif"); print "http://127.0.0.1/images/$pid-$count.gif\n"; } else { print "$_\n";; } $count++; }
This Perl script searches for JPG, GIF, and PNG, images in the carried content, once it is found, it uses mogrify utility that shipped with ImageMagick to flip the images and put the flipped image in /var/www/html/ which is the root directory for Apache server and apache service should be running of course, then send the flipped images as a response.
Add ownership for squid for this folder:
sudo usermod -aG www-data squid
Tell squid about this script. Open the configuration file and type the following:
... url_rewrite_program /home/likegeeks/flip.pl ...
sudo systemctl restart squid
The web has a lot of Perl scripts that play with the content, some of them are good, and some others are evil.