Playing with a Perl proxy. Part 1: Kitties everywhere

I’ve spent recently some time playing with the Perl module HTTP::Proxy which allows to create a proxy in a few lines of code. One interesting thing is that makes possible on live modifications of the content.

This code creates a proxy on the port 8080 and assings a filter to all html files. This filter will search for all img tags and will replace the source of the image.
If we run this script and configure our web browser to use a proxy on localhost:8080 we will start to see cats instead of some pictures.

Isn’t that great?

Well, it has some problems. To begin with I used a regex to parse the html instead of some module dedicated to it, so this code is messing around with the html and breaking some things. Nevertheless of that it will only alter the images with width and height properties defined. If the dimensions or the image are defined in css, javascript or other madness there is no simple way to know the appropriate size to get the right cat.

Because of this flaws I’ve tried another approach: tamper the image data itself and keep untouch the html code.

This works similar way but it applies a filter to all images and just change the image data for a different one. Besides, there are more things than cats. You can use something like proxy.pl apes to get: