BLOG POSTS
    MangoHost Blog / Audit Endpoints Using osquery: SQL-Powered Host Visibility in 2025
Audit Endpoints Using osquery: SQL-Powered Host Visibility in 2025

Audit Endpoints Using osquery: SQL-Powered Host Visibility in 2025

What Is This About?

Let’s talk about auditing endpoints in 2025 using the wild power of osquery. If you’re spinning up new servers, whether that’s a one-off VPS, Docker swarm, or a beefy dedicated box, you need to know what’s happening on your machines (and not just when you get that “disk full” Slack alert at 2am). osquery is the open-source tool that makes your infrastructure queryable like a database. Imagine poking around your fleet with SQL, asking questions like “Who just plugged in a USB?” or “Which process is eating all my RAM?” in seconds.

This article is your informal (but packed) guide to getting osquery set up fast, understanding what it does, and seeing if it’s the right fit for your setup. We’ll hit quick wins, real-life problems, setup guides, use cases, mistakes, myths, and a sprinkle of admin storytelling.

The Dramatic Reality Check

Picture this: You’re sipping your third coffee, debugging an odd spike in network traffic on your production server. Suddenly, you discover a process called /tmp/.x/hackme running as root. You freeze. Who started it? When? What other files have changed? Are you in the middle of a breach… or just a bad admin script gone wild?

This isn’t sci-fi. In 2025, endpoint attacks and insider threats are still a thing—maybe even more so. Cloud, VPS, containers, bare metal: attackers don’t care what you run, only if you’re watching. Traditional monitoring tools might miss the details. Enter osquery: your endpoint detective, powered by SQL.

Why Should You Care?

  • Instant Insight: Query your systems with SQL. No more clicking around dashboards or running 10 different shell commands.
  • Lightweight, Open, Free: Open-source, cross-platform, minimal overhead, and runs almost everywhere (Linux, macOS, Windows).
  • Perfect for DevOps, Sysadmins, and SREs: If you’re responsible for infrastructure—or even just a few critical servers—osquery gives you superpowers for auditing and compliance.
  • Automate and Alert: Integrate with your favorite SIEM, alerting, or log pipeline. Think: automate away your worries.

osquery 101: How Does It Work?

osquery turns your endpoint into a database you can query. Yep—run SQL directly against system state. Under the hood, it exposes virtual tables that map to everything from processes, users, and sockets to kernel modules, Docker containers, USB devices, and more.

  • Structure: osqueryd (daemon) runs in the background, collecting system info and responding to queries.
  • osqueryi: Interactive shell for poking around manually (great for debugging or one-off checks).
  • Configurable: Schedule queries, set up event-based monitoring, log to file or send to remote.

How osquery Talks SQL to Your Machine

  • Each “table” is a system data source: e.g., processes, users, listening_ports, docker_containers.
  • You run queries like:
    SELECT name, pid FROM processes WHERE name LIKE 'nginx%';
  • It’s fast: it uses optimized plugins and system APIs, not just parsing random files.

Pro tip: osquery can also watch for events (like file changes or new network listeners) with minimal overhead.

Use Case Tree & Benefits

  • Security Auditing: Find rogue processes, unknown users, suspicious changes in cron jobs.
  • Compliance: Prove you’re following CIS Benchmarks, PCI DSS, or SOC2 by showing evidence of proper config/state.
  • Incident Response: When stuff hits the fan, instantly check what changed, who logged in, or which binaries appeared.
  • Asset Inventory: Know exactly what’s running—down to the Docker containers or kernel modules level.
  • Performance Monitoring: Not a full APM, but handy for spot-checking process resource usage, open sockets, or disk space.
  • Automation: Combine with scripting to auto-remediate or alert (e.g., if SSH config changes, ping your Slack).

Bonus: Works across Linux, macOS, Windows, Docker containers (with caveats), and even cloud VMs.

Quickstart Guide: Step-By-Step Setup

Let’s get you running with osquery in 10 minutes (seriously). Pick your flavor: VPS, dedicated, Docker, or even your laptop. Need a playground? Order a VPS or dedicated server to try this out.

1. Install osquery

  • Debian/Ubuntu:
    sudo apt update
    sudo apt install osquery
        
  • CentOS/RHEL:
    sudo yum install osquery
        
  • macOS (with Homebrew):
    brew install osquery
        
  • Docker:
    docker run --rm -it --privileged \
      --name osquery \
      --volume /:/host:ro \
      --workdir /host \
      osquery/osquery:latest \
      osqueryi --nodisable_events
        

2. Poke Around (Interactive Mode)

sudo osqueryi

Try a few queries:

SELECT * FROM users;
SELECT name, pid FROM processes WHERE name LIKE '%sshd%';
SELECT * FROM listening_ports WHERE port > 1024;

3. Schedule Automated Queries (osqueryd)

Edit /etc/osquery/osquery.conf (or wherever your config lives). Example:

{
  "schedule": {
    "processes": {
      "query": "SELECT pid, name, path FROM processes WHERE name LIKE '%nginx%';",
      "interval": 60
    }
  }
}

Then run:

sudo systemctl start osqueryd
sudo systemctl enable osqueryd

4. Collect Logs

By default, logs land in /var/log/osquery/osqueryd.results.log. Pipe them to your SIEM, ELK, or favorite log shipper.

5. Try Event-Based Monitoring

Want to catch file changes? Enable the file_events table for select directories.

{
  "file_paths": {
    "config": [ "/etc/%%" ],
    "www": [ "/var/www/%%" ]
  },
  "schedule": {
    "file_events": {
      "query": "SELECT * FROM file_events WHERE action = 'UPDATED';",
      "interval": 60
    }
  }
}

Mini Glossary: Real-Talk Definitions

  • osqueryi: The cool SQL shell for your machine.
  • osqueryd: The background service that collects and logs stuff.
  • Virtual Table: Pretend-database-table, actually system info.
  • Event Table: Stuff that changes (e.g., file edits, logins, process starts).
  • Schedule: “Run this query every X seconds/minutes.”
  • Config: The JSON file that tells osquery what to do.

Showdown: Comic Comparison Table

  • osquery: “Ask me anything, but speak SQL. I’ll answer in milliseconds.”
  • Auditd: “I’m the grumpy old guard. Super detailed, but my config is arcane runes.”
  • Sysdig: “I see everything, but I’m hungrier for CPU. Also, install my kernel modules!”
  • ps/top/netstat: “Old school, one command at a time. Not automated, but I’m always there for you.”
  • ELK Stack: “Bring me all your logs! But first, mortgage your RAM.”

Winner for quick, SQL-powerful endpoint auditing? osquery, hands down—unless you need forensic-level logging (then: pair with auditd).

Beginner Mistakes, Myths & Other Tools

  • Mistake: Not scheduling queries. osquery won’t log anything unless you tell it what to watch!
  • Myth: “osquery slows down my server.” Not unless you schedule a bazillion queries at 1-second intervals. Be reasonable.
  • Mistake: Not checking logs. It’s easy to forget they’re sitting in /var/log/osquery.
  • Other tools: auditd, Falco, Sysdig, Auditbeat. Each has its quirks and strengths.

Should I Use This? Decision Tree

🤔 Are you running Linux/Windows/macOS?
        |
        ├── No → Sorry, osquery isn’t for routers or switches.
        |
        └── Yes
             |
             🤔 Want to ask “what’s running/changed” with SQL?
                |
                ├── No → Try classic tools (ps, netstat, auditd).
                |
                └── Yes
                    |
                    🤔 Need deep kernel forensics, or just quick audits?
                        |
                        ├── Deep Forensics → Pair with auditd/Falco.
                        |
                        └── Quick/Audit/Inventory → Go osquery!

Need a testbed? Order a VPS or dedicated server and try osquery in minutes.

Automation & Scripting Magic

osquery + Bash + Slack = Instant Alerts

#!/bin/bash
if osqueryi --json "SELECT * FROM processes WHERE name='malware'"; then
  curl -X POST -H 'Content-type: application/json' \
       --data '{"text":"🚨 Malware process spotted!"}' \
       https://hooks.slack.com/services/XXXX/YYY/ZZZ
fi

Want to go wild? Integrate osquery with your log pipeline, or trigger auto-remediation scripts when critical files change.

Mini Admin Story

Last year, an admin spun up a new production VM. Weeks later, a cron job started mining crypto. With osquery, a quick SELECT * FROM crontab WHERE command LIKE '%miner%'; caught the rogue job instantly. The admin nuked the process, patched the AMI, and started scheduling regular osquery audits. No more surprises.

The Wrap-Up & Recommendations

  • osquery is your endpoint sidekick—not a silver bullet, but a massive force multiplier for visibility, auditing, and automation.
  • It shines if you know (or want to learn) some basic SQL, and want a unified tool for inventory, auditing, or quick incident response.
  • Set up scheduled queries and log shipping for best results.
  • For compliance, osquery makes it easy to show “proof” of secure configs.
  • Runs great on VPS, dedicated servers, or even inside containers (with proper mounts).

Whether you’re a solo coder, DevOps pro, or managing a fleet—osquery is a geeky, powerful, open-source way to turn your servers into living, queryable databases. Try it, script it, and level up your host visibility in 2025!



This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.

This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.

Leave a reply

Your email address will not be published. Required fields are marked