Intro instalasi OSSEC
Bagaimana anda melacak aktivitas yang sah dan tidak sah di server anda? OSSEC adalah salah satu tool yang dapat anda instal di server anda untuk melacak aktivitas tersebut.
OSSEC adalah sistem deteksi intrusi berbasis open-source (host-based intrusion detection system / HIDS) yang melakukan analisis log, pengecekan integritas, pemantauan registri Windows, deteksi rootkit, peringatan berbasis waktu, dan respons aktif. Ini bisa digunakan untuk memantau satu server atau ribuan server dalam mode server / agent. OSSEC run di kebanyakan sistem operasi, termasuk Linux, OpenBSD, FreeBSD, MacOS, Solaris dan Windows.
Jika dikonfigurasi dengan benar, OSSEC dapat memberi anda tampilan real-time ke dalam apa yang terjadi di server anda.
Apa keuntungan OSSEC? Di bawah ini contoh email notifikasi dari OSSEC, memperlihatkan ada yang mengubah file /var/ossec/etc/ossec.conf.
OSSEC HIDS Notification.
2014 Nov 29 09:45:15
Received From: kuruji->syscheck
Rule: 552 fired (level 7) -> "Integrity checksum changed again (3rd time)."
Portion of the log(s):
Integrity checksum changed for: '/var/ossec/etc/ossec.conf'
Size changed from '7521' to '7752'
Jika anda menerima peringatan semacam itu, dan anda tidak mengharapkan file itu berubah, berarti anda tahu ada sesuatu yang tidak sah yang terjadi di server anda.
Berikut contoh email peringatan lainnya dari OSSEC, yang menunjukkan bahwa file /etc/ossec/testossec.txt telah dihapus.
OSSEC HIDS Notification.
2014 Nov 29 10:56:14
Received From: kuruji->syscheck
Rule: 553 fired (level 7) -> "File deleted. Unable to retrieve checksum."
Portion of the log(s):
File /etc/ossec/testossec.txt was deleted. Unable to retrieve checksum.
Sekali lagi, jika anda tidak menghapus file tersebut, anda harus mencari tahu apa yang terjadi pada server anda.
apt-get install libssl-dev build-essential zlib1g-dev postfix make gcc inotify-tools libsystemd-dev libpcre2-dev
apt update
cd /usr/local/src
wget -U ossec https://github.com/ossec/ossec-hids/archive/3.7.0.tar.gz
cd /usr/local/src
tar zxvf 3.7.0.tar.gz
cd ossec-hids-3.7.0/
./install.sh
Jawaban pertanyaan saat instalasi
(en/br/cn/de/el/es/fr/hu/it/jp/nl/pl/ru/sr/tr) [en]: <ENTER>
OSSEC HIDS v2.9.0 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.
- System: Linux refserver 4.4.0-21-generic
- User: root
- Host: refserver
-- Press ENTER to continue or Ctrl-C to abort. --
<ENTER>
1- What kind of installation do you want (server, agent, local, hybrid or help)? local
2- Setting up the installation environment.
- Choose where to install the OSSEC HIDS [/var/ossec]: <ENTER>
3- Configuring the OSSEC HIDS.
3.1- Do you want e-mail notification? (y/n) [y]: <ENTER>
- What's your e-mail address? [email protected]
- Do you want to use it? (y/n) [y]: <ENTER>
3.2- Do you want to run the integrity check daemon? (y/n) [y]: <ENTER>
3.3- Do you want to run the rootkit detection engine? (y/n) [y]: <ENTER>
- Do you want to enable active response? (y/n) [y]: <ENTER>
- Do you want to enable the firewall-drop response? (y/n) [y]: <ENTER>
- Do you want to add more IPs to the white list? (y/n)? [n]: <ENTER>
3.6- Setting the configuration to analyze the following logs:
-- /var/log/auth.log
-- /var/log/syslog
-- /var/log/dpkg.log
- 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 ---
<ENTER>
Tunggu beberapa saat karena sedang di compile. Hasil terakhir,
- The configuration can be viewed or modified at /var/ossec/etc/ossec.conf
--- Press ENTER to finish (maybe more information below). ---
<ENTER>
Start OSSEC
/var/ossec/bin/ossec-control status
Output:
ossec-monitord not running...
ossec-logcollector not running...
ossec-syscheckd not running...
ossec-analysisd not running...
ossec-maild not running...
ossec-execd not running...
Start OSSEC,
/var/ossec/bin/ossec-control start
Output:
Starting OSSEC HIDS v2.9.0 (by Trend Micro Inc.)...
Started ossec-maild...
Started ossec-execd...
Started ossec-analysisd...
Started ossec-logcollector...
Started ossec-syscheckd...
Started ossec-monitord...
Completed.
Cek status lagi,
/var/ossec/bin/ossec-control status
This output shows that OSSEC is running:
ossec-monitord is running...
ossec-logcollector is running...
ossec-syscheckd is running...
ossec-analysisd is running...
ossec-maild is running...
ossec-execd is running...
Harusnya akan dapat email kira-kira
OSSEC HIDS Notification.
2014 Nov 30 11:15:38
Received From: ossec2->ossec-monitord
Rule: 502 fired (level 3) -> "Ossec server started."
Portion of the log(s):
ossec: Ossec started.
Konfigurasi OSSEC untuk Real-time Alerts saat ada modifikasi File
Lakukan
cd /var/ossec
File / folder penting
/var/ossec/logs
/var/ossec/logs/ossec.log
/var/ossec/etc/ossec.conf
Edit file konfigurasi
cp /var/ossec/etc/ossec.conf /var/ossec/etc/ossec.conf.asli
vi /var/ossec/etc/ossec.conf
Jika emailnya ke localhost saja, bisa menggunakan,
<global>
<email_notification>yes</email_notification>
<email_to>[email protected]</email_to>
<smtp_server>localhost</smtp_server>
<email_from>[email protected]</email_from>
<email_maxperhour>12</email_maxperhour>
</global>
Cek /var/ossec/logs/ossec.log, pastikan tidak ada error seperti,
cat /var/ossec/logs/ossec.log | grep ERROR
Frekuensi Scan
Edit /var/ossec/etc/ossec.conf
vi /var/ossec/etc/ossec.conf
Lihat bagian
<syscheck>
<frequency>79200</frequency>
Tambahkan alert new file,
<syscheck>
<frequency>79200</frequency>
<alert_new_files>yes</alert_new_files>
Untuk testing bisa di ubah frekuensi ke 60, untuk operasional 79200 cukup.
Setting Directory & Perubahan File Edit /var/ossec/etc/ossec.conf
Edit
<directories check_all="yes">/etc,/usr/bin,/usr/sbin</directories>
<directories check_all="yes">/bin,/sbin</directories>
Ubah menjadi,
<directories report_changes="yes" realtime="yes" check_all="yes">/etc,/usr/bin,/usr/sbin</directories>
<directories report_changes="yes" realtime="yes" check_all="yes">/bin,/sbin</directories>
Bisa juga menambahkan directory yang harus di monitor misalnya,
<directories report_changes="yes" realtime="yes" check_all="yes">/etc,/usr/bin,/usr/sbin</directories>
<directories report_changes="yes" realtime="yes" check_all="yes">/bin,/sbin</directories>
<directories report_changes="yes" realtime="yes" restrict=".php|.js|.py|.sh|.html" check_all="yes">/home/agungsurya,/var/www</directories>
Local.rules
Rules & Local rules ada di
/var/ossec/rules/
/var/ossec/rules/local_rules.xml
/var/ossec/rules/ossec_rules.xml
Kita tertarik pada local_rules.xml & ossec_rules.xml, contoh mengubah rules 554 di ossec_rules.xml. isinya,
<rule id="554" level="0">
<category>ossec</category>
<decoded_as>syscheck_new_entry</decoded_as>
<description>File added to the system.</description>
<group>syscheck,</group>
</rule>
Yang perlu di lakukan,
cp /var/ossec/rules/local_rules.xml /var/ossec/rules/local_rules.xml.asli
vi /var/ossec/rules/local_rules.xml
Tambahkan
<group name="syscheck,">
<rule id="554" level="7" overwrite="yes">
<category>ossec</category>
<decoded_as>syscheck_new_entry</decoded_as>
<description>File added to the system.</description>
</rule>
</group>
Save file
Restart OSSEC Sesudah semua modifikasi di lakukan restart OSSEC
/var/ossec/bin/ossec-control restart
Coba alert perubahan file
Coba buat file, isi, dan delete file,
touch /home/agungsurya/coba.sh
touch /home/agungsurya/index.html
touch /usr/bin/coba.sh
touch /usr/bin/index.html
sleep 70
echo "percobaan" > /home/agungsurya/index.html
echo "coba" > /home/agungsurya/coba.sh
echo "percobaan" > /usr/bin/index.html
echo "coba" > /usr/bin/coba.sh
sleep 70
Cek apakah ada email, kira-kira,
rm /home/agungsurya/index.html
rm /home/agungsurya/coba.sh
Cek apakah ada email, kira-kira,