OSSEC 加固linux系統詳細配置

來源:互聯網
上載者:User

標籤:ossec linux 安全 centos 安裝 配置

ossec官方網站http://www.ossec.net/

ossec協助文檔http://ossec-docs.readthedocs.org/en/latest/manual/index.html

OSSEC是一個開源的基於主機的入侵偵測系統,執行日誌分析,檔案完整性檢查,政策監控,rootkit檢測,即時警示和積極響應。

它可以運行在大多數的作業系統,包括Linux,MacOS的時,Solaris,HP-UX,AIX和Windows

最新穩定版為2.8 下載頁面http://www.ossec.net/?page_id=19

Ossec部署方式為C/S,以下server:192.168.22.240   client:192.168.22.241

先關閉selinux,安裝常用包

環境 CentOS release 6.4(Final) x86_64

sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/sysconfig/selinux  yum install gcc gcc-c++ vim wget lrzsz ntpdate sysstat dstat wget -y


安裝服務端

Ip 192.168.22.240

yum install mysql mysql-server mysql-devel httpd php php-mysql –ytar -xzf ossec-hids-2.8.tar.gzcd ossec-hids-2.8cd src/# make setdbError: PostgreSQL client libraries notinstalled.Info: Compiled with MySQL support.   #ossec支援mysql資料庫# ./install

下面是安裝過程

en   #選擇語言Enter #繼續Server #安裝為server/usr/local/ossec #安裝目錄3.1- Do you want e-mail notification? (y/n)[y]: y   -What‘s your e-mail address? [email protected]   -What‘s your SMTP server ip/host? 127.0.0.1Enter # Running syscheck (integrity check daemon)Enter # Running rootcheck (rootkit detection)Enter #Active response enabledEnter # firewall-drop enabled (local) for levels >= 6Do you want to add more IPs to the whitelist? (y/n)? [n]: y  #設定ip白名單   -IPs (space separated):3.5- Do you want to enable remote syslog(port 514 udp)? (y/n) [y]:EnterEnter #開始安裝


安裝完成的設定檔及選項:

/usr/local/ossec/bin/ossec-control start/usr/local/ossec/bin/ossec-control stop/usr/local/ossec/etc/ossec.conf/usr/local/ossec/bin/manage_agents


# /usr/local/ossec/bin/ossec-control --helpUsage: /usr/local/ossec/bin/ossec-control{start|stop|restart|status|enable|disable}


# /usr/local/ossec/bin/ossec-control enable--helpInvalid enable option.Enable options: database, client-syslog,agentless, debugUsage: /usr/local/ossec/bin/ossec-controlenable [database|client-syslog|agentless|debug]


/usr/local/ossec/bin/ossec-control enabledatabase# service mysqld start/usr/bin/mysql_secure_installation# mysql -uroot –pmysql> create database ossec;mysql> grantINSERT,SELECT,UPDATE,CREATE,DELETE,EXECUTE on ossec.* to [email protected] by ‘ossec‘;mysql> grant INSERT,SELECT,UPDATE,CREATE,DELETE,EXECUTEon ossec.* to [email protected] identified by‘ossec‘;   #此句是為下面的analogimysql> flush privileges;mysql> \q


[[email protected] ossec-hids-2.8]# mysql-uossec -p ossec < src/os_dbd/mysql.schema

Enter password:

vim /usr/local/ossec/etc/ossec.conf  #在最後添加

<ossec_config>   <database_output>       <hostname>localhost</hostname>       <username>ossec</username>       <password>ossec</password>       <database>ossec</database>       <type>mysql</type>   </database_output></ossec_config>


添加128行內容,允許此網段的日誌

<remote>127    <connection>syslog</connection>128<allowed-ips>192.168.22.0/24</allowed-ips>129  </remote>


/usr/local/ossec/bin/ossec-control restart

此時,郵箱已經收到郵件了


 下面添加agent用戶端

# /usr/local/ossec/bin/manage_agents  (A)dd an agent (A).  (E)xtract key for an agent (E).  (L)ist already added agents (L).  (R)emove an agent (R).  (Q)uit.  #下面依次:A   #addPlease provide the following:   *A name for the new agent: agent1   *The IP Address of the new agent: 192.168.22.241   *An ID for the new agent[001]: 001Agent information:   ID:001  Name:agent1   IPAddress:192.168.22.241 Confirm adding it?(y/n): yAgent added.  ***************************************** OSSEC HIDS v2.8 Agent manager.     ** The following options are available: *****************************************  (A)dd an agent (A).  (E)xtract key for an agent (E).  (L)ist already added agents (L).  (R)emove an agent (R).  (Q)uit.Choose your action: A,E,L,R or Q: E  Available agents:   ID: 001, Name: agent1, IP: 192.168.22.241Provide the ID of the agent to extract thekey (or ‘\q‘ to quit): 001  Agent key information for ‘001‘ is: MDAxIGFnZW50MSAxOTIuMTY4LjIyLjI0MSBmYTcxYWE1ZWQxYTg0YTM3MDcwNTFkMGRkMDY4NTcyNDQ5NDY2MWRkYTI3ZTMxZsNhZDd3YmFjZjddZTFkMmNj  ** Press ENTER to return to the main menu.  Choose your action: A,E,L,R or Q: Q


# netstat -unlp|grep ossec    #ossec通訊是用udp  514,1514連接埠,

udp   0   0 0.0.0.0:514    0.0.0.0:*        4511/ossec-remoted  udp   0   0 0.0.0.0:1514   0.0.0.0:*         4513/ossec-remoted


vim /etc/sysconfig/iptables  #開啟iptables的連接埠-A INPUT -m state --state NEW -m udp -p udp--dport 514 -j ACCEPT-A INPUT -m state --state NEW -m udp -p udp--dport 1514 -j ACCEPTservice iptables restart


安裝用戶端

Ip 192.168.22.241

tar -xzf ossec-hids-2.8.tar.gz # cd ossec-hids-2.8# ./install.shY      #預設為enEnter        #開始安裝Agent       #作為代理/usr/local/ossec #安裝目錄192.168.22.240 #添加server的ipEnter   #Running syscheck (integrity check daemon)Enter   #Running rootcheck (rootkit detection)Enter   #active responseEnter   #開始安裝

安裝後的配置

/usr/local/ossec/bin/ossec-control start/usr/local/ossec/bin/ossec-control stop/usr/local/ossec/etc/ossec.conf/usr/local/ossec/bin/manage_agents

 設定agent

# /usr/local/ossec/bin/manage_agents***************************************** OSSEC HIDS v2.8 Agent manager.     ** The following options are available: *****************************************  (I)mport key from the server (I).  (Q)uit.Choose your action: I or Q: I * Provide the Key generated by the server.* The best approach is to cut and paste it.*** OBS: Do not include spaces or newlines. Paste it here (or ‘\q‘ to quit): MDAxIGFnZW50MSAxOTIuMTY4LjIyLjI0zSBmYTcxYWE1ZWQxYTg0YTM3MDcwNTFkMGRkMDY4NTcyNDQ5NDY2MWRkYTI3ZTMxZTNdZDc3YmFjZjdmZTFk5mNj Agent information:  ID:001  Name:agent1   IPAddress:192.168.22.241 Confirm adding it?(y/n): yAdded.** Press ENTER to return to the main menu. Choose your action: I or Q: Q


Ossec的日誌

/usr/local/ossec/logs/ossec.log


安裝web介面

ossec-wui介面

cd /var/wwwunzip ossec-wui-master.zipmv ossec-wui-master html/osseccd html/ossec/  # cat ossec_conf.php   /* Ossec directory */#$ossec_dir="/var/ossec";$ossec_dir="/usr/local/ossec";  # ./setup.sh Setting up ossec ui...  Username: ossecNew password: Re-type new password: Adding password for user ossecEnter your web server user name (e.g.apache, www, nobody, www-data, ...)apacheEnter your OSSEC install directory path(e.g. /var/ossec)/usr/local/ossecYou must restart your web server after thissetup is done. Setup completed successfuly.

 

# vim /etc/httpd/conf.d/ossec.conf  Alias /analogi /var/www/html/ossec<Directory /var/www/html/ossec>   Order deny,allow   Deny from all   Allow from 192.168.22.0/24Options -MultiViews   AuthName "OSSEC AUTH"   AuthType Basic   AuthUserFile /var/www/html/ossec/.htpasswd   Require valid-user</Directory>


別忘了把iptables的80開啟

-A INPUT -m state --state NEW -m tcp -p tcp--dport 80 -j ACCEPTchown apache:apache *service httpd restart

analogi介面

cd /var/www/htmlwgethttps://github.com/ECSC/analogi/archive/master.zipunzip analogi-master.zipmv analogi-master ossec/analogichown apache.apache -R osseccd ossec/analogicp db_ossec.php.new db_ossec.php vim db_ossec.phpdefine (‘DB_USER_O‘, ‘ossec‘);define (‘DB_PASSWORD_O‘, ‘ossec‘);define (‘DB_HOST_O‘, ‘localhost‘);define (‘DB_NAME_O‘, ‘ossec‘);  vim /etc/httpd/conf.d/analogi.confAlias /analogi /var/www/html/analogi<Directory /var/www/html/analogi>   Order deny,allow   Deny from all   Allow from 192.168.22.0/24</Directory>


查看狀態資訊

# /usr/local/ossec/bin/agent_control -lcOSSEC HIDS agent_control. List of availableagents:  ID: 000, Name: localhost.localdomain (server), IP: 127.0.0.1,Active/Local  ID: 001, Name: agent1, IP: 192.168.22.241, Active  # /usr/local/ossec/bin/list_agents -aagent1-192.168.22.241 is available.  # /usr/local/ossec/bin/ossec-control statusossec-monitord is running...ossec-logcollector is running...ossec-remoted is running...ossec-syscheckd is running...ossec-analysisd is running...ossec-maild is running...ossec-execd is running...ossec-dbd is running...


OSSEC的圖形介面

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/45/C0/wKiom1Pq1T6x-S7fAAM12H09WeQ484.jpg" title="QQ20140813110124.jpg" alt="wKiom1Pq1T6x-S7fAAM12H09WeQ484.jpg" />

analogi圖形介面

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/45/C1/wKioL1Pq1ojDJVmjAANOSzsaq7U906.jpg" title="QQ20140813110207.jpg" alt="wKioL1Pq1ojDJVmjAANOSzsaq7U906.jpg" />

收到ossec發送的郵件

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/45/C1/wKioL1Pq1r7S1xp8AAHU1bdTEgY197.jpg" title="QQ20140813110305.jpg" alt="wKioL1Pq1r7S1xp8AAHU1bdTEgY197.jpg" />

本文出自 “一顆石頭 BBOTTE的部落格” 部落格,請務必保留此出處http://bbotte.blog.51cto.com/6205307/1539285

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.