1ac78 [Solved] Configuring AIDE reporting - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Ports & Packages > Installation and Maintenance of FreeBSD Ports or Packages

Installation and Maintenance of FreeBSD Ports or Packages Installing and maintaining the FreeBSD Ports Collection or FreeBSD Packages (i.e. third party software).

Reply
 
Thread Tools Display Modes
  #1  
Old September 21st, 2011, 06:05
ghostcorps ghostcorps is offline
Member
 
Join Date: May 2009
Posts: 241
Thanks: 68
Thanked 0 Times in 0 Posts
Default Configuring AIDE reporting

Hi Guys

I have installed aide to help monitor my system, but I can not find the cron script or the base configuration file as opposed to /usr/local/etc/aide.conf.

From what I have read, I believe I need to locate the base config file so that I can set the MAILTO option. All the guides I have found say that the base config is /etc/default/aide, but they are all linux centric so the path is slightly incorrect but even if I go to /etc/defaults/ there is still no aide file there. Even find / | grep aide does not find it.

My next step it to run this on a cron. Once again the guides advise that there is a cron script here /etc/cron.daily/aide. I have searched though /etc/periodic but can not find it. I did find a Linux copy of aide.cron HERE, but I am not savvy enough to modify it correctly.


Am I missing some FreeBSD magic? Or will I need to do run aide manually?
__________________
FreeBSD 8.3 RELEASE

Last edited by ghostcorps; September 22nd, 2011 at 00:11.
Reply With Quote
  #2  
Old September 21st, 2011, 06:15
graudeejs's Avatar
graudeejs graudeejs is offline
Style(9) Addict
 
Join Date: Nov 2008
Location: Riga, Latvia
Posts: 4,521
Thanks: 422
Thanked 607 Times in 475 Posts
Default

/usr/local/etc/aide.conf.sample

remember on FreeBSD stuff is installed in /usr/local/ (unless it's a kernel module, which needs to be in /boot/modules/, or some other specific stuff, but these are rare exceptions)

You can always check ports pkg-plist and/or Makefile to check what and where files are installed
Reply With Quote
  #3  
Old September 21st, 2011, 06:47
ghostcorps ghostcorps is offline
Member
 
Join Date: May 2009
Posts: 241
Thanks: 68
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by graudeejs View Post
/usr/local/etc/aide.conf.sample

remember on FreeBSD stuff is installed in /usr/local/ (unless it's a kernel module, which needs to be in /boot/modules/, or some other specific stuff, but these are rare exceptions)

You can always check ports pkg-plist and/or Makefile to check what and where files are installed
Thanks for the reply

But /usr/local/etc/aide.conf does not have the MAILTO option.

This is the how-to I have been reffering to. You will see that there are two configuration files I needed to find. I had already located aide.conf before posting.

I'll see what Makefile tells me

[EDIT:] It looks like the FreeBSD port only uses one file. But that still leaves me trying to work out how to set my address. Surely it couldn't be as simple as adding MAILTO=root to /usr/local/etc/aide.conf could it?
__________________
FreeBSD 8.3 RELEASE

Last edited by ghostcorps; September 21st, 2011 at 06:53.
Reply With Quote
  #4  
Old September 21st, 2011, 07:29
graudeejs's Avatar
graudeejs graudeejs is offline
Style(9) Addict
 
Join Date: Nov 2008
Location: Riga, Latvia
Posts: 4,521
Thanks: 422
Thanked 607 Times in 475 Posts
Default

I dunno, perhaps read manual (aide.conf(5) your locally installed manual may be newer than online version)
Reply With Quote
  #5  
Old September 21st, 2011, 07:30
graudeejs's Avatar
graudeejs graudeejs is offline
Style(9) Addict
 
Join Date: Nov 2008
Location: Riga, Latvia
Posts: 4,521
Thanks: 422
Thanked 607 Times in 475 Posts
Default

Quick manual search doesn't show anything about mail.... (I might be wrong)
But you can always write custom script to send mail, if aide test fails
Reply With Quote
  #6  
Old September 21st, 2011, 07:36
ghostcorps ghostcorps is offline
Member
 
Join Date: May 2009
Posts: 241
Thanks: 68
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by graudeejs View Post
I dunno, perhaps read manual (aide.conf(5) your locally installed manual may be newer than online version)
Thanks again,

I have looked over a few versions of the aide.conf(5) and aide(1) manuals to no avail either.

As for writing a script, I wouldn't have a problem setting up a cron but a mail script would be a bit outside my limited abilities. I'm sure I could work it out but I was hoping I could use the native functions wherever possible.
__________________
FreeBSD 8.3 RELEASE
Reply With Quote
  #7  
Old September 21st, 2011, 07:56
ghostcorps ghostcorps is offline
Member
 
Join Date: May 2009
Posts: 241
Thanks: 68
Thanked 0 Times in 0 Posts
Default

I'm going to try to get the script below to work on FreeBSD. Any suggestions will be greatly appreciated

I will put the script here:
/etc/periodic/security/950.aide
Code:
#!/bin/sh

# email address for reports
email=

# max age of logs and databases in hours
# default 2160 = 90 days
maxage=2160

if [ -f "/usr/sbin/aide" ] && [ -d "/var/lib/aide" ]; then
        dstamp=`date +"%H%M-%m%d%Y"`
        data=/var/lib/aide
        log=/var/lib/aide/aide.log
        cur_db=$data/aide.db
        new_db=$data/aide.db.new

        if [ ! -f "$cur_db" ]; then
                /bin/nice -n 19 /usr/sbin/aide --init >> /dev/null 2>&1
                cp $new_db $cur_db
	fi

	 if [ -f "$cur_db" ]; then
                cur_db_dstamp=`stat -c "%y" $cur_db | tr '.' ' ' | tr -d ':-' | awk '{print$1"-"$2}'`
                cp -f $cur_db $cur_db.$cur_db_dstamp

                /usr/bin/gzip -f $cur_db.$cur_db_dstamp

                cur_log_dstamp=`stat -c "%y" $log | tr '.' ' ' | tr -d ':-' | awk '{print$1"-"$2}'`
                cp -f $log $log.$cur_log_dstamp

                mv -f $new_db $cur_db
                /bin/nice -n 19 /usr/sbin/aide --init >> /dev/null 2>&1
                /bin/nice -n 19 /usr/sbin/aide --compare >> /dev/null 2>&1
		HOSTNAME=`hostname`
		if [ ! -z "$email" ] && [ -f "$log" ]; then
			cat $log | mail -s "AIDE report on $HOSTNAME" $email
		fi
        fi

        if [ -f "/usr/sbin/tmpwatch" ]; then
                /usr/sbin/tmpwatch $maxage $data/
        fi
fi
__________________
FreeBSD 8.3 RELEASE
Reply With Quote
  #8  
Old September 21st, 2011, 08:00
graudeejs's Avatar
graudeejs graudeejs is offline
Style(9) Addict
 
Join Date: Nov 2008
Location: Riga, Latvia
Posts: 4,521
Thanks: 422
Thanked 607 Times in 475 Posts
Default

Script above assumes you have fully configured mail server (Sendmail or postfix, or whatever)

It will work fine for delivering mail to local users. (you might just need to fix some paths and/or flags)

The magic is
Code:
cat $log | mail -s "AIDE report on $HOSTNAME" $email
Reply With Quote
The Following User Says Thank You to graudeejs For This Useful Post:
ghostcorps (September 21st, 2011)
  #9  
Old September 21st, 2011, 08:16
ghostcorps ghostcorps is offline
Member
 
Join Date: May 2009
Posts: 241
Thanks: 68
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by graudeejs View Post
Script above assumes you have fully configured mail server (Sendmail or postfix, or whatever)

It will work fine for delivering mail to local users. (you might just need to fix some paths and/or flags)

The magic is
Code:
cat $log | mail -s "AIDE report on $HOSTNAME" $email
Thanks for your patience,


I have corrected all the paths, which 'seemed' easy enough. It doesn't work yet though, this is what I have come up with so far:

Code:
#!/bin/sh

# email address for reports
email=mymail@gmail.com

# max age of logs and databases in hours
# default 2160 = 90 days
maxage=2160

if [ -f "/usr/local/bin/aide" ] && [ -d "/var/db/aide" ]; then
        dstamp=`date +"%H%M-%m%d%Y"`
        data=/var/db/aide/databases
        log=/var/db/aide/aide.log
        cur_db=$data/aide.db
        new_db=$data/aide.db.new

        if [ ! -f "$cur_db" ]; then
                /usr/bin/nice -n 19 /usr/local/bin/aide --init >> /dev/null 2>&1
                cp $new_db $cur_db
        fi

         if [ -f "$cur_db" ]; then
                cur_db_dstamp=`stat -c "%y" $cur_db | tr '.' ' ' | tr -d ':-' | awk '{print$1"-"$2}'`
                cp -f $cur_db $cur_db.$cur_db_dstamp

                /usr/bin/gzip -f $cur_db.$cur_db_dstamp

                cur_log_dstamp=`stat -c "%y" $log | tr '.' ' ' | tr -d ':-' | awk '{print$1"-"$2}'`
                cp -f $log $log.$cur_log_dstamp

                mv -f $new_db $cur_db
                /usr/bin/nice -n 19 /usr/local/bin/aide --init >> /dev/null 2>&1
                /usr/bin/nice -n 19 /usr/local/bin/aide --compare >> /dev/null 2>&1
                HOSTNAME=`hostname`
                if [ ! -z "$email" ] && [ -f "$log" ]; then
                        cat $log | mail -s "AIDE report on $HOSTNAME" $email
                fi
        fi

        if [ -f "/usr/local/sbin/tmpwatch" ]; then
                /usr/local/sbin/tmpwatch $maxage $data/
        fi
fi
This is what happens:

# ./etc/periodic/security/950.aide
Code:
stat: illegal option -- c
usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...]
stat: illegal option -- c
usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...]
cp: /var/db/aide/aide.log: No such file or directory
mv: rename /var/db/aide/databases/aide.db.new to /var/db/aide/databases/aide.db: No such file or directory
So I change stat -c to stat -f and I get this:

# ./etc/periodic/security/950.aide
Code:
stat: %y: bad format
stat: /var/db/aide/aide.log: stat: No such file or directory
cp: /var/db/aide/aide.log: No such file or directory
%y in Linux is the Time of last modification. The FreeBSD analog is %m.

So after these minor changes, this is the result:

# ./etc/periodic/security/950.aide
Code:
stat: /var/db/aide/aide.log: stat: No such file or directory
cp: /var/db/aide/aide.log: No such file or directory
Which I think was easily fixed by touching /var/db/aide/aide.log

I now get this as the only output:

# ./etc/periodic/security/950.aide
Code:
Null message body; hope that's ok
I don't think that is ok, is it? aide.log is empty also.



On the other note, I am pretty sure my mail server works as I receive daily reports to my gmail account. Is this a fair assumption?
__________________
FreeBSD 8.3 RELEASE

Last edited by ghostcorps; September 21st, 2011 at 08:37.
Reply With Quote
  #10  
Old September 21st, 2011, 08:47
graudeejs's Avatar
graudeejs graudeejs is offline
Style(9) Addict
 
Join Date: Nov 2008
Location: Riga, Latvia
Posts: 4,521
Thanks: 422
Thanked 607 Times in 475 Posts
Default

I suppose
Reply With Quote
  #11  
Old September 21st, 2011, 09:58
Dies_Irae Dies_Irae is offline
Junior Member
 
Join Date: Sep 2011
Posts: 53
Thanks: 3
Thanked 13 Times in 11 Posts
Default

Quote:
Originally Posted by ghostcorps View Post
This is the how-to I have been reffering to.
One of the worst guide I have ever seen. The most useful info is "Also read the aide.conf manual page".

Quote:
Originally Posted by ghostcorps
I don't think that is ok, is it? aide.log is empty also.
aide won't create any logs, unless you tell him to act differently. The output is printed on standard output by default, see aide.conf(5)
Code:
report_url
    The url that the output is written to. There can be multiple instances of this
parameter. Output is written to all of them. The default is stdout.
All depends from how you have configured aide.conf, but if you have not touched the "report_url" setting your aide is sending the output to stdout - which your script discards happily.

Code:
/usr/bin/nice -n 19 /usr/local/bin/aide --init >> /dev/null 2>&1
/usr/bin/nice -n 19 /usr/local/bin/aide --compare >> /dev/null 2>&1
__________________
O quam contempta res est homo, nisi supra humana surrexerit. (Seneca)
Reply With Quote
The Following User Says Thank You to Dies_Irae For This Useful Post:
ghostcorps (September 21st, 2011)
  #12  
Old September 21st, 2011, 12:13
ghostcorps ghostcorps is offline
Member
 
Join Date: May 2009
Posts: 241
Thanks: 68
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by graudeejs View Post
The magic is
Code:
cat $log | mail -s "AIDE report on $HOSTNAME" $email
It certainly is!

Turns out the emails were going to the spam folder but they are empty.


So close.
__________________
FreeBSD 8.3 RELEASE
Reply With Quote
  #13  
Old September 21st, 2011, 13:53
Dies_Irae Dies_Irae is offline
Junior Member
 
Join Date: Sep 2011
Posts: 53
Thanks: 3
Thanked 13 Times in 11 Posts
Default

Your emails are empty because in your script the body of the message is the content of the file /var/db/aide/aide.log which is empty - and nothing is going to write something into it.

You should redirect the output of aide to this file:
Code:
/usr/bin/nice -n 19 /usr/local/bin/aide --init > /var/db/aide/aide.log 2>&1
/usr/bin/nice -n 19 /usr/local/bin/aide --compare > /var/db/aide/aide.log 2>&1
or set the "report_url" in your aide.conf:
Code:
report_url=file:/var/db/aide/aide.log
__________________
O quam contempta res est homo, nisi supra humana surrexerit. (Seneca)
Reply With Quote
The Following User Says Thank You to Dies_Irae For This Useful Post:
ghostcorps (September 21st, 2011)
  #14  
Old September 22nd, 2011, 00:11
ghostcorps ghostcorps is offline
Member
 
Join Date: May 2009
Posts: 241
Thanks: 68
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Dies_Irae View Post
Your emails are empty because in your script the body of the message is the content of the file /var/db/aide/aide.log which is empty - and nothing is going to write something into it.

You should redirect the output of aide to this file:
Code:
/usr/bin/nice -n 19 /usr/local/bin/aide --init > /var/db/aide/aide.log 2>&1
/usr/bin/nice -n 19 /usr/local/bin/aide --compare > /var/db/aide/aide.log 2>&1
or set the "report_url" in your aide.conf:
Code:
report_url=file:/var/db/aide/aide.log
Champion!

Thankyou
__________________
FreeBSD 8.3 RELEASE
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Solved] Portmaster reporting error? Mayhem30 Installation and Maintenance of FreeBSD Ports or Packages 5 June 26th, 2011 14:26
suhosin reporting canary mismatch with php-5.2.10 neildarlow Installation and Maintenance of FreeBSD Ports or Packages 3 November 13th, 2010 17:38
System monitoring with e-mail reporting ilemur System Hardware 2 March 5th, 2010 12:28
Portaudit reporting nsd2 vulnerable nerdsite Installation and Maintenance of FreeBSD Ports or Packages 0 June 29th, 2009 18:01
Squid Transparent Proxy Reporting Issue bdyzel Networking 1 June 9th, 2009 12:18


All times are GMT +1. The time now is 05:58.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0