Cara Menginstal Osquery di Ubuntu 18.04

Dalam panduan ini, kita akan belajar cara menginstal osquery di Ubuntu 18.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 18.04

Repositori Ubuntu default tidak berisi paket osquery. Namun, osquery menerbitkan repositori yang tepat untuk setiap rilis stabil. Untuk menambahkan repositori osquery apt ke Ubuntu 18.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.

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 -h/–helpopsi.

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

Osquery dapat dijalankan dalam mode mandiri menggunakan osqueryiatau 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

Saat osqueryidijalankan tanpa argumen apa pun, Anda akan dibawa ke prompt shell interaktif;

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

Anda dapat memperoleh bantuan dengan mengetik.helppada 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... osquery>

Berbagai atribut OS telah diubah menjadi tabel seperti konsep database. Oleh karena itu, untuk membuat daftar tabel tempat berbagai informasi sistem disimpan, jalankan.tablesperintah.

osquery>.tables
 => 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;

osquery> select * from os_version; +--------+-----------------------------+-------+-------+-------+-------+----------+---------------+----------+ | name | version | major | minor | patch | build | platform | platform_like | codename | +--------+-----------------------------+-------+-------+-------+-------+----------+---------------+----------+ | Ubuntu | 18.04.1 LTS (Bionic Beaver) | 18 | 4 | 0 | | ubuntu | debian | bionic | +--------+-----------------------------+-------+-------+-------+-------+----------+---------------+----------+ osquery>

Untuk menanyakan user non sistem,

osquery> 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 | amos | amos,,, | /home/amos | /bin/bash | | +-------+-------+------------+------------+----------+-------------+--------------+-------------------+------+ osquery>

Untuk memeriksa user yang masuk;

osquery> select user,host,time from logged_in_users where tty not like '~'; +-------+----------------+------------+ | user | host | time | +-------+----------------+------------+ | root | 192.168.43.149 | 1547894367 | | amos | 192.168.43.149 | 1547902074 | +-------+----------------+------------+ osquery>

Periksa waktu aktif sistem;

osquery> select * from uptime; +------+-------+---------+---------+---------------+ | days | hours | minutes | seconds | total_seconds | +------+-------+---------+---------+---------------+ | 0 | 4 | 35 | 32 | 16532 | +------+-------+---------+---------+---------------+ osquery>

Untuk menunjukkan interface jaringan dan alamat IP;

osquery> select interface,address,mask from interface_addresses where interface NOT LIKE '%lo%';
+-----------+----------------------------------+-----------------------+ | interface | address | mask | +-----------+----------------------------------+-----------------------+ | enp0s3 | 10.0.2.15 | 255.255.255.0 | | enp0s8 | 192.168.56.160 | 255.255.255.0 | | enp0s3 | fe80::3760:84e7:7371:50a1%enp0s3 | ffff:ffff:ffff:ffff:: | | enp0s8 | fe80::ccd8:e5fe:851:c19c%enp0s8 | ffff:ffff:ffff:ffff:: | +-----------+----------------------------------+-----------------------+

Mode tampilan dapat diubah dengan menjalankan perintah, di.mode MODEmana MODE dapat berupa baris, csv, cantik (default), kolom, daftar. Misalnya untuk mengatur tampilan ke mode garis;

osquery>.mode line
osquery> SELECT * FROM system_info; hostname = u18svr.example.com uuid = 9F23F1AC-B198-4EB6-8363-1ED87FB8B43E cpu_type = 6 cpu_subtype = 69 cpu_brand = Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz cpu_physical_cores = 1 cpu_logical_cores = 1 cpu_microcode = physical_memory = 2090295296 hardware_vendor = innotek GmbH hardware_model = VirtualBox hardware_version = 1.2 hardware_serial = 0 computer_name = u18svr local_hostname = u18svr.example.com

Daftar paket instal;

osquery> select * from deb_packages top limit 3; name = accountsservice version = 0.6.45-1ubuntu1 source = size = 440 arch = amd64 revision = 1ubuntu1 name = adduser version = 3.116ubuntu1 source = size = 624 arch = all revision = name = amd64-microcode version = 3.20180524.1~ubuntu0.18.04.2 source = size = 75 arch = amd64 revision = osquery>

Indah, bukan?. Jangan ragu untuk menjelajahi semua tabel lainnya.

Itu menandai akhir dari panduan kami tentang cara menginstal OSquery di Ubuntu 18.04. Selain instalasi, kami juga telah mempelajari cara kerja osquery dalam mode interaktif.

Anda dapat membaca lebih lanjut tentang osquery di sini.

Tutorial Terkait

Instal dan Atur Armada Kolide di Ubuntu 18.04

Instal Kolide Fleet Osquery Fleet Manager di Debian 10

Instal Osquery di Debian 10 Buster