Install Modsecurity di Apache: Difference between revisions

No edit summary
Line 1: Line 1:
ModSecurity dapat diinstal dengan menjalankan perintah berikut di terminal Anda:
  sudo apt-get install libapache2-mod-security2
  sudo apt install libapache2-mod-security2 -y


Atau, Anda juga dapat membangun ModSecurity secara manual dengan mengkloning repositori resmi ModSecurity Github.
Restart Apache:
/etc/init.d/apache2 restart


Setelah menginstal ModSecurity, aktifkan modul header Apache 2 dengan menjalankan perintah berikut:
Verify the version of ModSecurity is 2.8.0 or higher:
  sudo a2enmod headers
  apt-cache show libapache2-mod-security2


Setelah menginstal ModSecurity dan mengaktifkan modul header, Anda perlu me-restart layanan apache2, ini dapat dilakukan dengan menjalankan perintah berikut:
===OWASP ModSecurity Core Rule Set===
sudo systemctl restart apache2
The following steps are for Debian based distributions. File paths and commands for RHEL will differ slightly.


Anda sekarang harus menginstal ModSecurity. Langkah selanjutnya melibatkan mengaktifkan dan mengonfigurasi ModSecurity dan OWASP-CRS.
Move and change the name of the default ModSecurity file:
mv /etc/modsecurity/modsecurity.conf-recommended  modsecurity.conf


==Konfigurasi Modsecurity==
Install git if needed:
ModSecurity adalah firewall dan karenanya membutuhkan aturan untuk berfungsi. Bagian ini menunjukkan cara menerapkan Set Aturan Inti OWASP. Pertama, Anda harus menyiapkan file konfigurasi ModSecurity.
sudo apt install git


Hapus ekstensi .recommended dari nama file konfigurasi ModSecurity dengan perintah berikut:
Download the OWASP ModSecurity CRS from Github:
  sudo cp /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.conf
git clone https://github.com/SpiderLabs/owasp-modsecurity-crs.git


Dengan editor teks seperti vim, buka <code>/etc/modsecurity/modsecurity.conf</code> dan ubah nilai untuk <code>SecRuleEngine</code> menjadi <code>On</code>:
Navigate into the downloaded directory. Move and rename crs-setup.conf.example to crs-setup.conf. Then move rules/ as well.
cd owasp-modsecurity-crs


  # -- Rule engine initialization ----------------------------------------------
  mv crs-setup.conf.example /etc/modsecurity/crs-setup.conf
# Enable ModSecurity, attaching it to every transaction. Use detection
# only to start with, because that minimises the chances of post-installation
# disruption.
#
<span style="color:#ff0000">SecRuleEngine On</span>
...


Mulai ulang Apache untuk menerapkan perubahan:
  mv rules/ /etc/modsecurity/
  sudo systemctl restart apache2


ModSecurity sekarang harus dikonfigurasi untuk dijalankan. Langkah selanjutnya dalam proses ini adalah menyiapkan seperangkat aturan untuk secara aktif mencegah server web Anda dari serangan.
The configuration file should match the path above as defined in the IncludeOptional directive. Add another Include directive pointing to the rule set:


==Menyiapkan Set Aturan Inti ModSecurity OWASP==
<IfModule security2_module>
OWASP ModSecurity Core Rule Set (CRS) adalah seperangkat aturan deteksi serangan umum untuk digunakan dengan ModSecurity atau firewall aplikasi web yang kompatibel. CRS bertujuan untuk melindungi aplikasi web dari berbagai serangan, termasuk Sepuluh Teratas OWASP, dengan peringatan palsu yang minimal. CRS memberikan perlindungan terhadap banyak kategori serangan umum, termasuk SQL Injection, Cross Site Scripting, dan Local File Inclusion.
        # Default Debian dir for modsecurity's persistent data
 
        SecDataDir /var/cache/modsecurity
Untuk mengatur OWASP-CRS, ikuti prosedur yang diuraikan di bawah ini.
        # Include all the *.conf files in /etc/modsecurity.
        # Keeping your local configuration in that directory
        # will allow for an easy upgrade of THIS file and
        # make your life easier
        IncludeOptional /etc/modsecurity/*.conf
        Include /etc/modsecurity/rules/*.conf
</IfModule>


Pertama, hapus kumpulan aturan saat ini yang sudah dikemas sebelumnya dengan ModSecurity dengan menjalankan perintah berikut:
Restart Apache so that the changes will take effect:
  sudo rm -rf /usr/share/modsecurity-crs
  /etc/init.d/apache2 restart
 
Kloning repositori GitHub OWASP-CRS ke dalam direktori /usr/share/modsecurity-crs:
sudo git clone <nowiki>https://github.com/coreruleset/coreruleset</nowiki> /usr/share/modsecurity-crs
 
Ganti nama crs-setup.conf.example menjadi crs-setup.conf:
sudo mv /usr/share/modsecurity-crs/crs-setup.conf.example /usr/share/modsecurity-crs/crs-setup.conf
 
Ganti nama file aturan pengecualian permintaan default:
sudo mv /usr/share/modsecurity-crs/rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf.example /usr/share/modsecurity-crs/rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf


==Source==
==Source==
*[https://www.linode.com/docs/guides/securing-apache2-with-modsecurity/ linode.com]
*[https://www.linode.com/docs/guides/configure-modsecurity-on-apache/ linode.com]
 
[[Category:Security]]
[[Category:Server]]
[[Category:Website]]
[[Category:Tutorial]]
[[Category:Apache]]
[[Category:ModSecurity]]