Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions pureftpd/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
This is a set of simple nagios plugins written in perl, python, shell-script & powershell
for testing pureftpd-related parameters

# Usage

## check_symlink_log.sh:

This script checks is there are FTP accounts with root folcers set to paths that are symlinks. It relies on check_symlink_accounts.sh to fill in the logs first, and based on the log output check_symlink_log.sh will report OK or CRITICAL

```sh
./check_symlink_log.sh
```

### Exit codes
```
0 - OK
2 - CRITICAL
```

### Examples
Example call when there are users with symlink root directories
```sh
./check_symlink_log.sh
```
Returns:
```sh
CRITICAL - Number of ftp accounts with symlinks as root is 4. The full list can be seen in the /var/log/symlink.log
```

Example call when there are no users with symlink root directories
```sh
./check_symlink_log.sh
```
Returns:
```sh
OK - Number of ftp accounts with symlinks as root is 0
```
### Nagios client setup

Assuming you are using nrpe client on Linux, the check scripts should be put into: `/usr/lib/nagios/plugins/atomia/`

#### cron.d
New file in cron.d should be added with the content line this:

```sh
*/5 * * * * root /usr/lib/nagios/plugins/atomia/check_symlink_accounts.sh
```

#### nrpe.cfg

Configuratoin should be as follwong:

```sh
command[check_pureftpd_symlinks] = /usr/lib/nagios/plugins/atomia/check_symlink_log.sh
```

### Nagios server sertup

Since the script is a shell script that is triggered with `check_nrpe` example call for domain admins would be:

```sh
/usr/lib/nagios/plugins/check_nrpe -H ftp01.atomia.hostcenter.com -t 150 -c check_pureftpd_symlinks
```
20 changes: 20 additions & 0 deletions pureftpd/symlink check/check_symlink_accounts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /bin/bash
MYSQL=/usr/bin/mysql
LOGFILE=/var/log/symlink.log
TS=`date '+%Y-%m-%d %H:%M:%S'`
sylinks=0
$MYSQL --defaults-file=/etc/mysql/debian.cnf -N -e "use pureftpd; select Dir from users;" | \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work on RHEL based systems. You don't need the --defaults-file=/etc/mysql/debian.cnf specified. By default on our systems you can login without password if the script is running as root. This is not that secure but is the way that we are using it at the moment.

(while read dir; do
dir1=`echo "$dir" | sed 's/\/$//'`
if [ -L "${dir1}" ] && [ -e ${dir1} ] ; then
TS=`date '+%Y-%m-%d %H:%M:%S'`
echo "$TS $dir1 is symlink" >> $LOGFILE
((sylinks++))
fi
done

if [[ $sylinks -gt 0 ]]
then
echo "CRITICAL - Number of ftp accounts with symlinks as root is $sylinks" >> $LOGFILE
fi
Comment on lines +11 to +19

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case you had CRITICAL state in the log file /var/log/symlink.log and it recovered to OK, you will still have CRITICAL in the log.

I suggest having two files:

  1. The lock file that will have CRITICAL or OK at one moment i.e. /var/log/symlink.lock
  2. The next log that will check if CRITICAL accounts are found can be /var/log/symlink.log

On line 18, you could log CRITICAL only to the lock file with > so the lock will get overridden.

Issue with this would be if, an attacker was fast enough and Nagios does not alert for 1 CRITICAL. It can be configured differently in Nagios.

)
14 changes: 14 additions & 0 deletions pureftpd/symlink check/check_symlink_log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#! /bin/bash
LOGFILE=/var/log/symlink.log
TS=`date '+%Y-%m-%d %H:%M:%S'`

OUTPUT=`grep CRITICAL $LOGFILE | tail -1`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check here maybe in the lock file instead of the log.


if [[ -n $OUTPUT ]]
then
echo "$OUTPUT. The full list can be seen in the $LOGFILE "
exit 2
else
echo "OK - Number of ftp accounts with symlinks as root is 0"
exit 0
fi