Instal Osquery di Ubuntu 20.04

Dalam panduan ini, kita akan belajar cara menginstal osquery di Ubuntu 20.04. Osquery adalah alat opensource yang menanyakan sistem operasi seolah-olah itu adalah database relasional. Ini memanfaatkan kueri seperti SQL untuk mengumpulkan informasi Sistem Operasi untuk kinerja, keamanan, analisis audit kepatuhan. Ini berjalan di berbagai platform seperti Linux, FreeBSD, MacOS, sistem Windows.

Instal Osquery di Ubuntu 20.04

Instal Repositori APT Osquery

Repositori Ubuntu default tidak berisi paket osquery. Namun, osquery menerbitkan repositori yang tepat untuk setiap rilis stabil. Untuk menambahkan repositori osquery apt ke Ubuntu 20.04, buat daftar sumber osquery;

echo "deb [arch=amd64] https://pkg.osquery.io/deb deb main" | sudo tee /etc/apt/sources.list.d/osquery.list

Impor kunci penandatanganan repositori

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

Perbarui paket sistem Anda

sudo apt update

Setelah pembaruan selesai, instal osquery di Ubuntu 20.04;

sudo apt install osquery

Komponen osquery

Paket Osquery menginstal tiga komponen dasar;

  • osqueryctl – Ini adalah skrip pembantu osquery untuk menguji konfigurasi/penyebaran osquery serta mengelola service osqueryd.
  • osqueryd – adalah daemon osquery untuk menjadwalkan kueri dan merekam perubahan status OS.
  • osqueryi– adalah shell interaktif osquery. Dari shell, Anda dapat menjalankan berbagai kueri untuk menjelajahi status OS tersebut.

Untuk mempelajari useran perintah di atas, Anda dapat melewati opsi -h/–help.

osqueryctl -h
Usage: /usr/bin/osqueryctl {clean|config-check|start|stop|status|restart}

Misalnya untuk memulai, menghentikan dan restart osqueryd menggunakan osqueryctl, jalankan perintah;

osqueryctl start osqueryd
osqueryctl stop osqueryd
osqueryctl restart osqueryd

Menjalankan Osquery

Osquery dapat dijalankan dalam mode standalone menggunakan osqueryi atau dapat dijalankan sebagai service menggunakan osqueryd. Dalam panduan ini, kita akan fokus pada cara menggunakan shell interaktif osquery untuk menanyakan berbagai aktivitas sistem.

Menjalankan osquery dalam mode mandiri

Kapan osqueryi dijalankan tanpa argumen apa pun, ini akan membawa Anda ke prompt shell interaktif;

osqueryi
Using a virtual database. Need help, type '.help'osquery>

Anda dapat memperoleh bantuan dengan mengetik.help pada prompt shell.

osquery>.help
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>

Tabel Informasi Sistem

Osquery mengubah berbagai atribut OS menjadi tabel seperti konsep database. Oleh karena itu, untuk membuat daftar tabel dari mana berbagai informasi sistem disimpan, jalankan.tablesperintah di dalamosqueryi mengingatkan.

osqueryi

osquery>.tables

keluaran sampel;

=> acpi_tables => apt_sources => arp_cache => augeas => authorized_keys => block_devices => carbon_black_info => carves => chrome_extensions => cpu_time … => time => uptime => usb_devices => user_events => user_groups => user_ssh_keys => users => yara => yara_events => yum_sources osquery>

Sebagai contoh tujuan, mari kita lihat apa saja yang terdapat pada beberapa tabel;

select * from os_version;
+--------+---------------------------+-------+-------+-------+-------+----------+---------------+----------+--------+ | name | version | major | minor | patch | build | platform | platform_like | codename | arch | +--------+---------------------------+-------+-------+-------+-------+----------+---------------+----------+--------+ | Ubuntu | 20.04.1 LTS (Focal Fossa) | 20 | 4 | 0 | | ubuntu | debian | focal | x86_64 | +--------+---------------------------+-------+-------+-------+-------+----------+---------------+----------+--------+

Untuk menanyakan user sistem yang uidnya lebih besar dari 1000,

select * from users where uid >=1000;
+-------+-------+------------+------------+-----------+-------------+-----------------+-------------------+------+ | uid | gid | uid_signed | gid_signed | username | description | directory | shell | uuid | +-------+-------+------------+------------+-----------+-------------+-----------------+-------------------+------+ | 65534 | 65534 | 65534 | 65534 | nobody | nobody | /nonexistent | /usr/sbin/nologin | | | 1000 | 1000 | 1000 | 1000 | koromicha | koromicha | /home/koromicha | /bin/bash | | | 65534 | 65534 | 65534 | 65534 | nobody | nobody | / | /usr/sbin/nologin | | +-------+-------+------------+------------+-----------+-------------+-----------------+-------------------+------+

Untuk membuat daftar semua user yang masuk;

select user,tty,host,time from logged_in_users where tty not like '~';
+-----------+-------+--------------+------------+ | user | tty | host | time | +-----------+-------+--------------+------------+ | koromicha | tty1 | | 1613887707 | | koromicha | pts/0 | 192.168.57.1 | 1613888358 | +-----------+-------+--------------+------------+

Periksa waktu aktif sistem;

select * from uptime;
+------+-------+---------+---------+---------------+ | days | hours | minutes | seconds | total_seconds | +------+-------+---------+---------+---------------+ | 0 | 1 | 21 | 49 | 4909 | +------+-------+---------+---------+---------------+

Untuk menunjukkan interface jaringan dan alamat IP;

select interface,add
ress,mask from interface_addresses where interface NOT LIKE '%lo%';
+-----------+---------------------------------+-----------------------+ | interface | address | mask | +-----------+---------------------------------+-----------------------+ | enp0s3 | 10.0.2.15 | 255.255.255.0 | | enp0s8 | 192.168.57.3 | 255.255.255.0 | | enp0s3 | fe80::a00:27ff:fe5c:52a%enp0s3 | ffff:ffff:ffff:ffff:: | | enp0s8 | fe80::a00:27ff:fe7f:8415%enp0s8 | ffff:ffff:ffff:ffff:: | +-----------+---------------------------------+-----------------------+

Mode tampilan keluaran perintah Osquery

Mode tampilan keluaran perintah osquery dapat diubah dengan menjalankan perintah,.mode MODEdari dalamosqueryi shell prompt, di mana MODE bisa line, csv, pretty(standar), column,list.

Misalnya untuk mengatur tampilan ke mode garis;

osquery>.mode line

Saat Anda menjalankan kueri, output dihasilkan baris demi baris;

SELECT * FROM system_info;
 hostname = ubuntu20 uuid = 269c209d-fc67-ec4f-bf56-c759a8296e14 cpu_type = x86_64 cpu_subtype = 142 cpu_brand = Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz cpu_physical_cores = 1 cpu_logical_cores = 1 cpu_microcode = physical_memory = 2084356096 hardware_vendor = innotek GmbH hardware_model = VirtualBox hardware_version = 1.2 hardware_serial = 0 board_vendor = Oracle Corporation board_model = VirtualBox board_version = 1.2 board_serial = 0 computer_name = ubuntu20 local_hostname = ubuntu20

Daftar paket sistem yang diinstal;

select * from deb_packages top limit 3;
 name = accountsservice version = 0.6.55-0ubuntu12~20.04.4 source = size = 452 arch = amd64 revision = 0ubuntu12~20.04.4 status = install ok installed maintainer = Ubuntu Developers <[email protected]> section = admin priority = optional name = adduser version = 3.118ubuntu2 source = size = 624 arch = all revision = status = install ok installed maintainer = Ubuntu Core Developers <[email protected]> section = admin priority = important

Keluar dari shell Interaktif Osquery

Untuk keluar dari shell interaktif osqueri, osquery>, gunakan perintah.exitatau cukup tekanControl+d tombol kombinasi keyboard.

osquery>.exit

Menjalankan Osquery sebagai service

osquerydadalah daemon osquery untuk menjadwalkan kueri dan merekam perubahan status OS. Anda dapat menggunakan daemon ini untuk menjalankan service Osquery.

Agar ini berfungsi, Anda perlu menyalin contoh konfigurasi Osquery ke /etc/osquerydirektori sebagai berikut;

cp /usr/share/osquery/osquery.example.conf /etc/osquery/osquery.conf

Selanjutnya, bahwa service;

systemctl start osqueryd

Memeriksa statusnya;

systemctl status osqueryd
● osqueryd.service - osquery Daemon Loaded: loaded (/lib/systemd/system/osqueryd.service; disabled; vendor preset: enabled) Active: active (running) since Sun 2021-02-21 07:42:48 UTC; 18s ago Process: 66618 ExecStartPre=/bin/sh -c if [ ! -f $FLAG_FILE ]; then touch $FLAG_FILE; fi (code=exited, status=0/SUCCESS) Process: 66633 ExecStartPre=/bin/sh -c if [ -f $LOCAL_PIDFILE ]; then mv $LOCAL_PIDFILE $PIDFILE; fi (code=exited, status=0/SUCCESS) Main PID: 66634 (osqueryd) Tasks: 14 (limit: 2282) Memory: 7.6M CGroup: /system.slice/osqueryd.service ├─66634 /usr/bin/osqueryd --flagfile /etc/osquery/osquery.flags --config_path /etc/osquery/osquery.conf └─66637 /usr/bin/osqueryd Feb 21 07:42:48 ubuntu20 systemd[1]: Starting osquery Daemon... Feb 21 07:42:48 ubuntu20 systemd[1]: Started osquery Daemon. Feb 21 07:42:48 ubuntu20 osqueryd[66634]: osqueryd started [version=4.6.0]

Nah, itu dia tentang cara menginstal Osquery di Ubuntu 20.04. Anda dapat terus menjelajahi alat yang luar biasa ini.

Bacaan lebih lanjut

Dokumentasi Osquery

Tutorial lainnya

Instal dan Atur Armada Kolide di Ubuntu 18.04

Instal Kolide Fleet Osquery Fleet Manager di Debian 10

Instal Osquery di Debian 10 Buster