Archive for the 'Networking' Category

Aug 20 2009

Firewalling brute force attempts with IPTables

Published by Brian under Computers, Linux, Networking, Tlf

Almost 24 hours per day, The Linux Fix is inundated with FTP and SSH brute force attempts to our server farm.   This has compromised a few our our customer’s accounts from time to time, and I decided it was time to come up with a solution.

The problem is tricky–we must leave FTP and SSH open to the entire world, but at the same time be selective on what we black list.   How do you make that determination?  Strictly on bad login credentials?

We could, but that would mean that we’d inadvertently lock out real users.  A better solution we found has to do with timing connection attempts.   With IPTables, we can keep a counter based upon source IP–and track how many new socket attempts are made within a certain span of time.     For instance, if we detect the IP address 1.2.3.4 making 5 connection attempts within 60 seconds, there is a darn good chance it isn’t someone mistyping a password.

Here is how we did it, based upon another script we found out in the Internets:

#!/bin/bash
/sbin/iptables -N SSH
/sbin/iptables -N SSH_BLACKLIST
/sbin/iptables -A SSH_BLACKLIST -m recent --name SSH_COUNTER --set -j LOG --log-level warn --log-prefix "Blocked: "
/sbin/iptables -A SSH_BLACKLIST -j REJECT
/sbin/iptables -A SSH -m recent --name SSH_COUNTER --update --seconds 300 -j REJECT
/sbin/iptables -A SSH -m recent --name SSH --rcheck --seconds 60 --hitcount 5 -j SSH_BLACKLIST
/sbin/iptables -A SSH -m recent --name SSH --rcheck --seconds 2 -j LOG --log-level warn --log-prefix "Added: "
/sbin/iptables -A SSH -m recent --name SSH --update --seconds 2 -j REJECT
/sbin/iptables -A SSH -m recent --name SSH_COUNTER --remove -j LOG --log-level warn --log-prefix "Removed: "
/sbin/iptables -A SSH -m recent --name SSH --set -j ACCEPT
/sbin/iptables -A INPUT -m state --state NEW -p tcp -m tcp --dport 22 -j SSH

This creates two new tables, SSH and SSH_BLACKLIST.   Upon the intial connection attempt, the IP is added to the SSH_COUNTER counter.   If the same IP address is seen again within 60 seconds, it is duly noted–however no action is taken until the hitcount reaches 5.   In that case, the rules jump to the SSH_BLACKLIST table, it is logged, and subsequent connections from that IP are dropped for 5 minutes until things calm down.   In order to do this for FTP, just rename the targets as appropriate and change the target port to 21 on the last line.

The nice thing about this set up is that it is auto-cleaning.  After 5 minutes of no activity, the counter forgets about the IP address and things return to normal.   We’ve found that this is just enough protection to drastically reduce bruteforce attempts, yet not get in the way of normal usage by our customers.  Over time, this has become our favorite technique and we’ve begun to implement it on any Internet-facing machine with open SSH ports.

One response so far

Oct 24 2008

Trixbox, VPNs, NAT, and the 20 second dropping issue

Published by Brian under Asterisk, Networking, Tlf, Trixbox, VoIP

I usually don’t like to cross-post between blogs, but this problem seems prevalent enough that it needs more exposure.   We’ve solved it at TLF, and here’s how:

http://www.thelinuxfix.com/blog/2008/10/24/trixbox-vpns-and-the-20-second-issue/

No responses yet

Jul 01 2008

Time Machine via AFP

I have been itching to get Time Machine to work over a (unsupported) network-shared volume since we’re unwilling to drop the cash for a Time Capsule.  I’ve seen quite a few different posts on how to get it done, including the terminal trick to tell Time Machine to use unsupported volumes, but none of them quite worked.

The best I could get was Time Machine to begin to write the files to the share, but after a few seconds die with a vague “Backup disk could not be created error”.  This stumped me for a bit until I came across this.  Apparently sometime around 10.5.2, Apple introduced a new, undocumented “feature” to Time Machine that causes it to fail over network volumes when doing the initial backup.   However, once the files are created it will work fine.

So, the magical combination is as follows:

  • CentOS 5 with Netatalk-2.0.3 compiled, installed, and configured per this post.  Note: I also had to modify etc/cnid_dbd/dbif.c with the same code change as specified there, but YMMV.
  • OS X Leopard, patched to 10.5.4.
  • Changes to Netatalk’s netatalk.conf file per this post at the Gentoo Wiki.
  • Following the post linked above precisely.

Once that happened, Time Machine has begun to work great over AFP to our backup volume–even for multiple Macs connecting to the same share. Behold!

Time Machine working over a Net Share

It probably doesn’t need saying; but this is clearly an unsupported way to use Time Machine.  It has been running this way for me only about a day.    If you’re concerned about having to troubleshoot problems that may pop up down the road, especially regarding backups; picking up a Time Capsule is probably a far better idea.

One response so far

Jan 25 2008

Building the EtherSAN: Part 2

Published by Brian under Clustering, Linux, Networking, Storage, ethersan

In the first part of “Building the EtherSan”, I outlined The Linux Fix’s business needs and reasons for building out an ethernet-based storage area network (SAN), a relatively uncommon platform. In this part I discuss the design and products that were chosen to prove its viability before purchasing equipment for testing.

So the time had come to build out a rig and see if this new idea would work. Worries about a failure of the test were unwarranted: If I ran into a major problem while testing, I would always be able to repurpose the equipment in another fashion.

Here’s a crude diagram of what I was trying to achieve.

As you probably notice, there is a blatant single point of failure–the ethernet switch. Normally, intuition says implement two switches and do failover. Problem is that would require more money in terms of a second switch and additional NICs for the client servers. In my experience the switch would be the least likely to fail, while the servers would be the most likely–so it was a calculated and designed-in risk. Besides, it would be trivial to add another switch and do it “right” at a later date.

I had no prior experience shopping for dedicated disk storage, so to get an idea of what was available I shot an email off to ePowerhouse PC, a customer of ours. I explained the goals we were trying to achieve as well as our need for low entry price.

Terry at ePC has been a great resource for getting The Linux Fix parts quickly, and uncommon ones at that. He made a suggestion of using arrays from a company called Infortrend, since ePC was already a reseller for that particular vendor. After doing some more research I found an Infortrend fiber-based array that used lower-priced (but still high performing) SATA-II hard disks for storage. After some specification digging and decision making, I chose the EonStor A24F-R2430, which provides dual-redundant SATA-to-3bgps Fiber controller modules with an eight-port integrated fiber switch. A nice, elegant, all-in-one solution. Did I mention it supports 24 hard drives? TLF’s storage needs would be solved for quite some time! It turned out to be a great choice, a perfect blend of value and performance for us.

For the head-end NFS cluster servers, I chose a pair of low-end Dell PowerEdge 860 1U servers. The PowerEdge 860 has an available PCIe slot for a fiber host bus adapter (HBA), as well as an optional quad-core Xeon. Being that these servers were going to be clustered, I was not overly concerned with individual redundancy and opted for a cheaper software-based RAID solution on each. However, the pricey Dell Remote Access Controller was necessity because of RedHat’s Cluster Suite. RHCS requires a “fencing” device in order to reboot a server remotely in the event of error–and the DRAC suffices for that task (there are shortcomings to this, do your own research!). As I had mentioned in the previous article, fiber equipment is insanely expensive; in our case the Emulex fiber HBA was 20% of the server price! However, the lower entry price of the PowerEdge 860 offset that and we still ended up with a bargain.

As for the ethernet switch, I fell back to my old reliable favorite, the Dell PowerConnect 5324. It’s worked well for TLF in the past, is reliable, and provides plenty of bang for the buck.

Finally, I purchased twenty four 250 gigabyte SATA-II drives. At the time, 250 gig hard disks were the price-to-value point, and depending on the type of RAID used on the array, we would end up with roughly 5 terabytes of usable space. An important detail that Terry mentioned to me was to ensure the hard drive model was included on Infortrend’s compatibility list, and that made the decision on which models to purchase easier.

Overall price tag for the equipment came out to approximately $16,000, and broke down about like this:

PowerEdge 860 Servers (w/HBA): $1,200/ea
PowerConnect 5234 GigE Switch: $800
EonStor A24F-R2430: $11,000
Seagate SATA HDs 250GB: $2800

Sounds expensive, but when pricing out equivalent storage options from a well-known vendor such as NetApp, $3.00/gb isn’t a bad deal at all. The only thing left was to ensure I was going to get a well performing, expandable storage network.

All that was left to do was wait for the equipment to arrive and being my tests, which will be the topics I cover in the next post. Stay tuned!

3 responses so far

Jan 24 2008

Cabling as an art

Published by Brian under Geeky, Networking

Any true geek is impressed by a neat cabling job.  There’s something about the order that results from equally banded cables in conjunction with blinking lights that makes the heart warm.Here are a few snapshots of the cleanest cabling jobs I’ve seen.  Compare that with what I thought was a nice cabling job (sorry for the poor quality, cell phone shot) from one of the Linux Fix racks, and I feel like a slob!

No responses yet

Next »