Tuesday, November 24, 2009

Tunnel Firefox through SSH with a SOCKS Proxy

You should always be careful when connecting to a public WiFi connection, you don't want to end up like these poor saps at the Defcon convention.

I'm sure you have found yourself in a situation where you had an overzealous network filter block websites on a public connection (like at a library, work, or school). Or perhaps you don't quite trust the connection you are on?

If you have a Linux box at home that you can SSH into, you can set up a socks proxy to tunnel firefox over an SSH connection. To anyone else it will appear as if you were surfing from your servers connection.

The command is:

ssh -D 8080 user@host -N

(This will work with putty on windows too)

Leave that terminal running in the background then in firefox go to...

Tools > Options (Edit > Prefrences in Linux) > Advanced > Network > Connection Settings

And set up a manual proxy configuration under the SOCKS Host to connect to localhost (IP: 127.0.0.1) and port 8080.

You can also set up Pidgin to use a SOCKS proxy in the same way for more secure IM conversations.

Cheers.

Sunday, November 8, 2009

Set up a free Dynamic DNS for your home Ubuntu server.

This tutorial assumes you are using Debian based linux, such as ubuntu, and you have a server set up with root privileges on a home connection.

Update: Your router might already have Dynamic DNS functionality built it, specifically for the DynDNS service. If you can use that instead it will save yourself a lot of trouble! If not, read on and good luck :-)

DNS stands for Domain Name System, it is the service that allows you to go to google.com instead of having to remember google's IP address. A Dynamic DNS service will accept a change in IP address for a domain name. So instead of remembering your latest IP address assigned from your ISP to connect to your home server we will only have to remember one name, for example myhomeserver.dyndns.org. The server will then report any IP changes to the Dynamic DNS service.

There are a number of free Dynamic DNS services out there, for this tutorial we will be using DynDNS.

Head over to http://www.dyndns.com/ and enter in a name for your server.



You will then need to make an account with Dynamic DNS. Once you are finished it should set an IP address from where you logged in from by default. Now we are going to get your Ubuntu server to check if there is a change in IP address and if so log into your DynDNS account and report the change.

To accomplish this we are going to use the ddclient program.

First lets get ddclient from synaptic; execute this command:
sudo apt-get install ddclient

It will then run through a command line based installer and ask you a few questions to set up a basic config file. Answer all the questions it asks you, the DynDNS hostname you set, your DynDNS username and password, etc.

The tricky part is when it asks, "Enter the interface which is used for using dynamic DNS service."

If you are not behind a router or a firewall you can simply enter: eth0

But in my case I am behind a router so I cannot see what my global IP is, so I am going to use another server that will check the IP for me.

So if you are behind a router just skip this question and we will fix it manually in the config file later.

After synaptic is done installing ddclient we are going to have to manually edit the config file and add a few things. For this tutorial I am going to use emacs to edit the files.

Run the command: sudo emacs /etc/ddclient.conf

Your config file should look something like this:


# Configuration file for ddclient generated by debconf
#
# /etc/ddclient.conf

pid=/var/run/ddclient.pid
protocol=dyndns2
use=if, if=
server=members.dyndns.org
login=[your dyndns username]
password=[your dyndns password]
yoursite.dyndns.org


If your server is not behind a router then the use line should be set to "use=if, if=eth0".

However if your server is behind a router change this line,

use=if, if=

to this,

use=web, web=checkip.dyndns.com/, web-skip='IP Address'

And lastly put a new line that says,

daemon=600

This will tell the script to check your IP address every 10 minutes (600 seconds) using checkip.dyndns.com as a reference. If the IP has changed it will send an update to DynDNS else it will wait another 10 min and check again. The smallest value you are allowed to set for the update interval is every 60 seconds.

If you are using the emacs editor hold down the CTRL key and hit "X", then "S" to save your file. Then hold down CTRL again and hit "Z" to get back to the command line.


So your final configuration file should look something like this,


# Configuration file for ddclient generated by debconf
#
# /etc/ddclient.conf

daemon=600 #reports IP every 600 seconds

pid=/var/run/ddclient.pid
protocol=dyndns2
use=web, web=checkip.dyndns.com/, web-skip='IP Address'
server=members.dyndns.org
login=[your dyndns username]
password=[your dyndns password]
yoursite.dyndns.org



Now that we are all configured it is time to restart the ddclient program.

Cross your fingers and execute this command,

sudo /etc/init.d/ddclient restart

Assuming everything is set up properly ddclient should report any IP address changes. Now there is still one problem, DynDNS expects an update at LEAST once a month or else it will set your account as inactive. This is an issue if you keep the same IP for more than a month.

To avoid this we are going to make a cron job that will force ddclient to update every month.

Execute the command "crontab -e". You will be greeted with a simple editor. Add this on a new line,


00 00 28 * * ddclient -host yoursite.dyndns.org -force


Then hold down CTRL and hit X, it will ask you if you want to save, type "y" to say yes and hit enter.

Everything should work beautifully now!

Cheers.

Wednesday, July 1, 2009

Early 80's Pirate Computers

Pete Perkins, an early pioneer of pirate hardware. He created, improved, and sold copies of Apple and IBM computers. A much simpler time for computers indeed. Core Duo's are great but when it comes to homebrew 8 bit was, and still is, king.

"Whatever you're mind can conceive and your heart can believe, than you can achieve; that's the purpose of this chip."
-Pete Perkins


Friday, March 27, 2009

Internet Controled Car v2 Parallel Port



My first version of the Internet Controled Car used a BASIC stamp to handle serial communication. This was a mundane task for a complex and expensive little microchip

This new version uses a parallel port printer cable which is controlled by a C program on the server. Using a parallel port also fixed an issue where the direction commands would get "stuck" if you hit two keys at once as the BASIC stamp code didn't have a buffer. I also mounted the components to a piece of wood and some standoffs so it wasn't a mess of wires all over the place.


The Parallel Port C Program

The parallel port program, written in C, will take a parameter to set the data lines, that is pins 2 through 9, to a logic high or logic low.

Example: ppp 1l 2l 3h 5h 8l



Here is the C source code for Linux.

#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/io.h>

//#include <asm/io.h>
// Didn't work, replaced with sys/io.h


char *binprint( unsigned char x, char *buf )
{
int i;
for( i=0; i<8; i++ )
buf[7-i]=(x&(1<<i))?'1':'0';
buf[8]=0;
return buf;
}

int main( int argc, char *argv[] )
{
char c;
unsigned char val;
char buf[9];
int x;
if( argc<2 )
{
printf("Example usage: ppp 1l 2l 3h 5h 8l\n");
return 2;
}
if( ioperm(888,1,1) )
{
printf("Couldn't find parallel port (888)\n");
return 1;
}
val = inb(888);
printf("old = %s\n",binprint(val,buf));
for( x=1; x<argc; x++ )
if( argv[x][1]!='h' )
val &= ~(1<<(argv[x][0]-'1'));
else
val |= 1<<(argv[x][0]-'1');
printf("new = %s\n",binprint(val,buf));
outb(val,888);
return 0;
}

To compile save the above code, in a text editor, as ppp.c
Then in the command line execute,
gcc ppp.c -o ppp

And then drop the compiled executable into $/bin/ so it can be executed from anywhere as a linux command.

Flash controller code:
The flash controller is pretty similar to netcar v1, it detects what arrowkey is being pressed and sends the information to the PHP script. I did change the variables though so use the new actionscript,

Download: car_remote_pp.as

PHP
The PHP program, combined with the C program, is basiaclly replacing what the BASIC stamp did, turning pins high and low to control the relays.

The PHP program gets the command from the flash aplication and, depending on what that command is, executes the C program with the paramaters to turn the proper data pins logic high or low.

In my hardware configuration I mapped pin 2 for forward, so to make the car go forward you would execute,
ppp 1h
2l
Pin 3 is mapped to backward so I make 2 a logic low because you can't be going forward and backward at the same time.

To make PHP execute a program you put the command in single quotes, for example 'ppp 1h 2l'

Let this PHP file sit in the same directory as your flash app.

Hardware
The rest of the hardware, for me, is the same as Net Car v1 sans the Basic Stamp. You will have to find a parallel port cable to splice open and use a multimeter with a continuity check to find what wires correspond to the data pins and, of course, ground. If you can find a ribbon cable parallel port those are very easy to solder into a chip socket and can be plugged into and removed from a breadboard or another chip socket if you decide to make a circuit board.

The hardware interface to the car remote circuit will be a little bit different depending on how the remote works. I used some double pole, double throw relays, turned on by transistors, to make the connections on the circuit board, which replaced what would normally be the connections made by the controller sticks. Now that I think about it I could have just used the transistors. You may have to put a diode on the base to make sure no higher voltage can back-feed into the lower voltage TTL circuitry, because most car remotes operate on 9v. Please correct me if I am wrong!

Edit: A couple of people recommended in the comments to use optoisolators instead of relays. They draw less power off the parallel port and are simpler, and quieter, than having a transistor turn on a relay. Actually now that I think of it using relay's is probably the most ridiculous idea I have ever had! I kinda like the clicking sound though :-)

The next step is to put a mini wireless webcam on it and stream the video through a webcam service. Or you can just have a webcam look at the car in a room and drive it around with an overview.

Let me know if you complete this project successfully, take a video and post it as a video response to my youtube video.

Friday, February 13, 2009

Epoch win! Happy 1234567890.

On Friday the 13th on Feb 2009 at 23:31:30 GMT human time, Unix time hit 1234567890.

Unix time is measured in the number of seconds elapsed since January 1st, 1970 (Midnight Coordinated Universal time (UTC)


Thursday, February 12, 2009

Net Neutrality

It's not often I get to do a highschool school project on something I am interested in. I made this video, with some friends, for my global issues class. It came out pretty good for an all-nighter.

A special thanks to Burnsy for staying up to record and ftp narrations to me on the fly.

Saturday, February 7, 2009

Internet Controled Car v1 BASIC Stamp

Update: I found a better way to do this using a parallel printer port instead, I recommend that instead of using a BASIC Stamp.

The BASIC Stamp microcontroller is a neat little device to play with and very simple to program. It can also handle RS232 serial data. With a little flash actionscript, some very simple PHP, and an Ubuntu Linux server I modified an RC car so that it could be driven from anywhere on the internets.

This is how it works:
The client program, written in Flash Actionscript, detects if an arrow key is down or up and sends the appropriate ASCII character to a PHP server side script, using the sendAndLoad function and the POST method. The PHP script takes that ASCII character, for example capital W for forward, and writes it to the com server’s com port.

Flash controler code:
I'm sure this is very possible to do in Javascript, instead of flash Actionscript. If anyone wants to post a Javascript version in the comments I would be happy to add it to the article.

Download: car_remote.as

PHP:
Sending data through a com-port is really easy in Linux. The com-port is treated as a file and can be written to by a PHP script. The com-port “file” is located in “/dev/ttyS0”; ttyS0 is com-port 1, ttyS1 would be com-port 2, etc.
PHP Script

This “writes” your command variable to the servers com-port. To make the comport writable by everyone execute the following command,
sudo chmod a+w /dev/ttyS0

Serial Cable:


To make the RS232 cable I took a 9-pin com port female connector and a USB cable wire and solderd pins 2, for receiving data, 3, for transmitting data, and 5, for ground. For the car I don’t really need to receive data, as I am only interested in transmitting commands to it, so really you only need pins 2 and 5.

Input to the BASIC Stamp:



The next step is to take the RS232 output and put it into a BASIC Stamp microcontroller. But before you do this you must convert the RS232 +/- 12v signal into a +5v signal for the microcontroller to handle the input. To do this you need a MAX232 chip to build a UART circut (a quick google search can tell you how to build one). To take an input from, in my case, port 0 you say


cmd VAR Byte
SERIN 0, 84, [cmd]


Then whatever ASCII character is put in is saved in “cmd”. You can then turn on and off other ports depending on what cmd is.

Relays:


Now that we can turn pins high and low, depending on what arrow key is pressed on the first controller program, we can turn on transistors. I have my transistors click on a “double pole, double throw” relay. I crakced open the RC car controller and had the relays make the proper connections to make the car go forward, back, left, and right (replacing what was once the mechanical connecters of the sticks).

So say we want the car to go forward, ASCII character capital W mapped to the up arrow key. When the BASIC Stamp gets this character it makes P1 go high and turns on the transistor which then turns on the relay. The relay makes the proper connection on the RC Car’s controller circuit to go forward. When the up-arrow comes back up the client program sends a lower case w turn the relay off. Same for back, left, and right.

Now you can set up a webcam to see the car and drive it around from anywhere in the world. This concept can be used to control anything you want over the Internet.