Setup OSSEC Host intrusion Preventing / Detecting system pada OpenBSD


Project ini sebenarnya adalah untuk keluarga besar komunitas security. Penulis membutuhkan sistem dimana bisa memonitor setiap pergerakan pada sistem operasi, seperti perubahan file, pengunaan network(ssh, http, etc), dan mendeksi serangan yang masuk ke dalam server, setelah ia menandai sebuah penyerangan terjadi, bisa melakukan respon untuk melakukan pertahanan. Plus melakukan alert melalui email, memberitahukan setiap perubahan pada file maupun penyerangan. Hayaa banyak sekali maunya penulis ini =D maklum paraniod.

OSSEC-lah yang akan penulis tanam. Semua kemauan penulis diatas, ada pada OSSEC agar efektif pada kali ini OSSEC akan di setup tidak pada mode client-server, tetapi local saja, karena hostnya hanya satu. Mungkin pada kesempatan(proyek) selanjutnya akan penulis jelaskan bagaiamana setup OSSEC client-server.

Kali ini penulis akan mencoba berbagi bagaimana setup OSSEC HIDS / HIPS pada sistem operasi OpenBSD.  Pada dasarnya setupnya mudah, tapi bukan langkahnya yang perlu kita ingat tapi bagaimana kita harus tau betul workflow dan pilihan yang tepat. OSSEC adalah sebuah tool yang bekerja pada level host, tidak seperti snort yang bekerja pada network.

Yang terpenting adalah kita harus tau bagaimana OSSEC bekerja, bagaimana ia mendeksi perubahan file, serangan, juga merespon sesuatu pada host. Ok mari kita mulai, jadilah user root untuk melakukannya hal dibawah ini:


1. Melakukan download OSSEC kemudian mengekstraknya:
# wget -c www.ossec.net/files/ossec-hids-2.6.tar.gz
# tar -zxvf ossec-hids-2.6.tar.gz

2. Memulai proses instalasi:
# cd ossec-hids-2.6
# sh install.sh

  ** Para instalação em português, escolha [br].
  ** èŠäœ¿çšäž­æè¿¡å®è£
, 请éæ© [cn].
  ** Fur eine deutsche Installation wohlen Sie [de].
  ** Îια εγκαÏ
                    άÏÏ
                        αÏη ÏÏ
                                α ÎλληΜικά, εÏιλέΟÏ
                                                                ε [el].
  ** For installation in English, choose [en].
  ** Para instalar en Español , eliga [es].
  ** Pour une installation en français, choisissez [fr]
  ** Per l'installazione in Italiano, scegli [it].
  ** æ¥æ¬èªã§ã€ã³ã¹ããŒã«ããŸãïŒéžæããŠäžãã
                                        ïŒ[jp].
  ** Voor installatie in het Nederlands, kies [nl].
  ** Aby instalowaÄ w jÄzyku Polskim, wybierz [pl].
  ** ÐÐ»Ñ ÐžÐœÑÑÑÑкÑОй пП ÑÑÑаМПвке Ма ÑÑÑÑкПЌ ,ввеЎОÑе [ru].
  ** Za instalaciju na srpskom, izaberi [sr].
  ** TÃŒrkçe kurulum için seçin [tr].
  (en/br/cn/de/el/es/fr/it/jp/nl/pl/ru/sr/tr) [en]:


 OSSEC HIDS v2.6 Installation Script - http://www.ossec.net

 You are about to start the installation process of the OSSEC HIDS.
 You must have a C compiler pre-installed in your system.
 If you have any questions or comments, please send an e-mail
 to dcid@ossec.net (or daniel.cid@gmail.com).

  - System: OpenBSD fw.unixhat.com 5.0
  - User: root
  - Host: fw.unixhat.com


  -- Press ENTER to continue or Ctrl-C to abort. --

1- What kind of installation do you want (server, agent, local or help)? local

  - Local installation chosen.

2- Setting up the installation environment.

 - Choose where to install the OSSEC HIDS [/var/ossec]:

    - Installation will be made at  /var/ossec .

3- Configuring the OSSEC HIDS.

  3.1- Do you want e-mail notification? (y/n) [y]: y
   - What's your e-mail address? alert@unixhat.com
   - What's your SMTP server ip/host? 127.0.0.1

  3.2- Do you want to run the integrity check daemon? (y/n) [y]: y

   - Running syscheck (integrity check daemon).

  3.3- Do you want to run the rootkit detection engine? (y/n) [y]: y

   - Running rootcheck (rootkit detection).

  3.4- Active response allows you to execute a specific
       command based on the events received. For example,
       you can block an IP address or disable access for
       a specific user.
       More information at:
       http://www.ossec.net/en/manual.html#active-response

   - Do you want to enable active response? (y/n) [y]: y

     - Active response enabled.

   - By default, we can enable the host-deny and the
     firewall-drop responses. The first one will add
     a host to the /etc/hosts.deny and the second one
     will block the host on iptables (if linux) or on
     ipfilter (if Solaris, FreeBSD or NetBSD).
   - They can be used to stop SSHD brute force scans,
     portscans and some other forms of attacks. You can
     also add them to block on snort events, for example.

   - Do you want to enable the firewall-drop response? (y/n) [y]:

     - firewall-drop enabled (local) for levels >= 6

   - Default white list for the active response:
      - 192.168.163.2

   - Do you want to add more IPs to the white list? (y/n)? [n]: n

  3.6- Setting the configuration to analyze the following logs:
    -- /var/log/messages
    -- /var/log/authlog
    -- /var/log/secure
    -- /var/log/xferlog
    -- /var/log/maillog

 - If you want to monitor any other file, just change
   the ossec.conf and add a new localfile entry.
   Any questions about the configuration can be answered
   by visiting us online at http://www.ossec.net .


   --- Press ENTER to continue ---

5- Installing the system
 - Running the Makefile
INFO: Little endian set.

 *** Making zlib (by Jean-loup Gailly and Mark Adler)  ***
gcc -c -g -Wall -I../../ -I../../headers  -DDEFAULTDIR=\"/var/ossec\" -DLOCAL -DUSE_OPENSSL     -DARGV0=\"zlib\" -DXML_VAR=\"var\" -DOSSECHIDS *.c
ar cru libz.a *.o
ranlib libz.a
cp -pr zlib.h zconf.h ../../headers/
cp -pr libz.a ../

====================
 - System is OpenBSD.
 - Init script modified to start OSSEC HIDS during boot.

 - Configuration finished properly.

 - To start OSSEC HIDS:
                /var/ossec/bin/ossec-control start

 - To stop OSSEC HIDS:
                /var/ossec/bin/ossec-control stop

 - The configuration can be viewed or modified at /var/ossec/etc/ossec.conf


    Thanks for using the OSSEC HIDS.
    If you have any question, suggestion or if you find any bug,
    contact us at contact@ossec.net or using our public maillist at
    ossec-list@ossec.net
    ( http://www.ossec.net/main/support/ ).

    More information can be found at http://www.ossec.net

    ---  Press ENTER to finish (maybe more information below). ---

2. Setelah instalasi selesai, ada rule yang perlu kita tambahkan 
ke dalam /etc/pf.conf

      table <ossec_fwtable> persist #ossec_fwtable
      block in quick from <ossec_fwtable> to any
      block out quick from any to <ossec_fwtable>

Reload konfigurasi pf:
# pfctl -f /etc/pf.conf

3. Mari kita jalankan ossec, agar semua komponen ossec bisa bekerja:
# /var/ossec/bin/ossec-control start
# ps -ax|grep ossec
19221 ??  S       0:00.08 /var/ossec/bin/ossec-maild
29558 ??  I       0:00.04 /var/ossec/bin/ossec-execd
25191 ??  I       0:02.75 /var/ossec/bin/ossec-analysisd
14478 ??  S       0:00.15 /var/ossec/bin/ossec-logcollector (ossec-logcollect)
22228 ??  I       0:30.44 /var/ossec/bin/ossec-syscheckd
23163 ??  I       0:00.10 /var/ossec/bin/ossec-monitord

4. Saatnya mencoba apakah ossec sudah bekerja dengan baik atau belum.

Cobalah untuk scanning host menggunakan nmap, atau bisa menggunakan nikto, maka kita akan mendapatkan alert melalui email yang telah kita daftarkan.

Alhamduilillah selesai sudah dokumentasinya, so far ip penyerang kebanyakan datang dari cina.