Tuesday, March 15, 2011

Do It Yourself HTTP Proxy

How often do you find yourself accessing the Internet through a school's network, only to discover that the site you want to visit is blocked? When you turn to a proxy to let you access the site, what if the proxy site is blocked? What if you can't find an unblocked proxy? Well, usually you'd be out of luck. However, with a little planning ahead, you can make yourself a personal proxy that will most likely never be blocked. To do this, we're just need to set up an Apache web server with PHP. Here's how you do it in 4 simple steps. I included instructions on how to do this on both Windows and Linux (Ubuntu)
HTTP server courtesy of the lovely Apache Software Foundation
On a second note, I'm taking suggestions for future articles! Drop a comment on what you'd like to learn, and I'll try to write up a tutorial for you. I don't have OSX, so anything Mac related is out. Anything else if fair game though. Thanks!




1. Setting Up a WAMP/LAMP Server


The first step to getting our server up is to actually install the server. We're going to be using Apache, since it is the most popular free web server software out there. In order to let us use server side scripting, we're also going to install PHP. PHP is an easy to learn and powerful language that will be more than capable of providing the resources for powering our proxy.

Since we might as well do it now, I'm going to show you how to set up a WAMP (Windows, Apache, MySQL, PHP) server for Windows, or a LAMP (Linux, Apache, MySQL, PHP) server for Linux.

1. The first step is to download Apache. If you're on Ubuntu, you can get it out of the software repositories really easily.


apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server


It's going to ask you a few questions for MySQL, like passwords and users. It's pretty straightforward, but just try not to lose any password information.


If you're on Windows, it's also pretty easy. Just download the installation files for ApacheMySQL, and PHP. Choose the binaries, unless you want to go through a whole lot of trouble for pretty much nothing. So just install the software, and it should ask you a few simple questions on preferences and passwords. Make sure you check "Install for all users" so that it will install as a service. For "network domain", just enter localhost. 


2. Testing the LAMP/WAMP Server


Now we're going to test our server to make sure all portions of our LAMP/WAMP server are working.


On both Linux and Windows, you can just go to your browser and type "http://localhost" or "http://127.0.0.1" without the quotes as the address. The second is the loopback IP, which means "this computer" on every machine. Anyway, you should see a nice standard welcome page from Apache signaling that the web server portion is working. If it's not working, restart and check again. If it's still not working, try reinstalling, maybe something went wrong. 


To test both the PHP and MySQL packages, we're going to make use of the phpinfo() function. Create a text document called index.php and add this to it:

<?php
phpinfo();
?>

Save this and place it in your root web directory. On Linux, it's /var/www/ and on Windows it's C:\Program Files\Apache Software Foundation\Apache2.2\htdocs by default.


Resart the Apache server on Windows by going to Start>Programs>Apache HTTP Server>Control Apache Server>Resart. On Linux, just run this in a terminal with root privileges:


service apache2 restart


Now go to your server (localhost or 127.0.0.1) in your browser and you should see a whole bunch of info. Search for "mysql" and make sure that it's enabled. If so, you're all set for the final step!


3. The Proxy


Now that we have the underlying server working, we just need to get the proxy up! To do this, we're going to use a premade PHP proxy script, PHProxy. You can download it from here. 


Take the archive, and drop the files inside your root web directory, the same way we dropped index.php into it before. Make sure you delete the old index.php we made before adding the new files. Now, just restart your server and go to localhost in the browser. You should see something like this:
and boom goes the dynamite
4. Reaching Your Proxy From Outside Your Local Network


It's really cool that you have this working when you are at the computer running the server, but it's even cooler when you can access it from anywhere in the world! If you're behind a router, it's a bit more difficult, but it can be done thanks to port forwarding.


  1. Without a router:
    1. Get your IP by going to a site like whatismyip.com
    2. Take that IP, and just add "http://" in front of it. Just type that in the URL bar wherever you are, and you'll be looking at a nice, unblocked proxy!
  2. With a router:
    1. Check your local IP. Open up a terminal and type "ifconfig" on Linux or "ipconfig" on Windows. Your local IP will generally start with a 10.x.x.x or 192.x.x.x and end in a number from 2-255
    2. You need to access your router settings. This is different for each type of router, so I can't help you there. Generally, you can just go to the router's IP address, which is usually 10.x.x.1 if thats the form of your local IP, or 192.x.x.1. Replace the x's with the values from ifconfig or ipconfig. 
    3. Once you have access to the settings, you need to forward Port 80 to your local IP. This is the IP the ifconfig or ipconfig you learned in the previous step. Save the settings.
    4. Now get your external IP by going to a site like whatismyip.com
    5. Take that IP, and just add "http://" in front of it. Just type that in the URL bar wherever you are, and you'll be looking at a nice, unblocked proxy!

That's it! Enjoy your unfiltered Internet wherever you may roam. If you have any questions, just post them in the comments and I'll get back to you as soon as possible.

23 comments:

  1. You most likely won't even have access to this in school as ISPs purposely block port 80 to make sure you don't run a data center out of your house.

    ReplyDelete
  2. I've already tried this and it works. However, if you do run into that problem you can just select a different port to run Apache on, and just include that in the IP you're trying to connect to. So, say if you switch the port from the standard 80 to 333, you would just change it to "http://your-ip:333" in the URL bar on your browser.

    ReplyDelete
  3. i used to just use remote desktop on the lowest settings since my school would block anything they thought was a proxy (regularly adding new sites to the list).

    just use a low level account so if your password is sniffed,keylogged, the account has no powers but web browsing.

    @Ryan Donahue you don't have to use port 80. Use 8080 or 1337. whatever you set it to.

    ReplyDelete
  4. Oh wow this is great
    this has happened to me many times at my school and I already have wamp server installed so this will be extremely useful

    ReplyDelete
  5. Well, a good choice is portable Tor as well. But Tor gives me a headache most of the time because many servers have "tor" somewhere in their hostname. Any way to avoid this?

    ReplyDelete
  6. thanks for some cool tips actually I have no idea what tutorial I 'd like to have

    ReplyDelete
  7. Wow thats a lot of work for a single proxy.

    ReplyDelete
  8. This is great info, thanks KB!
    it really helps with privacy on the internet.

    ReplyDelete
  9. This is awesome, I could use this for my work. Risky though.

    ReplyDelete
  10. hehe, I remember back in high school simply changing the port to view blocked sites, but this is pretty nifty as well.

    ReplyDelete
  11. Thanks for the positive feedback everyone! If anyone has any requests, just leave it as a comment for any of my posts.

    ReplyDelete
  12. I have a feeling your knowledge is way over my head! Ill stick to skiing and finger typing away on my blog...ok not quite finger typing. Your tutorials are very straightforward tho..keep em coming!

    ReplyDelete
  13. Awesome stuff man! By the way, check out my blog when you get the chance! http://fillintheblanksx.blogspot.com/

    ReplyDelete
  14. Even tho nothing at my school is blocked, I thank you for this information + followed

    ReplyDelete
  15. interesting! I tried again with proxy and I didn't made it. this guide looks really good. I'll give it a go when I need it

    ReplyDelete

Please leave a comment