OSQuery は、https://osquery.io/downloads/ よりダウンロードします。
Ubuntu であれば、Debian 用のパッケージをクリックします。その後プログラムを開く(ソフトウェアのインストール)」もしくは「ファイルを保存」するのダイアログが表示されるので「プログラムを開く」を選択してインストールします。
デフォルトの設定ファイルをコピーします。
$ sudo cp /usr/share/osquery/osquery.example.conf /etc/osquery/osquery.conf
OSQuery を起動します。
$ sudo systemctl start osqueryd.service
再起動後もデフォルトで OSQuery を起動する場合。
$ sudo systemctl enable osqueryd.service
OSQuery は、FaceBook がオープンソースとして公開したLinux、Windows、macOS、およびFreeBSDのローレベルなオペレーティングシステムのモニタリングツールです。手動でOS全体の各種ステータスを取得するにはOSに関する知識全般が必要ですが、OSQuery はOSに関する各種情報をSQLライクなクエリを発行し、問い合わせして取得するのが特徴です。
インストール後、osqueryi と実行するとSQLライクなモードになります。.help と実行するとヘルプ画面が表示されます。.tables と実行するとテーブルの一覧が表示されるので取得したい情報のテーブルをパラメータにSQLクエリを発行します。
詳細は、OSQuery のドキュメントを参照して下さい。
https://osquery.readthedocs.io/en/stable/
$ osqueryi
osquery> .help
:
.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
:
osquery> .tables
OS のバージョン情報
osquery> select * from os_version;
+--------+---------------------------+-------+-------+-------+-------+----------+---------------+----------+
| name | version | major | minor | patch | build | platform | platform_like | codename |
+--------+---------------------------+-------+-------+-------+-------+----------+---------------+----------+
| Ubuntu | 18.10 (Cosmic Cuttlefish) | 18 | 10 | 0 | | ubuntu | debian | cosmic |
+--------+---------------------------+-------+-------+-------+-------+----------+---------------+----------+
ログイン中のユーザ一覧
osquery> select * from logged_in_users;
+-----------+----------+-------+-------------------+------------+------+
| type | user | tty | host | time | pid |
+-----------+----------+-------+-------------------+------------+------+
| boot_time | reboot | ~ | 4.18.0-16-generic | 1552093203 | 0 |
| runlevel | runlevel | ~ | 4.18.0-16-generic | 1552093267 | 53 |
| user | taro | :0 | :0 | 1552093438 | 3471 |
| user | taro | pts/1 | 192.168.2.107 | 1552093656 | 4656 |
+-----------+----------+-------+-------------------+------------+------+
ユーザのログイン履歴
osquery> select * from last;
+----------+-------+------+------+------------+-------------------+
| username | tty | pid | type | time | host |
+----------+-------+------+------+------------+-------------------+
| reboot | ~ | 0 | 2 | 1550876026 | 4.18.0-10-generic |
| taro | :0 | 2872 | 7 | 1550876090 | :0 |
| runlevel | ~ | 53 | 1 | 1550876113 | 4.18.0-10-generic |
+----------+-------+------+------+------------+-------------------+