Posts Tagged ‘python’

Getting ban-happy with DenyHosts

Wednesday, October 25th, 2006

Several times a day, computers somewhere in India or China (usually) launch brute force and dictionary attacks on my server to try and get SSH access. To anyone running their own server who regularly browses their SSH logs (/var/log/secure or /var/log/auth.log, depending on your distro) this is old news. Checking my logs, I’d see 80-100 failed login attempts from a single IP address trying a whole ass-load of non-existant user names and passwords.

I have SSH locked down fairly well, with remote root logins off and disabling password authentication in favor of RSA based keys. However, I opted to leave SSH on the default port 22, which undoubtedly accounts for all the attacks. Usually, I’d place the offending IP in my /etc/hosts.deny file, banning it for eternity with an “ALL:[bad IP address]“. Still, this meant that I banned them after the fact.

So, I installed DenyHosts. It’s a python script that can run as a daemon, monitoring my /var/log/auth.log for login attempts using non-valid users and/or passwords. After a few failed or invalid logins, the attacking IP is automatically added to /etc/hosts.deny, nipping a prolonged attack in the bud—just the way I like it.

DenyHosts is highly configurable, letting you you specify all types of rules such as how many failed logins are allowed before banning, specifics of what services to ban and for how long (hours, years, eternity). You can have DenyHosts email reports to you and also have it synchronize against a master list of bad IPs that’s bolstered by over 4,000 users. It’s pretty damn cool. In one day, I had three separate attacks, promptly caught and banned.

Batch uploading to Flickr with uploadr.py

Monday, January 2nd, 2006

I use Linux at home and I’m also a big fan of Flickr and use the service to store and share all my photos online, including my gratuitous cat photos, embarrassing and revealing though they may be.

The problem I face using this service with Linux is that while Flickr supplies uploading applications for most operating systems, they kind of leave Linux out to dry. Luckily, several people have written programs to fill this void. If you only have a few photos to upload, you can get by using uploading via web page, but if you just got back from vacation or shameless cat worship and you’ve got 40-100 images to put up, you need a batch uploader or you’re going to go insane.

I had some success using Flickr Uploadr. It worked well enough until I chose to merge my Flickr account with my Yahoo account (Flickr users know what I’m talking about). After that, I couldn’t get it to work. Faced with the headache of finding, installing and setting up a usable replacement, I started getting pretty frustrated with the missing dependencies, incorrect Java packages and shit I didn’t have the time or patience for. I just wanted to upload a few photos, not perform an appendectomy.

Fortunately, I spotted uploadr.py. It’s a simple Python script that lets you specify a folder on your computer to serve as the “live” folder. Put your photos there, run the script and they are uploaded to your account. It’s no frills. You can’t rename, set tags, resize or add to sets, but honestly, I’m happy to be able to upload by only running a simple script. I can do all the rest later, once they’re up and I’m logged into Flickr’s batch edit.