{"id":10041,"date":"2021-08-13T21:09:57","date_gmt":"2021-08-13T18:09:57","guid":{"rendered":"https:\/\/kifarunix.com\/?p=10041"},"modified":"2024-03-18T18:54:41","modified_gmt":"2024-03-18T15:54:41","slug":"install-osquery-on-rocky-linux-8","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-osquery-on-rocky-linux-8\/","title":{"rendered":"Install Osquery on Rocky Linux 8"},"content":{"rendered":"\n
In this guide, we are going to learn how to install osquery on Rocky Linux 8. Osquery<\/a> is an opensource tool that queries an operating system as if it were a relational database. It leverage SQL-like queries to gather Operating System information for performance, security, compliance audit analysis. It runs on multiple platforms such as Linux, FreeBSD, MacOS, Windows systems.<\/p>\n\n\n\n The default Rocky Linux repositories does not contain the osquery package.<\/p>\n\n\n\n However, osquery publishes the stable releases to YUM repository. <\/p>\n\n\n\n To add osquery YUM repository to Rocky Linux 8, run the command below;<\/p>\n\n\n\n This installs Osquery yum repository, and you can confirm by running the command below;<\/p>\n\n\n\n Sample output;<\/p>\n\n\n\n Once the repository is in place, you can then install Osquery by running the command below.<\/p>\n\n\n\n Osquery package installs three basic components;<\/p>\n\n\n\n In order to learn the usage of the commands above, you can pass the -h\/\u2013help option.<\/p>\n\n\n\n For example to start, stop and restart osqueryd using osqueryctl, run the commands;<\/p>\n\n\n\n Osquery can be run:<\/p>\n\n\n\n In this guide, we are going to focus on how to use the osquery interactive shell to query various system activities.<\/p>\n\n\n\n When You can obtain help by typing Osquery converts various OS attributes into tabular like database concepts. Hence, to list tables from which various system information is stored, run the Sample output;<\/p>\n\n\n\n For example purposes, let us see what is contained on some of the tables;<\/p>\n\n\n\n To query system users whose uid is greater than 1000,<\/p>\n\n\n\n To list all logged in users;<\/p>\n\n\n\n Check system uptime;<\/p>\n\n\n\n To show network interfaces and IP addresses;<\/p>\n\n\n\n See the Osquery tables columns on osquery Schemas page<\/a>.<\/p>\n\n\n\n The osquery command output view mode can be changed by running the command, For example to set the view to line mode;<\/p>\n\n\n\n The when you run the queries, output is produced line by line;<\/p>\n\n\n\n List installed system packages;<\/p>\n\n\n\n To exit osqueri interactive shell, osquery>, use the command For this to work, you need to copy the sample Osquery configuration to Next, that the service;<\/p>\n\n\n\n Checking the status;<\/p>\n\n\n\n Osquery Documentation<\/a><\/p>\n\n\n\n Install Redmine on Ubuntu 20.04<\/a><\/p>\n\n\n\n Install Redmine on Rocky Linux 8<\/a><\/p>\n\n\n\nInstalling Osquery on Rocky Linux 8<\/h2>\n\n\n\n
Install Osquery YUM Repository<\/h3>\n\n\n\n
curl -L https:\/\/pkg.osquery.io\/rpm\/GPG | sudo tee \/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-osquery<\/code><\/pre>\n\n\n\n
dnf config-manager --add-repo https:\/\/pkg.osquery.io\/rpm\/osquery-s3-rpm.repo<\/code><\/pre>\n\n\n\n
dnf repolist | grep osquery<\/code><\/pre>\n\n\n\n
osquery-s3-rpm-repo name=osquery RPM repository - x86_64<\/code><\/pre>\n\n\n\n
Install Osquery<\/h3>\n\n\n\n
dnf --enablerepo osquery-s3-rpm-repo install osquery -y<\/code><\/pre>\n\n\n\n
Components of osquery<\/h3>\n\n\n\n
\n
osqueryctl<\/code><\/strong> \u2013 This is an osquery helper script for testing osquery configuration\/deployment as well as managing the osqueryd service.<\/li>\n\n\n\n
osqueryd<\/strong><\/code> \u2013 is an osquery daemon for scheduling queries and recording the changes in the state of OS.<\/li>\n\n\n\n
osqueryi<\/code><\/strong> \u2013 is an osquery interactive shell. From the shell, you can run various queries to explore that state of your OS.<\/li>\n<\/ul>\n\n\n\n
osqueryctl -h<\/code><\/pre>\n\n\n\n
Usage: \/usr\/bin\/osqueryctl {clean|config-check|start|stop|status|restart}<\/code><\/pre>\n\n\n\n
osqueryctl start osqueryd<\/code><\/pre>\n\n\n\n
osqueryctl stop osqueryd<\/code><\/pre>\n\n\n\n
osqueryctl restart osqueryd<\/code><\/pre>\n\n\n\n
Running Osquery on Rocky Linux 8<\/h3>\n\n\n\n
\n
osqueryi<\/code><\/strong> or <\/li>\n\n\n\n
osqueryd<\/code><\/strong><\/li>\n<\/ul>\n\n\n\n
Running osquery in standalone mode<\/h3>\n\n\n\n
osqueryi<\/code><\/strong> is run without any arguments, it takes you to the interactive shell prompt;<\/p>\n\n\n\n
osqueryi<\/code><\/pre>\n\n\n\n
Using a virtual database. Need help, type '.help'
osquery><\/code><\/pre>\n\n\n\n.help<\/code><\/strong> on the shell prompt. Notice the dot (.)<\/strong>.<\/p>\n\n\n\n
osquery> .help<\/code><\/pre>\n\n\n\n
\nWelcome to the osquery shell. Please explore your OS!\nYou are connected to a transient 'in-memory' virtual database.\n\n.all [TABLE] Select all from a table\n.bail ON|OFF Stop after hitting an error\n.connect PATH Connect to an osquery extension socket\n.disconnect Disconnect from a connected extension socket\n.echo ON|OFF Turn command echo on or off\n.exit Exit this program\n.features List osquery's features and their statuses\n.headers ON|OFF Turn display of headers on or off\n.help Show this message\n.mode MODE Set output mode where MODE is one of:\n csv Comma-separated values\n column Left-aligned columns see .width\n line One value per line\n list Values delimited by .separator string\n pretty Pretty printed SQL results (default)\n.nullvalue STR Use STRING in place of NULL values\n.print STR... Print literal STRING\n.quit Exit this program\n.schema [TABLE] Show the CREATE statements\n.separator STR Change separator used by output mode\n.socket Show the local osquery extensions socket path\n.show Show the current values for various settings\n.summary Alias for the show meta command\n.tables [TABLE] List names of tables\n.types [SQL] Show result of getQueryColumns for the given query\n.width [NUM1]+ Set column widths for \"column\" mode\n.timer ON|OFF Turn the CPU timer measurement on or off\n<\/code><\/pre>\n\n\n\n
Listing Osquery system Information tables<\/h4>\n\n\n\n
.tables<\/strong><\/code> command within the osqueryi<\/strong> prompt.<\/p>\n\n\n\n
osqueryi<\/code><\/strong><\/code><\/pre>\n\n\n\n
osquery> .tables<\/code><\/pre>\n\n\n\n
\n=> acpi_tables\n=> apt_sources\n=> arp_cache\n=> augeas\n=> authorized_keys\n=> block_devices\n=> carbon_black_info\n=> carves\n=> chrome_extensions\n=> cpu_time\n\u2026\n=> time\n=> uptime\n=> usb_devices\n=> user_events\n=> user_groups\n=> user_ssh_keys\n=> users\n=> yara\n=> yara_events\n=> yum_sources\nosquery>\n<\/code><\/pre>\n\n\n\n
Querying Osquery system tables<\/h4>\n\n\n\n
select * from os_version;<\/code><\/pre>\n\n\n\n
\n+-------------+------------------------------------------+-------+-------+-------+-------+----------+---------------+----------+--------+\n| name | version | major | minor | patch | build | platform | platform_like | codename | arch |\n+-------------+------------------------------------------+-------+-------+-------+-------+----------+---------------+----------+--------+\n| Rocky Linux | Rocky Linux release 8.4 (Green Obsidian) | 8 | 4 | 0 | | rhel | rhel | | x86_64 |\n+-------------+------------------------------------------+-------+-------+-------+-------+----------+---------------+----------+--------+\n<\/code><\/pre>\n\n\n\n
select * from users where uid >=1000;<\/code><\/pre>\n\n\n\n
\n+-------+-------+------------+------------+-----------+----------------------+-----------------+---------------+------+\n| uid | gid | uid_signed | gid_signed | username | description | directory | shell | uuid |\n+-------+-------+------------+------------+-----------+----------------------+-----------------+---------------+------+\n| 65534 | 65534 | 65534 | 65534 | nobody | Kernel Overflow User | \/ | \/sbin\/nologin | |\n| 1000 | 1000 | 1000 | 1000 | kifarunix | | \/home\/kifarunix | \/bin\/bash | |\n+-------+-------+------------+------------+-----------+----------------------+-----------------+---------------+------+\n<\/code><\/pre>\n\n\n\n
select user,tty,host,time from logged_in_users where tty not like '~';<\/code><\/pre>\n\n\n\n
\n+-----------+-------+--------------+------------+\n| user | tty | host | time |\n+-----------+-------+--------------+------------+\n| kifarunix | tty1 | | 1628876993 |\n| root | pts\/0 | 192.168.60.1 | 1628875575 |\n+-----------+-------+--------------+------------+\n<\/code><\/pre>\n\n\n\n
select * from uptime;<\/code><\/pre>\n\n\n\n
\n+------+-------+---------+---------+---------------+\n| days | hours | minutes | seconds | total_seconds |\n+------+-------+---------+---------+---------------+\n| 0 | 4 | 21 | 49 | 4909 |\n+------+-------+---------+---------+---------------+\n<\/code><\/pre>\n\n\n\n
select interface,address,mask from interface_addresses where interface NOT LIKE '%lo%';<\/code><\/pre>\n\n\n\n
\n+-----------+----------------------------------+-----------------------+\n| interface | address | mask |\n+-----------+----------------------------------+-----------------------+\n| enp0s3 | 10.0.2.15 | 255.255.255.0 |\n| enp0s8 | 192.168.60.19 | 255.255.255.0 |\n| enp0s3 | fe80::689b:622:1eaf:287a%enp0s3 | ffff:ffff:ffff:ffff:: |\n| enp0s8 | fe80::301d:abeb:ad8b:6c56%enp0s8 | ffff:ffff:ffff:ffff:: |\n+-----------+----------------------------------+-----------------------+\n<\/code><\/pre>\n\n\n\n
Osquery command output view modes<\/h3>\n\n\n\n
.mode MODE<\/code> from within the
osqueryi<\/code><\/strong> shell prompt, where MODE can be
line<\/code><\/strong>,
csv<\/strong><\/code>,
pretty<\/strong><\/code> (default),
column<\/strong><\/code>,
list<\/code><\/strong>.<\/p>\n\n\n\n
osquery> .mode line<\/strong><\/code><\/pre>\n\n\n\n
SELECT * FROM system_info;<\/code><\/pre>\n\n\n\n
\n hostname = rocky8.kifarunix-demo.com\n uuid = 85dd4d36-5e88-864a-b6e8-1919f794534a\n cpu_type = x86_64\n cpu_subtype = 142\n cpu_brand = Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz\ncpu_physical_cores = 1\n cpu_logical_cores = 1\n cpu_microcode = \n physical_memory = 848629760\n hardware_vendor = innotek GmbH\n hardware_model = VirtualBox\n hardware_version = 1.2\n hardware_serial = 0\n board_vendor = Oracle Corporation\n board_model = VirtualBox\n board_version = 1.2\n board_serial = 0\n computer_name = rocky8.kifarunix-demo.com\n local_hostname = rocky8.kifarunix-demo.com\n<\/code><\/pre>\n\n\n\n
select * from rpm_packages top limit 3;<\/code><\/pre>\n\n\n\n
\n name = NetworkManager\n version = 1.30.0\n release = 10.el8_4\n source = NetworkManager-1.30.0-10.el8_4.src.rpm\n size = 7215759\n sha1 = f910dc05b56f78fcec2386ac164fcba0316299fa\n arch = x86_64\n epoch = 1\n install_time = 1628844768\n vendor = Rocky\npackage_group = System Environment\/Base\n\n name = NetworkManager-libnm\n version = 1.30.0\n release = 10.el8_4\n source = NetworkManager-1.30.0-10.el8_4.src.rpm\n size = 9262984\n sha1 = 25eb93263187481d1475d2dd5b25d8639808e04a\n arch = x86_64\n epoch = 1\n install_time = 1628844766\n vendor = Rocky\npackage_group = Development\/Libraries\n\n name = NetworkManager-team\n version = 1.30.0\n release = 10.el8_4\n source = NetworkManager-1.30.0-10.el8_4.src.rpm\n size = 49616\n sha1 = f8a8fbd59ba1a1901e27ab2833aa8705902965c6\n arch = x86_64\n epoch = 1\n install_time = 1628844958\n vendor = Rocky\npackage_group = System Environment\/Base\n<\/code><\/pre>\n\n\n\n
Exit Osquery Interactive shell<\/h4>\n\n\n\n
.exit<\/strong><\/code> or simply press
Control+d<\/code><\/strong> keyboard combination keys.<\/p>\n\n\n\n
osquery> .exit<\/strong><\/code><\/pre>\n\n\n\n
Running Osquery as a service<\/h3>\n\n\n\n
osqueryd<\/strong><\/code> is an osquery daemon for scheduling queries and recording the changes in the state of OS. You can use this daemon to run Osquery a service.<\/p>\n\n\n\n
\/etc\/osquery<\/strong><\/code> directory as follows;<\/p>\n\n\n\n
cp \/usr\/share\/osquery\/osquery.example.conf \/etc\/osquery\/osquery.conf<\/code><\/pre>\n\n\n\n
systemctl start osqueryd<\/code><\/pre>\n\n\n\n
systemctl status osqueryd<\/code><\/pre>\n\n\n\n
\n\u25cf osqueryd.service - The osquery Daemon\n Loaded: loaded (\/usr\/lib\/systemd\/system\/osqueryd.service; disabled; vendor preset: disabled)\n Active: active (running) since Fri 2021-08-13 21:03:04 EAT; 5s ago\n Process: 2244 ExecStartPre=\/bin\/sh -c if [ -f $LOCAL_PIDFILE ]; then mv $LOCAL_PIDFILE $PIDFILE; fi (code=exited, status=0\/SUCCESS)\n Process: 2241 ExecStartPre=\/bin\/sh -c if [ ! -f $FLAG_FILE ]; then touch $FLAG_FILE; fi (code=exited, status=0\/SUCCESS)\n Main PID: 2245 (osqueryd)\n Tasks: 14 (limit: 4938)\n Memory: 9.5M\n CGroup: \/system.slice\/osqueryd.service\n \u251c\u25002245 \/usr\/bin\/osqueryd --flagfile \/etc\/osquery\/osquery.flags --config_path \/etc\/osquery\/osquery.conf\n \u2514\u25002248 \/usr\/bin\/osqueryd\n\nAug 13 21:03:04 rocky8.kifarunix-demo.com systemd[1]: Starting The osquery Daemon...\nAug 13 21:03:04 rocky8.kifarunix-demo.com systemd[1]: Started The osquery Daemon.\nAug 13 21:03:04 rocky8.kifarunix-demo.com osqueryd[2245]: osqueryd started [version=4.9.0]\nAug 13 21:03:07 rocky8.kifarunix-demo.com osqueryd[2245]: I0813 21:03:07.644742 2248 eventfactory.cpp:156] Event\n<\/code><\/pre>\n\n\n\n
Further Reading<\/h3>\n\n\n\n
Other Tutorials<\/h3>\n\n\n\n