lamehacks

Stuff is fun

Archive for November, 2008

Secure command line chat using netcat and openssl

Wednesday, November 26th, 2008

Instant messaging networks are practical and simple to use. Though most of the people use themĀ  without worries, they do in fact bring up a major concern, privacy. Not only your messages are transmitted in plain text over the internet so somebody in between can sniff them, they are not sent directly to the recipient. Instead, they are sent to the IM provider’s server and then delivered to the recipient. What this means is that you are trusting wharever you communicate over IM to your IM provider which can log all your messages and do whatever it wants with them.

If you use an UNIX based operative system, this little shell script implements a simple and secure way to chat. It’s more of a proof of concept than a every-day usable script. Despite that is fully functional and fun.
It works simply by sending encrypted text over a TCP socket created with netcat. The text is encrypted using openssh.

#!/bin/sh

#change this if your port is busy
port=3004

usage () {
	echo "******************** SSSLCHAT ********************"
	echo "U S A G E"
	echo "SERVER: ssslchat.sh server [password]"
	echo "CLIENT: ssslchat.sh client [password] [ip|hostname]"
	exit 1
}

mode=$1
pass=$2
ip_or_host=$3

encode(){

	password=$1

	while [ True ]
	do
		read userinput
		encodedmessage=`echo "$userinput" | openssl enc -rc4 -k $password | openssl enc -a`
		echo "$encodedmessage"
	done
}

decode(){

	password=$1

	while [ True ]
	do
		read encodedinput
		decodedmessage=`echo "$encodedinput" | openssl enc -d -a | openssl enc -d -rc4 -k $password`
		echo "+$decodedmessage"
	done
}

case $mode in
	"server") encode $pass | nc -l -p $port | decode $pass ;;
	"client") encode $pass | nc $ip_or_host $port | decode $pass ;;
	*) usage ;;
esac

Both the server and the client need to use the same password for it to work.

Download

Simple java socket client

Sunday, November 9th, 2008

Time for a really lame application.
I made this to try out the swing application framework. Putting together an application like this takes about five minutes and about 20 lines of code. You red right, 20.
First, I thought about making a peer-to-peer chat, but i ended up doing something even simpler, a guided socket client. It only supports text input and is not threaded, so don’t get surprised if the GUI gets unresponsive during a request.
(more…)

Solving sudoku puzzles with perl

Saturday, November 8th, 2008

Solving sudoku puzzles manually is quite a boring thing to do IMHO. Now writing a working solution to all 9×9 sudoku puzzles is pure fun! I wrote this script a while ago, it was a fun way to learn perl. Yes it was my very first contact with perl, so do not bash!

(more…)

Timestamped tarballs

Monday, November 3rd, 2008

There is a ton of version control software solutions out there. Personally I find them all overkill when it comes to provide version control to a project maintanined by one single person.
Simplicity is beautiful and efficient, for this purpose I can’t think of anything simpler than timestamped tarballs. Save this script, make it executable and place it somewhere where your environment can see it.

#!/bin/bash
#
# Author: Pedro
# Description: A quick timestamped.tar.gz archiver
# Date:19-09-2008
# License: I don't care.
# Check out http://lamehacks.net for more little tricks
#
if [[ "$1" = "" || "$1" = "--help" ]]; then
        echo "

        Usage: timestamptarball 

        "
        exit 1
fi

date "+%Y.%m.%d-%H.%m_" | xargs -I {} tar -cvvzf  {}`basename $1`.tar.gz  $1
. .

Entries (RSS) and Comments (RSS).