Crowdsec-ekin zerbitzari anitzeko ingurunea

Izenburutzat hain mingarria duen honi esker, Crowdseci zer egiten dion azaltzen saiatuko gara… Ohikoa izango den moduan gure erakundeko makina bakoitzean Crowdsec agentea edukitzea, elkarri komunikatzeko aukera emango diegu erasoak saihesteko.

Esto es, Windows edo Linux duen talde bat erasotzen bada, erakundeko gainerako makinak erasoa jakin dezake eta erasotzailearen IP helbidea blokeatu dezake atea jo aurretik. Lehenetsi bezala, esan dezagun Crowdsec tokiko moduan funtzionatzen duela, Crowdsec agentearen bakoitza bere API Zerbitzari Lokalarekin komunikatzen da, Egin beharko duguna da guztiak LAPI zerbitzari berarekin komunikatzea.

Zerbitzari Lokala API,

Comenzamos, lehenengo, makina honetan nahi duguna, API zerbitzari gisa funtzionatuko duten beste agenteentzako. Beraz, konfigurazio fitxategian gaitzen dugu ‘ /etc/crowdsec/config.yaml’, entzun egingo duen IP eta portua adierazten dugu:

api:
...
  zerbitzaria:
...
    listen_uri: 192.168.2.10:8080
...

‘/etc/crowdsec/local_api_credentials.yaml’-ean’ IP helbide berbera bakarrik:

url: http://192.168.2.10:8080
...

Aldaketak aplikatzeko berrabiarazten dugu:

sudo systemctl restart crowdsec

Crowdsec agenteak,

orain, Crowdsec duten beste makinak zerbitzariaren Local API-rekin erregistratu behar ditugu, eta gainera, makina bakoitzeko LAPI desgaituko dugu erabiliko ez delako.

Topicetik kanpo jartzeko, edozein kasutan Crowdsec ez badago helmuga makinara instalatuta, orain da momentua 😉 Aurreko postetan daukazu nola babestu Windows bat, Linux…

Onena, etorri, va, nos registramos contra el LAPI server desde cada agente con:

sudo cscli lapi register -u http://192.168.2.10:8080
    INFO[14-11-2022 10:14:08 PM] Successfully registered to Local API (LAPI)
    INFO[14-11-2022 10:14:08 PM] Local API credentials dumped to '/etc/crowdsec/local_api_credentials.yaml'
 WARN[14-11-2022 10:14:08 PM] Run 'sudo systemctl reload crowdsec' for the new configuration to be effective.

Paramos nuestro propio servidor API ya que no lo usaremos:

sudo cp /lib/systemd/system/crowdsec.service /etc/systemd/system/crowdsec.service

Y añadimos '-no-api’ en el fichero de configuración de Crowdsec '/etc/systemd/system/crowdsec.service’

...
ExecStart=/usr/bin/crowdsec -c /etc/crowdsec/config.yaml -no-api
...

Finally recargamos los servicios para usar esta nueva configuración:

sudo systemctl daemon-reload
sudo systemctl restart crowdsec

Ahora ya si nos vamos al servidor LAPI, podremos ver que hay solicitudes de conexiones pendientes con el comando 'sudo cscli machines list':

---------------------------------------------------------------------------------------------------------
 NAME IP ADDRESS LAST UPDATE STATUS VERSION AUTH TYPE LAST HEARTBEAT
---------------------------------------------------------------------------------------------------------
 b91d17c64c4e4a2 192.168.x.xxx 2022-11-14T22:18:00Z ✔️ v1.4.1-debian password 19s
 9c70ab3970dd4cc 192.168.x.xxx 2022-11-14T22:14:08Z 🚫 password ⚠️ 4m11s
---------------------------------------------------------------------------------------------------------

Validamos las máquinas ejecutando 'sudo cscli machines validate 9c70ab3970dd4cc’

sudo cscli makinek 9c70ab3970dd4cc
 INFO[14-11-2022 10:19:35 PM] makina '9c70ab3970dd4cc' arrakastaz balioztatu da

Y volvemos a verify 'sudo cscli machines list':

---------------------------------------------------------------------------------------------------------
 NAME IP ADDRESS LAST UPDATE STATUS VERSION AUTH TYPE LAST HEARTBEAT
---------------------------------------------------------------------------------------------------------
 b91d17c64c4e4a   192.168.x.xxx  2022-11-14T22:19:00Z  ✔️       v1.4.1-debian  pasahitza   40s
 9c70ab3970dd4cc  192.168.x.xxx  2022-11-14T22:19:35Z  ✔️                      pasahitza   5s
---------------------------------------------------------------------------------------------------------

Ez ahaztu Crowdsec berriz kargatzea agente bakoitzean balioztatu ondoren, con:

sudo systemctl restart crowdsec

Arintzeak,

orain, arriskua arintzeko, baldintza jakinei aurre egiteko arriskuak murrizteko ekintzak aplikatzeko, bouncers erabiliko ditugu. Lehenik, API zerbitzaritik, agenteen bouncers-ek behar dituzten tokenak sortuko ditugu. Agente bakoitzean behar dugun bouncer bakoitzarekin egingo dugu, adibidez 'sudo cscli bouncers add OS-JITSI-05-suebakiak’

API giltza 'OS-JITSI'rako-05-fw':
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Gorde mesedez giltza hau, ez baituzu berreskuratu ahal izango!

En cada agente de Crowdsec deberemos instalar el bouncer que necesitemos, en este caso nos basaremos en los bouncer de tipo firewall, para cada OS, hay un bouncer compatible: Windows firewall, iptables, nftables, ipset, pf… Si tenemos iptables:

sudo apt install crowdsec-firewall-bouncer-iptables -y

Y editamos el fichero de configuración del bouncer del firewall ‘ /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml’ indicando la dirección IP de nuestro LAPI server y el token que acabamos de generarle:

...
api_url: http://192.168.2.10:8080/
api_key: xxxxxxxxxxx
...

Reiniciamos el servicio del bouncer del firewall:

sudo systemctl restart crowdsec-firewall-bouncer
sudo systemctl status crowdsec-firewall-bouncer

eta prest! Esta máquina quedará preparada, podrá agregar en el firewall del SO entradas denegando el acceso a determinadas direcciones IP que le comunique el servidor de APIs.

Podremos desde el servidor LAPI verificar el estado de los bouncers con 'sudo cscli bouncers list':

-----------------------------------------------------------------------------------------------------------------------
 NAME IP ADDRESS VALID LAST API PULL TYPE VERSION AUTH TYPE
-----------------------------------------------------------------------------------------------------------------------
 OS-JITSI-05-fw 192.168.x.xxx ✔️ 2023-02-02T16:40:16Z crowdsec-firewall-bouncer v0.0.24-debian api-key
 OS-ELK-03-fw 192.168.x.xxx ✔️ 2023-02-02T16:40:11Z crowdsec-firewall-bouncer v0.0.24-debian api-key
 OS-GRA-04-fw 192.168.x.xxx ✔️ 2023-02-02T16:40:11Z crowdsec-firewall-bouncer v0.0.24-debian api-key
 OS-NGINX-01-fw 192.168.x.xxx ✔️ 2023-02-02T16:40:10Z crowdsec-firewall-bouncer v0.0.24-debian api-key
 OS-NGINX-01-mirror 192.168.x.xxx ✔️ 2023-02-02T16:40:18Z crowdsec-blocklist-mirror v0.0.1-9-g86d6 api-key
 OS-OTRS-01-fw 192.168.x.xxx ✔️ 2023-02-02T16:40:16Z crowdsec-firewall-bouncer v0.0.24-debian api-key
...
------------------------------------------------------------------------------------------------------------------------

eta prest! Con esto va quedando la malla cerrada! Todos nuestros Crowdsec de la organización se hablarán mediante un único servidor de API, por lo que todos quedarán igualmente protegidos, compartiendo una única lista de direcciones IPs negra, bloqueando en sus respectivos FWs a las IPs de los atacantes…

Abracitos! Que vaya MUY bien 😉

Izenburuko mezuak

Egilea

nheobug@bujarra.com
Autor del blog Bujarra.com Cualquier necesidad que tengas, ez zalantzarik izan nirekin harremanetan jartzeko, ahal duzun guztietan laguntzen saiatuko naiz, partekatu ahal dudan guztietan ;) . Dokumentuez gozatu!!!