osquery è uno strumento gratuito e open source che trasforma lo stato del sistema operativo in tabelle interrogabili tramite SQL. Permette di analizzare processi, utenti, pacchetti, porte di rete, memoria, cron e molto altro.
In questa guida vedremo come installarlo su Debian 10 e come eseguire alcune query utili.
Prerequisiti
- Server Debian 10.
- Password di root configurata.
Aggiornamento del sistema
apt-get update -y
apt-get upgrade -y
Riavvia il server.
Installazione
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1484120AC4E9F8A1A577AEEE97A80C63C9D8B80B
apt-get install software-properties-common -y
add-apt-repository 'deb [arch=amd64] https://pkg.osquery.io/deb deb main'
apt-get update -y
apt-get install osquery -y
osqueryctl start osqueryd
osqueryctl status osqueryd
Componenti principali
- osqueryi: shell interattiva.
- osqueryd: demone di monitoraggio.
- osqueryctl: helper per configurazione e controllo servizio.
Avvia la shell:
osqueryi
Elenca le tabelle disponibili:
osquery> .tables
Query utili
Informazioni hardware:
select hostname,cpu_physical_cores,physical_memory from system_info;
Utenti del sistema:
SELECT * FROM users;
Utenti attualmente collegati:
select * from logged_in_users where type = 'user';
Memoria:
select * from memory_info;
Carico medio:
select * from load_average;
Pacchetti Debian installati:
select * from deb_packages limit 5;
Processi in ascolto su tutte le interfacce:
SELECT DISTINCT processes.name, listening_ports.port, processes.pid FROM listening_ports JOIN processes USING (pid) WHERE listening_ports.address = '0.0.0.0';
Cron:
select command, path from crontab;
Porte aperte:
select * from listening_ports;
Processi più numerosi:
select count(pid) as total, name from processes group by name order by total desc limit 5;
Conclusione
osquery permette di ispezionare il sistema tramite SQL. Queste query possono essere combinate in controlli schedulati per individuare processi sospetti, software indesiderato o modifiche impreviste.