Sunday, October 7, 2007

How-to: Make Firefox default browser for Thunderbird

One thing that bugged the hell out of me was the fact that Thunderbird did not know about Firefox. I get a lot of RSS feeds in my inbox and the damn things just won't open. So what you say? "You just click the link and magically Firefox starts with a new tab and the most sought after page". Wrong. What you have to do is ctrl-click the link, click on "copy link location", do an alt-tab, paste the link in firefox and then press enter while you are controlling yourself from pounding every object that's on your desk . I mean, how hard can it be for the great Mozilla Foundation to integrate the two seamlessly and without any tweaks in the configs? Don't get me wrong. I do love their products. But in my opinion this is one of those cases where some polish (sorry Poland people) will come in handy. So, until they came up for a better way of selecting a default browser here is the way to go:

  • Fire up Thunderbird.
  • Go to Edit - Preferences - Advanced - General - Config editor
  • Make a new string network.protocol-handler.app.http with /opt/mozilla/bin/firefox
  • Same for network.protocol-handler.app.http - /opt/mozilla/bin/firefox

Who in their right mind will use the same application for https and http anyway? Sheesh. Strange f*cking world we're leaving in. :)


Powered by ScribeFire.

Friday, October 5, 2007

Python Scripting Tutorial, Part one

Introduction

Python is a great tool to work with. I like the fact that I can accomplish all sorts of tasks, from socket programming to web development to GUI) in just one language. Python has an incredible standard library, it is very readable and I found it to be very fast. I prefer it over BASH because it seems I just can make the damn thing work.

In this series, we'll first start on with some very simple scripts and then move on, developing on those and adding more features. This is a hands-on tutorial, because you have to write the code and try to understand it. As I always comment my code excessively when writing tutorials, I won't explain the same thing twice.

In this part you will learn how to:
  • find out if a program is running by searching for its pid
  • get simple command line arguments
  • learn what a list is and how to access it
Scenario

As you may already know, I have moved my sshd port to 8722 on my servers (they are all in sync). Also, I use only public/private keys for authentification using ssh-agent and ssh-add. I found it very cumbersome that everytime I want to ssh to see if ssh-agent is already running, then if it's not, ssh-add the key, and type that long command. Here is the command that I actually type to get into one of my hosts:

ssh rsavu@host1 -p 8722

The problem is I don't have any short hosts like host1 in /etc/hosts and I just want to make a script that automates this task (okay, admit I need it just for the sake of argument).

What should the script do? Well, if it receives an argument (user@host is necessary) it should connect to that host using the port 8722. If it doesn't receive any arguments it should print a menu with known hosts.

What to improve on in the next parts

  • check if the format of the first argument is user@host
  • read hosts from /etc/hosts
  • read all other options from a configuration file that can be thrown through a command line argument or be a predefined one
  • suppressing any warnings
The script

#!/usr/bin/python
"""
That thing above is called a shabang line for anyone that did not know that
It instructs the shell what interpreter should be used for the following
lines of code
"""

"""
These are the libraries we are going to work with.
"""
import sys
import os
"""
The main function
"""
def main(argv):
# First let's find out if ssh-agent is working
pid = os.system("pidof -s ssh-agent")
if pid == 256:
os.system("ssh-agent")
os.system("ssh-add")
# Let's see how many arguments we have
argc = len(argv)
# Test if we don't have any argument
if argc == 1:
# This is a list
knownHosts = ["user@host1", "user@host2"]
printTable(knownHosts)
# Request some input from the user and transform it in an integer
option = int(raw_input("Choose an option: "))
remoteHost = knownHosts[option-1]
elif argc == 2:
remoteHost = argv[1]
cmd = 'ssh ' + remoteHost + ' -p 8722'
print cmd

"""
Prints a table with know hosts
"""
def printTable(knownHosts):
i = 1
for host in knownHosts:
# In the next line the statement `i` makes us able concat a string and int
print `i` + ". " + host
i = i+1

"""
This basically means that if this file is ran independently and not included
in any other file it should call function main with that argument.
More on this another time
"""
if __name__ == '__main__':
main(sys.argv[0:])

Friday, September 21, 2007

Htop in FreeBSD

I've always loved the top replacement named htop that's available in linux. I usually run my screen session with rtorrent, mc and htop opened. I was a bit dissapointed where the usually nitty-gritty method of installing software in FreeBSD (using the ports collection) has failed me when trying to get htop working on my server.
Here is a quick reminder for me (and everyone else for that matter) on how to get htop working on FreeBSD along with the linux compatibility layer.

First you have to dynamically load the linux object in the kernel:

kldload linux

Then we have to make this loading permanent so add linux_enable="YES" to /etc/rc.conf.

After this, install a linux layer:

cd /usr/ports/emulators/linux_base-fc4 (for some strange reason fc6 is not working for me)
make install distclean

Go to /etc/fstab and add the following line:

linproc /compat/linux/proc linprocfs rw 0 0

Mount the new filesystem: mount linproc and go to /usr/ports/sysutils/htop and install as usual.

As soon as I figure out a method of getting a screenshot from my box I will post it :D

Bye for now.

Sunday, September 9, 2007

Thwarting SSH Attacks

Oh my gosh! These SSH attacks are getting worse by the minute. A few months ago I found that one of my accounts on my desktop was hacked and was sponsoring bandwidth to some IRC bots and abusive scanning. The problem was that I had setup a user with a lame password for a friend of mine so he could get used to the linux command line. Even though I asked him to change the password, he didn't and that resulted in a complaint from a server to my ISP. Having investigated a little I found a huge auth.log with some brute-force attempts at ssh password.
Yesterday I started my ssh server on the laptop and because I was very busy I left the laptop running. Today I come home to find a 300K /var/log/auth.log file (which in my opinion - for a freshly installed box with 22h of uptime is a lot). Something had to be done. I hardened my sshd config and searched for something to throttle down the attacks.

Securing SSH

Installing ssh is a breeze. Just type pacman -S openssh, add sshd to your DAEMONS line in /etc/rc.conf.
Now let's take a look at our sshd config and see what we can do to harden our existing installation.
sudo vi /etc/ssh/sshd_config

  • Delete the comment before #Port 22 and let's give it something like 2222.
  • The protocol should be always set to Protocol 2 because Protocol 1 is insecure
  • LoginGraceTime 30
  • PermitRootLogin no. Actually it is better to disallow root from the securetty file (more on that later).
  • PasswordAuthentification no as you only want people to log in if they have a private key. (more on that subject later)
  • Banner /etc/issue.ssh - Put some text in this file - something like: Unauthorized access prohibited. Any activity will be logged.

Saturday, September 8, 2007

SSH attacks

Oh my gosh! These SSH attacks are getting worse by the minute. A few months ago I found that one of my accounts on my desktop was hacked and was sponsoring bandwidth to some IRC bots and abusive scanning. The problem was that I had setup a user with a lame password for a friend of mine so he could get used to the linux command line. Even though I asked him to change the password, he didn't and that resulted in a complaint from a server to my ISP. Having investigated a little I found a huge auth.log with some brute-force attempts at ssh password.
Yesterday I started my ssh server on the laptop and because I was very busy I left the laptop running. Today I come home to find a 300K /var/log/auth.log file (which in my opinion - for a freshly installed box with 22h of uptime is a lot). Something had to be done. I hardened my sshd config and searched for something to throttle down the attacks.