Login Register


Tutorial Turning a Home Computer into a Proxy Server. filter_list
Author
Message
Turning a Home Computer into a Proxy Server. #1
I guess this should go here?

So I decided to provide you guys with a guide to turning your home computer into a proxy So I decided to provide you guys with a guide to turning your home computer into a proxy server.
Not only did I want a proxy server, but for ease of access, and just something to do, I wanted a GUI interface to go with it all.
While doing all this, I got a bit caught up and also added a web interface.
The original application I wrote for a windows machine, I don't plan on releasing the code for, however for this tutorial I did come up with some similar code in Python to give you an idea of how I set up the application.

This entire tutorial is based on using Windows, although you can technically institute most of this (aside from the method of setting proxy settings) on most distributions of Linux as well as Mac OSX.

Setting up a Web Interface

The first step in setting up a web interface that will be accessible from outside your Local Area Network, is getting a web development environment such as XAMPP or WAMP. I guess it's really your choice and all, but keep in mind XAMPP is cross-platform, which sometimes makes it the preferred alternative. Regardless though, I have more experience with WAMP, so I went with WAMP on Windows. Just go to their website and install the WAMP server according to your machine specs. Also, you're going to need Visual C++ 2010 SP1 Redistributable Package x86 or x64.

Once you've installed WAMP, navigate to your WAMP directory which is usually something like C:\wamp and file the folder labeled www. This is where you'll want to store the web application we'll be downloading in a moment, and when you put everything online, the index.php/index.html in that directory will be your home page.

Now that you've gotten acquainted with WAMP we're going to need a web application. We could build our own, and it wouldn't really be that complicated, but for those less web development savy people like myself, a great alternative is installing PHProxy.

PHProxy is this neat little web proxy that allows you to bypass restrictions such as filters. When you connect to your home proxy server (if I'm correct) the request to whatever website you're trying to access will actually be sent from your home server, which doesn't have a filter. That's how it allows you to bypass filters on a LAN.

After you've downloaded PHProxy, you need to unzip it, and drag all the files into that www directory, replacing any index.php or index.html/htm file with the index.php file found in PHProxy. To test to see if you've installed it correctly, simply navigate to "http://localhost".

It's really that simple. After you've installed it, you can make any kind of tweaks and modifications you want as long as it conforms to the license provided with PHProxy (which I haven't examined at all). So, modify at your own risk. You should probably keep the bottom PHProxy link visible. Wink

Port Forwarding on your Router

You need to do this. If you want your web application accessible from outside your LAN, this is a must. Port forwarding is a bit different for every router, but you should be able to a bunch of guides for whichever router you have on PortForward. What I did, was forward port 80 and port 443 for HTTP and HTTPS. Once you've done this and WAMP is up and running, you can click the WAMP tray icon, and put your application "online". You might run into a few issues, but those can be resolved by some simple error googling.
To confirm your application is online, visit WhatIsMyIP to grab your IP address. Your home server will be running from that address. So simply navigate to http://yourip on n a machine that's not on your local area network. That's very important. If it is on the same network as you, that won't work.

Putting Your Web Application Online

When Tree came out with his auto-activation method, the use of FreeDNS really prompted this method of uploading your application. You can use freedns to point one of the thousands of subdomains you can get for FREE to your home server's IP address. Just follow these simple steps.

  1. Make a freedns account, as Tree said, use a valid email.
  2. After you've logged in, go to the Registry link on the far left.
  3. Search whatever phrase you want for your domain. For example, you could search "proxy" and use one of the 10 or so proxy domains without buying your own.
  4. Click on whichever domain you'd link, and an option screen listing type, subdomain, domain, destination, TTL, and wildcard should come up. The only thing you need to do is set your subdomain and your destination.

Your subdomain should be whatever you want it to be, for example, mycoolproxy.proxybiz.net or something. In this case, mycoolproxy would be the subdomain you entered. Here's the really important part though. As the destination you MUST enter the external IP address of your home server. FreeDNS will fill this input box out with your IP address, make sure it's the IP address of your home server and not a laptop you're using. Then simply save your settings and navigate to your site. mycoolproxy.proxybiz.net should direct you to your custom home server proxy home page.

There's many other ways to set up your own domain, none of which I'll go into now. But just google "make my own domain" if you feel like paying for a custom name.

Running a secondary (traditional) proxy

To use the IP address of your home computer as a proxy on, say, Internet Explorer or Google Chrome, you'll need the IP and a port number, and a web application just won't suffice as far as I know.
To set up this second section, I used something called Privoxy. Go to the URL, download Privoxy, and install it.
The only issues I've had with Privoxy are some bugs I've been able to iron out.
After you've downloaded Privoxy, open up the application, and your server should be live. I've had a few problems with it, and you might need to change a certain text file's contents. If you receive an error (which you probably will) just Google the error and you'll see all the answers are the same. Unfortunately I didn't write down the error and don't have time to reproduce it tonight.
So during installation you can set up Privoxy to run at startup (which is probably what you want). After it's open your proxy server is live. As long as port forwarding is turned on, you can use your home proxy server from your web browser by using the IP of your home server and the port 8118

Setting up an Application to do it for Us

As I said before, I wanted a GUI frontend because that's just the kind of guy I am. The original one I wrote wasn't in Python, but for this tutorial I whipped up a quick, working representation. Albeit the code isn't very good (mainly because I don't actually know Python) and it doesn't conform to all the PEP-8 standards. So forgive me for that. But either way, here's the code.
It was written for Python 2.7.3 and uses only imports from the Python standard library.

PHP Code:
import os import sys import time import urllib2 import socket import ConfigParser from subprocess import call from sys import stdout #Global Variables ini = ConfigParser.RawConfigParser() ini_file = 'proxy_config.ini' server = '127.0.0.1' port = 8118 address = '%s:%i' % (server, port) status = 'off' #Check Status of Proxy def check_status(): global status ini.read(ini_file) status = ini.get('SETTINGS', 'status') return status #Read Settings from ini File def read_info(): global server, port ini.read(ini_file) server = ini.get('SETTINGS', 'server') port = ini.getint('SETTINGS', 'port') #Prompt User for Settings def prompt_info(): global server, port, status server = raw_input('Please enter the IP address of your proxy server: ') port = int(raw_input('Please enter the port number your proxy server is running on: ')) status = raw_input('Is the proxy server currently on or off (on/off)?: ') #Write Data to ini File ini.add_section('SETTINGS') ini.set('SETTINGS', 'server', server) ini.set('SETTINGS', 'port', port) ini.set('SETTINGS', 'status', status) write_ini() #Proxy Status Checking def is_invalid_proxy(proxy): try: proxy_handler = urllib2.ProxyHandler({'http': proxy}) opener = urllib2.build_opener(proxy_handler) opener.addheaders = [('User-agent', 'Mozilla/5.0')] urllib2.install_opener(opener) req = urllib2.Request('http://www.google.com') sock = urllib2.urlopen(req) except urllib2.HTTPError, e: stdout.write('Error Code: ', e.code) return e.code except Exception, detail: stdout.write('Error: ', detail) return True return False #Turn Proxy on/off by Writing Info to Registry def write_registry(bool_value): if (bool_value): call('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f') call('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d ' + address + ' /f') else: call('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f') call('reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /f') stdout.write('Settings have successfully been written to registry.\n') #Process to Turn on the Proxy def turn_on(): global address read_info() address = '%s:%i' % (server, port) #Proxy Check os.system('title Proxy Configuration') stdout.write('Connecting to the server %s on the port %i...\n' % (server, port)) time.sleep(2) if is_invalid_proxy(address): stdout.write('Unable to connect to home proxy server on %s\n' % address) else: stdout.write('Successfully connected to proxy server on %s!\n' % address) time.sleep(0.5) stdout.write('Writing settings to registry...\n') time.sleep(0.5) write_registry(True) ini.set('SETTINGS', 'status', 'on') write_ini() #Process to Turn off the Proxy def turn_off(): stdout.write('Writing settings to registry...\n') time.sleep(0.5) write_registry(False) ini.set('SETTINGS', 'status', 'off') write_ini() #Write Current Settings to the ini File def write_ini(): with open(ini_file, 'w') as configfile: ini.write(configfile) def __main__(): #Check if ini File Exists if (os.path.exists(ini_file) == 0): prompt_info() #Check if Proxy is on or off if (check_status() == 'on'): stdout.write('The proxy is currently on. Turning off the proxy now...\n') turn_off() else: stdout.write('The proxy is currently off. Turning on the proxy now...\n') turn_on() __main__() raw_input('Press any key to exit.')


The code is actually pretty shit and incredibly inefficient, but again, I don't know Python and it was written quick and dirty for the purpose of this tutorial. Any code criticisms and critiques would be appreciated, since though I'm not trying to learn Python at the moment, I'd still love the feedback.

The code essentially works off of an .ini file called proxy_config.ini. Any information should be in the format.

Code:
[SETTINGS] server = 127.0.0.1 port = 8118 status = on


Even without an .ini file, the code will create its own, according to your input. The code will then check the proxy server to see if it's open for connection (by making a request to google.com utilizing the proxy server). It will then set proxy settings on a Windows machine to those specified.

It does this through this module

PHP Code:
#Turn Proxy on/off by Writing Info to Registry def write_registry(bool_value): if (bool_value): call('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f') call('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d ' + address + ' /f') else: call('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f') call('reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /f') stdout.write('Settings have successfully been written to registry.\n')


Here, you can see the registry values edited to either turn the proxy settings on or off.
That's really what's behind the entire application.

So there you go. That's my guide on turning your home computer into a proxy server and writing an application to connect to this server.
[Image: xlbdwZT.png]

Reply

RE: Turning a Home Computer into a Proxy Server. #2
Wow that's really in-depth. Although what would be the point of having a proxy on your computer, wouldn't you want it on someone else's?

Reply

RE: Turning a Home Computer into a Proxy Server. #3
(08-04-2013, 06:21 PM)Kinanizer Wrote: Wow that's really in-depth. Although what would be the point of having a proxy on your computer, wouldn't you want it on someone else's?

Exactly, Like say if You " R.A.T " someone you could do like that or a botnet or something idk. I don't really do any of that.
[Image: xlbdwZT.png]

Reply

RE: Turning a Home Computer into a Proxy Server. #4
(08-04-2013, 09:37 PM)Blue Wrote: Exactly, Like say if You " R.A.T " someone you could do like that or a botnet or something idk. I don't really do any of that.

I suppose, but with all the free and secure proxies out there I feel like it'd be a waste. Although I guess I just don't have a use for it. But you did make a really HQ TUT here, hopefully it helps someone.

Reply

RE: Turning a Home Computer into a Proxy Server. #5
Very nice tutorial. I'd just use a VPN, although this is great for people that need a quick proxy.
[Image: 7ajmN5P.jpg]

Telegram: Oni_SL (Link)

Reply







Users browsing this thread: