Sucess story and Many Thanks(Sorry for the long winded post)

General discussions here

Moderator: rgerhards

Sucess story and Many Thanks(Sorry for the long winded post)

Postby mph on Tue Sep 23, 2008 6:30 pm

Thanks for a great software package. I was almost at wits end when I found this.

A Little Background: Our FTP server is being attacked on a regular basis. Under an attack there are upwards of 60 hits per minute, usually from half way around the globe. I don't really know what they think is on our server, but they're determined to get in, or at least not let anybody else get in. The first time I saw the attacks there were over 25K connection attempts in less than 6 hours. I had no way of stopping them. We run a Cisco ASA firewall and their threat detection wasn't doing the trick. So I decided to use a little Linux trickery and write a small script to help thwart their efforts. Basically, an expect script to logon to the firewall via command line and shun the offending IP address until the attack stopped. First, I had to get info on when the server was being attacked. Initially I setup a separate log file for the firewall that rotated every 5 minutes and had the program scan it for attacks. It was the only thing I could think of since our firewall log files grow to over 4 million entries a week. This was quite messy and eventually unacceptable. Enter pla2 (PIX logging architecture.) A database driven software that allows viewing of the PIX activities. Finally, a simple query to pull records based in time. This worked well for the first few weeks, but again the database grew way too big. Daily pruning of 7,000 records took over an hour, which left the FTP server vulnerable until the operation finished. Again unacceptable. I'm not adept at perl programing, so modifying or extracting what I needed from pla2 in a timely fashion wasn't really an option. So began the hunt for something that would go straight from system to a database.

Four days ago I found rsyslog on the net. My disto(s) of Linux also had a package for it. I installed it, but the package was quite a few versions old, 2.0.1. As of this writing there's up to at least 3.21.4. Needless to say it didn't work. So back to the website. I downloaded the latest stable package 3.18.4. This was promising, but I could not get the regular expressions to pull the data I needed. They say the 3rd times the charm. So it was. I was hesitant to use a development version on a production server, but was not disappointed! It took quite a bit of lurking around the forums here and gathering info elsewhere, but I'm now able to save only the FTP traffic to our server into a database while still continuing to log all firewall traffic to the normal log file. This cuts down the database size by quantum measures. The only real problem I had were pulling only the fields I wanted since Cisco's log format is so unique(being polite.)

Here's what I ended up with. This will pull the date, time, source and destination IP and ports. The config file discards anything other than traffic to the server on port 21... a way cool feature I might add.

Code: Select all
$template std_format, "%timestamp% %FROMHOST% %msg%\n"
local6.*     /var/log/firewall.log;std_format

:msg, !contains, "OurFTPServer.com(21)"  ~

$template ftp,"insert into traffic_log (log_time, log_src_ip, log_src_pt, log_dst_ip, log_dst_pt) values ('%timegenerated:::date-mysql%', '%msg:R,ERE,1,BLANK,0:(\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b)--end%', '%msg:R,ERE,1,BLANK:Internet/.*\((.*)\) ->.*--end%', '%msg:R,ERE,1,BLANK,0:DMZ\/(\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b)--end%', '%msg:R,ERE,1,BLANK:Internet/.*\((.*)\) hit-cnt.*--end%')",sql

local6.*      :ommysql:localhost,Database,User,Secret;ftp


If anyone knows of a better way to do this... I'm all ears! I searched and tried all kinds of regex's to get the IP, but this was the only one, that I could find that worked.

I'm only on day one of production logging of the FTP traffic, but I can foresee no headaches on the horizon.

Thanks Again, I think you may have saved my bacon and my FTP server.

Best Regards,

M.P.H.
mph
Avarage
 
Posts: 16
Joined: Tue Sep 23, 2008 4:19 pm

Professional Services Information

  • Custom written rsyslog.conf?
  • Maintenance Contract?
  • Installation support?

Re: Sucess story and Many Thanks(Sorry for the long winded post)

Postby rgerhards on Wed Sep 24, 2008 12:30 pm

Hi,

thanks for the report, I really enjoyed reading it :)

As for the extraction: could you post a sample of the "unique" format (nice said, btw ;)). I would like to double-check if there is an easier way to extract (I doubt...) but therefore I need to see one.

Thanks,
Rainer
User avatar
rgerhards
Site Admin
 
Posts: 1780
Joined: Thu Feb 13, 2003 11:57 am

Re: Sucess story and Many Thanks(Sorry for the long winded post)

Postby mph on Wed Sep 24, 2008 3:09 pm

Rainer,

Here's an example from the ASA firewall: Note: IP addresses have been changed to protect the Guilty, the Innocent, and all between. :roll:
Code: Select all
Sep 24 09:07:43 10.1.1.55 Sep 24 2008 09:07:43: %ASA-7-710005: TCP request discarded from 11.11.11.22/80 to Internet:123.123.123.66/26535
Sep 24 09:07:43 10.1.1.55 Sep 24 2008 09:07:43: %ASA-6-106015: Deny TCP (no connection) from 10.0.0.234/40489 to 234.234.234.16/16009 flags ACK  on interface Inside
Sep 24 09:07:44 10.1.1.55 Sep 24 2008 09:07:44: %ASA-7-106100: access-list Inside_access_in permitted tcp Inside/10.0.0.234(40493) -> Internet/234.234.234.16(16009) hit-cnt 1 first hit [0xa2e84fca, 0xbbc5afe2]


One of the problems is that "Crisco" (as I like to call it) has different line formats, depending on the message. For my purpose I can narrow the formatting problems by filtering on the key word "access-list."

Question, Is there any way to make the template parameters variables? I.E.
Please excuse me if the syntax or verbage is not correct. I still can't wrink without thighting... Sorry that write without thinking regex stuff yet.
Code: Select all
date="%timestamp:::date-mysql%"
match_1_="%msg:R,ERE,1,BLANK:"
match_2_="%msg:R,ERE,2,BLANK:"
ip="$match_1(\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b)--end%"

$template tmplt "insert into traffic_log (log_time, log_src_ip, log_dst_ip) values ('$date', '$match_1_$ip', '$match_2_$ip')",sql
Or something along this order. This would make the (at least this) template MUCH easier to read and assemble. Also saves a LOT of typing, or cutting and pasting if you as lazy as I am. :wink:

Regards,

MPH
mph
Avarage
 
Posts: 16
Joined: Tue Sep 23, 2008 4:19 pm

Re: Sucess story and Many Thanks(Sorry for the long winded post)

Postby rgerhards on Wed Sep 24, 2008 3:20 pm

OK, I see what you mean. Looks like I can not find something else that's easier to do right now.

On the laziness: believe me, it's hard to find someone lazier than me (why else, after all, should I have started programming?) ;) So I more than understand your desire. Actually, this is part of a larger effort, the enhanced scripting engine. Unfortunately, I am pushing this towards the future ever and ever again as more important things come in between... (things you can not even do in ugly ways, so things you can do in ugly ways are less important because, after all, you can do them ;)).

Rainer
User avatar
rgerhards
Site Admin
 
Posts: 1780
Joined: Thu Feb 13, 2003 11:57 am

Re: Sucess story and Many Thanks(Sorry for the long winded post)

Postby mph on Wed Sep 24, 2008 4:04 pm

Rainer,

Thanks for the reply and update. Ok, things are just gonna get uglier! :D After setting this up yesterday and having a couple of FTP attacks last night, I've decided I need more info for tracking, etc... I started working on putting more fields in the database this morning. I'm trying not to use the field functionality as I may add other log entry types into the mix later. I think that a careful combination of Expression-Based Filters and templates should do the trick.

If anyone's interested, I'll post what I come up with when I get it figured out. It may take a couple of days to get what (I think) I want.

Regards,

MPH
mph
Avarage
 
Posts: 16
Joined: Tue Sep 23, 2008 4:19 pm

Re: Sucess story and Many Thanks(Sorry for the long winded post)

Postby rgerhards on Wed Sep 24, 2008 4:10 pm

I'd be interested ;)

BTW: did you have a look at phpLogCon? It is a graphical front end for syslog data and we have recently added cross-log searches and ip/domain lookups. All of this is an effort to get to better analysis if there is an attack. A demo is available at

http://demo.phplogcon.org/index.php?sourceid=Source3

The page is a weblog, but I think you get the idea ;)

Rainer
User avatar
rgerhards
Site Admin
 
Posts: 1780
Joined: Thu Feb 13, 2003 11:57 am

Re: Sucess story and Many Thanks(Sorry for the long winded post)

Postby mph on Wed Sep 24, 2008 4:38 pm

I hadn't looked yet. I have a tendency to get distracted when I multitask on too many things. Firewall, Internet police, C PHP & script programming, troubleshooting, etc... Another day in the life of IT. 8) I will check it out once I get this settled. I'll also be looking at the WinSyslog for our critical servers sometime here in the future.
mph
Avarage
 
Posts: 16
Joined: Tue Sep 23, 2008 4:19 pm

Re: Sucess story and Many Thanks(Sorry for the long winded post)

Postby rgerhards on Wed Sep 24, 2008 4:48 pm

Take your time :) I'd personally opt for at least a dual-core brain, but my request was denied by higher powers ;)
User avatar
rgerhards
Site Admin
 
Posts: 1780
Joined: Thu Feb 13, 2003 11:57 am

Google Ads



Return to General

Who is online

Users browsing this forum: No registered users and 0 guests

cron