{"id":11385,"date":"2021-12-14T23:15:14","date_gmt":"2021-12-14T20:15:14","guid":{"rendered":"https:\/\/kifarunix.com\/?p=11385"},"modified":"2024-03-18T07:42:53","modified_gmt":"2024-03-18T04:42:53","slug":"monitor-windows-systems-using-elastic-osquery-manager","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/monitor-windows-systems-using-elastic-osquery-manager\/","title":{"rendered":"Monitor Windows Systems using Elastic Osquery Manager"},"content":{"rendered":"\n
In this tutorial, you will learn how to monitor Windows systems using Elastic Osquery manager. The recent versions of Elastic now supports integration with Osquery manager<\/a>.<\/p>\n\n\n\n With Osquery in Kibana, you can:<\/em><\/p>\n\n\n\n Note that we are using Windows 10<\/strong> in this setup.<\/p>\n\n\n\n We discussed how you can setup Elastic Fleet Manager in our previous tutorial on how to Ship System Logs to ELK Stack using Elastic Agents<\/a>.<\/p>\n\n\n\n Once you have setup Fleet Manager, integrate Osquery manager to Elastic stack.<\/p>\n\n\n\n Integrate Osquery Manager with ELK Stack<\/a><\/p>\n\n\n\n Ensure that the agent policy that you will enroll the Windows agent to DOES NOT have Fleet Manager Integration.<\/p>\n\n\n\n In our setup for example, we will enroll our agents to a Default Policy<\/strong> with System<\/strong> and Osquery manager<\/strong> integrations;<\/p>\n\n\n Depending on the current version of your Elastic stack, download the version of Elastic agent that matches your current version of Elastic stack to your Windows system<\/p>\n\n\n\n In this setup, for example, we are running Elastic Stack 7.17.0<\/a>. Hence, we have downloaded Elastic Agent 7.17.0 for our Windows system.<\/p>\n\n\n\n You can simply grab the download link and pull it using PowerShell.<\/p>\n\n\n\n Open and run PowerShell as administrator;<\/p>\n\n\n\n Extract the Archive<\/p>\n\n\n\n In order to collect data from your Windows hosts and sent it Elastic stack, you need to add the Windows host to the Fleet manager.<\/p>\n\n\n\n To<\/p>\n\n\n\n Be sure to set the proper Elasticsearch IP as well the credentials for a user with the proper permissions.<\/strong><\/p>\n\n\n\n Once the agent has been successfully enrolled, log in to Kibana and check agent status under Fleet agents.<\/p>\n\n\n\n The agent status could be Updating<\/strong> or if it has updated and started the communications with the Fleet server, then you should see status Healthy<\/strong>.<\/p>\n\n\n\n And there you go. You can click on the agent name to view the related logs;<\/p>\n\n\n\n You can also check the dashboards for various event activity under Data Streams<\/strong>.<\/p>\n\n\n\n Sample metrics dashboard.<\/p>\n\n\n\n Similarly, from Osquery integration, you should be able to run live queries against your Windows host agent.<\/p>\n\n\n\n Thus;<\/p>\n\n\n\n That marks the end of our tutorial.<\/p>\n\n\n\n Kibana Osquery<\/a><\/p>\n\n\n\n Configure Logstash Elasticsearch Basic Authentication<\/a><\/p>\n\n\n\n How to Enable Basic Authentication on ELK Stack<\/a><\/p>\n\n\n\n\n
Monitoring Windows Systems using Elastic Osquery Manager<\/h2>\n\n\n\n
Setup Fleet Manager on Elastic Stack<\/h3>\n\n\n\n
Integrate Osquery Manager with ELK Stack<\/h3>\n\n\n\n
<\/figure><\/div>\n\n\n
Download Elastic Agent Installer for Windows Systems<\/h3>\n\n\n\n
cd C:\\Users\\<username<\/strong>>\\Downloads<\/code><\/pre>\n\n\n\n
Invoke-WebRequest -Uri \"https:\/\/artifacts.elastic.co\/downloads\/beats\/elastic-agent\/elastic-agent-7.17.0-windows-x86_64.zip\" -OutFile elastic-agent-7.17.0-windows-x86_64.zip<\/code><\/pre>\n\n\n\n
Expand-Archive -Path .\\elastic-agent-7.17.0-windows-x86_64.zip -DestinationPath .<\/code><\/pre>\n\n\n\n
Add Windows Elastic Agent to Fleet Manager<\/h3>\n\n\n\n
\n
\n
<\/figure>\n\n\n\n
\n
\n
--insecure<\/code><\/strong> flag to the install\/enroll command.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n
.\\elastic-agent.exe install `\n--url=http:\/\/192.168.58.22:8220 `\n--enrollment-token=WXM4YnhuNEJ5Z29oREY1bTNidTY6UlJsNEk1WTNSeVdkRndtWlBnTk5kZw== `\n--insecure<\/code><\/pre>\n\n\n\n
<\/figure>\n\n\n\n
Install Elastic Agents in Windows system and Enroll it to Fleet Manager<\/h3>\n\n\n\n
\n
elastic-agent.exe<\/code><\/strong>.<\/li>\n<\/ul>\n\n\n\n
cd C:\\Users\\kifarunix\\Downloads\\elastic-agent-7.17.0-windows-x86_64\\elastic-agent-7.17.0-windows-x86_64<\/code><\/pre>\n\n\n\n
ls<\/code><\/pre>\n\n\n\n
Directory: C:\\Users\\kifarunix\\Downloads\\elastic-agent-7.17.0-windows-x86_64\\elastic-agent-7.17.0-windows-x86_64\n\nMode LastWriteTime Length Name\n---- ------------- ------ ----\nd----- 13\/12\/2021 7:04 PM data\n------ 13\/12\/2021 9:48 PM 41 .build_hash.txt\n------ 13\/12\/2021 9:48 PM 41 .elastic-agent.active.commit\n------ 13\/12\/2021 9:48 PM 45319640 elastic-agent.exe<\/strong>\n------ 13\/12\/2021 9:48 PM 9243 elastic-agent.reference.yml\n------ 13\/12\/2021 9:48 PM 9240 elastic-agent.yml\n------ 13\/12\/2021 9:48 PM 13675 LICENSE.txt\n------ 13\/12\/2021 9:48 PM 1964303 NOTICE.txt\n------ 13\/12\/2021 9:48 PM 863 README.md\n<\/code><\/pre>\n\n\n\n
\n
.\\elastic-agent.exe install `\n--url=https:\/\/192.168.58.22:8220 `\n--enrollment-token=WXM4YnhuNEJ5Z29oREY1bTNidTY6UlJsNEk1WTNSeVdkRndtWlBnTk5kZw== `\n--insecure\n<\/code><\/pre>\n\n\n\n
\n
Elastic Agent will be installed at C:\\Program Files\\Elastic\\Agent and will run as a service. Do you want to continue? [Y\n\/n]:y\n2021-12-13T20:05:25.219+0300 WARN [tls] tlscommon\/tls_config.go:98 SSL\/TLS verifications disabled.\n2021-12-13T20:05:25.653+0300 INFO cmd\/enroll_cmd.go:442 Starting enrollment to URL: https:\/\/192.168.58.22:8220\/\n2021-12-13T20:05:26.464+0300 WARN [tls] tlscommon\/tls_config.go:98 SSL\/TLS verifications disabled.\n2021-12-13T20:06:03.501+0300 INFO cmd\/enroll_cmd.go:250 Successfully triggered restart on running Elastic Agent.\nSuccessfully enrolled the Elastic Agent.\nElastic Agent has been successfully installed.\n<\/code><\/pre>\n\n\n\n
\n
C:\\Program Files\\Elastic\\Agent<\/code><\/strong>.<\/li>\n\n\n\n
Get-Service | Where Name -like *Elastic*<\/code><\/pre>\n\n\n\n
Status Name DisplayName\n------ ---- -----------\nRunning<\/strong> Elastic Agent Elastic Agent<\/code><\/pre>\n\n\n\n
\n
ls 'C:\\Program Files\\Elastic\\Agent\\data\\elastic-agent-93708b\\install\\*\\*beat.yml'<\/code><\/pre>\n\n\n\n
Directory: C:\\Program Files\\Elastic\\Agent\\data\\elastic-agent-93708b\\install\\filebeat-7.17.0-windows-x86_64\n\n\nMode LastWriteTime Length Name\n---- ------------- ------ ----\n-a---- 13\/12\/2021 12:13 AM 8273 filebeat.yml\n\n\n Directory: C:\\Program Files\\Elastic\\Agent\\data\\elastic-agent-93708b\\install\\metricbeat-7.17.0-windows-x86_64\n\n\nMode LastWriteTime Length Name\n---- ------------- ------ ----\n-a---- 13\/12\/2021 12:08 AM 6899 metricbeat.yml\n\n\n Directory: C:\\Program Files\\Elastic\\Agent\\data\\elastic-agent-93708b\\install\\osquerybeat-7.17.0-windows-x86_64\n\n\nMode LastWriteTime Length Name\n---- ------------- ------ ----\n-a---- 13\/12\/2021 12:11 AM 6504 osquerybeat.yml\n<\/code><\/pre>\n\n\n\n
\n
Stop-Service -Name 'Elastic Agent'<\/code><\/pre>\n\n\n\n
\n
filebeat.yml<\/code><\/strong>,
metricbeat.yml<\/code><\/strong> and
osquerybeat.yml<\/code><\/strong> and change these configs from;<\/li>\n<\/ul>\n\n\n\n
# ---------------------------- Elasticsearch Output ----------------------------\noutput.elasticsearch:\n # Array of hosts to connect to.\n hosts: [\"localhost:9200\"]<\/strong>\n\n # Protocol - either `http` (default) or `https`.\n #protocol: \"https\"\n\n # Authentication credentials - either API key or username\/password.\n #api_key: \"id:api_key\"\n #username: \"elastic\"\n #password: \"changeme\"<\/strong>\n<\/code><\/pre>\n\n\n\n
# ---------------------------- Elasticsearch Output ----------------------------\noutput.elasticsearch:\n # Array of hosts to connect to.\n hosts: [\"192.168.58.22:9200\"]\n\n # Protocol - either `http` (default) or `https`.\n #protocol: \"https\"\n\n # Authentication credentials - either API key or username\/password.\n #api_key: \"id:api_key\"\n username: \"elastic\"\n password: \"password\"\n<\/code><\/pre>\n\n\n\n
\n
Restart-Service -Name 'Elastic Agent'<\/code><\/pre>\n\n\n\n
Verifying Windows Agent Status on Fleet manager<\/h3>\n\n\n\n
<\/figure>\n<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
Querying Windows Agent using Osquery on ELK<\/h3>\n\n\n\n
\n
<\/figure><\/div>\n\n\n
\n
<\/figure><\/div>\n\n\n
\n
\nSELECT name AS name, version AS version, 'Program (Windows)' AS type, 'programs' AS source FROM programs UNION SELECT name AS name, version AS version, 'Package (Python)' AS type, 'python_packages' AS source FROM python_packages UNION SELECT name AS name, version AS version, 'Browser plugin (IE)' AS type, 'ie_extensions' AS source FROM ie_extensions UNION SELECT name AS name, version AS version, 'Browser plugin (Chrome)' AS type, 'chrome_extensions' AS source FROM chrome_extensions UNION SELECT name AS name, version AS version, 'Browser plugin (Firefox)' AS type, 'firefox_addons' AS source FROM firefox_addons UNION SELECT name AS name, version AS version, 'Package (Chocolatey)' AS type, 'chocolatey_packages' AS source FROM chocolatey_packages UNION SELECT name AS name, version AS version, 'Package (Atom)' AS type, 'atom_packages' AS source FROM atom_packages;\n<\/code><\/pre>\n\n\n\n
<\/figure>\n\n\n\n
\n
Reference<\/h3>\n\n\n\n
Other Tutorials<\/h3>\n\n\n\n