OSSEC: building an OpenBSD package

OSSEC is an Open Source Host-based Intrusion Detection System that performs log analysis, file integrity checking, policy monitoring, rootkit detection, real-time alerting and active response.

It runs on most operating systems, including Linux, MacOS, Solaris, HP-UX, AIX and OpenBSD.

There is no OSSEC package available on the OSSEC website or in the OpenBSDs ports repositry, so I’ve decided to create an OpenBSD on my own.
OpenBSD packages are pretty easy to create and are very useful when installing, upgrading or deleting software on a server.

One of the disadvantages when creating an OpenBSD package, is that you will need to have X11 installed on your OpenBSD system.
In the following example I have used OpenBSD 5.8 to create a package for OSSEC 2.8.2 (OSSEC 2.8.3 doesn’t compile on OpenBSD 5.8)

Step 1: Prerequisites

You will also need a compiler:

Step 2: Download and repack the source

Since the Makefile for OSSEC is in the src/ sub directory, we will create a proxy Makefile in /usr/src/ossec-hids-2.8.2

I have actually taken the original Makefile from src/ and narrowed it down to the following:

We will also edit the ‘ossec-clients.sh‘ script, because we will use this script as a start/stop script. We will have to set the path name in this script.

And that’s the only thing we will need to change in the sources, we can now repackage it.

Step 3: Prepare the ports directory

The following steps explain how to set up a ports directory in /usr/ports for OSSEC, in order to build the package.
Custom made packages are built in /usr/ports/mystuff. In there, we will have to one sub directory for the package category (we will use security) and in there the package name, which in our case will be ossec-hids.

The configuration file for building an OpenBSD package is a Makefile. There is a template file in /usr/ports/infrastructure/templates/Makefile.template which can be used.

This file of course needs editing. Not everything is required in this file, so I have narrowed the Makefile down to what I need it for:

The above Makefile will install OSSEC in /var/ossec and will only install the agent files. It does not install the server files.

Step 4: Test the settings

First we will make a checksum and then we will start a fake compile run, to see if everything compiles nicely.

If there were no errors, then we are ready to create the actual package.

Step 5: Create the OpenBSD package

Normally we do not need to edit the PLIST file, but I wanted to create an ossec user upon installation and chown the /var/ossec directory to that user.
So I have added the following lines to the top of pkg/PLIST:

And these to the bottom:

Afterwards you will need to run:

Now we are ready to build the package:

That’s it! This package can now be installed with the ‘pkg_add‘ command.


Leave a Reply

Your email address will not be published. Required fields are marked *