Created by Pendekar-Pendekar CSC PNJ

Collaborated with Midnight Club & Komunitas Belajar FreeBSD Indonesia

Alat tempur:

  1. Do’a, Ikhtiar & Tawakkal.
  2. VMware / Virtualbox atau Cloud Hosting
  3. ISO FreeBSD 11.0 i386 atau amd64 (ftp://ftp.belajarfreebsd.or.id:1021/pub/ISO/)
  4. Ketelitian :p

Assalamualaikum Warahmatullahi Wabarakatuh

Bismillahirrahmanirrahim

===========HAPROXY===========

OS: FreeBSD 11

Load Balancer: HAProxy 1.7.5

Spec: 2 vCore, 2 GB vRAM, 20 GB vHDD

Created by Pendekar CSC

Collaborated with Midnight Club & Komunitas Belajar FreeBSD Indonesia

==================================

=====Install Screen=====

//Fungsinya untuk save session SSH

# cd /usr/ports/sysutils/screen && make install clean && rehash

//Login SSH & jalankan screen

# screen

//Jika disconnect ketika remote, silahkan login kembali kemudian resume session

# screen -r -d

=====Persiapan Alat Tempur=====

Pre-Requisites

3 Server (1 Server HAProxy + 2 Web Server)

//Diasumsikan webserver telah diinstall

IP Server HAProxy 2 (NIC)        : 172.168.1.1/25 (WAN)

                                  192.168.1.1/29 (LAN)

IP Webserver 1                        : 192.168.1.2/29 (LAN)

IP Webserver 2                        : 192.168.1.3/29 (LAN)

=====Install & Config HAPROXY=====

# cd /usr/ports/net/haproxy && make install clean && rehash

//Selama proses instalasi pilih sesuai kebutuhan (default)

//Finish Install

//Buat direktori haproxy & direktori log  di dalamnya

# mkdir -p /usr/local/etc/haproxy/log

//Buat file haproxy.conf di dalam direktori haproxy yang baru dibuat

# cd /usr/local/etc/haproxy

# touch haproxy.conf

//Isi file haproxy.conf seperti contoh di bawah, silahkan pilih salah satu:

//#Simple Configuration: Hanya ada 1 rules proxy untuk protokol http/tcp atau

//#HAProxy Configuration with SSL Termination: Bisa digunakan untuk multiple rules proxy (frontend & backend) + SSL

=====Simple Configuration =====

//Save & Exit

=====HAProxy Configuration with SSL Termination=====

//Create file .pem untuk SSL. Diasumsikan sudah ada file .crt & .key

//create folder untuk meletekkan file SSL

# mkdir /etc/ssl/csc-pnj

//Letakkan kedua file dalam folder tersebut

//Gabungkan file .crt dengan .key agar menjadi .pem

# cat csc-pnj.crt csc-pnj.key > csc-pnj.pem

//input value dibawah ini pada haproxy.conf

//Save & Exit

=====Config Logging=====

//Tambahkan value berikut pada /etc/syslogd.conf

//Exit & save

//Buat symlink haproxy.log di /var/log untuk memudahkan pencarian log

# ln -s /usr/local/etc/haproxy/log/haproxy.log /var/log/haproxy.log

=====Start Service=====

//create system user & group untuk menjalankan service haproxy

# pw useradd haproxy

//change ownership & group menjadi haproxy

# chown -R haproxy:haproxy /usr/local/etc/haproxy

//Check File Configuration

//Pastikan lokasi anda berada di direktori /usr/local/etc/haproxy

# haproxy -f haproxy.conf -c

//Jika muncul warning seperti ini:

//Kalau web diakses dari client yg menggunakan Java7 ke bawah sebaiknya di ignore saja

//Jika tidak, bisa kita tuning valuenya ke max 2048 untuk meningkatkan enkripsi Diffie-Hellman

//Tambahkan value berikut pada block “global” di /usr/local/etc/haproxy/haproxy.conf

//Save & Exit

//Cek kembali konfigurasi haproxy

# haproxy -f haproxy.conf -c

//Aktifkan service haproxy saat booting & ubah direktori file configuration

# sysrc haproxy_enable=YES

# sysrc haproxy_config=/usr/local/etc/haproxy/haproxy.conf

//Restart service syslogd

# service syslogd restart

//Jalankan Service HAProxy

# service haproxy start

//Service HAProxy telah berjalan di background pada port 80 & 443

# sockstat -4l | grep haproxy

//Load Balancer siap untuk digunakan

//Tes akses dari client akses IP/Domain Server HAProxy

//Saat akses pertama request akan di forward ke webserver 1

//Tes refresh page

//Saat akses kedua request akan di forward ke webserver 2

//Ini efek dari algoritma roundrobin

//Enable HAProxy stats page untuk melihat statistic usage

//Input value ini pada blok “defaults” di haproxy.conf

//Save & exit

//Akses dari web browser (IP)/stats

//Masukkan user & password sesuai config

//Tampilan Statistik HAProxy

Sampai disini kita telah berhasil dalam membuat Load Balancer untuk mengakses website atau apps.

Untuk selanjutnya silahkan kembangkan kreatifitas kalian dalam penggunaan fitur Load Balance menggunakan HAProxy ini, masih banyak yang bisa di oprek.

Ditunggu komentar, saran/kritiknya untuk membangun semangat ngoprek kami 😊

Akhir kata Wassalamualaikum Warahmatullahi Wabarakatuh. #HappyNgoprek

=====DONE=====

        Regards, Jakarta, 27 April 2017

        

Pendekar-pendekar CSC

#UnlimitedConnection

Referensi:

  1. http://www.tecmint.com/install-haproxy-load-balancer-in-linux/
  2. https://dzone.com/articles/high-availability-load
  3. https://serversforhackers.com/load-balancing-with-haproxy
  4. https://serversforhackers.com/using-ssl-certificates-with-haproxy
  5.  http://www.knowarth.com/haproxy-load-balancer-configuration/
  6. https://github.com/kura/kura.io/blob/master/content/hpkp-http-public-key-pinning-with-haproxy.rst#extracting-the-public-key-information
  7. http://www.mattzuba.com/2015/07/hardening-haproxy-for-an-a-rating/
  8. https://github.com/BetterCrypto/Applied-Crypto-Hardening/blob/master/src/configuration/Proxies/HAProxy/haproxy.cfg
  9. https://neverendingsecurity.wordpress.com/tag/haproxy/
  10. https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
  11. http://www.loadbalancer.org/blog/simple-denial-of-service-dos-attack-mitigation-using-haproxy-2
  12. https://panel.bullten.net/knowledgebase/6/Installing-HAProxy-For-Load-Blancing-And-Protecting-Apache-From-DDos.html
  13. https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning
  14. https://raymii.org/s/articles/HTTP_Public_Key_Pinning_Extension_HPKP.html
  15. https://servernesia.com/2564/cara-membuat-http-public-key-pinning/
  16. http://yollyrinaldi.blogspot.co.id/2016_10_09_archive.html

Tutorial & PoC by Aulia Rahman – Founder CSC PNJ

Sponsored by BATI - Cloud Service Provider: https://portal.mybaticloud.com/

Supported by MAGNet – Internet Service Provider: https://mag.net.id/

Thanks to Om Andy Hidayat - Founder Belajar FreeBSD Indonesia http://belajarfreebsd.or.id/beranda/

This topic has been discussed on Midnight Club | (Bukan) Programmer

Forum Discussion: https://www.facebook.com/groups/csc.pnj/

“Jangan jadikan keterbatasan sebagai penghalang dalam menggapai kesuksesan”

– Aulia Rahman (CSC PNJ 2011)

===== BONUS HARDENING =====

//Strong SSL Chiper

//Letakkan di block global

//Before Hardening

C:\Users\hp\AppData\Local\Microsoft\Windows\INetCache\Content.Word\Before SSL Hardening.png

//After Hardening SSL Chiper

C:\Users\hp\AppData\Local\Microsoft\Windows\INetCache\Content.Word\After SSL Hardening.png

//Avoid Header Injection and exploit

//Letakkan di block frontend

//Before Header Hardening

C:\Users\hp\AppData\Local\Microsoft\Windows\INetCache\Content.Word\Before Header Hardening.png

//After Header Hardening

//Pada percobaan ini ketika kita implementasi HTTP Public-Key-Pins (HPKP) pada server HAProxy tidak akan berfungsi. Dikarenakan request port 80 & 443 di forward ke Webserver, seharusnya kita setting HPKP di masing-masing file configuration Webserver (httpd.conf atau nginx.conf)

C:\Users\hp\AppData\Local\Microsoft\Windows\INetCache\Content.Word\Invalid pin-sha256.png

=====Generate HTTP Public-Key-Pins (HPKP)=====

//Untuk generate HPKP menjadi base64 bisa menggunakan file SSL seperti .csr .crt .key .pem & nama domain atau mudahnya silahkan kunjungi website berikut https://report-uri.io/home/pkp_hash

//Diasumsikan file yang dibutuhkan ada pada direktori /etc/ssl/csc-pnj

//Pilih salah satu, akan menghasilkan value yang sama

//File .csr

# openssl req -in my-signing-request.csr -pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64

//File .key

# openssl rsa -in my-rsa-key-file.key -outform der -pubout | openssl dgst -sha256 -binary | openssl enc -base64

//File .crt

# openssl x509 -in my-certificate.crt -pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64

//File .pem

# openssl x509 -in my-file.pem -pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64

//Nama Domain

# openssl s_client -servername csc-pnj.org -connect csc-pnj.org:443 | openssl x509 -pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64

//Berikut contoh hasil generate HPKP dalam format base64

//Hash berikut yang akan kita input dalam variable pin-sha256=”Base64+Primary”;

//pin-sha256= “hm2YAv5fioZh+ZlK8rVs0Sc5NPDIMHqycX8TongFo8A=” di file configuration webserver.

//Ingat untuk buat HPKP Backup Key untuk mencegah ketika SSL kita expired agar tidak terjadi error ketika akses website/app.

=====Generate HTTP Public-Key-Pins (HPKP) - Backup Key=====

//Lakukan pada masing-masing Webserver untuk membuat HPKP Backup

# mkdir /etc/ssl/csc-pnj

# cd /etc/ssl/csc-pnj

# openssl genrsa -out backup.key 4096

# openssl rsa -in backup.key -outform der -pubout | openssl dgst -sha256 -binary | openssl enc -base64

//Hash berikut yang akan kita input dalam variable pin-sha256=” Base64+Backup”;

//pin-sha256= “3+BpwAUs+sYNzyj0b+7ZalhHLhSVWTWaKxiMnoKrx10=” di file configuration webserver.

//Contoh Input HPKP pada Apache Webserver (httpd.conf)

//Enable module “mod_headers”

//Contoh Input HPKP pada NGINX Webserver (nginx.conf)

//Enable module ngx_http_headers_module

=====Hardening Online Checking=====

//SSL Chiper : https://www.ssllabs.com/ssltest/analyze.html

C:\Users\hp\AppData\Local\Microsoft\Windows\INetCache\Content.Word\SSL Optimize.png

//Header : https://securityheaders.io

//HTTP Public Key Pins (HPKP) : https://report-uri.io/home/pkp_analyse

C:\Users\hp\AppData\Local\Microsoft\Windows\INetCache\Content.Word\HPKP Optimize.png

//Securing from POST attack

//prevent attackers from clogging resources and ultimately harming the well-being of not only your equipment but your entire organization at the same time

//letakkan di block frontend

//Avoid DDOS

https://panel.bullten.net/knowledgebase/6/Installing-HAProxy-For-Load-Blancing-And-Protecting-Apache-From-DDos.html

C:\Users\au714nzg\Documents\628980040173-1357905296.jpg

                Copyright 2017 - Computer Student Club Politeknik Negeri Jakarta

#UnlimitedConnection

Web: csc-pnj.org | Twitter: @CSC_PNJ

FB Group: https://www.facebook.com/groups/csc.pnj/ | Fanspage: https://www.facebook.com/CSCPNJ/