GNU/Linux >> Linux Esercitazione >  >> Debian

Come installare osquery su Debian 10

osquery è uno strumento gratuito e open source sviluppato da Facebook che può essere utilizzato per interrogare informazioni relative al sistema operativo, inclusi utilizzo della memoria, pacchetti installati, informazioni sui processi, utenti di accesso, porte di ascolto e molti altri. Può essere eseguito su diversi sistemi operativi tra cui Windows, Linux, FreeBSD e MacOS. È uno strumento molto utile per una varietà di casi d'uso per la risoluzione dei problemi relativi alle prestazioni e alle operazioni. Viene fornito con molti strumenti che ti aiutano a eseguire analisi e monitoraggio del sistema operativo.

In questo tutorial impareremo come installare e usare osquery su Debian 10.

Prerequisiti

  • Un server che esegue Debian 10.
  • Sul tuo server è configurata una password di root.

Per iniziare

Prima di iniziare, è una buona idea aggiornare il pacchetto del sistema all'ultima versione. Puoi aggiornare tutti i pacchetti con il seguente comando:

apt-get update -y
apt-get upgrade -y

Una volta aggiornati tutti i pacchetti, riavvia il sistema per applicare le modifiche.

Installa osquery

Per impostazione predefinita, osquery non è disponibile nel repository predefinito di Debian 10. Quindi dovrai aggiungere il repository osquery nel tuo sistema.

Innanzitutto, scarica e aggiungi la chiave GPG con il seguente comando:

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1484120AC4E9F8A1A577AEEE97A80C63C9D8B80B

Quindi, aggiungi il repository osquery con il seguente comando:

apt-get install software-properties-common -y
add-apt-repository 'deb [arch=amd64] https://pkg.osquery.io/deb deb main'

Quindi, aggiorna il repository e installa osquery con il seguente comando:

apt-get update -y
apt-get install osquery -y

Una volta terminata l'installazione, avvia il servizio osquery con il seguente comando:

osqueryctl start osqueryd

Puoi anche verificare lo stato di osquery con il seguente comando:

osqueryctl status osqueryd

Dovresti vedere il seguente output:

? osqueryd.service - The osquery Daemon
   Loaded: loaded (/lib/systemd/system/osqueryd.service; disabled; vendor preset: enabled)
   Active: active (running) since Sun 2020-04-19 15:21:57 UTC; 6s ago
  Process: 25333 ExecStartPre=/bin/sh -c if [ ! -f $CONFIG_FILE ]; then echo {} > $CONFIG_FILE; fi (code=exited, status=0/SUCCESS)
  Process: 25334 ExecStartPre=/bin/sh -c if [ ! -f $FLAG_FILE ]; then touch $FLAG_FILE; fi (code=exited, status=0/SUCCESS)
  Process: 25336 ExecStartPre=/bin/sh -c if [ -f $LOCAL_PIDFILE ]; then mv $LOCAL_PIDFILE $PIDFILE; fi (code=exited, status=0/SUCCESS)
 Main PID: 25337 (osqueryd)
    Tasks: 13 (limit: 4701)
   Memory: 6.4M
   CGroup: /system.slice/osqueryd.service
           ??25337 /usr/bin/osqueryd --flagfile /etc/osquery/osquery.flags --config_path /etc/osquery/osquery.conf
           ??25339 /usr/bin/osqueryd

Apr 19 15:21:57 debian10 systemd[1]: Starting The osquery Daemon...
Apr 19 15:21:57 debian10 systemd[1]: Started The osquery Daemon.
Apr 19 15:21:57 debian10 osqueryd[25337]: osqueryd started [version=4.2.0]
Apr 19 15:21:57 debian10 osqueryd[25337]: I0419 15:21:57.261158 25339 events.cpp:863] Event publisher not enabled: auditeventpublisher: Publish
Apr 19 15:21:57 debian10 osqueryd[25337]: I0419 15:21:57.261485 25339 events.cpp:863] Event publisher not enabled: syslog: Publisher disabled v

Lavorare con osquery

osquery include tre utili componenti osqueryi, osqueryd e osqueryctl. L'osqueryi è una shell interattiva osquery e non comunica con un demone. Puoi usare la shell per eseguire query ed esplorare lo stato corrente del tuo sistema operativo. osqueryd è il demone di monitoraggio dell'host che può essere utilizzato per pianificare le query e registrare le modifiche allo stato del sistema operativo. osqueryctl è uno script di supporto per testare la configurazione.

Puoi eseguire il seguente comando per connetterti alla shell osquery:

osqueryi

Dovresti ottenere il seguente output:

Using a virtual database. Need help, type '.help'

Quindi, esegui il comando .help per vedere tutte le opzioni disponibili con osquery:

osquery> .help

Dovresti ottenere il seguente output:

Welcome to the osquery shell. Please explore your OS!
You are connected to a transient 'in-memory' virtual database.

.all [TABLE]     Select all from a table
.bail ON|OFF     Stop after hitting an error
.echo ON|OFF     Turn command echo on or off
.exit            Exit this program
.features        List osquery's features and their statuses
.headers ON|OFF  Turn display of headers on or off
.help            Show this message
.mode MODE       Set output mode where MODE is one of:
                   csv      Comma-separated values
                   column   Left-aligned columns see .width
                   line     One value per line
                   list     Values delimited by .separator string
                   pretty   Pretty printed SQL results (default)
.nullvalue STR   Use STRING in place of NULL values
.print STR...    Print literal STRING
.quit            Exit this program
.schema [TABLE]  Show the CREATE statements
.separator STR   Change separator used by output mode
.socket          Show the osquery extensions socket path
.show            Show the current values for various settings
.summary         Alias for the show meta command
.tables [TABLE]  List names of tables
.types [SQL]     Show result of getQueryColumns for the given query
.width [NUM1]+   Set column widths for "column" mode
.timer ON|OFF      Turn the CPU timer measurement on or off
osquery> 

Ci sono molte tabelle disponibili per la query. Puoi elencare tutte le tabelle con il seguente comando:

osquery> .table

Dovresti ottenere il seguente output:

  => acpi_tables
  => apparmor_profiles
  => apt_sources
  => arp_cache
  => atom_packages
  => augeas
  => authorized_keys
  => block_devices
  => carbon_black_info
  => carves
  => chrome_extensions
  => cpu_time
  => cpuid
  => crontab
  => curl
  => curl_certificate
  => deb_packages
  => device_file
  => device_hash
  => device_partitions
  => disk_encryption
  => dns_resolvers
  => docker_container_labels
  => docker_container_mounts

Puoi trovare le varie informazioni di sistema usando la tabella sopra con osquery.

Sistema di monitoraggio con osquery

Puoi monitorare l'utilizzo della memoria, elaborare le informazioni, lo spazio su disco, accedere agli utenti e molti altri con osquery.

Innanzitutto, avvia la shell osquery con il seguente comando:

osqueryi

Successivamente, puoi ottenere le informazioni sul nome host del tuo sistema, il core della CPU e la memoria fisica con il seguente comando:

osquery> select hostname,cpu_physical_cores,physical_memory from system_info;

Dovresti ottenere il seguente output:

+------------+--------------------+-----------------+
| hostname   | cpu_physical_cores | physical_memory |
+------------+--------------------+-----------------+
| debian10   | 1                  | 1032937472      |
+------------+--------------------+-----------------+

Per ottenere le informazioni sul file ssh_config eseguire la seguente query:

osquery> select * from ssh_configs;

Dovresti ottenere il seguente output:

W0419 15:47:17.043509 25397 virtual_table.cpp:959] The ssh_configs table returns data based on the current user by default, consider JOINing against the users table
W0419 15:47:17.043740 25397 virtual_table.cpp:974] Please see the table documentation: https://osquery.io/schema/#ssh_configs
+-----+--------+--------------------------+---------------------+
| uid | block  | option                   | ssh_config_file     |
+-----+--------+--------------------------+---------------------+
| 0   | host * | sendenv lang lc_*        | /etc/ssh/ssh_config |
| 0   | host * | hashknownhosts yes       | /etc/ssh/ssh_config |
| 0   | host * | gssapiauthentication yes | /etc/ssh/ssh_config |
+-----+--------+--------------------------+---------------------+
osquery> 

Per ottenere un elenco di tutti gli utenti nel tuo sistema, esegui la seguente query:

osquery> SELECT * FROM users;

Dovresti ottenere il seguente output:

+-------+-------+------------+------------+-----------------+------------------------------------+----------------------+-------------------+------+
| uid   | gid   | uid_signed | gid_signed | username        | description                        | directory            | shell             | uuid |
+-------+-------+------------+------------+-----------------+------------------------------------+----------------------+-------------------+------+
| 0     | 0     | 0          | 0          | root            | root                               | /root                | /bin/bash         |      |
| 1     | 1     | 1          | 1          | daemon          | daemon                             | /usr/sbin            | /usr/sbin/nologin |      |
| 2     | 2     | 2          | 2          | bin             | bin                                | /bin                 | /usr/sbin/nologin |      |
| 3     | 3     | 3          | 3          | sys             | sys                                | /dev                 | /usr/sbin/nologin |      |
| 4     | 65534 | 4          | 65534      | sync            | sync                               | /bin                 | /bin/sync         |      |
| 5     | 60    | 5          | 60         | games           | games                              | /usr/games           | /usr/sbin/nologin |      |
| 6     | 12    | 6          | 12         | man             | man                                | /var/cache/man       | /usr/sbin/nologin |      |
| 7     | 7     | 7          | 7          | lp              | lp                                 | /var/spool/lpd       | /usr/sbin/nologin |      |

Se vuoi elencare tutti gli utenti non di sistema nel tuo sistema, esegui la seguente query:

osquery> select * from users where uid <= 1000 limit 3;

Dovresti ottenere il seguente output:

+-----+-----+------------+------------+----------+-------------+-----------+-------------------+------+
| uid | gid | uid_signed | gid_signed | username | description | directory | shell             | uuid |
+-----+-----+------------+------------+----------+-------------+-----------+-------------------+------+
| 0   | 0   | 0          | 0          | root     | root        | /root     | /bin/bash         |      |
| 1   | 1   | 1          | 1          | daemon   | daemon      | /usr/sbin | /usr/sbin/nologin |      |
| 2   | 2   | 2          | 2          | bin      | bin         | /bin      | /usr/sbin/nologin |      |
+-----+-----+------------+------------+----------+-------------+-----------+-------------------+------+

Per ottenere l'elenco degli utenti attualmente loggati, eseguire la seguente query:

osquery> select * from logged_in_users where type = 'user';

Dovresti ottenere il seguente output:

+------+------+-------+--------------+------------+-------+
| type | user | tty   | host         | time       | pid   |
+------+------+-------+--------------+------------+-------+
| user | root | pts/0 | 27.61.217.59 | 1587309538 | 19279 |
| user | root | pts/1 | 27.61.217.59 | 1587310737 | 25378 |
| user | root | pts/2 | 27.61.217.59 | 1587310997 | 25394 |
+------+------+-------+--------------+------------+-------+

Per visualizzare le informazioni sulla memoria del tuo sistema, esegui la seguente query:

osquery> select * from memory_info;

Dovresti ottenere il seguente output:

+--------------+-------------+----------+------------+-------------+-----------+-----------+------------+-----------+
| memory_total | memory_free | buffers  | cached     | swap_cached | active    | inactive  | swap_total | swap_free |
+--------------+-------------+----------+------------+-------------+-----------+-----------+------------+-----------+
| 4138455040   | 2407211008  | 79745024 | 1384751104 | 0           | 556371968 | 954744832 | 0          | 0         |
+--------------+-------------+----------+------------+-------------+-----------+-----------+------------+-----------+
osquery> 

Per trovare il carico medio del tuo sistema esegui la seguente query:

osquery> select * from load_average;

Dovresti ottenere il seguente output:

+--------+----------+
| period | average  |
+--------+----------+
| 1m     | 0.000000 |
| 5m     | 0.000000 |
| 15m    | 0.000000 |
+--------+----------+
osquery> 

Per ottenere un elenco dei primi cinque pacchetti nel tuo sistema, esegui la seguente query:

osquery> select * from deb_packages top limit 5;

Dovresti ottenere il seguente output:

+-------------------+------------+--------------+------+-------+----------+
| name              | version    | source       | size | arch  | revision |
+-------------------+------------+--------------+------+-------+----------+
| acpi-support-base | 0.142-8    | acpi-support | 43   | all   | 8        |
| acpid             | 1:2.0.31-1 |              | 146  | amd64 | 1        |
| adduser           | 3.118      |              | 849  | all   |          |
| apparmor          | 2.13.2-10  |              | 1833 | amd64 | 10       |
| apt               | 1.8.2      |              | 4064 | amd64 |          |
+-------------------+------------+--------------+------+-------+----------+

Per ottenere informazioni sui processi in esecuzione nel tuo sistema, esegui la seguente query:

osquery> SELECT DISTINCT processes.name, listening_ports.port, processes.pid FROM listening_ports JOIN processes USING (pid) WHERE listening_ports.address = '0.0.0.0';

Dovresti ottenere il seguente output:

+------+------+-----+
| name | port | pid |
+------+------+-----+
| sshd | 22   | 729 |
+------+------+-----+

Per trovare tutti gli accessi precedenti esegui la seguente query:

osquery> select * from last;

Dovresti ottenere il seguente output:

+----------+-------+-------+------+------------+--------------+
| username | tty   | pid   | type | time       | host         |
+----------+-------+-------+------+------------+--------------+
| root     | pts/0 | 1448  | 7    | 1587365277 | 27.61.217.41 |
| root     | pts/1 | 13392 | 7    | 1587368569 | 27.61.217.41 |
|          | pts/0 | 1004  | 8    | 1587376329 |              |
|          | pts/1 | 13321 | 8    | 1587376821 |              |
|          | ttyS0 | 748   | 8    | 1587465619 |              |
|          | tty1  | 749   | 8    | 1587465619 |              |
| root     | pts/0 | 1057  | 7    | 1587465664 | 27.61.217.9  |
| root     | pts/1 | 1375  | 7    | 1587465846 | 27.61.217.9  |
+----------+-------+-------+------+------------+--------------+

Per elencare tutti i lavori pianificati da crontab eseguire la seguente query:

osquery> select command, path from crontab ;

Dovresti ottenere il seguente output:

+----------------------------------------------------------------------------------------------------------------------------------------+-------------------+
| command                                                                                                                                | path              |
+----------------------------------------------------------------------------------------------------------------------------------------+-------------------+
| root cd / && run-parts --report /etc/cron.hourly                                                                                       | /etc/crontab      |
| root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )                                                       | /etc/crontab      |
| root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )                                                      | /etc/crontab      |
| root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )                                                     | /etc/crontab      |
| root if [ -x /usr/share/mdadm/checkarray ] && [ $(date +\%d) -le 7 ]; then /usr/share/mdadm/checkarray --cron --all --idle --quiet; fi | /etc/cron.d/mdadm |

Per trovare tutte le porte aperte nel tuo sistema, esegui la seguente query:

osquery> select * from listening_ports;

Dovresti ottenere il seguente output:

+------+------+----------+--------+------------+-----+--------+----------------------------------------+---------------+
| pid  | port | protocol | family | address    | fd  | socket | path                                   | net_namespace |
+------+------+----------+--------+------------+-----+--------+----------------------------------------+---------------+
| 444  | 53   | 6        | 2      | 127.0.0.53 | 13  | 14910  |                                        | 4026531993    |
| 729  | 22   | 6        | 2      | 0.0.0.0    | 3   | 16940  |                                        | 4026531993    |
| 664  | 3306 | 6        | 2      | 127.0.0.1  | 69  | 15824  |                                        | 4026531993    |
| 544  | 6379 | 6        | 2      | 127.0.0.1  | 6   | 15472  |                                        | 4026531993    |
| 729  | 22   | 6        | 10     | ::         | 4   | 16951  |                                        | 4026531993    |
| 544  | 6379 | 6        | 10     | ::1        | 7   | 15473  |                                        | 4026531993    |
| 759  | 80   | 6        | 10     | ::         | 4   | 17009  |                                        | 4026531993    |
| 444  | 53   | 17       | 2      | 127.0.0.53 | 12  | 14909  |                                        | 4026531993    |
| 405  | 58   | 255      | 10     | ::         | 15  | 16039  |                                        | 4026531993    |

Per elencare i primi 5 processi più attivi, esegui la seguente query:

osquery> select count(pid) as total, name from processes group by name order by total desc limit 5;

Dovresti ottenere il seguente output:

+-------+---------+
| total | name    |
+-------+---------+
| 4     | sshd    |
| 3     | apache2 |
| 2     | systemd |
| 2     | bash    |
| 2     | agetty  |
+-------+---------+

Conclusione

Nel tutorial sopra, abbiamo imparato come installare e usare osquery in Debian 10. osquery è uno strumento molto utile per trovare backdoor, malware o qualsiasi processo zombie nel tuo sistema. Per ulteriori informazioni su osquery, visita la pagina della documentazione di osquery.


Debian
  1. Come installare R su Debian 9

  2. Come installare R su Debian 10

  3. Come installare Apache ZooKeeper su Debian 10

  4. Come installare Ionic Framework su Debian 10

  5. Come installare WildFly su Debian 11

Come installare Vai su Debian 10

Come installare LEMP in Debian 7

Come installare Flectra su Debian 10

Come installare OpenNebula su Debian 10

Come installare TeamViewer su Debian 10

Come installare Vai su Debian