Security Monitoring and Enforcement with Cfengine 3
Cfengine, from the start, has had security as a key part of its design and use scenarios. Here, I demonstrate how Cfengine 3 can be used to increase the security of a Linux system by monitoring file checksums, monitoring filesystems for suspicious filenames, monitoring running processes, monitoring open ports and managing sshd.conf.
Because Cfengine 3 is under active development, I suggest you install the latest version from the Cfengine Source Archive (see Resources).
The purpose of this article is to give practical examples of how you can use Cfengine to increase security on a Linux system. See the Quick Start Guide in the Resources section of this article for help in learning the Cfengine language. (I don't provide a tutorial on the Cfengine language here.) This article is based on Cfengine version 3.1.5a1.
Cfengine 3.1.4 shipped with 214 unit tests that can double as examples of Cfengine's functionality. They are installed to /usr/local/share/doc/cfengine/. I've adopted unit_change_detect.cf into detect_changes_in_etc.cf (Listing 1).
Listing 1. detect_changes_in_etc.cf
# GNU GPL 3
###################################################
#
# Change detect
#
###################################################
body common control
{
bundlesequence => { "detect_changes_in_etc" };
}
###################################################
bundle agent detect_changes_in_etc
{
files:
"/etc"
changes => detect_all_change,
depth_search => recurse("inf");
}
###################################################
body changes detect_all_change
{
report_changes => "all";
update_hashes => "true";
}
###################################################
body depth_search recurse(d)
{
depth => "$(d)";
}
Run this with:
cf-agent -KIf detect_changes_in_etc.cf
cf-agent is the component of Cfengine that actually makes changes to the system. (There are other components to serve files, monitor system activity and so on. cf-agent is the piece that makes changes to the system, and the one you'd use to start learning Cfengine.) In the command above:
-K — tells cf-agent to ignore time-based locks and allows you to run cf-agent repeatedly (no “cool-off” period, which might otherwise kick in to prevent system overload).
-I — tells cf-agent to inform you of its actions and any changes made to the system.
-f — specifies the policy filename.
On the first pass, cf-agent builds a file information database containing file timestamps and inode numbers and builds an MD5 hash for each file. You should see something like this:
# cf-agent -KIf detect_changes_in_etc.cf
!! File /etc/hosts.allow was not in MD5
database - new file found
I: Made in version 'not specified' of
'detect_changes_in_etc.cf' near line 22
...
#
There are two messages here, alert and info.
Cfengine prefixes its output to help you understand what kind of output it is (in other words, metadata):
Informational messages start with “I”.
Reports start with “R”.
Alerts start with !! or ALERT.
Notice of changes to the system starts with ->.
In the above case, the alert message is accompanied with an info message about the policy that was in effect when the alert was produced, its version number (if supplied) and the line number.
I didn't specify the version number, but the line number is useful. Line 22 is:
changes => detect_all_change,
This is the line responsible for Cfengine adding /etc/passwd to the MD5 database. It tells Cfengine what to do about changes—to detect them.
Now, I run cf-agent again, and it runs quietly. The contents of /etc match the MD5 sum database:
# cf-agent -KIf detect_changes_in_etc.cf #
Next, I edit /etc/hosts.allow to add “sshd: ALL” to simulate an unauthorized change. Watch cf-agent scream:
# cf-agent -KIf detect_changes_in_etc.cf !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ALERT: Hash (MD5) for /etc/hosts.allow changed! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -> Updating hash for /etc/hosts.allow to MD5=2637c1edeb55081b330a1829b4b98c45 I: Made in version 'not specified' of './detect_changes_in_etc.cf' near line 22 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ALERT: inode for /etc/hosts.allow changed 38901878 -> 38901854 ALERT: Last modified time for /etc/hosts.allow changed Sat Jan 29 17:09:26 2011 -> Mon Jan 31 08:00:02 2011 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
There are three alerts:
MD5 hash changed (because the contents changed).
The inode number changed (when vi saved the file).
The modification time changed (when vi saved the file).
Reminder: messages about actions that Cfengine takes are prefixed with “->”:
-> Updating hash for /etc/hosts.allow to MD5=2637c1edeb55081b330a1829b4b98c45
You can set up Cfengine to complain via e-mail or syslog, so even if the intruder tampers with the MD5 database, the alarm will sound. In commercial versions of Cfengine (Nova), you can set up multiple Cfengine nodes to share their MD5 databases and monitor and cross-check each other.
You can run this check fairly often—every five minutes, if you like and if your hardware will sustain it. (Computing lots of MD5 sums can be expensive on CPU and disk I/O.) Is the added security worth it to you?
Aleksey Tsalolikhin has been a UNIX/Linux system administrator for 14 years.
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
- RSS Feeds
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- Validate an E-Mail Address with PHP, the Right Way
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Download the Free Red Hat White Paper "Using an Open Source Framework to Catch the Bad Guy"
- Tech Tip: Really Simple HTTP Server with Python
- Home, My Backup Data Center
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.




1 hour 9 min ago
1 hour 38 min ago
2 hours 36 min ago
4 hours 5 min ago
5 hours 13 min ago
6 hours 17 sec ago
6 hours 21 min ago
12 hours 35 min ago
18 hours 14 min ago
1 day 14 min ago