Archive | Linux

A UNIX-like operating system.

Brute Force Detection (BFD) script for vsftpd

vsftpd is the “very secure file transfer protocol daemon” and a great product to use for file transfers. Unfortunately, a bunch of script kiddies and zombies runs scripts guessing the 2283 most common user name and password combinations. Sometimes, I’ll see several of these runs of login attempts in a single day, peaking one day at over 13 thousand bogus login attempts. I resent the amount of time, resources, bandwidth and power my server has to spend rejecting these attempts.

Last year, I blogged about the script Brute Force Detection that works with many servers and reads the logs to ban repeated failed login attempts. Unfortunately, it did not have the settings to read vsftpd generated logs, and there were not any directions simple enough for me to understand to set one up. A year passes, I read more, learn more, expecially the great Man Page of the Month sessions at MonadLUG, and I find a couple of hours to hack at this, motivated by yet another log report filled with vsftpd login attempts. Here’s what I did:

BFD uses rules files that are portions of scripts customized for the particular log to read, the messages to look for, and the locations at which the IP addresses of the offending attacker can be found. When each rule file in turn is read into the main BFD script, it becomes part of a set of commands that slices and dices the log, finds the (adjustable) number of excessive attempts, and issues the commands to ban attempts from that IP address. The trick is figuring out what commands you need to implement to return the stream of IP addresses in the correct format. Here’s an example, the sshd rule file:

REQ="/usr/sbin/proftpd"
if [ -f "$REQ" ]; then
LP="/var/log/secure"
TLOG_TF="proftpd"
TRIG="15"

## PROFTP
ARG_VAL=`$TLOGP $LP $TLOG_TF | grep -w proftpd | grep -iwf $PATTERN_FILE | tr '[]' ' ' | tr -d '()' | awk '{print$10" "$13}' | tr -d ':' | awk '{print$1":"$2}' | grep -E '[0-9]+'`
fi

Boy, is that inscrutable! Here’s a quick tour: REQ is the required file (the binary that runs proftpd) so the script only runs if there is such a file (“fi” is the shell script equivalent of “if” – cute!). The other variables are used to feed the main processing line, starting with ARG_VAL. This line processes the log (named LP) through a series of pipes that filters the result down to the items that need to be processed. Grep processes lines through Globally searching, using Regular Expressions and Prints them through to the next command in the pipe. TR translates characters from one set to another, or -Deletes them. Awk is a simple text processing language, really handing for tricks like printing the tenth and thirteenth words out of a line.

Here’s the trick to working this out: take a log file you know has your suspect violations, use cat to feed it into the beginning of the pipe described above, and add item-by-item to the pipe to figure out what each does and what the final result looks like, in this case a text file IP Addresses and login names, something like:

192.168.1.1:fred
192.168.1.1:fred
192.168.1.1:fred
192.168.1.1:fred
192.168.1.1:barney
192.168.1.1:charlie
192.168.1.1:dave
192.168.1.1:eric

This is what BFD gets fed bac k to it. Then, it counts the number of attempts, compares that against the TRIG value set above, and if it exceeds the trigger level, executes the command (set in BFD’s configuration file, conf.bfd) to ban the offending attacker. (It also optionally sends an email to the admin, a good idea to ensure you’ve got things set up properly.)

Now, your installation of vsftpd may be a little different from mine, your logs may have different names and columns in different orders, so use this script only after testing out that it works properly with your configuration. Best of luck with it. Here’s my implementation of a script to detect vsftpd script kiddie attacks:

REQ="/usr/sbin/vsftpd"
if [ -f "$REQ" ]; then
LP="/var/log/messages"
TLOG_TF="vsftpd"
TRIG="15"

## VSFTPD
ARG_VAL=`$TLOGP $LP $TLOG_TF | grep -w vsftpd | grep -i rhost | grep -iwf $PATTERN_FILE | awk '{print $13":"$12}'| tr -d '[]()?@'| cut -d = -f 2,4 | grep -E '[0-9]+'`
fi

The cut command is a new one here: like the use of awk it lets you pick particular columns to slice out of the line, but also gives you the option to specify the delimiter that sets off the columns. In this case, I use cut to pick off the second half of two columns that are formatted as “rhost=192.168.1.1” and “ruser=badguy@badplace.com” to pick off the second values from each of those columns.

DLSLUG notes, 7-June-2007

The Dartmouth – Lake Sunapee Linux User Group held their meeting on the usual first Thursday, but at a new location: the Dartmouth Regional Technology Center, where Bill McGonigle has recently set up his new offices. Nice place!

Seven attendees found their way to the meeting, and we had an informal chat covering a wide range of issue: the challenges of single-person consultancies, the business of consulting, Nagios, Dartware, a new version of Logo from MIT, having a presence at Hanover’s Street Fest (July 28, btw).

Bill had an interesting proposal: that the group create a “chuck box” (Boy Scouts’ term, ref: http://www.troop168.net/forms/patrolboxa.htm) that could contain a GNHLUG-booth-in-a-box: a banner, handouts, a tent/canopy,… what else? Interesting idea.

Bill also recommended we check out http://www.zazzle.com if we’re considering making promotional items.

Good times had by all. No DLSLUG meeting in July; instead, you’re encouraged to come to the GNHLUG-wide BBQ July 15th. Hope to see you there!

MonadLUG meeting notes, 14-June-2007: Ed Haynes of WindRiver: real-time and Linux

Bill Sconce posted the notes from the MonadLUG meeting of 14-June-2007, one I had to miss due to client projects. It sounds like it was a really interesting meeting. The push to tweak the kernel of Linux to be responsive in a real-time environment benefits us all, as some portions of that specialized work can be rolled into the main-line kernel code. This is one of the great benefits of Open Source, where developers “scratching their itch” – working on their specific needs – can contribute back to the greater community at little or no cost to them.

I heard a similar sentiment voiced at FUDCon ’07 Boston in presentations about the One Laptop Per Child machines: in tracing down some of the code that was running down the batteries on these cute little laptops, the OLPC crowd found entire classes of code that were working fine on desktop and server machines plugged into the wall, but wasting CPU cycles when a different algorithm could be implemented that was more power-friendly. This doesn’t just benefit the OLPC crowd; some of their work goes back into mainline kernels where it makes everyone’s laptop battery last longer, server stacks idle cooler, requiring less AC power and less Air Conditioning power, lowering the heat-disapation requirements of data centers, and slowing global warming. Yet another case of Open Source saving the world.

ongoing · I’ve Seen This Movie

Tim Bray is ticked and he’s not going to take it any more: in I’ve Seen This Movie, Tim blogs,

One would assume that the world’s largest software company, when facing a technology choice, would take the trouble to actually, you know, understand the technologies involved, but the evidence doesn’t support that assumption.
Why? · The thing is, I’ve seen this movie before: The movie where there’s an emerging standard that’s got some buzz and looks promising and maybe it’ll raise the tide and float all our boats a little higher, and then Microsoft says they won’t play.

Geez. Nothing new on the internet but repeats. There’s a great conclusion. Worth reading the entire post.

MonadLUG, 14-June-2007: Ed Haynes: Real-time in Linux

MonadLUG is fortunate this month to have Ed Haynes of Wind River make a presentation on Real-time processing in Linux. Group coordinator Charlie Farinella posts the announcement:

Who: Ed Haynes, Wind River
What: Real-Time
Date: Thursday June 14, 2007
Time: 7:00PM
Where: SAU 1 office, 106 Hancock Rd., Peterborough
http://wiki.gnhlug.org/twiki2/bin/view/Www/MonadLUG

Linux is finding itself used in more applications that can be characterized as “Real Time”. What is a Real-Time system? What impact does it have to the Linux OS, and how has Linux evolved to better meet real-time challenges? What’s the difference between “soft” and “hard” real-time? A live demonstration will be held to characterize the performance of difference linux kernels.

Presenting will be Ed Haynes from Wind River. Ed currently serves as a technical resource for the New England Wind River region. He has 10 years experience as a software developer on embedded realtime systems and also led IPv6 development at Nortel.

Sounds like a good meeting!

Fedora 7 available for download – get yours now!

Fedora 7, code-named “moonshine” is complete and now ready for download. Check out the BitTorrent feeds at http://torrent.fedoraproject.org/ for the fastest downloads and to pitch in a little of your upload bandwidth to spread the good words.

Lots of neat stuff in this version of Fedora. First, the “Core” is gone from the name. The “Core” and “Extras” designations have been removed and the distribution united into one package. This isn’t just a repackaging issue, but a huge change in the governance of the Fedora project, one that’s taken a couple of releases to iron out. The entire distro was selected, built and distributed on public servers by the community, and not behind the walls of Red Hat nor any other private company. This openness, I’ve been told, extends to every aspect of the project. Openness and transparency is good. That doesn’t mean the project has been abandoned, though: I understand a number of Red Hat employees work on Fedora as a major part of their job. Yet another great example of how Free software can support people’s livelihoods.

A lot of work was devoted to the Pungi build process to assemble the distro itself. It’s now possible for mere mortals to create their own custom builds (“spins” as in spinning CDs, in the terms of the builders) to create their own specialized, targetted, rebranded, mini-, maxi- or personal distro. Examples of this already available from Fedora include a LiveCD and a KDE LiveCD. While it’s not running F7 yet, Pungi-built MythDora 4.0 (recently Slashdotted) is a great example of what we can create with the Pungi tool.

Lots and lots of other features are in the release notes and we all have our favorite to look for, so I encourage you to go there for the definitive list. For me, I’ll also mention better hardware support, Network Manager (rocks!), PPC support (time to dual boot the iMac!), boot-from-USB-live-distro!, better, faster, more capable, more compatible. Compare and contrast this with new distributions of other operating systems which are offering a pretty desktop and less ability to work with your stuff. It’s all about choice. This one’s an easy choice.

MonadLUG notes, 10-May-2007, dd and Seth Cohn, Drupal

Ten attendees made it to the May meeting of the Monadnock Valley Linux User Group, held as usual on the second Thursday of the month at the School Administrative Unit #1 offices, Hancock Road, Peterborough.

Bill Freeman presented his thoughts on the Man Page of the Month: dd. Bill provided two pages of notes. Quite the discussion followed obscure and useful things dd could do, such as preserve floppy drive images for posterity, copy music CDs to images for subsequent loopback mount and playing, copy and restore bootblock records and of course read and write tapes.

Seth Cohn was the featured speaker of the night and spoke on Drupal, the content management system. Seth has screenshots of a surprising number and variety of sites that are running on Drupal, presented a bit of Drupal history – seems it’s been around for a long time, and had a fairly stable history – and its current state, with fairly large and active communities of developers and implementors. He covered a bit of the architecture and philosophy of the modular design of Drupal and did the fairly painless install and initial configuration. 9 PM came too soon as there was lots more to see.

Thanks to Seth for presentation, to Bill for MPoM, to Charlie for organizing the meeting and to all for attending and participating.

WordPress 2.2 released

WordPress 2.2 has been released, and it looks like it’s got some pretty cool features:

On behalf of the entire WordPress team, I’m proud and excited to announce the immediate availability of version 2.2 “Getz” for download. This version includes a number of new features, most notably Widgets integration, and over two hundred bug fixes. It’s named in honor of tenor saxophonist Stan Getz.

It also looks like a big enough change not to be an overwrite-and-see-if-it-works update, but rather a carefully planned backup, parallel, switchover, test, test, test process. Look for the upgrade here in the coming weeks…

Notes from CentraLUG, 7-May-2007: Ben Scott on OpenWRT

Seven attendees got to enjoy the last CentraLUG meeting at the New Hampshire Technical Institute Library this academic year. The school will be closing on Friday, and summer hours will not accommodate CentraLUG. Stay tuned on an announcement of a summer location for June, July and August (September will have no meeting due to the Labor Day holiday).

Ben Scott was the featured presenter this evening, showing off the OpenWRT Linux distribution for embedded devices. The list of supported hardware [Updated the link — Ted] goes far beyond the initial LinkSys WRT-54G model to include products from dozens of other vendors. Many attendees brought their own routers for show-and-tell or backup. I had a v.1 WRT54G which I opened for folks to inspect. I also brought the compact (and alas, not yet flashable) WRT54GC. Bruce Dawson brought the WRTSL54GS, a Linux-flashable unit that includes a built-in USB connection. While Ben wrestled with the network and projector, we entertained ourselves well (and heckled Ben).

Ben had a well-prepared presentation, with schematics of the units, pictures of the circuit boards and some of hacks performed upon them, and a live demo of upgrading the unit from stock firmware to use the OpenWRT firmware and X-Wrt interface [3]. The OpenWRT includes a package manager and a large number of packages have been ported to the OpenWRT environment, ready for download. and installation.

Installation was uneventful – the Murphy gods must have been busy torturing the students in their finals week – and simple: select the “upload” option from the web interface and point to the OpenWrt image. Installation takes a short time and requires the router to be rebooted. Ben strongly advised clearing your browser cache, since the “same device” is going to be responding with different responses.

Ben gave us a quick tour of the OpenWRT interface and plunged right into installing X-Wrt. X-Wrt extends the interface and makes management far simpler, with some pretty incredible tools, like live SVG graphs showing actual network usage. Pretty impressive stuff.

Folks considering buying a new WRT54 will want to look for a “GL” unit where the “L” is Linux, the “GS” versions “Speedbooster” with more RAM or the “SL54GS” “Storage Link” that includes the USB connection also.

Bill also notes that it is possible to “brick” a unit. Ben says there are ways to de-brick them. Google ought to help, as would a post to GNHLUG.

Thanks to Ben for the great presentation, to Bill Sconce for providing the projector and notes, and to all for attending and participating.

MonadLUG, 10-May-2007: Seth Cohn presents Drupal

The monthly meeting of the Monadnock region Linux User Group takes place as usual on the second Thursday of the month at the SAU #1 offices in Peterborough. Details and directions here.

Seth Cohn will be presenting Drupal, http://www.drupal.org. I’m looking forward to it. The LUGs have been privileged to see a couple presentations on CMSes: Jonathan Linowes presented Xaraya, and Barrie North Joomla! It’s great that there are som many great choices!

Powered by WordPress. Designed by Woo Themes

This work by Ted Roche is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States.