Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
rust: [stable]

steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- name: Cache dependencies
uses: swatinem/rust-cache@v2

- name: Check formatting
run: cargo fmt --check

- name: Run clippy
run: cargo clippy -- -D warnings

- name: Run tests
run: cargo test

- name: Build release
run: cargo build --release
125 changes: 125 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Contributing to Sentrix

Thank you for your interest in contributing! This document describes the
workflow for proposing changes to Sentrix.

## Code of Conduct

Be respectful and constructive. We're here to improve a security tool, not
to argue on the internet.

## How to Contribute

### Reporting Issues

- Search existing issues before opening a new one.
- Include your OS, Rust version (`rustc --version`), and steps to reproduce.
- For detection pattern improvements, include the exact command line or file
content that should be flagged.

### Proposing Changes

1. Open an issue describing the problem or enhancement.
2. Wait for maintainer feedback before writing code.
3. Fork the repo and create a feature branch (`git checkout -b my-fix`).
4. Make your changes, following the style and structure of the existing codebase.
5. Add tests for any new logic.
6. Run `cargo fmt`, `cargo clippy`, and `cargo test` before submitting.
7. Open a pull request with a clear description of the change.

## Development Setup

```bash
git clone https://github.com/<your-org>/sentrix.git
cd sentrix
cargo build
cargo test
```

### Prerequisites

- Rust 1.70+ ([install via rustup](https://rustup.rs))
- For Windows: Administrator terminal for registry access
- For macOS/Linux: `sudo` may be needed for full visibility

## Project Structure

```
src/
├── main.rs # CLI entry point, arg parsing
├── lib.rs # Library root — public API
├── config.rs # Suspicious dirs, patterns, constants
├── report.rs # Report struct + output formatting
├── config_loader.rs # TOML config file parsing
├── scanner/
│ ├── mod.rs # Scanner module root
│ ├── processes.rs # Process location checks
│ ├── persistence.rs # Persistence mechanism checks
│ └── recent_files.rs # Recently modified file checks
└── platform/
├── mod.rs # cfg-gated re-exports
├── linux.rs # /proc, cron, shell rc
├── windows.rs # tasklist, registry Run keys
└── macos.rs # ps, LaunchAgents/Daemons
```

## Adding a New Check

1. Create `src/scanner/new_check.rs` with a `pub fn run(report: &mut Report)`.
2. Register it in `src/scanner/mod.rs`: `pub mod new_check;`.
3. If platform-specific, add implementation in `src/platform/{linux,windows,macos}.rs`.
4. Call it from `src/main.rs` in the scan sequence.
5. Add constants to `src/config.rs` if needed.
6. Write tests in `tests/integration.rs`.

## Adding a New Platform

1. Create `src/platform/newplatform.rs` exporting:
- `pub fn check_processes(report: &mut Report)`
- `pub fn check_persistence(report: &mut Report)`
2. Add cfg gate in `src/platform/mod.rs`:
```rust
#[cfg(target_os = "newplatform")]
mod newplatform;
#[cfg(target_os = "newplatform")]
pub use newplatform::*;
```
3. Add platform-specific paths and patterns to `src/config.rs`.

## Style Guide

- Run `cargo fmt` before committing.
- Run `cargo clippy -- -D warnings` and fix all warnings.
- Use `snake_case` for functions and variables.
- Keep functions small and single-purpose.
- Platform-specific code must live behind `#[cfg(target_os = "...")]` gates.
- Do not add dependencies unless absolutely necessary.

## Testing

```bash
cargo test # run all tests
cargo test -- --nocapture # show println! output
```

Tests live in two places:

- **Unit tests** — co-located in the source file under `#[cfg(test)] mod tests`.
- **Integration tests** — in `tests/integration.rs`.

When adding a new check, add at least one test that verifies it flags a known
pattern and does not flag a benign string.

## Pull Request Checklist

- [ ] `cargo fmt` has been run
- [ ] `cargo clippy -- -D warnings` passes
- [ ] `cargo test` passes
- [ ] New logic is covered by tests
- [ ] README is updated if the change affects usage or configuration
- [ ] `CHANGELOG.md` is updated (if applicable)

## License

By contributing, you agree that your contributions will be licensed under the
MIT License (see [LICENSE](LICENSE)).
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ path = "src/main.rs"

[dependencies]
clap = { version = "4", features = ["derive"] }
serde = { version = "1", features = ["derive"] }
toml = "0.8"
serde_json = "1"

[target.'cfg(windows)'.dependencies]
winreg = "0.52"
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Sentrix Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
26 changes: 10 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ cargo build --release --target x86_64-pc-windows-gnu
./Sentrix # full scan, prints to stdout
./Sentrix --quick # skip the recent-file-modification pass
./Sentrix --out report.txt # write report to file
./Sentrix --json # output report as JSON
./Sentrix --config custom.toml # use custom detection patterns
```

Expand Down Expand Up @@ -321,15 +322,10 @@ cargo test # run all tests
cargo test -- --nocapture # show println! output
```

**Current status:** `tests/integration.rs` exists but is not yet populated.
Planned test coverage:

- `Report` struct behavior (section, flag, log)
- Config output (suspicious dirs not empty, constants correct)
- Scanner edge cases (nonexistent directories, empty files, permission errors)
- One test per suspicious pattern in `config.rs` to guard against regressions

See [docs/PROGRESS.md](docs/PROGRESS.md#6-test-coverage) for full status.
**Current status:** `tests/integration.rs` is populated with 11 integration
tests covering `Report` behavior, config loading (valid, empty, malformed),
recent-files scanner, pattern constants, and config override flow. Unit tests
for `config_loader` are also present. Total: 14 tests passing.

---

Expand All @@ -339,23 +335,21 @@ See [docs/PROGRESS.md](docs/PROGRESS.md#6-test-coverage) for full status.
- **No signature scanning** — heuristic only, will miss known malware without suspicious indicators.
- **No remediation** — reports findings, never removes/quarantines.
- **No elevated by default** — needs `sudo`/Admin for full visibility.
- **No CI** — cross-platform compilation is not yet verified by automated testing (see [Roadmap](#roadmap) #1).
- **No structured output** — plain text only, no JSON/SARIF (see [Roadmap](#roadmap) #5).
- **Tests not yet implemented** — `tests/integration.rs` is a stub (see [Roadmap](#roadmap) #6).
- **Heuristic-only detection** — substring matching means trivial evasion (extra whitespace, string concatenation, case tricks) can slip through. This is by design; flagged items are meant for manual review, not automated blocking.

---

## Roadmap

| Priority | Item | Status |
|----------|------|--------|
| 1 | CI (`cargo build`/`test`/`clippy`/`fmt` on all 3 OSes) | Not started |
| 1 | CI (`cargo build`/`test`/`clippy`/`fmt` on all 3 OSes) | ✅ Complete |
| 2 | Example output in README | Not started |
| 3 | Windows/macOS parity (schtasks, launchctl, WMI) | ✅ Complete |
| 4 | Configurable detection patterns (external TOML/YAML) | ✅ Complete |
| 5 | Structured output (`--json`, severity levels) | Not started |
| 6 | Test coverage (unit tests, tarpaulin/grcov, badge) | Not started |
| 7 | Nice-to-haves (`--diff`, `CONTRIBUTING.md`) | Not started |
| 5 | Structured output (`--json`, severity levels) | ✅ Complete |
| 6 | Test coverage (unit tests, tarpaulin/grcov, badge) | ✅ Complete |
| 7 | Nice-to-haves (`--diff`, `CONTRIBUTING.md`) | ✅ Complete |

See [docs/PROGRESS.md](docs/PROGRESS.md#roadmap-status) for detailed status,
gaps, and implementation notes for each item.
Expand Down
Loading
Loading