osquery ログインしているユーザーを抽出する

osquery ログインしているユーザーを抽出する

osqueryでログインしているユーザーを抽出するクエリを記述してます。

環境

  • OS AlmaLinux 8.3
  • osquery 4.8.0

ユーザーを抽出

ログインしているユーザーを抽出するには、

osqueryiを実行して

osqueryi

ログインユーザーを抽出するには、以下のクエリを実行します。

osquery> select * from logged_in_users;

<出力結果>
+-----------+----------+-------+------------------------------+------------+-------+
| type      | user     | tty   | host                         | time       | pid   |
+-----------+----------+-------+------------------------------+------------+-------+
| boot_time | reboot   | ~     | 4.18.0-240.22.1.el8_3.x86_64 | 1621578312 | 0     |
| runlevel  | runlevel | ~     | 4.18.0-240.22.1.el8_3.x86_64 | 1621578400 | 53    |
| user      | testuser | :1    | :1                           | 1621578667 | 2883  |
| dead      |          | pts/1 |                              | 1621647830 | 14396 |
| user      | testuser | pts/0 | 192.168.101.77               | 1621657774 | 16547 |
+-----------+----------+-------+------------------------------+------------+-------+

ログイン履歴は、以下で確認できます。

select * from last;

+----------+-------------+---------+------+------------+-----------------+
| username | tty         | pid     | type | time       | host            |
+----------+-------------+---------+------+------------+-----------------+
| testuser | :1          | 6133    | 7    | 1617857801 | :1              |
| testuser | pts/1       | 53598   | 7    | 1617860091 | xxx.xxx.xxx.xxx |
|          | pts/0       | 886377  | 8    | 1621496924 |                 |
| testuser | :1          | 2883    | 7    | 1621578667 | :1              |
| testuser | pts/1       | 14396   | 7    | 1621646822 | xxx.xxx.xxx.xxx |
|          | pts/1       | 14396   | 8    | 1621647830 |                 |
| testuser | pts/0       | 16547   | 7    | 1621657774 | xxx.xxx.xxx.xxx |
+----------+-------------+---------+------+------------+-----------------+