| Crates.io | osquery-rust-ng |
| lib.rs | osquery-rust-ng |
| version | 1.0.0 |
| created_at | 2025-07-01 23:33:17.926379+00 |
| updated_at | 2025-07-01 23:33:17.926379+00 |
| description | Rust bindings for Osquery |
| homepage | https://github.com/withzombies |
| repository | https://github.com/withzombies/osquery-rust |
| max_upload_size | |
| id | 1734219 |
| size | 158,679 |
By providing Rust bindings for Osquery this crate facilitates the implementation of Osquery extensions.
Clone the repository and build the workspace:
git clone https://github.com/withzombies/osquery-rust.git
cd osquery-rust
cargo build --workspace
Run tests:
cargo test --workspace
The project uses a workspace structure with the main library and several examples. All examples are built automatically when you build the workspace.
Here's a simple example of creating a table plugin that reports system uptime:
use osquery_rust_ng::prelude::*;
#[derive(Default)]
struct UptimeTable;
impl ReadOnlyTable for UptimeTable {
fn name(&self) -> &str {
"uptime"
}
fn columns(&self) -> Vec<ColumnDef> {
vec![
ColumnDef::new("days", ColumnType::Integer),
ColumnDef::new("hours", ColumnType::Integer),
ColumnDef::new("minutes", ColumnType::Integer),
ColumnDef::new("seconds", ColumnType::Integer),
]
}
fn generate(&self, _constraints: &QueryConstraints) -> Result<Vec<Row>, String> {
let uptime_seconds = std::fs::read_to_string("/proc/uptime")
.map_err(|e| e.to_string())?
.split_whitespace()
.next()
.ok_or("Failed to parse uptime")?
.parse::<f64>()
.map_err(|e| e.to_string())? as u64;
let days = uptime_seconds / 86400;
let hours = (uptime_seconds % 86400) / 3600;
let minutes = (uptime_seconds % 3600) / 60;
let seconds = uptime_seconds % 60;
Ok(vec![Row::from_iter([
("days", days.to_string()),
("hours", hours.to_string()),
("minutes", minutes.to_string()),
("seconds", seconds.to_string()),
])])
}
}
fn main() {
let mut server = Server::new(None, "/path/to/osquery/socket").unwrap();
server.register_plugin(Plugin::table(UptimeTable::default()));
server.run().unwrap();
}
Table plugins allow you to expose data as SQL tables in osquery. There are two types:
ReadOnlyTable traitTable trait for full CRUD operationsSee the examples directory for complete implementations.
Logger plugins receive log data from osquery and can forward it to various backends:
use osquery_rust_ng::plugin::{LoggerPlugin, LogStatus};
struct MyLogger;
impl LoggerPlugin for MyLogger {
fn name(&self) -> String {
"my_logger".to_string()
}
fn log_string(&self, message: &str) -> Result<(), String> {
println!("Log: {}", message);
Ok(())
}
fn log_status(&self, status: &LogStatus) -> Result<(), String> {
println!("[{}] {}:{} - {}",
status.severity, status.filename, status.line, status.message);
Ok(())
}
}
There are three ways to run your extension:
osqueryi --extension /path/to/extension--socket /path/to/osquery.sockSee the examples README for detailed integration instructions.
The repository includes several complete examples:
/proc/meminfo as a queryable tableEach example includes its own README with specific build and usage instructions.
We welcome contributions! Here's how to get started:
cp .hooks/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
This project maintains high code quality standards:
cargo fmtThe pre-commit hook automatically runs these checks.
Run the full test suite:
cargo test --workspace
mainPlease report issues on GitHub with:
The project is organized as a Cargo workspace:
table-proc-meminfo/ - Read-only table examplewriteable-table/ - Full CRUD table exampletwo-tables/ - Multiple tables in one extensionlogger-file/ - File logger pluginlogger-syslog/ - Syslog logger pluginconfig-file/ - An example that loads a config from a json fileconfig-static/ - An example that provides a static configThis project contributed the support for Unix Domain Sockets to Apache Thrift's Rust crate.