特殊:Badtitle/NS100:Upside-Down-TernetHowTo:修订间差异
小无编辑摘要 |
小无编辑摘要 |
||
第57行: | 第57行: | ||
Create and edit a file called 'flip.pl' in `/usr/local/bin`. Paste the following: | Create and edit a file called 'flip.pl' in `/usr/local/bin`. Paste the following: | ||
<pre><nowiki> | <pre><nowiki> | ||
#!/usr/bin/perl | #!/usr/bin/perl | ||
$|=1; | $|=1; | ||
$count = 0; | $count = 0; | ||
第108行: | 第108行: | ||
# Enable routing. | # Enable routing. | ||
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward | |||
# Masquerade. | # Masquerade. |
2010年5月20日 (四) 00:42的最新版本
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/Upside-Down-TernetHowTo }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/af | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|Afrikaans| [[::Upside-Down-TernetHowTo/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/ar | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|العربية| [[::Upside-Down-TernetHowTo/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/az | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|azərbaycanca| [[::Upside-Down-TernetHowTo/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/bcc | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|جهلسری بلوچی| [[::Upside-Down-TernetHowTo/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/bg | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|български| [[::Upside-Down-TernetHowTo/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/br | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|brezhoneg| [[::Upside-Down-TernetHowTo/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/ca | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|català| [[::Upside-Down-TernetHowTo/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/cs | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|čeština| [[::Upside-Down-TernetHowTo/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/de | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|Deutsch| [[::Upside-Down-TernetHowTo/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/el | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|Ελληνικά| [[::Upside-Down-TernetHowTo/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/es | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|español| [[::Upside-Down-TernetHowTo/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/fa | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|فارسی| [[::Upside-Down-TernetHowTo/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/fi | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|suomi| [[::Upside-Down-TernetHowTo/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/fr | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|français| [[::Upside-Down-TernetHowTo/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/gu | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|ગુજરાતી| [[::Upside-Down-TernetHowTo/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/he | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|עברית| [[::Upside-Down-TernetHowTo/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/hu | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|magyar| [[::Upside-Down-TernetHowTo/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/id | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|Bahasa Indonesia| [[::Upside-Down-TernetHowTo/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/it | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|italiano| [[::Upside-Down-TernetHowTo/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/ja | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|日本語| [[::Upside-Down-TernetHowTo/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/ko | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|한국어| [[::Upside-Down-TernetHowTo/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/ksh | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|Ripoarisch| [[::Upside-Down-TernetHowTo/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/mr | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|मराठी| [[::Upside-Down-TernetHowTo/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/ms | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|Bahasa Melayu| [[::Upside-Down-TernetHowTo/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/nl | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|Nederlands| [[::Upside-Down-TernetHowTo/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/no | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|norsk| [[::Upside-Down-TernetHowTo/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/oc | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|occitan| [[::Upside-Down-TernetHowTo/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/pl | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|polski| [[::Upside-Down-TernetHowTo/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/pt | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|português| [[::Upside-Down-TernetHowTo/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/ro | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|română| [[::Upside-Down-TernetHowTo/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/ru | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|русский| [[::Upside-Down-TernetHowTo/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/si | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|සිංහල| [[::Upside-Down-TernetHowTo/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/sq | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|shqip| [[::Upside-Down-TernetHowTo/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/sr | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|српски / srpski| [[::Upside-Down-TernetHowTo/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/sv | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|svenska| [[::Upside-Down-TernetHowTo/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/th | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|ไทย| [[::Upside-Down-TernetHowTo/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/tr | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|Türkçe| [[::Upside-Down-TernetHowTo/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/vi | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|Tiếng Việt| [[::Upside-Down-TernetHowTo/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/yue | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|粵語| [[::Upside-Down-TernetHowTo/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/zh | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|中文| [[::Upside-Down-TernetHowTo/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/zh-hans | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|中文(简体)| [[::Upside-Down-TernetHowTo/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Upside-Down-TernetHowTo | UbuntuHelp:Upside-Down-TernetHowTo | {{#if: | :}}Upside-Down-TernetHowTo}}/zh-hant | • {{#if: UbuntuHelp:Upside-Down-TernetHowTo|中文(繁體)| [[::Upside-Down-TernetHowTo/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:Upside-Down-TernetHowTo|:Upside-Down-TernetHowTo|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :Upside-Down-TernetHowTo/zh | | {{#ifexist: Upside-Down-TernetHowTo/zh | | {{#ifeq: {{#titleparts:Upside-Down-TernetHowTo|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:Upside-Down-TernetHowTo|1|-1|}} | zh | | }}
- title Upside-Down-Ternet HowTo
Introduction
~-Note: This guide was tested using Ubuntu 8.10. Previous versions may not work.-~ This is a HowTo for setting up Upside-Down-Ternet on Ubuntu. Basically, when a user browses the web, all the images are flipped upside-down. While it's not useful, it's quite a good April Fool's prank. The process uses a transparent proxy, web server, and script to flip the images. Web traffic is routed to the proxy, instead of the default gateway, which is intercepted by the proxy which then downloads and modifies the images and then serves them back to the client browser.
Setting up the proxy
The proxy used in this guide is Squid v2.7.
Installation
There are two versions of Squid in the repositories, Squid 2.7 (package name `squid`) and Squid 3 (package name `squid3`), the former will be installed.
sudo apt-get install squid
Configuration
Squid's configuration file is located at `/etc/squid/squid.conf`. The file comes pre-configured with default settings which you should not delete. Modify the file as follows:
- On the line starting with #http_access allow localnet, change it to read:
acl localnet src [your network range, e.g. 192.168.0.1/24] http_access allow localnet
- On the line starting with http_port 3128, append transparent so it reads:
http_port 3128 transparent
- Find the section TAG: url_rewrite_program. At the bottom of the section you should see #Default: none. Replace that line with
url_rewrite_program /usr/local/bin/flip.pl
Reload the configuration file:
sudo service squid reload
Setting up the webserver
Apache 2 will be used as the web server.
Installation
sudo apt-get install apache2
Configuration
Apache's default configuration file works fine and does not need to be changed. However, as Apache is going to be serving the modified images, a directory where those images are stored needs to be created. Create a directory where the images are to be stored and set the correct directory permissions:
sudo mkdir /var/www/images sudo chown www-data:www-data /var/www/images sudo chmod 755 /var/www/images
The images retrieved by Squid are owned by the user and group proxy. Add www-data (the user Apache runs under) to the proxy group so Apache can access the images:
sudo usermod -aG proxy www-data
Restart Apache to load changes:
service apache2 restart
Image Script
Create and edit a file called 'flip.pl' in `/usr/local/bin`. Paste the following:
#!/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++; }
Change the scripts file permissions:
sudo chmod 755 /usr/local/bin/flip.pl
Install mogrify, the program that flips the images:
sudo apt-get install mogrify
Note that you can change the script to blur or swirl the images instead of flipping them. Just edit the script and replace the -flip option with any valid mogrify option.
Networking Setup
Finally, run the following commands to turn your computer into a gateway and redirect traffic to the proxy:
#delete all rules sudo iptables -F sudo iptables -t nat -F sudo iptables -t mangle -F sudo iptables -X # Enable routing. echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward # Masquerade. sudo iptables -t nat -A POSTROUTING -j MASQUERADE # Transparent proxying sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3128
You'll then need to configure your users' default gateway to point to your computer's IP address. This varies by setup so it's not detailed here. That's it, you're done, enjoy.
References
- http://www.ex-parrot.com/~pete/upside-down-ternet.html - Upside-Down-Ternet, the original setup.
- http://www.debian-administration.org/articles/71 - Transparent proxies via Squid.
- https://wiki.aronsson.nu/howto/linux/turn-the-web-upside-down - Squid 3 implementation.
- http://www.worldofvishnu.com/tech/hack-the-computers-in-your-lan/ - Upside-Down-Ternet for your LAN.
- http://www.debian-administration.org/users/johns/weblog/1 - Another version with ARP spoofing.