Difference between revisions of "ModSecurity: Instalasi ModSecurity dan ModEvasive"

From OnnoWiki
Jump to navigation Jump to search
 
(8 intermediate revisions by the same user not shown)
Line 23: Line 23:
 
  ln -s /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.1 /usr/lib/libxml2.so.2.9.1
 
  ln -s /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.1 /usr/lib/libxml2.so.2.9.1
  
* Instalasi ModSecurity
+
==Instalasi & Konfigurasi ModSecurity==
  
 +
Instalasi
  
  sudo apt-get install libapache-mod-security
+
  sudo apt-get install libapache2-mod-security2
  
2. Configure ModSecurity rules.
+
Konfigurasi rules / aturan di ModSecurity
  
    Activate the recommended default rules to get things going. Configure as needed. For complete information refer to the ModSecurity Reference Manual - click here.
+
* Aktifkan aturan / rules default agar bisa beroperasi. Konfigurasi apa yang kita butuhkan.  
 +
* Copy konfigurasi rekomended
  
 
  sudo mv /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.conf
 
  sudo mv /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.conf
  
    The default folder for ModSecurity rules is /etc/modsecurity/ . All .conf files will be included and need to be configured as required.
+
* Folder default rules ModSecurity adalah /etc/modsecurity/ . Semua file .conf yang perlu dikonfigurasi terdapat disitu.
    We need to activate all the base rules and make sure they also get loaded.  
+
* Kita perlu mengaktifkan semua rule dasar dan meyakinkan bahwa ModSecurity dapat di load.  
    You might want to edit the SecRequestBodyLimit option in the modsecurity.conf file.
+
* Kita perlu mengedit opsi SecRequestBodyLimit di file modsecurity.conf  
    SecRequestBodyLimit limits the page request size and limits file uploads to 128 KB by default. Change this to the size of files you would accept uploaded to the server.
+
* SecRequestBodyLimit membatasi ukuran page yang di minta dan membatasi upload file menjadi default 128 KB. Ubah ini sesuai dengan kebutuhan / ijin yang kita berikan untuk meng-upload file ke server.
    This settings is very important as it limits the size of all files that can be uploaded to the server. For CMS sites using Drupal or Wordpress this setting is the source of much pain.  
+
* Konfigurasi ini sangat penting karena akan membatasi besarnya file yang dapat di upload ke server. Untuk situs CMS yang menggunakan Drupal atau Wordpress konfigurasi ini yang akan menjadi sumber pening di kepala.
    Open the Terminal Window and enter :
+
* Buka terminal dan edit:
  
 
  sudo vi /etc/modsecurity/modsecurity.conf
 
  sudo vi /etc/modsecurity/modsecurity.conf
  
    First activate the rules by editing the SecRuleEngine option and set to On.
+
* Aktifkan aturan / rule dengan mengedit SecRuleEngine dari DetectionOnly menjadi On.
  
 
  SecRuleEngine On
 
  SecRuleEngine On
  
    Edit the following to option to increase the request limit to 16 MB and save the file :
+
* Edit opsi berikut untuk menaikan request limit ke 16Mbyte dan save file:
  
 
  SecRequestBodyLimit 16384000
 
  SecRequestBodyLimit 16384000
 
  SecRequestBodyInMemoryLimit 16384000
 
  SecRequestBodyInMemoryLimit 16384000
  
3. Download and install the latest OWASP Core Rule Set.
+
atau biarkan sesuai dengan default
  
    We need to download and install the latest OWASP ModSecurity Core Rule Set from the project website. Click here for more information.
+
SecRequestBodyLimit 13107200
    We will also activate the default CRS config file modsecurity_crs_10_setup.conf.example
+
SecRequestBodyNoFilesLimit 131072
    If you prefer not to use the latest rules, replace master below with the a specific version you would like to use e.g :  v2.2.5 
+
 
    Open the Terminal Window and enter :
+
==Download dan Install OWASP Core Rule Set yang terakhir==
 +
 
 +
* Kita perlu men-download dan meng-instalasi OWASP ModSecurity Core Rule Set terbaru dari web https://github.com/SpiderLabs/owasp-modsecurity-crs/tarball/master
 +
* Kita perlu mengaktifkan file konfigurasi CRS default
 +
 
 +
modsecurity_crs_10_setup.conf.example
 +
 
 +
* Buka terminal dan lakukan:
  
 
  cd /tmp
 
  cd /tmp
Line 63: Line 72:
 
  sudo tar -zxvf SpiderLabs-owasp-modsecurity-crs.tar.gz
 
  sudo tar -zxvf SpiderLabs-owasp-modsecurity-crs.tar.gz
 
  sudo cp -R SpiderLabs-owasp-modsecurity-crs-*/* /etc/modsecurity/
 
  sudo cp -R SpiderLabs-owasp-modsecurity-crs-*/* /etc/modsecurity/
 
 
  sudo rm SpiderLabs-owasp-modsecurity-crs.tar.gz
 
  sudo rm SpiderLabs-owasp-modsecurity-crs.tar.gz
 
  sudo rm -R SpiderLabs-owasp-modsecurity-crs-*
 
  sudo rm -R SpiderLabs-owasp-modsecurity-crs-*
 
  sudo mv /etc/modsecurity/modsecurity_crs_10_setup.conf.example /etc/modsecurity/modsecurity_crs_10_setup.conf
 
  sudo mv /etc/modsecurity/modsecurity_crs_10_setup.conf.example /etc/modsecurity/modsecurity_crs_10_setup.conf
  
    Now we create symbolic links to all activated base rules. Open a terminal window and enter :
+
* Kita perlu membuat link simbolik untuk mengaktifkan semua base rule. Buka terminal dan lakukan:
  
 
  cd /etc/modsecurity/base_rules
 
  cd /etc/modsecurity/base_rules
Line 75: Line 83:
 
  for f in * ; do sudo ln -s /etc/modsecurity/optional_rules/$f /etc/modsecurity/activated_rules/$f ; done  
 
  for f in * ; do sudo ln -s /etc/modsecurity/optional_rules/$f /etc/modsecurity/activated_rules/$f ; done  
  
    Now add these rules to Apache2. Open a terminal window and enter:
+
* Tambahkan rule ke Apache2. Buka terminal dan lakukan:
  
  sudo vi /etc/apache2/mods-available/mod-security.conf
+
  sudo vi /etc/apache2/mods-avaolable/security2.conf
 +
sudo vi /etc/apache2/mods-enabled/security2.conf  
  
    Add the following to towards the end of the file with other includes  and save the file :
+
tambahkan di akhir ke dua file tersebut
  
 
  Include "/etc/modsecurity/activated_rules/*.conf"
 
  Include "/etc/modsecurity/activated_rules/*.conf"
  
4. Check if ModSecurity is enabled and restart Apache.
+
* Cek apakah ModSecurity sudah enabled. Sebelum me-restart Apache2 cek apakah modules sudah diload dengan baik. Buka terminal dan lakukan:
 +
 
 +
sudo a2enmod headers
 +
sudo a2enmod security2
  
    Before restarting Apache2 check if the modules has been loaded.
+
Akan keluar
    Open the Terminal Window and enter :
 
  
  sudo a2enmod headers
+
  Considering dependency unique_id for security2:
  sudo a2enmod mod-security
+
  Module unique_id already enabled
 +
Module security2 already enabled
  
 
Restart Apache2 webserver
 
Restart Apache2 webserver
  
  sudo /etc/init.d apache2 restart
+
  sudo /etc/init.d/apache2 restart
  
 
atau
 
atau
  
service apache2 restart
+
service apache2 restart
  
5. Install ModEvasive.
+
==Instalasi ModEvasive==
  
    Open the Terminal Window and enter :
+
Instalasi
  
 
  sudo apt-get install libapache2-mod-evasive
 
  sudo apt-get install libapache2-mod-evasive
  
6. Create log file directory for mod_evasive.
+
Buat directory untuk log file dari mod_evasive.
 
 
    Open the Terminal Window and enter :
 
  
 
  sudo mkdir /var/log/mod_evasive
 
  sudo mkdir /var/log/mod_evasive
 
    Change the log folder permissions :
 
 
 
  sudo chown www-data:www-data /var/log/mod_evasive/
 
  sudo chown www-data:www-data /var/log/mod_evasive/
  
7. Create mod-evasive.conf file and configure ModEvasive.
+
Buat file mod-evasive.conf dan konfigurasi ModEvasive.
  
    Open the Terminal Window and enter :
+
sudo vi /etc/apache2/mods-available/evasive.conf
  
sudo vi /etc/apache2/mods-available/mod-evasive.conf
+
Tambahkan kalimat berikut, dan ubah nilai email maupun nilai lainnnya yang perlu diubah:
  
     and add the following, changing the email value, and other options below as required :
+
<IfModule mod_evasive20.c>
 +
    DOSHashTableSize    3097
 +
    DOSPageCount        2
 +
    DOSSiteCount        50
 +
    DOSPageInterval     1
 +
    DOSSiteInterval    1
 +
    DOSBlockingPeriod  10
 +
 +
    DOSEmailNotify      username@domain.com
 +
    # DOSSystemCommand    "su - someuser -c '/sbin/... %s ...'"
 +
    DOSLogDir          "/var/log/mod_evasive"
 +
    DOSWhitelist  127.0.0.1
 +
</IfModule>
  
<ifmodule mod_evasive20.c>
 
    DOSHashTableSize 3097
 
    DOSPageCount  2
 
    DOSSiteCount  50
 
    DOSPageInterval 1
 
    DOSSiteInterval  1
 
    DOSBlockingPeriod  10
 
    DOSLogDir  /var/log/mod_evasive
 
    DOSEmailNotify  EMAIL@DOMAIN.com
 
    DOSWhitelist  127.0.0.1
 
</ifmodule>
 
  
8. Fix mod-evasive email bug
+
* Jika ada kesulitan e-mail yang tidak jalan, kita dapat mencoba membuat symlink berikut
 
 
    Because of this bug mod-evasive does not send emails on Ubuntu 12.04.
 
    A temporary workaround is to create symlink to the mail program.
 
    Open the Terminal Window and enter :
 
  
 
  sudo ln -s /etc/alternatives/mail /bin/mail/
 
  sudo ln -s /etc/alternatives/mail /bin/mail/
  
9. Check if ModEvasive is enabled and restart Apache.
+
* Cek ModEvasive apakah sudah enable
  
    Before restarting Apache2 check if the module has been loaded.
+
sudo a2enmod evasive
    Open the Terminal Window and enter :
 
  
sudo a2enmod mod-evasive
+
* Restart Apache2 webserver
 
 
Restart Apache2 webserver
 
  
 
  sudo /etc/init.d/apache2 restart
 
  sudo /etc/init.d/apache2 restart

Latest revision as of 14:14, 30 March 2015

  • Instalasi dan konfigurasi modul ModSecurity dan mod_evasive Apache2 di Ubuntu server.
  • Semua menjadi jauh lebih mudah daripada sebelumnya dalam menginstal kedua modul keamanan yang sangat baik ini untuk Apache2 di Ubuntu LTS, karena kedua modul tersedia dalam dalam repositori standar Ubuntu.
  • Ini hanya titik awal untuk mendapatkan mod_security dan mod_evasive agar bekerja. Silahkan mengacu pada dokumentasi kedua proyek untuk berbagai opsi konfigurasi yang tersedia dan mengkonfigurasi pengaturan keamanan anda sesuai kebutuhan.


Kebutuhan

  • Instalasi Ubuntu LTS server, or yang terbaru di mesin anda.
  • Instalasi Apache2 webserver, di setup dan di konfigurasi:
sudo apt-get install apache2 php5 php5-xmlrpc php5-mysql php5-gd php5-cli \
php5-curl mysql-client mysql-server
  • Instalasi dependensi yang dibutuhkan untuk modsecurity
sudo apt-get install libxml2 libxml2-dev libxml2-utils \
libaprutil1 libaprutil1-dev
  • Untuk mengguna 64bit, perlu menambahkan link berikut
ln -s /usr/lib/x86_64-linux-gnu/libxml2.so /usr/lib/libxml2.so
ln -s /usr/lib/x86_64-linux-gnu/libxml2.so.2 /usr/lib/libxml2.so.2
ln -s /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.1 /usr/lib/libxml2.so.2.9.1

Instalasi & Konfigurasi ModSecurity

Instalasi

sudo apt-get install libapache2-mod-security2

Konfigurasi rules / aturan di ModSecurity

  • Aktifkan aturan / rules default agar bisa beroperasi. Konfigurasi apa yang kita butuhkan.
  • Copy konfigurasi rekomended
sudo mv /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.conf
  • Folder default rules ModSecurity adalah /etc/modsecurity/ . Semua file .conf yang perlu dikonfigurasi terdapat disitu.
  • Kita perlu mengaktifkan semua rule dasar dan meyakinkan bahwa ModSecurity dapat di load.
  • Kita perlu mengedit opsi SecRequestBodyLimit di file modsecurity.conf
  • SecRequestBodyLimit membatasi ukuran page yang di minta dan membatasi upload file menjadi default 128 KB. Ubah ini sesuai dengan kebutuhan / ijin yang kita berikan untuk meng-upload file ke server.
  • Konfigurasi ini sangat penting karena akan membatasi besarnya file yang dapat di upload ke server. Untuk situs CMS yang menggunakan Drupal atau Wordpress konfigurasi ini yang akan menjadi sumber pening di kepala.
  • Buka terminal dan edit:
sudo vi /etc/modsecurity/modsecurity.conf
  • Aktifkan aturan / rule dengan mengedit SecRuleEngine dari DetectionOnly menjadi On.
SecRuleEngine On
  • Edit opsi berikut untuk menaikan request limit ke 16Mbyte dan save file:
SecRequestBodyLimit 16384000
SecRequestBodyInMemoryLimit 16384000

atau biarkan sesuai dengan default

SecRequestBodyLimit 13107200
SecRequestBodyNoFilesLimit 131072

Download dan Install OWASP Core Rule Set yang terakhir

modsecurity_crs_10_setup.conf.example
  • Buka terminal dan lakukan:
cd /tmp
sudo wget -O SpiderLabs-owasp-modsecurity-crs.tar.gz https://github.com/SpiderLabs/owasp-modsecurity-crs/tarball/master
sudo tar -zxvf SpiderLabs-owasp-modsecurity-crs.tar.gz
sudo cp -R SpiderLabs-owasp-modsecurity-crs-*/* /etc/modsecurity/
sudo rm SpiderLabs-owasp-modsecurity-crs.tar.gz
sudo rm -R SpiderLabs-owasp-modsecurity-crs-*
sudo mv /etc/modsecurity/modsecurity_crs_10_setup.conf.example /etc/modsecurity/modsecurity_crs_10_setup.conf
  • Kita perlu membuat link simbolik untuk mengaktifkan semua base rule. Buka terminal dan lakukan:
cd /etc/modsecurity/base_rules
for f in * ; do sudo ln -s /etc/modsecurity/base_rules/$f /etc/modsecurity/activated_rules/$f ; done
cd /etc/modsecurity/optional_rules
for f in * ; do sudo ln -s /etc/modsecurity/optional_rules/$f /etc/modsecurity/activated_rules/$f ; done 
  • Tambahkan rule ke Apache2. Buka terminal dan lakukan:
sudo vi /etc/apache2/mods-avaolable/security2.conf 
sudo vi /etc/apache2/mods-enabled/security2.conf 

tambahkan di akhir ke dua file tersebut

Include "/etc/modsecurity/activated_rules/*.conf"
  • Cek apakah ModSecurity sudah enabled. Sebelum me-restart Apache2 cek apakah modules sudah diload dengan baik. Buka terminal dan lakukan:
sudo a2enmod headers
sudo a2enmod security2

Akan keluar

Considering dependency unique_id for security2:
Module unique_id already enabled
Module security2 already enabled

Restart Apache2 webserver

sudo /etc/init.d/apache2 restart

atau

service apache2 restart

Instalasi ModEvasive

Instalasi

sudo apt-get install libapache2-mod-evasive

Buat directory untuk log file dari mod_evasive.

sudo mkdir /var/log/mod_evasive
sudo chown www-data:www-data /var/log/mod_evasive/

Buat file mod-evasive.conf dan konfigurasi ModEvasive.

sudo vi /etc/apache2/mods-available/evasive.conf

Tambahkan kalimat berikut, dan ubah nilai email maupun nilai lainnnya yang perlu diubah:

<IfModule mod_evasive20.c>
    DOSHashTableSize    3097
    DOSPageCount        2
    DOSSiteCount        50
    DOSPageInterval     1
    DOSSiteInterval     1
    DOSBlockingPeriod   10

    DOSEmailNotify      username@domain.com
    # DOSSystemCommand    "su - someuser -c '/sbin/... %s ...'"
    DOSLogDir           "/var/log/mod_evasive"
    DOSWhitelist   127.0.0.1
</IfModule>


  • Jika ada kesulitan e-mail yang tidak jalan, kita dapat mencoba membuat symlink berikut
sudo ln -s /etc/alternatives/mail /bin/mail/
  • Cek ModEvasive apakah sudah enable
sudo a2enmod evasive
  • Restart Apache2 webserver
sudo /etc/init.d/apache2 restart

atau

service apache2 restart

Referensi