📜 ⬆️ ⬇️

We turn over the Internet on April 1st

image

In order to arrange a complete revolution of the Internet we need

1) Server distributing Internet for local network
2) Proxy server
3) 15 minutes time
')
The scheme is very simple. The proxy will work in transparent mode and transfer all links to images to the script, which can download and modify these images.



Squid configuration:

  acl localnet src 192.168.0.0/24
 http_access allow localnet
 http_port 3128 transparent
 url_rewrite_program /usr/local/bin/flip.pl 


Pictures will fall in / var / www / images
You need to properly configure the rights. Since in ubuntu squid will work from under the proxy user

Script to convert images. Save as /usr/local/bin/flip.pl

 #! / usr / bin / perl
 $ | = 1;
 $ count = 0;
 $ pid = $$;
 while (<>) {
         chomp $ _;
         if ($ _ = ~ /(.*\.jpg)/i) {
                 $ url = $ 1;
                 system ("/ usr / bin / wget", "-q", "-O", "/ var / www / images / $ pid- $ count.jpg", "$ url");
                 system ("/ usr / bin / mogrify", "-flip", "/ var / www / 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", "/ var / www / images / $ pid- $ count.gif", "$ url");
                 system ("/ usr / bin / mogrify", "-flip", "/ var / www / images / $ pid- $ count.gif");
                 print "http://127.0.0.1/images/$pid-$count.gif\n";

         }
         elsif ($ _ = ~ /(.*\.png)/i) {
                 $ url = $ 1;
                 system ("/ usr / bin / wget", "-q", "-O", "/ var / www / images / $ pid- $ count.png", "$ url");
                 system ("/ usr / bin / mogrify", "-flip", "/ var / www / images / $ pid- $ count.png");
                 print "http://127.0.0.1/images/$pid-$count.png\n";

         }
         else {
                 print "$ _ \ n" ;;
         }
         $ count ++;
 }


After that we include a redirect to iptables:

  sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3128 

Source: https://habr.com/ru/post/141197/


All Articles