{"id":33,"date":"2014-09-23T18:34:33","date_gmt":"2014-09-23T16:34:33","guid":{"rendered":"http:\/\/www.underealm.com\/tech\/?p=33"},"modified":"2017-01-04T16:05:00","modified_gmt":"2017-01-04T15:05:00","slug":"ossec-splunk-installation","status":"publish","type":"post","link":"https:\/\/www.underealm.com\/tech\/2014\/09\/ossec-splunk-installation\/","title":{"rendered":"OSSEC Agent\/Server + Splunk installation"},"content":{"rendered":"<p><a href=\"http:\/\/tonyonsecurity.com\/2013\/03\/13\/ossec-for-website-security-part-i\/\">There is<\/a> <a href=\"http:\/\/ossec-docs.readthedocs.org\/en\/latest\/manual\/installation\/index.html\">a lot of<\/a> <a href=\"http:\/\/ossec-docs.readthedocs.org\/en\/latest\/manual\/installation\/install-source-unattended.html\">documentation<\/a> to be read about the installation of OSSEC, but it&#8217;s usually sparse and focused either on a local autonomous setup or on hundreds of VMs setups. In this article we will navigate through the necessary steps to set up a small OSSEC installation with the OSSEC agent running offsite on a web\/mail server and the OSSEC server running onsite. Additionally we will take a look at Splunk and install it on the OSSEC server machine, which will make it easier to manage bigger volumes of data later on.<\/p>\n<h5>Prerequisites<\/h5>\n<p>In order to compile and install OSSEC you will need <strong>build-essential<\/strong> on Ubuntu machines and <strong>MySQL\/PostgreSQL<\/strong> for database support. You can read more details about this <a href=\"http:\/\/ossec-docs.readthedocs.org\/en\/latest\/manual\/installation\/installation-requirements.html\">here<\/a>.<\/p>\n<h5>Agent\/Server installation<\/h5>\n<p>Installing the agent and the server is as easy as running the script (after checksumming it) and answering a few questions, although you should keep (most of) the defaults since they&#8217;re solid, and then build up on them.<\/p>\n<pre class=\"toolbar:2 nums:false\" title=\"OSSEC Agent Install on Ubuntu\" lang=\"cmd\"><code># wget http:\/\/www.ossec.net\/files\/ossec-hids-.tar.gz\r\n# wget http:\/\/www.ossec.net\/files\/ossec-hids--checksum.txt\r\n# cat ossec-hids-_checksum.txt\r\nMD5 (ossec-hids-.tar.gz) = MD5SUM\r\nSHA1 (ossec-hids-.tar.gz) = SHA1SUM\r\nMD5 (ossec-agent-.exe) = MD5SUM_EXE\r\nSHA1 (ossec-agent-.exe) = SHA1SUM_EXE\r\n\r\n# md5sum ossec-hids-.tar.gz\r\nMD5 (ossec-hids-.tar.gz) = MD5SUM\r\n# sha1sum ossec-hids-.tar.gz\r\nSHA1 (ossec-hids-.tar.gz) = SHA1SUM\r\n\r\n# tar -zxvf ossec-hids-*.tar.gz\r\n# cd ossec-hids-*\r\n# .\/install.sh<\/code><\/pre>\n<h5>Basic server\/agent configuration<\/h5>\n<p>After the server configuration, you will need to manage the agents. On the server you will use <strong>manage_agents<\/strong> command to insert a number of agents with their ids, names and ip addresses.<\/p>\n<pre class=\"toolbar:2 nums:false\" lang=\"cmd\"><code>****************************************\r\n* OSSEC HIDS v2.8 Agent manager.       *\r\n* The following options are available: *\r\n****************************************\r\n   (A)dd an agent (A).\r\n   (E)xtract key for an agent (E).\r\n   (L)ist already added agents (L).\r\n   (R)emove an agent (R).\r\n   (Q)uit.\r\nChoose your action: A,E,L,R or Q:<\/code><\/pre>\n<p>After adding the agents on the server, you need to extract the agent keys.<\/p>\n<pre class=\"toolbar:2 nums:false\" lang=\"cmd\"><code>Choose your action: A,E,L,R or Q: e\r\n\r\nAvailable agents:\r\n   ID: 001, Name: NAME, IP: IP\r\nProvide the ID of the agent to extract the key (or '\\q' to quit): 001\r\n\r\nAgent key information for '001' is:\r\nIMPORTANT_HASH<\/code><\/pre>\n<p>You now need to add the hash to the agent, through <strong>manage_client<\/strong>.<\/p>\n<pre class=\"toolbar:2 nums:false\" lang=\"cmd\"><code>****************************************\r\n* OSSEC HIDS v2.8 Agent manager.       *\r\n* The following options are available: *\r\n****************************************\r\n   (I)mport key from the server (I).\r\n   (Q)uit.\r\nChoose your action: I or Q: i\r\n\r\n* Provide the Key generated by the server.\r\n* The best approach is to cut and paste it.\r\n*** OBS: Do not include spaces or new lines.\r\n\r\nPaste it here (or '\\q' to quit): IMPORTANT_HASH\r\n\r\nAgent information:\r\n   ID:001\r\n   Name:NAME\r\n   IP Address:IP\r\n\r\nConfirm adding it?(y\/n): y\r\nAdded.<\/code><\/pre>\n<p>If you remembered to configure the firewall rules properly, allowing traffic on <strong>UDP 1514<\/strong>, you should now have them synced upon restart. If everything is working as expected you will find the ossec-agentd connection in the logs within <strong>\/var\/ossec\/logs\/ossec.log<\/strong>: <em>ossec-agentd(4102): INFO: Connected to the server (hostname\/ipaddress:1514)<\/em>.<\/p>\n<h5>Adding global agent configurations<\/h5>\n<p>One of the smart moves that extend the capability of OSSEC is the possibility to push configurations to the agents. Anyone who managed a botnet knows how powerful this can be, and OSSEC is no exception. Let&#8217;s suppose we&#8217;re behind a static IP, say, 1.2.3.4: by logging in through SSH, moving files through FTP and changing configuration files around we would generate a lot of white noise, but we can fix that by adding a simple agent configuration on our server side:<\/p>\n<pre class=\"toolbar:1 show-lang:2\" title=\"\/var\/ossec\/etc\/shared\/agent.conf\" lang=\"xml\"><code><agent_config>\r\n  <global>\r\n    <white_list>1.2.3.4<\/white_list>\r\n  <\/global>\r\n<\/agent_config><\/code><\/pre>\n<p>After a reset of the OSSEC processes the agent.conf will be pushed\/pulled, and the IP should be now successfully white-listed. This method also allows to set <a href=\"http:\/\/ossec-docs.readthedocs.org\/en\/latest\/syntax\/head_agent_config.html\">specific rules for sets of agents<\/a>, by specifying the names to which the configurations apply.<\/p>\n<h5>Agent configuration: we need to go deeper<\/h5>\n<p>As explained <a href=\"http:\/\/tonyonsecurity.com\/2013\/03\/13\/ossec-for-website-security-part-i\/\">in this article<\/a>, stopping to the defaults is no good practice. While all the base scenarios have been covered, specific needs have not. Using multi-user hosting or logging? You need to add these logs manually. Mail servers? These too. For some reasons you have verbose MySQL logging? This will need to be added too. That&#8217;s easily done by simply appending the specified logs and type to either the agent ossec.conf or the server agent.conf, whichever suits your needs best:<\/p>\n<pre class=\"toolbar:1 show-lang:2\" title=\"\/var\/ossec\/etc\/ossec.conf\" lang=\"xml\"><code>  <localfile>\r\n    <log_format>syslog<\/log_format>\r\n    <location>\/var\/log\/dovecot.log<\/location>\r\n  <\/localfile>\r\n\r\n  <localfile>\r\n    <log_format>apache<\/log_format>\r\n    <location>\/var\/log\/domains-*.log<\/location>\r\n  <\/localfile><\/code><\/pre>\n<p>Remember that you can use wildcards and strftime for the logs, but not together. Also there are <a href=\"http:\/\/ossec-docs.readthedocs.org\/en\/latest\/manual\/monitoring\/#element-location\">a few pitfalls<\/a> in using wildcards you should be aware of.<\/p>\n<h5>Tweaking the server for Splunk<\/h5>\n<p>At this point we have a working agent\/server configuration, but we want to push it a step further to make use of Splunk. Even though my setup has OSSEC and Splunk sharing the same machine I chose a syslog client configuration, and the reason is simple: through the use of <a href=\"http:\/\/ossec-docs.readthedocs.org\/en\/latest\/syntax\/head_ossec_config.syslog_output.html?highlight=syslog_output#element-syslog_output\">syslog_output<\/a> I am able to increase the granularity by raising or lowering the alert level as I see fit, while also allowing me to add a separate OSSEC server elsewhere without the need to reconfigure Splunk. It&#8217;s a win-win. The changes are to be made inside ossec.conf:<\/p>\n<pre class=\"toolbar:1 show-lang:2\" title=\"\/var\/ossec\/etc\/ossec.conf\" lang=\"xml\"><code>  <syslog_output>\r\n    <server>127.0.0.1<\/server>\r\n    <port>PORT_NUMBER<\/port>\r\n  <\/syslog_output><\/code><\/pre>\n<p>You should put the syslog_output before the &lt;rules&gt; tag. This is all it takes to be ready for Splunk<\/p>\n<h5>Where to start Splunking<\/h5>\n<p>Silly puns aside, we will need the <a href=\"http:\/\/www.splunk.com\/download\/\">Splunk software<\/a> and the <a href=\"https:\/\/apps.splunk.com\/app\/300\/\">Reporting and Management for OSSEC<\/a>. Given my setup I downloaded the deb package on the server, and the app tgz on my workstation. The installation is as easy as running a few commands:<\/p>\n<pre lang=\"cmd\"><code># dpkg -i splunk---.deb\r\n# \/opt\/splunk\/bin\/splunk enable boot-start -user splunk<\/code><\/pre>\n<p>On a Ubuntu server this will install the required files, and make it start on boot running as <em>splunk<\/em> user. Before running it though, we need to make a change that will allow us to receive information from OSSEC. The following code can be added in the <strong>inputs.conf<\/strong> after the <strong>[default]<\/strong> section:<\/p>\n<pre class=\"toolbar:1\" title=\"\/opt\/splunk\/etc\/system\/default\/inputs.conf\" lang=\"ini\"><code>[udp:\/\/127.0.0.1:PORT_NUMBER]\r\ndisabled = false\r\nsourcetype = ossec<\/code><\/pre>\n<p>This will start the UDP server, as per our mission. There are other modes available if you chose not to use the syslog_output method, but I will not go into that for now, I will just leave you the <a href=\"https:\/\/apps.splunk.com\/app\/300\/#\/documentation\">app documentation<\/a> as reference.<\/p>\n<p>At this point most of our work is done. Once the server is started (with <strong>service splunk start<\/strong> in my case) you can connect to it through its web interface, which should be up at <strong>http:\/\/ipaddress:8000\/<\/strong> and perfectly running. After the login you can navigate to <strong>App &gt; Manage Apps\u2026<\/strong> and click <strong>Install app from file<\/strong>, selecting the app tgz we downloaded earlier. If everything has been done correctly data should be now flowing, and a simple <strong>sourcetype=&#8221;ossec&#8221;<\/strong> query should hold all the collected information.<\/p>\n<p>What to do with it, you ask? Well, that&#8217;s your job now \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is a lot of documentation to be read about the installation of OSSEC, but it&#8217;s usually sparse and focused either on a local autonomous setup or on hundreds of VMs setups. In this article we will navigate through the necessary steps to set up a small OSSEC installation with the OSSEC agent running offsite [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[19,60,16,17,18,58],"class_list":["post-33","post","type-post","status-publish","format-standard","hentry","category-ossec","tag-installation-configuration","tag-ossec","tag-ossec-agent","tag-ossec-server","tag-splunk","tag-sysad"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/posts\/33"}],"collection":[{"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":5,"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"predecessor-version":[{"id":122,"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/posts\/33\/revisions\/122"}],"wp:attachment":[{"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}