{"id":1944,"date":"2015-11-24T02:43:19","date_gmt":"2015-11-24T02:43:19","guid":{"rendered":"http:\/\/blog.webhost.pro\/?p=1944"},"modified":"2015-11-24T02:48:54","modified_gmt":"2015-11-24T02:48:54","slug":"how-to-install-ossec","status":"publish","type":"post","link":"https:\/\/webhostpro.com\/blog\/how-to-install-ossec\/","title":{"rendered":"How to install OSSEC"},"content":{"rendered":"<h3 id=\"introduction\">Getting started<\/h3>\n<p><strong>Q. How do you keep track of authorized and unauthorized activity on your server?<\/strong><\/p>\n<p>A. OSSEC is\u00a0one of the best current tools to monitor any suspicious activity.<\/p>\n<p>OSSEC is an open-source, host-based intrusion detection system (HIDS) that performs log analysis, integrity checking, rootkit detection, time-based alerting, and active response. It can be used to monitor one server or thousands of servers in a server\/agent mode.<\/p>\n<p>If properly configured, OSSEC can give you a real-time view\u00a0of\u00a0what&#8217;s happening on your server.<\/p>\n<p><strong>This tutorial was\u00a0made\u00a0to\u00a0show you how to install and configure OSSEC.<\/strong><\/p>\n<p><strong>What are the benefits of OSSEC?<\/strong><\/p>\n<p>Below is an example of an email notification from OSSEC, showing that the file <span class=\"highlight\">\/var\/ossec\/etc\/ossec.conf<\/span>was modified.<\/p>\n<pre class=\"code-pre \"><code>OSSEC HIDS Notification.\r\n2014 Nov 29 09:45:15\r\n\r\nReceived From: kuruji-&gt;syscheck\r\nRule: 552 fired (level 7) -&gt; \"Integrity checksum changed again (3rd time).\"\r\nPortion of the log(s):\r\n\r\nIntegrity checksum changed for: '\/var\/ossec\/etc\/ossec.conf'\r\nSize changed from '7521' to '7752'\r\n<\/code><\/pre>\n<p>If you received such an alert, and you were not expecting that file to change, then you know that something unauthorized has happened on your server.<\/p>\n<p>Here&#8217;s another example email alert from OSSEC, showing that the file <span class=\"highlight\">\/etc\/ossec\/testossec.txt<\/span> was deleted.<\/p>\n<pre class=\"code-pre \"><code>OSSEC HIDS Notification.\r\n2014 Nov 29 10:56:14\r\n\r\nReceived From: kuruji-&gt;syscheck\r\nRule: 553 fired (level 7) -&gt; \"File deleted. Unable to retrieve checksum.\"\r\nPortion of the log(s):\r\n\r\nFile <span class=\"highlight\">\/etc\/ossec\/testossec.txt<\/span> was deleted. Unable to retrieve checksum.\r\n<\/code><\/pre>\n<p>Again, if you did not delete the file, you should figure out what is happening on your server.<\/p>\n<p><em>It also has more than just monitoring as we mentions before, read on to learn more.<\/em><\/p>\n<h3 id=\"prerequisites\">What you will need.<\/h3>\n<p>This tutorial assumes you have a server with root access and a command line interface like putty available for the server.<\/p>\n<ul>\n<li>Centos\u00a0server<\/li>\n<li>This tutorial is\u00a0easiest to do\u00a0as the <strong>root<\/strong> user:<\/li>\n<\/ul>\n<pre class=\"code-pre \"><code>sudo su<\/code><\/pre>\n<ul>\n<li>Installation of OSSEC involves some compiling, so you need <code>gcc<\/code> and <code>make<\/code> installed. You can install both by installing a single package called <code>build-essential<\/code><\/li>\n<li>You also need to install a package called <code>inotify-tools<\/code>, which is required for real-time alerting to work.<\/li>\n<\/ul>\n<p>To install all required packages, first update the server:<\/p>\n<pre class=\"code-pre \"><code>apt-get update\r\n<\/code><\/pre>\n<p>Then install the packages:<\/p>\n<pre class=\"code-pre \"><code>apt-get install build-essential inotify-tools\r\n<\/code><\/pre>\n<div data-unique=\"step-1-\u2014-download-and-verify-ossec\"><\/div>\n<h3 id=\"step-1-\u2014-download-and-verify-ossec\">Download<\/h3>\n<p>In this step, you&#8217;ll download the OSSEC tarball and a file containing its cryptographic checksums.<\/p>\n<p>Since this a security article, we&#8217;re going to do a little extra work to verify that we&#8217;re installing valid software. The idea is that you generate the MD5 and SHA1 checksums of the downloaded OSSEC tarball and compare them with those in the checksum file. If they match, then you can assume that the tarball has not been tampered with.<\/p>\n<pre class=\"code-pre \"><code>wget -U ossec http:\/\/www.downloadspot.com\/wp-content\/uploads\/2015\/11\/ossec-hids-2.8.2.tar.gz<\/code><\/pre>\n<h2><\/h2>\n<h3 id=\"step-2-\u2014-install-ossec\">Install<\/h3>\n<p>OSSEC can be installed\u00a0all servers and VPS systems.<\/p>\n<p>Before installation can start, you have to untar\u00a0the file. You do that by typing:<\/p>\n<pre class=\"code-pre \"><code>tar -zxf ossec-hids-2.8.2.tar.gz\r\n<\/code><\/pre>\n<p>Now\u00a0you should have a directory named <span class=\"highlight\">ossec-hids-2.8.2<\/span>. To start installation, you have to change (cd) into that directory:<\/p>\n<pre class=\"code-pre \"><code>cd ossec-hids-2.8.2\r\n<\/code><\/pre>\n<p>The only file of interest to us in that listing is <span class=\"highlight\">install.sh<\/span>. That&#8217;s the OSSEC installation script. To start the\u00a0installation, type:<\/p>\n<pre class=\"code-pre \"><code>.\/install.sh\r\n<\/code><\/pre>\n<p>You will have\u00a0to answer some installation questions now.<\/p>\n<p><strong>The correct entries to use are shown in <span class=\"highlight\">red<\/span>.<\/strong><\/p>\n<p>So if your language is English, press <code>ENTER<\/code>. Otherwise, type the two letters for your language and press ENTER.<\/p>\n<pre class=\"code-pre \"><code>  (en\/br\/cn\/de\/el\/es\/fr\/hu\/it\/jp\/nl\/pl\/ru\/sr\/tr) [en]:\r\n\r\n<\/code><\/pre>\n<p>After selecting the language, you should see this:<\/p>\n<pre class=\"code-pre \"><code>OSSEC HIDS v2.8 Installation Script - http:\/\/www.ossec.net\r\n\r\n You are about to start the installation process of the OSSEC HIDS.\r\n You must have a C compiler pre-installed in your system.\r\n If you have any questions or comments, please send an e-mail\r\n to dcid@ossec.net (or daniel.cid@gmail.com).\r\n\r\n  - System: Linux kuruji 3.13.0-36-generic\r\n  - User: root\r\n  - Host: kuruji\r\n\r\n  -- Press ENTER to continue or Ctrl-C to abort. --\r\n<\/code><\/pre>\n<p>Press ENTER\u00a0and\u00a0you will\u00a0get:<\/p>\n<pre class=\"code-pre \"><code>1- What kind of installation do you want (server, agent, local, hybrid or help)? <span class=\"highlight\">local<\/span>\r\n<\/code><\/pre>\n<p>Type <code><span class=\"highlight\">local<\/span><\/code> and press ENTER to get:<\/p>\n<pre class=\"code-pre \"><code>  - Local installation chosen.\r\n\r\n2- Setting up the installation environment.\r\n\r\n  - Choose where to install the OSSEC HIDS [\/var\/ossec]:\r\n<\/code><\/pre>\n<p>Accept the default and press ENTER\u00a0to\u00a0get:<\/p>\n<pre class=\"code-pre \"><code>    - Installation will be made at  \/var\/ossec .\r\n\r\n3- Configuring the OSSEC HIDS.\r\n\r\n  3.1- Do you want e-mail notification? (y\/n) [y]:\r\n<\/code><\/pre>\n<p>Press ENTER.<\/p>\n<pre class=\"code-pre \"><code>  - What's your e-mail address? user<span class=\"highlight\">@example.com<\/span>\r\n<\/code><\/pre>\n<p>Type the email address where you want to receive notifications from OSSEC.<\/p>\n<pre class=\"code-pre \"><code>  - We found your SMTP server as: mail.example.com.\r\n  - Do you want to use it? (y\/n) [y]:\r\n\r\n--- Using SMTP server:  mail.example.com.\r\n<\/code><\/pre>\n<p>Press ENTER unless you have a specific SMTP server setting you want to use.<\/p>\n<p>Now&#8217;s time to let OSSEC know what checks it should be running. In response to any prompt from the script, accept the default by pressing <code>ENTER<\/code>.<\/p>\n<p>ENTER for the integrity check daemon.<\/p>\n<pre class=\"code-pre \"><code>  3.2- Do you want to run the integrity check daemon? (y\/n) [y]:\r\n\r\n- Running syscheck (integrity check daemon).\r\n<\/code><\/pre>\n<p>ENTER for rootkit detection.<\/p>\n<pre class=\"code-pre \"><code>  3.3- Do you want to run the rootkit detection engine? (y\/n) [y]:\r\n\r\n- Running rootcheck (rootkit detection).\r\n<\/code><\/pre>\n<p>ENTER for active response.<\/p>\n<pre class=\"code-pre \"><code>  3.4- Active response allows you to execute a specific command based on the events received.  \r\n\r\n   Do you want to enable active response? (y\/n) [y]:\r\n\r\n   Active response enabled.\r\n<\/code><\/pre>\n<p>Accept the defaults for firewall-drop response. Your output may show some IPv6 options \u2013 that&#8217;s fine.<\/p>\n<pre class=\"code-pre \"><code>  Do you want to enable the firewall-drop response? (y\/n) [y]:\r\n\r\n- firewall-drop enabled (local) for levels &gt;= 6\r\n\r\n   - Default white list for the active response:\r\n      - 8.8.8.8\r\n      - 8.8.4.4\r\n\r\n   - Do you want to add more IPs to the white list? (y\/n)? [n]:\r\n<\/code><\/pre>\n<p><strong>You can\u00a0add your IP address here, but it&#8217;s not necessary.<\/strong><\/p>\n<p>OSSEC will now present a default list of files that it will monitor. Additional files can be added after installation, so press ENTER.<\/p>\n<pre class=\"code-pre \"><code>3.6- Setting the configuration to analyze the following logs:\r\n    -- \/var\/log\/auth.log\r\n    -- \/var\/log\/syslog\r\n    -- \/var\/log\/dpkg.log\r\n\r\n - If you want to monitor any other file, just change\r\n   the ossec.conf and add a new localfile entry.\r\n   Any questions about the configuration can be answered\r\n   by visiting us online at http:\/\/www.ossec.net .\r\n\r\n\r\n   --- Press ENTER to continue ---\r\n<\/code><\/pre>\n<p>By this time, the installer has all the information it needs to install OSSEC. Kick back and let the installer do its thing. Installation takes about 5 minutes. If installation is successful, you are now ready to start and configure OSSEC.<\/p>\n<blockquote><p><strong>Note:<\/strong> One reason installation might fail is if a compiler is not installed. In that case, you&#8217;ll get an error like this:<\/p>\n<pre class=\"code-pre \"><code>5- Installing the system\r\n - Running the Makefile\r\n.\/install.sh: 85: .\/install.sh: make: not found\r\n\r\n Error 0x5.\r\n Building error. Unable to finish the installation.\r\n<\/code><\/pre>\n<p>If you get that error, then you need to install <code>build-essential<\/code>, as explained in the Prerequisites section of the tutorial.<\/p><\/blockquote>\n<p>If installation succeeds, you should see this type of output:<\/p>\n<pre class=\"code-pre \"><code> - System is Debian (Ubuntu or derivative).\r\n - Init script modified to start OSSEC HIDS during boot.\r\n\r\n - Configuration finished properly.\r\n\r\n - To start OSSEC HIDS:\r\n                \/var\/ossec\/bin\/ossec-control start\r\n\r\n - To stop OSSEC HIDS:\r\n                \/var\/ossec\/bin\/ossec-control stop\r\n\r\n - The configuration can be viewed or modified at \/var\/ossec\/etc\/ossec.conf\r\n\r\n    ---  Press ENTER to finish (maybe more information below). ---\r\n<\/code><\/pre>\n<p>OSSEC is now installed. The next step is to start it.<\/p>\n<div data-unique=\"step-3-\u2014-start-ossec\"><\/div>\n<h3 id=\"step-3-\u2014-start-ossec\">Start OSSEC<\/h3>\n<p>By default OSSEC is configured to start at boot, but the first time, you&#8217;ll have to start it manually.<\/p>\n<p>If you want to check its current status, type:<\/p>\n<pre class=\"code-pre \"><code>\/var\/ossec\/bin\/ossec-control status\r\n<\/code><\/pre>\n<p>Expected output:<\/p>\n<pre class=\"code-pre \"><code>ossec-monitord not running...\r\nossec-logcollector not running...\r\nossec-syscheckd not running...\r\nossec-analysisd not running...\r\nossec-maild not running...\r\nossec-execd not running...\r\n<\/code><\/pre>\n<p>That tells you that none of OSSEC&#8217;s processes are running.<\/p>\n<p>To start OSSEC, type:<\/p>\n<pre class=\"code-pre \"><code>\/var\/ossec\/bin\/ossec-control start\r\n<\/code><\/pre>\n<p>You should see it starting up:<\/p>\n<pre class=\"code-pre \"><code>Starting OSSEC HIDS v2.8 (by Trend Micro Inc.)...\r\nStarted ossec-maild...\r\nStarted ossec-execd...\r\nStarted ossec-analysisd...\r\nStarted ossec-logcollector...\r\nStarted ossec-syscheckd...\r\nStarted ossec-monitord...\r\nCompleted.\r\n<\/code><\/pre>\n<p>If you check the status again, you should get confirmation that OSSEC is now running.<\/p>\n<pre class=\"code-pre \"><code>\/var\/ossec\/bin\/ossec-control status\r\n<\/code><\/pre>\n<p>This output shows that OSSEC is running:<\/p>\n<pre class=\"code-pre \"><code>ossec-monitord is running...\r\nossec-logcollector is running...\r\nossec-syscheckd is running...\r\nossec-analysisd is running...\r\nossec-maild is running...\r\nossec-execd is running...\r\n<\/code><\/pre>\n<p>Right after starting OSSEC, you should get an email that reads like this:<\/p>\n<pre class=\"code-pre \"><code>OSSEC HIDS Notification.\r\n2014 Nov 30 11:15:38\r\n\r\nReceived From: ossec2-&gt;ossec-monitord\r\nRule: 502 fired (level 3) -&gt; \"Ossec server started.\"\r\nPortion of the log(s):\r\n\r\nossec: Ossec started.\r\n<\/code><\/pre>\n<p>That&#8217;s another confirmation that OSSEC is working and will send you email alerts whenever something it&#8217;s configured to monitor happens. Even when it is restarted, OSSEC will send you an email.<\/p>\n<p>If you didn&#8217;t get this email right away, don&#8217;t worry. You may still need to tweak your email settings (which we&#8217;ll cover later in the tutorial) to make sure your OSSEC server&#8217;s emails can get through to your mail provider. This is especially true for some 3rd-party email service providers like Google and Fastmail.<\/p>\n<div data-unique=\"step-4-\u2014-configure-ossec-for-real-time-alerts-on-file-modifications\"><\/div>\n<h3 id=\"step-4-\u2014-configure-ossec-for-real-time-alerts-on-file-modifications\">Configure OSSEC for Real-time Alerts on File Modifications<\/h3>\n<p>Next, work with\u00a0OSSEC&#8217;s files and directories, and learn how to change OSSEC&#8217;s monitoring and alert settings.<\/p>\n<h4 id=\"getting-to-know-ossec-39-s-directory-structure\">OSSEC&#8217;s directory structure<\/h4>\n<p>OSSEC&#8217;s default directory is a <em>chroot<\/em>-ed (sandbox) environment that only a user with root (admin) privileges can access. A standard user cannot <code>cd<\/code> into <code>\/var\/ossec<\/code> or even list the files in it. As the root (or admin) user, however, you can.<\/p>\n<p>So, <code>cd<\/code> into the installation directory by typing:<\/p>\n<pre class=\"code-pre \"><code>cd \/var\/ossec\r\n<\/code><\/pre>\n<p>To list the files in your new working directory, type:<\/p>\n<pre class=\"code-pre \"><code>ls -lgG\r\n<\/code><\/pre>\n<p>You should see these files and directories:<\/p>\n<pre class=\"code-pre \"><code>total 40\r\ndr-xr-x---  3 4096 Nov 26 14:56 active-response\r\ndr-xr-x---  2 4096 Nov 20 20:56 agentless\r\ndr-xr-x---  2 4096 Nov 20 20:56 bin\r\ndr-xr-x---  3 4096 Nov 29 00:49 etc\r\ndrwxr-x---  5 4096 Nov 20 20:56 logs\r\ndr-xr-x--- 11 4096 Nov 20 20:56 queue\r\ndr-xr-x---  4 4096 Nov 20 20:56 rules\r\ndrwxr-x---  5 4096 Nov 20 21:00 stats\r\ndr-xr-x---  2 4096 Nov 20 20:56 tmp\r\ndr-xr-x---  3 4096 Nov 29 18:34 var\r\n<\/code><\/pre>\n<ul>\n<li>OSSEC&#8217;s main configuration file is in the <code>\/var\/ossec\/etc<\/code> directory.<\/li>\n<li>Predefined rules are in the <code>\/var\/ossec\/rules<\/code> directory<\/li>\n<li>Commands used to manage OSSEC are in <code>\/var\/ossec\/bin<\/code><\/li>\n<li>Take note of the <code>\/var\/ossec\/logs<\/code> directory. If OSSEC ever throws an error, the<code>\/var\/ossec\/logs\/ossec.log<\/code> file in that directory is the first place to look<\/li>\n<\/ul>\n<h3 id=\"main-configuration-file-var-ossec-etc-ossec-conf\">Main configuration file, \/var\/ossec\/etc\/ossec.conf<\/h3>\n<p>To access the main configuration file, you have to change into <code>\/var\/ossec\/etc<\/code>. To do that, type:<\/p>\n<pre class=\"code-pre \"><code>cd \/var\/ossec\/etc\r\n<\/code><\/pre>\n<p>If you do an <code>ls<\/code> while in that directory, you&#8217;ll see these files and directories:<\/p>\n<pre class=\"code-pre \"><code>ls -lgG\r\n<\/code><\/pre>\n<p>Results:<\/p>\n<pre class=\"code-pre \"><code>total 120\r\n-r--r----- 1 97786 Sep  8 22:03 decoder.xml\r\n-r--r----- 1  2842 Sep  8 22:03 internal_options.conf\r\n-r--r----- 1  3519 Oct 30 13:46 localtime\r\n-r--r----- 1  7752 Nov 29 09:45 ossec.conf\r\n-rw-r----- 1    87 Nov 20 20:56 ossec-init.conf\r\ndrwxrwx--- 2  4096 Nov 20 21:00 shared\r\n<\/code><\/pre>\n<p>The main configuration file is <code>\/var\/ossec\/etc\/ossec.conf<\/code>.<\/p>\n<p>Before modifying the file, make a backup copy, just in case. To make that copy, use the <code>cp<\/code> command like so:<\/p>\n<pre class=\"code-pre \"><code>cp \/var\/ossec\/etc\/ossec.conf \/var\/ossec\/etc\/ossec.conf.00\r\n<\/code><\/pre>\n<p>The idea is if your changes don&#8217;t work or mess up the system, you can revert to the copy and be back to normal. It&#8217;s the simplest disaster recovery practice that you should always take advantage of.<\/p>\n<p>Now, open <code>ossec.conf<\/code> by using the <code>nano<\/code> editor.<\/p>\n<pre class=\"code-pre \"><code>nano \/var\/ossec\/etc\/ossec.conf\r\n<\/code><\/pre>\n<p>The configuration file is a very long XML file with several sections.<\/p>\n<h3 id=\"email-settings\">Email settings<\/h3>\n<p>The first configuration options you&#8217;ll see are the email credentials you specified during installation. If you need to specify a different email address and\/or SMTP server, this is the place to do it.<\/p>\n<pre class=\"code-pre \"><code>&lt;global&gt;\r\n    &lt;email_notification&gt;yes&lt;\/email_notification&gt;\r\n    &lt;email_to&gt;user@example.com&lt;\/email_to&gt;\r\n    &lt;smtp_server&gt;mail.example.com.&lt;\/smtp_server&gt;\r\n    &lt;email_from&gt;ossecm@ossec_server&lt;\/email_from&gt;\r\n&lt;\/global&gt;\r\n<\/code><\/pre>\n<p>By default, OSSEC sends 12 emails per hour, so you&#8217;ll not be flooded with email alerts. You can increase or decrease that value by adding the <code>&lt;email_maxperhour&gt;<span class=\"highlight\">N<\/span>&lt;\/email_maxperhour&gt;<\/code> setting to that section so that it reads:<\/p>\n<pre class=\"code-pre \"><code>&lt;global&gt;\r\n    &lt;email_notification&gt;yes&lt;\/email_notification&gt;\r\n    &lt;email_to&gt;user@example.com&lt;\/email_to&gt;\r\n    &lt;smtp_server&gt;mail.example.com.&lt;\/smtp_server&gt;\r\n    &lt;email_from&gt;ossecm@ossec_server&lt;\/email_from&gt;\r\n    <span class=\"highlight\">&lt;email_maxperhour&gt;N&lt;\/email_maxperhour&gt;<\/span>\r\n&lt;\/global&gt;\r\n<\/code><\/pre>\n<p>Please replace <code><span class=\"highlight\">N<\/span><\/code> with the number of emails you want to receive per hour, between <strong>1<\/strong> and <strong>9999<\/strong>.<\/p>\n<p>Some third-party email service providers (Google and Fastmail, for example) will silently drop alerts sent by OSSEC if the <code>&lt;email_from&gt;<\/code> address does not contain a valid domain part, like the one in the code block above. To avoid that, make sure that that email address contains a valid domain part. For example:<\/p>\n<pre class=\"code-pre \"><code>&lt;global&gt;\r\n    &lt;email_notification&gt;yes&lt;\/email_notification&gt;\r\n    &lt;email_to&gt;user@example.com&lt;\/email_to&gt;\r\n    &lt;smtp_server&gt;mail.example.com.&lt;\/smtp_server&gt;\r\n    &lt;email_from&gt;user<span class=\"highlight\">@ossec_server.com<\/span>&lt;\/email_from&gt;\r\n&lt;\/global&gt;\r\n<\/code><\/pre>\n<p>The <code>&lt;email_to&gt;<\/code> and <code>&lt;email_from&gt;<\/code> addresses can be the same. For example:<\/p>\n<pre class=\"code-pre \"><code>&lt;global&gt;\r\n    &lt;email_notification&gt;yes&lt;\/email_notification&gt;\r\n    &lt;email_to&gt;user<span class=\"highlight\">@example.com<\/span>&lt;\/email_to&gt;\r\n    &lt;smtp_server&gt;mail.example.com.&lt;\/smtp_server&gt;\r\n    &lt;email_from&gt;user<span class=\"highlight\">@example.com<\/span>&lt;\/email_from&gt;\r\n&lt;\/global&gt;\r\n<\/code><\/pre>\n<p>If you don&#8217;t want to use an external email provider&#8217;s SMTP server, you can specify your own SMTP server. If your SMTP server is running on the same server as OSSEC, change the <code>&lt;smtp_server&gt;<\/code>setting to <code><span class=\"highlight\">localhost<\/span><\/code>. For example:<\/p>\n<pre class=\"code-pre \"><code>&lt;global&gt;\r\n    &lt;email_notification&gt;yes&lt;\/email_notification&gt;\r\n    &lt;email_to&gt;user@example.com&lt;\/email_to&gt;\r\n    &lt;smtp_server&gt;<span class=\"highlight\">localhost<\/span>&lt;\/smtp_server&gt;\r\n    &lt;email_fromuser@example.com&lt;\/email_from&gt;\r\n&lt;\/global&gt;\r\n<\/code><\/pre>\n<p>OSSEC does not send real-time alerts by default, but this tutorial calls for real-time notifications, so that&#8217;s one aspect that you&#8217;re going to modify.<\/p>\n<p>If you still aren&#8217;t receiving expected emails from OSSEC, check the logs at <code>\/var\/ossec\/logs\/ossec.log<\/code>for mail errors.<\/p>\n<p>Example mail errors:<\/p>\n<pre class=\"code-pre \"><code>2014\/12\/18 17:48:35 os_sendmail(1767): WARN: End of DATA not accepted by server\r\n2014\/12\/18 17:48:35 ossec-maild(1223): ERROR: Error Sending email to 74.125.131.26 (smtp server)\r\n<\/code><\/pre>\n<p>You can use these error messages to help you debug any issues with receiving email notifications.<\/p>\n<h3 id=\"frequency-of-scans\">Frequency of scans<\/h3>\n<p>In the <code>&lt;syscheck&gt;<\/code> section of <code>ossec.conf<\/code>, which starts like this:<\/p>\n<pre class=\"code-pre \"><code>&lt;syscheck&gt;\r\n    &lt;!-- Frequency that syscheck is executed - default to every 22 hours --&gt;\r\n    &lt;frequency&gt;79200&lt;\/frequency&gt;\r\n\r\n<\/code><\/pre>\n<p>We will turn on alerts for new file creation. Add the line <code>&lt;alert_new_files&gt;yes&lt;\/alert_new_files&gt;<\/code> so that it reads like this:<\/p>\n<pre class=\"code-pre \"><code>&lt;syscheck&gt;\r\n    &lt;!-- Frequency that syscheck is executed - default to every 22 hours --&gt;\r\n    &lt;frequency&gt;79200&lt;\/frequency&gt;\r\n\r\n    <span class=\"highlight\">&lt;alert_new_files&gt;yes&lt;\/alert_new_files&gt;<\/span>\r\n<\/code><\/pre>\n<p>For testing purposes, you may also want to set the frequency of the system check to be much lower. By default, the system check is run every 22 hours. For testing purposes, you may want to set this to once a minute, that is, <code>60<\/code> seconds. <strong>Revert this to a sane value when you are done testing.<\/strong><\/p>\n<pre class=\"code-pre \"><code>&lt;syscheck&gt;\r\n    &lt;!-- Frequency that syscheck is executed - default to every 22 hours --&gt;\r\n    &lt;frequency&gt;<span class=\"highlight\">60<\/span>&lt;\/frequency&gt;\r\n\r\n    &lt;alert_new_files&gt;yes&lt;\/alert_new_files&gt;\r\n<\/code><\/pre>\n<h3 id=\"directory-and-file-change-settings\">Directory and file change settings<\/h3>\n<p>Right after that, you should see the list of system directories that OSSEC monitors. It reads like:<\/p>\n<pre class=\"code-pre \"><code>&lt;!-- Directories to check  (perform all possible verifications) --&gt;\r\n&lt;directories check_all=\"yes\"&gt;\/etc,\/usr\/bin,\/usr\/sbin&lt;\/directories&gt;\r\n&lt;directories check_all=\"yes\"&gt;\/bin,\/sbin&lt;\/directories&gt;\r\n<\/code><\/pre>\n<p>Let&#8217;s enable real-time monitoring by adding the settings <code>report_changes=\"yes\" realtime=\"yes\"<\/code> to each line. Modify these lines so they read:<\/p>\n<pre class=\"code-pre \"><code>&lt;!-- Directories to check  (perform all possible verifications) --&gt;\r\n&lt;directories <span class=\"highlight\">report_changes=\"yes\" realtime=\"yes\"<\/span> check_all=\"yes\"&gt;\/etc,\/usr\/bin,\/usr\/sbin&lt;\/directories&gt;\r\n&lt;directories <span class=\"highlight\">report_changes=\"yes\" realtime=\"yes\"<\/span> check_all=\"yes\"&gt;\/bin,\/sbin&lt;\/directories&gt;\r\n<\/code><\/pre>\n<p><code>report_changes=\"yes\"<\/code> does exactly what is says. Ditto for <code>realtime=\"yes\"<\/code>.<\/p>\n<p>In addition to the default list of directories that OSSEC has been configured to monitor, you can add new directories that you wish to monitor. In this next section, I&#8217;m going to tell OSSEC to monitor <code>\/home\/user<\/code>and <code>\/var\/www<\/code>. For that, I&#8217;m going to add a new line right under the existing ones, so that that section now reads:<\/p>\n<pre class=\"code-pre \"><code>&lt;!-- Directories to check  (perform all possible verifications) --&gt;\r\n&lt;directories report_changes=\"yes\" realtime=\"yes\" check_all=\"yes\"&gt;\/etc,\/usr\/bin,\/usr\/sbin&lt;\/directories&gt;\r\n&lt;directories report_changes=\"yes\" realtime=\"yes\" check_all=\"yes\"&gt;\/bin,\/sbin&lt;\/directories&gt;\r\n\r\n<span class=\"highlight\">&lt;directories report_changes=\"yes\" realtime=\"yes\" restrict=\".php|.js|.py|.sh|.html\" check_all=\"yes\"&gt;\/home\/user,\/var\/www&lt;\/directories&gt;<\/span>\r\n<\/code><\/pre>\n<p>You should modify the directories to match your desired settings. If your user is not named <strong>user<\/strong>, you will want to change the path to the home directory.<\/p>\n<p>For the new directories to monitor, we&#8217;ve added the <code>restrict<\/code> option, which tells OSSEC to monitor only the specified file formats. You don&#8217;t have to use that option, but it comes in handy when you have other files, like image files, that you don&#8217;t want OSSEC to alert on.<\/p>\n<p>That&#8217;s all the changes for <code>ossec.conf<\/code>. Save and close the file.<\/p>\n<h3>Restart OSSEC<\/h3>\n<p>All that&#8217;s left now is to restart OSSEC, something that has to be done any time you modify OSSEC&#8217;s files. To restart OSSEC type:<\/p>\n<pre class=\"code-pre \"><code>\/var\/ossec\/bin\/ossec-control restart\r\n<\/code><\/pre>\n<p>If all is working correctly, you should receive an email from OSSEC\u00a0telling\u00a0you it has started.<\/p>\n<h3 id=\"step-5-\u2014-trigger-file-change-alerts\">Triggers<\/h3>\n<p>And depending on what happens in the directories that OSSEC has been configured to monitor, you should be getting emails that read something like this:<\/p>\n<p>Now try creating a sample file in <code>\/home\/user<\/code><\/p>\n<pre class=\"code-pre \"><code>touch \/home\/user\/index.html\r\n<\/code><\/pre>\n<p>Wait a minute. Add some content:<\/p>\n<pre class=\"code-pre \"><code>nano \/home\/user\/index.html\r\n<\/code><\/pre>\n<p>Wait a minute. Delete the file:<\/p>\n<pre class=\"code-pre \"><code>rm \/home\/user\/index.html\r\n<\/code><\/pre>\n<p>You should start receiving notifications like this:<\/p>\n<pre class=\"code-pre \"><code>OSSEC HIDS Notification.\r\n2014 Nov 30 18:03:51\r\n\r\nReceived From: ossec2-&gt;syscheck\r\nRule: 550 fired (level 7) -&gt; \"Integrity checksum changed.\"\r\nPortion of the log(s):\r\n\r\nIntegrity checksum changed for: '\/home\/sammy\/index.html'\r\nSize changed from '21' to '46'\r\nWhat changed:\r\n1c1,4\r\n&lt; This is an html file\r\n---\r\n\r\n    &lt;!doctype html&gt; &lt;p&gt;This is an html file&lt;\/p&gt;\r\n\r\nOld md5sum was: '4473d6ada73de51b5b36748627fa119b'\r\nNew md5sum is : 'ef36c42cd7014de95680d656dec62de9'\r\nOld sha1sum was: '96bd9d685a7d23b20abd7d8231bb215521bcdb6c'\r\nNew sha1sum is : '5ab0f31c32077a23c71c18018a374375edcd0b90'\r\n\r\n<\/code><\/pre>\n<p>Or this:<\/p>\n<pre class=\"code-pre \"><code>OSSEC HIDS Notification.\r\n2014 Dec 01 10:13:31\r\n\r\nReceived From: ossec2-&gt;syscheck\r\nRule: 554 fired (level 7) -&gt; \"File added to the system.\"\r\nPortion of the log(s):\r\n\r\nNew file '\/var\/www\/header.html' added to the file system.\r\n<\/code><\/pre>\n<blockquote><p><strong>Note:<\/strong> OSSEC does not send out real-time alerts on file additions, only on file modifications and deletions. Alerts on file additions go out after a full system check, which is governed by the frequency check time in <code>ossec.conf<\/code>.<\/p>\n<pre class=\"code-pre \"><code>nano \/var\/ossec\/etc\/ossec.conf\r\n<\/code><\/pre>\n<p>Setting for <code>frequency<\/code>:<\/p>\n<pre class=\"code-pre \"><code>&lt;syscheck&gt;\r\n    &lt;!-- Frequency that syscheck is executed - default to every 22 hours --&gt;\r\n    &lt;frequency&gt;79200&lt;\/frequency&gt;\r\n<\/code><\/pre>\n<\/blockquote>\n<p>Again, if you are not getting emails check your <code>\/var\/ossec\/logs\/ossec.logfile<\/code> for more details.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Getting started Q. How do you keep track of authorized and unauthorized activity on your server? A. OSSEC is\u00a0one of the best current tools to monitor any suspicious activity. OSSEC is an open-source, host-based intrusion detection system (HIDS) that performs log analysis, integrity checking, rootkit detection, time-based alerting, and active response. It can be used&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1947,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wpai_generated_summary":"","wpai_meta_description":"","footnotes":""},"categories":[8,6,10],"tags":[768,327,750,767,769],"class_list":["post-1944","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server-tips","category-website-news","category-website-tips","tag-how-to","tag-install","tag-manage","tag-ossec","tag-server-security"],"_links":{"self":[{"href":"https:\/\/webhostpro.com\/blog\/wp-json\/wp\/v2\/posts\/1944","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostpro.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostpro.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostpro.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostpro.com\/blog\/wp-json\/wp\/v2\/comments?post=1944"}],"version-history":[{"count":0,"href":"https:\/\/webhostpro.com\/blog\/wp-json\/wp\/v2\/posts\/1944\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostpro.com\/blog\/wp-json\/wp\/v2\/media\/1947"}],"wp:attachment":[{"href":"https:\/\/webhostpro.com\/blog\/wp-json\/wp\/v2\/media?parent=1944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostpro.com\/blog\/wp-json\/wp\/v2\/categories?post=1944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostpro.com\/blog\/wp-json\/wp\/v2\/tags?post=1944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}