Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
757fd3125d |
Generated
-1
@@ -710,7 +710,6 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -36,6 +36,7 @@ members = [
|
||||
"crates/aw-rus-healthd",
|
||||
"crates/detmir-check",
|
||||
"crates/detmir-core",
|
||||
"crates/security-finding-inbox",
|
||||
"crates/dlp-health-check",
|
||||
"crates/dlp-content-analyzer",
|
||||
"crates/dlp-admin-cli",
|
||||
@@ -57,6 +58,7 @@ members = [
|
||||
"crates/detmir-heal-safe",
|
||||
"crates/detmir-status",
|
||||
"crates/detmir-state",
|
||||
"crates/containment-engine",
|
||||
"crates/tsj-guardian-status",
|
||||
"crates/tsj-guardian-watchdog",
|
||||
]
|
||||
|
||||
@@ -176,6 +176,10 @@ fn run() -> Result<i32> {
|
||||
&root.join("detections/open_cases_from_detections.sql"),
|
||||
&mut summary,
|
||||
)?;
|
||||
let security_inbox_schema = root.join("security/security_finding_inbox.sql");
|
||||
if security_inbox_schema.exists() {
|
||||
run_sql_file(&client, &security_inbox_schema, &mut summary)?;
|
||||
}
|
||||
if !cli.skip_briefs {
|
||||
let _ = run_optional_script(&root.join("ops/run_manager_brief.sh"));
|
||||
let _ = run_optional_script(&root.join("ops/run_recovery_brief.sh"));
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "containment-engine"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
publish.workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
chrono.workspace = true
|
||||
clap.workspace = true
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
sha2.workspace = true
|
||||
File diff suppressed because it is too large
Load Diff
@@ -32,6 +32,8 @@ reqwest.workspace = true
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
urlencoding.workspace = true
|
||||
sha2.workspace = true
|
||||
zip = { version = "2", default-features = false, features = ["deflate"] }
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile.workspace = true
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
use std::fs::{self, File};
|
||||
use std::io::{self, Read};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
use chrono::Utc;
|
||||
use clap::Parser;
|
||||
use fs2::FileExt;
|
||||
use hayabusa_tools::{guess_host_from_filename, read_json_file};
|
||||
use hayabusa_tools::{env_bool, env_string, guess_host_from_filename, read_json_file};
|
||||
use serde_json::{Value, json};
|
||||
use sha2::{Digest, Sha256};
|
||||
use zip::ZipArchive;
|
||||
|
||||
const LOCK_PATH: &str = "/opt/hayabusa/state/aw-hayabusa-autoprocess.lock";
|
||||
const WRAPPER: &str = "/usr/local/bin/aw-hayabusa";
|
||||
const LINKER: &str = "/usr/local/bin/aw-hayabusa-link-case";
|
||||
const CASE_ALERT: &str = "/usr/local/bin/aw-hayabusa-case-alert";
|
||||
const SECURITY_FINDING_INBOX: &str = "/usr/local/bin/security-finding-inbox";
|
||||
const LATEST_INTAKE: &str = "/opt/hayabusa/state/latest-intake.json";
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
@@ -20,6 +25,9 @@ struct Cli {
|
||||
#[arg(long, default_value = "/opt/activitywatch/aw-rus-ops/drop")]
|
||||
drop_dir: PathBuf,
|
||||
|
||||
#[arg(long, default_value = "/opt/hayabusa/quarantine/drop")]
|
||||
quarantine_dir: PathBuf,
|
||||
|
||||
#[arg(long, default_value_t = true)]
|
||||
once: bool,
|
||||
}
|
||||
@@ -65,16 +73,43 @@ fn run() -> Result<i32> {
|
||||
println!("no zip packages in drop dir");
|
||||
return Ok(0);
|
||||
}
|
||||
let mut operational_failures = 0usize;
|
||||
for zip_path in zips {
|
||||
let result = process_one(&zip_path)?;
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&json!({
|
||||
"processed": zip_path.display().to_string(),
|
||||
"latest_intake": result.latest_intake,
|
||||
"case_alert": result.case_alert,
|
||||
}))?
|
||||
);
|
||||
if let Err(err) = validate_drop_inputs(&zip_path) {
|
||||
let quarantine_dir = quarantine_drop_package(&cli.quarantine_dir, &zip_path, &err)?;
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&json!({
|
||||
"quarantined": zip_path.display().to_string(),
|
||||
"quarantine_dir": quarantine_dir.display().to_string(),
|
||||
"reason": err.to_string(),
|
||||
}))?
|
||||
);
|
||||
continue;
|
||||
}
|
||||
match process_one(&zip_path) {
|
||||
Ok(result) => {
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&json!({
|
||||
"processed": zip_path.display().to_string(),
|
||||
"latest_intake": result.latest_intake,
|
||||
"case_alert": result.case_alert,
|
||||
"security_finding_ingest": result.security_finding_ingest,
|
||||
}))?
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
operational_failures += 1;
|
||||
eprintln!(
|
||||
"ERROR: operational failure while processing {}: {err:#}",
|
||||
zip_path.display()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if operational_failures > 0 {
|
||||
bail!("{operational_failures} operational Hayabusa package failure(s)");
|
||||
}
|
||||
Ok(0)
|
||||
}
|
||||
@@ -82,6 +117,7 @@ fn run() -> Result<i32> {
|
||||
struct ProcessResult {
|
||||
latest_intake: Value,
|
||||
case_alert: Option<Value>,
|
||||
security_finding_ingest: Option<Value>,
|
||||
}
|
||||
|
||||
fn list_zips(drop_dir: &Path) -> Result<Vec<PathBuf>> {
|
||||
@@ -96,6 +132,42 @@ fn list_zips(drop_dir: &Path) -> Result<Vec<PathBuf>> {
|
||||
Ok(zips)
|
||||
}
|
||||
|
||||
fn validate_drop_inputs(zip_path: &Path) -> Result<()> {
|
||||
validate_zip_package(zip_path)?;
|
||||
load_sidecars(zip_path)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_zip_package(zip_path: &Path) -> Result<()> {
|
||||
let file = File::open(zip_path).with_context(|| format!("open {}", zip_path.display()))?;
|
||||
let mut archive =
|
||||
ZipArchive::new(file).with_context(|| format!("read zip {}", zip_path.display()))?;
|
||||
if archive.is_empty() {
|
||||
bail!("zip package has no entries: {}", zip_path.display());
|
||||
}
|
||||
for index in 0..archive.len() {
|
||||
let mut entry = archive
|
||||
.by_index(index)
|
||||
.with_context(|| format!("read zip entry {index} from {}", zip_path.display()))?;
|
||||
let name = entry.name().replace('\\', "/");
|
||||
if name.starts_with('/') || name.split('/').any(|part| part == "..") {
|
||||
bail!(
|
||||
"unsafe zip entry in {}: {}",
|
||||
zip_path.display(),
|
||||
entry.name()
|
||||
);
|
||||
}
|
||||
io::copy(&mut entry, &mut io::sink()).with_context(|| {
|
||||
format!(
|
||||
"test zip entry {} from {}",
|
||||
entry.name(),
|
||||
zip_path.display()
|
||||
)
|
||||
})?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn process_one(zip_path: &Path) -> Result<ProcessResult> {
|
||||
let sidecars = load_sidecars(zip_path)?;
|
||||
let host = guess_host(zip_path, &sidecars);
|
||||
@@ -123,6 +195,7 @@ fn process_one(zip_path: &Path) -> Result<ProcessResult> {
|
||||
],
|
||||
)?;
|
||||
let latest = read_json_file(Path::new(LATEST_INTAKE))?;
|
||||
let security_finding_ingest = ingest_security_finding_best_effort(Path::new(LATEST_INTAKE))?;
|
||||
let report_dir = PathBuf::from(
|
||||
latest
|
||||
.get("report_dir")
|
||||
@@ -154,6 +227,7 @@ fn process_one(zip_path: &Path) -> Result<ProcessResult> {
|
||||
return Ok(ProcessResult {
|
||||
latest_intake: latest,
|
||||
case_alert,
|
||||
security_finding_ingest,
|
||||
});
|
||||
}
|
||||
run_checked(
|
||||
@@ -171,9 +245,63 @@ fn process_one(zip_path: &Path) -> Result<ProcessResult> {
|
||||
Ok(ProcessResult {
|
||||
latest_intake: latest,
|
||||
case_alert,
|
||||
security_finding_ingest,
|
||||
})
|
||||
}
|
||||
|
||||
fn ingest_security_finding_best_effort(intake_path: &Path) -> Result<Option<Value>> {
|
||||
if !env_bool("AW_SECURITY_FINDING_INBOX_ENABLED", false) {
|
||||
return Ok(None);
|
||||
}
|
||||
let binary = PathBuf::from(env_string(
|
||||
"AW_SECURITY_FINDING_INBOX_BIN",
|
||||
SECURITY_FINDING_INBOX,
|
||||
));
|
||||
let required = env_bool("AW_SECURITY_FINDING_INBOX_REQUIRED", false);
|
||||
if !binary.is_file() {
|
||||
let message = format!(
|
||||
"security finding inbox binary not found: {}",
|
||||
binary.display()
|
||||
);
|
||||
if required {
|
||||
bail!("{message}");
|
||||
}
|
||||
eprintln!("WARNING: {message}");
|
||||
return Ok(Some(json!({"ok": false, "warning": message})));
|
||||
}
|
||||
let min_severity = env_string("AW_SECURITY_FINDING_INBOX_MIN_SEVERITY", "medium");
|
||||
let output = Command::new(&binary)
|
||||
.arg("ingest-hayabusa")
|
||||
.arg("--intake")
|
||||
.arg(intake_path)
|
||||
.arg("--min-severity")
|
||||
.arg(min_severity)
|
||||
.output()
|
||||
.with_context(|| format!("run {}", binary.display()))?;
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
if !output.status.success() {
|
||||
let message = format!(
|
||||
"security finding ingest failed: status={} stderr={}",
|
||||
output.status,
|
||||
stderr.trim()
|
||||
);
|
||||
if required {
|
||||
bail!("{message}");
|
||||
}
|
||||
eprintln!("WARNING: {message}");
|
||||
return Ok(Some(json!({"ok": false, "warning": message})));
|
||||
}
|
||||
let payload = serde_json::from_str(stdout.trim()).unwrap_or_else(|_| {
|
||||
json!({
|
||||
"ok": true,
|
||||
"stdout": stdout.trim(),
|
||||
"stderr": stderr.trim()
|
||||
})
|
||||
});
|
||||
Ok(Some(payload))
|
||||
}
|
||||
|
||||
fn load_sidecars(zip_path: &Path) -> Result<Sidecars> {
|
||||
let base = zip_path.with_extension("");
|
||||
let caseid_path = base.with_extension("caseid");
|
||||
@@ -241,6 +369,108 @@ fn archive_drop_package(report_dir: &Path, zip_path: &Path) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn quarantine_drop_package(
|
||||
quarantine_root: &Path,
|
||||
zip_path: &Path,
|
||||
err: &anyhow::Error,
|
||||
) -> Result<PathBuf> {
|
||||
fs::create_dir_all(quarantine_root)
|
||||
.with_context(|| format!("create {}", quarantine_root.display()))?;
|
||||
let name = zip_path
|
||||
.file_name()
|
||||
.and_then(|name| name.to_str())
|
||||
.unwrap_or("package.zip");
|
||||
let stamp = Utc::now().format("%Y%m%dT%H%M%SZ");
|
||||
let mut quarantine_dir = quarantine_root.join(format!("{stamp}_{}", sanitize_component(name)));
|
||||
if quarantine_dir.exists() {
|
||||
quarantine_dir = quarantine_root.join(format!(
|
||||
"{stamp}_{}_{}",
|
||||
sanitize_component(name),
|
||||
std::process::id()
|
||||
));
|
||||
}
|
||||
fs::create_dir_all(&quarantine_dir)
|
||||
.with_context(|| format!("create {}", quarantine_dir.display()))?;
|
||||
|
||||
let sha256 = if zip_path.is_file() {
|
||||
Some(sha256_file(zip_path)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
move_if_exists(zip_path, &quarantine_dir)?;
|
||||
let base = zip_path.with_extension("");
|
||||
for sidecar in [
|
||||
base.with_extension("caseid"),
|
||||
base.with_extension("meta.json"),
|
||||
zip_path.with_extension("zip.sha256"),
|
||||
] {
|
||||
move_if_exists(&sidecar, &quarantine_dir)?;
|
||||
}
|
||||
let reason = json!({
|
||||
"quarantined_at": Utc::now().to_rfc3339(),
|
||||
"source": "aw-hayabusa-autoprocess-rust",
|
||||
"original_path": zip_path.display().to_string(),
|
||||
"sha256": sha256,
|
||||
"reason": err.to_string(),
|
||||
"detail": format!("{err:#}"),
|
||||
"operator_action": "inspect source package, re-export EVTX archive if needed, then replay by moving a fixed package back to the drop directory",
|
||||
});
|
||||
fs::write(
|
||||
quarantine_dir.join("reason.json"),
|
||||
serde_json::to_string_pretty(&reason)?,
|
||||
)
|
||||
.with_context(|| format!("write {}", quarantine_dir.join("reason.json").display()))?;
|
||||
Ok(quarantine_dir)
|
||||
}
|
||||
|
||||
fn move_if_exists(path: &Path, target_dir: &Path) -> Result<()> {
|
||||
if !path.exists() {
|
||||
return Ok(());
|
||||
}
|
||||
let target = target_dir.join(path.file_name().context("quarantine file name")?);
|
||||
fs::rename(path, &target)
|
||||
.or_else(|_| {
|
||||
fs::copy(path, &target)?;
|
||||
fs::remove_file(path)
|
||||
})
|
||||
.with_context(|| format!("move {} to {}", path.display(), target.display()))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn sha256_file(path: &Path) -> Result<String> {
|
||||
let mut file = File::open(path).with_context(|| format!("open {}", path.display()))?;
|
||||
let mut hasher = Sha256::new();
|
||||
let mut buf = [0u8; 8192];
|
||||
loop {
|
||||
let read = file
|
||||
.read(&mut buf)
|
||||
.with_context(|| format!("read {}", path.display()))?;
|
||||
if read == 0 {
|
||||
break;
|
||||
}
|
||||
hasher.update(&buf[..read]);
|
||||
}
|
||||
Ok(format!("{:x}", hasher.finalize()))
|
||||
}
|
||||
|
||||
fn sanitize_component(value: &str) -> String {
|
||||
let clean = value
|
||||
.chars()
|
||||
.map(|ch| {
|
||||
if ch.is_ascii_alphanumeric() || matches!(ch, '.' | '_' | '-') {
|
||||
ch
|
||||
} else {
|
||||
'_'
|
||||
}
|
||||
})
|
||||
.collect::<String>();
|
||||
if clean.is_empty() {
|
||||
"package".to_string()
|
||||
} else {
|
||||
clean
|
||||
}
|
||||
}
|
||||
|
||||
fn guess_host(zip_path: &Path, sidecars: &Sidecars) -> Option<String> {
|
||||
if let Some(host) = &sidecars.host {
|
||||
if !host.is_empty() {
|
||||
@@ -302,3 +532,57 @@ fn run_capture(program: &Path, args: &[String]) -> Result<Captured> {
|
||||
stderr: String::from_utf8_lossy(&output.stderr).to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::io::Write;
|
||||
|
||||
#[test]
|
||||
fn invalid_zip_is_rejected_before_accept() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let zip_path = dir.path().join("bad.zip");
|
||||
fs::write(&zip_path, b"not a zip").unwrap();
|
||||
|
||||
let err = validate_drop_inputs(&zip_path).unwrap_err();
|
||||
assert!(err.to_string().contains("read zip"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quarantine_moves_package_sidecars_and_writes_reason() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let drop = dir.path().join("drop");
|
||||
let quarantine = dir.path().join("quarantine");
|
||||
fs::create_dir_all(&drop).unwrap();
|
||||
let zip_path = drop.join("HOST-20260624.zip");
|
||||
fs::write(&zip_path, b"bad").unwrap();
|
||||
fs::write(drop.join("HOST-20260624.meta.json"), b"{bad").unwrap();
|
||||
fs::write(drop.join("HOST-20260624.caseid"), b"30").unwrap();
|
||||
|
||||
let err = anyhow::anyhow!("bad zip");
|
||||
let target = quarantine_drop_package(&quarantine, &zip_path, &err).unwrap();
|
||||
|
||||
assert!(!zip_path.exists());
|
||||
assert!(target.join("HOST-20260624.zip").is_file());
|
||||
assert!(target.join("HOST-20260624.meta.json").is_file());
|
||||
assert!(target.join("HOST-20260624.caseid").is_file());
|
||||
let reason = fs::read_to_string(target.join("reason.json")).unwrap();
|
||||
assert!(reason.contains("bad zip"));
|
||||
assert!(reason.contains("aw-hayabusa-autoprocess-rust"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid_zip_with_backslash_entry_is_accepted_by_precheck() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let zip_path = dir.path().join("ok.zip");
|
||||
let file = File::create(&zip_path).unwrap();
|
||||
let mut zip = zip::ZipWriter::new(file);
|
||||
let options = zip::write::SimpleFileOptions::default()
|
||||
.compression_method(zip::CompressionMethod::Deflated);
|
||||
zip.start_file("evtx\\sample.evtx", options).unwrap();
|
||||
zip.write_all(b"evtx").unwrap();
|
||||
zip.finish().unwrap();
|
||||
|
||||
validate_drop_inputs(&zip_path).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
[package]
|
||||
name = "security-finding-inbox"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
publish.workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
chrono.workspace = true
|
||||
clap.workspace = true
|
||||
hayabusa-tools = { path = "../hayabusa-tools" }
|
||||
reqwest.workspace = true
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
sha2.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile.workspace = true
|
||||
File diff suppressed because it is too large
Load Diff
@@ -79,6 +79,13 @@ Behavior:
|
||||
- optional `*.caseid` sidecar with the same basename triggers automatic bounded case linkage
|
||||
- processed `*.zip` is moved out of `drop/` into `report_dir/input-drop/` to avoid repeated re-trigger loops
|
||||
- sidecars are archived into `report_dir/input-sidecars/`
|
||||
- bad drop packages are rejected before `accept`, moved to
|
||||
`/opt/hayabusa/quarantine/drop/<timestamp>_<package>/`, and recorded with a
|
||||
`reason.json` file instead of blocking later packages
|
||||
- bad or partially extracted incoming packages are moved to
|
||||
`/opt/hayabusa/quarantine/incoming/<timestamp>_<package>/`; `process-inbox`
|
||||
continues with the remaining queue and does not trip systemd start-limit only
|
||||
because of one poison archive
|
||||
|
||||
## Windows direct upload into the drop zone
|
||||
|
||||
@@ -118,4 +125,43 @@ Production scheduled task on `SHARKON2025`:
|
||||
|
||||
Do not switch this task back to `SYSTEM` on the current RDP host: Task Scheduler starts `powershell.exe` under `SYSTEM`, but the process exits with `0xC0000142` before the upload script starts.
|
||||
|
||||
Server-side processing accepts Windows zip packages with backslash path separators and UTF-8 BOM in sidecar JSON. `aw-hayabusa-autoprocess` processes the full incoming queue after accepting a drop package, so stale incoming files from an earlier failed run are drained before the latest intake is recorded.
|
||||
Server-side processing accepts Windows zip packages with backslash path
|
||||
separators and UTF-8 BOM in sidecar JSON. `aw-hayabusa-autoprocess` processes
|
||||
the full incoming queue after accepting a drop package, so stale incoming files
|
||||
from an earlier failed run are drained before the latest intake is recorded.
|
||||
|
||||
Poison-package handling is fail-closed:
|
||||
|
||||
- Rust `aw-hayabusa-autoprocess-rust` validates the zip and sidecars before
|
||||
calling `aw-hayabusa accept`.
|
||||
- A corrupt/empty/unsafe drop package is quarantined with its `.meta.json`,
|
||||
`.caseid`, optional checksum sidecar and `reason.json`.
|
||||
- `aw-hayabusa process-inbox` isolates a failed incoming package instead of
|
||||
aborting the whole batch.
|
||||
- Operators replay only a fixed/re-exported package by moving it back to the
|
||||
drop zone or incoming queue. Do not edit quarantined evidence in place.
|
||||
|
||||
## Security Finding Inbox integration
|
||||
|
||||
`aw-hayabusa-autoprocess-rust` can publish a normalized suspicious-workstation
|
||||
finding after a successful intake is written to `/opt/hayabusa/state/latest-intake.json`.
|
||||
|
||||
Default is disabled to keep forensic processing independent from ClickHouse:
|
||||
|
||||
```bash
|
||||
AW_SECURITY_FINDING_INBOX_ENABLED=false
|
||||
```
|
||||
|
||||
Enable after the ClickHouse schema and CLI are installed:
|
||||
|
||||
```bash
|
||||
AW_SECURITY_FINDING_INBOX_ENABLED=true
|
||||
AW_SECURITY_FINDING_INBOX_BIN=/usr/local/bin/security-finding-inbox
|
||||
AW_SECURITY_FINDING_INBOX_MIN_SEVERITY=medium
|
||||
AW_SECURITY_FINDING_INBOX_REQUIRED=false
|
||||
```
|
||||
|
||||
With `AW_SECURITY_FINDING_INBOX_REQUIRED=false`, a temporary ClickHouse/inbox
|
||||
failure is logged as warning and does not poison the Hayabusa backlog. Use
|
||||
`true` only when the operator wants inbox publication failure to become an
|
||||
operational failure for the drop service.
|
||||
|
||||
@@ -14,6 +14,7 @@ HAYA_STAGING_DIR="${AW_HAYABUSA_STAGING_DIR:-${HAYA_ROOT}/inbox/staging}"
|
||||
HAYA_ARCHIVE_PACKAGES_DIR="${AW_HAYABUSA_ARCHIVE_PACKAGES_DIR:-${HAYA_ROOT}/archive/packages}"
|
||||
HAYA_ARCHIVE_EXTRACTED_DIR="${AW_HAYABUSA_ARCHIVE_EXTRACTED_DIR:-${HAYA_ROOT}/archive/extracted}"
|
||||
HAYA_LOGS_DIR="${AW_HAYABUSA_LOGS_DIR:-${HAYA_ROOT}/state/logs}"
|
||||
HAYA_QUARANTINE_DIR="${AW_HAYABUSA_QUARANTINE_DIR:-${HAYA_ROOT}/quarantine/incoming}"
|
||||
LAST_REPORT_DIR=""
|
||||
|
||||
usage() {
|
||||
@@ -57,7 +58,8 @@ ensure_layout() {
|
||||
"${HAYA_INCOMING_DIR}" \
|
||||
"${HAYA_STAGING_DIR}" \
|
||||
"${HAYA_ARCHIVE_PACKAGES_DIR}" \
|
||||
"${HAYA_ARCHIVE_EXTRACTED_DIR}"
|
||||
"${HAYA_ARCHIVE_EXTRACTED_DIR}" \
|
||||
"${HAYA_QUARANTINE_DIR}"
|
||||
}
|
||||
|
||||
run_logged() {
|
||||
@@ -405,7 +407,8 @@ process_one_package() {
|
||||
|
||||
package_sha256="$(sha256sum "${package_path}" | awk '{print $1}')"
|
||||
if ! extract_zip_normalized "${package_path}" "${stage_dir}"; then
|
||||
fail "normalized zip extraction failed for ${package_path}"
|
||||
echo "ERROR: normalized zip extraction failed for ${package_path}" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local manifest_path host evtx_root archive_pkg_dir archive_extract_dir status report_dir
|
||||
@@ -453,7 +456,47 @@ process_one_package() {
|
||||
if [ -n "${report_dir}" ]; then
|
||||
echo "Report directory: ${report_dir}"
|
||||
fi
|
||||
[ "${status}" = "ok" ] || fail "Package workflow ended with status=${status}; archived for inspection"
|
||||
if [ "${status}" != "ok" ]; then
|
||||
echo "ERROR: Package workflow ended with status=${status}; archived for inspection" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
quarantine_incoming_package() {
|
||||
local package_path="$1"
|
||||
local reason="$2"
|
||||
local ts package_name package_base safe_base target_dir stage_dir sha256
|
||||
ts="$(date -u +%Y%m%dT%H%M%SZ)"
|
||||
package_name="$(basename "${package_path}")"
|
||||
package_base="${package_name%.zip}"
|
||||
safe_base="$(sanitize "${package_name}")"
|
||||
[ -n "${safe_base}" ] || safe_base="package.zip"
|
||||
target_dir="${HAYA_QUARANTINE_DIR}/${ts}_${safe_base}"
|
||||
mkdir -p "${target_dir}"
|
||||
sha256=""
|
||||
if [ -f "${package_path}" ] && command -v sha256sum >/dev/null 2>&1; then
|
||||
sha256="$(sha256sum "${package_path}" | awk '{print $1}')"
|
||||
fi
|
||||
for candidate in "${package_path}" "${package_path}.sha256" "${package_path}.host"; do
|
||||
if [ -e "${candidate}" ]; then
|
||||
mv "${candidate}" "${target_dir}/"
|
||||
fi
|
||||
done
|
||||
stage_dir="${HAYA_STAGING_DIR}/${package_base}"
|
||||
if [ -d "${stage_dir}" ]; then
|
||||
mv "${stage_dir}" "${target_dir}/staging-partial"
|
||||
fi
|
||||
cat >"${target_dir}/reason.json" <<EOF
|
||||
{
|
||||
"quarantined_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
|
||||
"source": "aw-hayabusa process-inbox",
|
||||
"original_path": "${package_path}",
|
||||
"sha256": "${sha256}",
|
||||
"reason": "${reason}",
|
||||
"operator_action": "inspect source package, re-export EVTX archive if needed, then replay by moving a fixed package back to incoming or drop"
|
||||
}
|
||||
EOF
|
||||
echo "Quarantined failed incoming package: ${target_dir}" >&2
|
||||
}
|
||||
|
||||
process_inbox() {
|
||||
@@ -482,15 +525,26 @@ process_inbox() {
|
||||
esac
|
||||
ensure_layout
|
||||
|
||||
local count=0 pkg
|
||||
local count=0 failed=0 pkg
|
||||
while IFS= read -r pkg; do
|
||||
process_one_package "${pkg}" "${mode}"
|
||||
count=$((count + 1))
|
||||
if process_one_package "${pkg}" "${mode}"; then
|
||||
count=$((count + 1))
|
||||
else
|
||||
failed=$((failed + 1))
|
||||
if [ -f "${pkg}" ]; then
|
||||
quarantine_incoming_package "${pkg}" "process_one_package failed"
|
||||
else
|
||||
echo "Package failed after archive/move, see archive intake manifest for details: ${pkg}" >&2
|
||||
fi
|
||||
fi
|
||||
if [ "${limit}" -gt 0 ] && [ "${count}" -ge "${limit}" ]; then
|
||||
break
|
||||
fi
|
||||
done < <(find "${HAYA_INCOMING_DIR}" -maxdepth 1 -type f -name '*.zip' | sort)
|
||||
[ "${count}" -gt 0 ] || echo "No packages in ${HAYA_INCOMING_DIR}"
|
||||
if [ "${failed}" -gt 0 ]; then
|
||||
echo "process-inbox completed with quarantined_or_archived_failures=${failed}" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
|
||||
@@ -66,6 +66,9 @@ File 1C + reglog + host telemetry
|
||||
- `grafana/provisioning/dashboards/files/1c-telemetry-board.json` — telemetry dashboard по состоянию файловых баз, reglog growth, busy markers и host load.
|
||||
- `detections/build_entity_timeline.sql` — сборка единого timeline слоя.
|
||||
- `detections/open_cases_from_detections.sql` — шаблон открытия cases из detections.
|
||||
- `security/security_finding_inbox.sql` — schema Security Finding Inbox:
|
||||
подозрительные станции, raw finding evidence, workflow/executor events и
|
||||
latest-state view для DetMir Portal.
|
||||
- `ops/etl-cron.example` — legacy cron example; production использует
|
||||
`aw-1c-ingest.timer`.
|
||||
- `ops/retention-policy.md` — минимальная retention policy.
|
||||
|
||||
@@ -10,6 +10,16 @@ services:
|
||||
ports:
|
||||
- "${CLICKHOUSE_PORT}:8123"
|
||||
- "${CLICKHOUSE_NATIVE_PORT}:9000"
|
||||
healthcheck:
|
||||
test:
|
||||
[
|
||||
"CMD-SHELL",
|
||||
"clickhouse-client --host 127.0.0.1 --user \"$${CLICKHOUSE_USER}\" --password \"$${CLICKHOUSE_PASSWORD}\" --database \"$${CLICKHOUSE_DB}\" --query 'SELECT 1' >/dev/null",
|
||||
]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 5
|
||||
start_period: 30s
|
||||
volumes:
|
||||
- clickhouse_1c_data:/var/lib/clickhouse
|
||||
- ./clickhouse/init:/docker-entrypoint-initdb.d:ro
|
||||
|
||||
@@ -76,6 +76,14 @@ docker exec -i "${CH_CONTAINER}" clickhouse-client \
|
||||
--database "${CLICKHOUSE_DB}" \
|
||||
< "${ROOT}/detections/open_cases_from_detections.sql"
|
||||
|
||||
if [[ -f "${ROOT}/security/security_finding_inbox.sql" ]]; then
|
||||
docker exec -i "${CH_CONTAINER}" clickhouse-client \
|
||||
--user "${CLICKHOUSE_USER}" \
|
||||
--password "${CLICKHOUSE_PASSWORD}" \
|
||||
--database "${CLICKHOUSE_DB}" \
|
||||
< "${ROOT}/security/security_finding_inbox.sql"
|
||||
fi
|
||||
|
||||
if [[ "${RUN_MANAGER_BRIEF_AFTER_INGEST}" == "1" ]]; then
|
||||
if ! "${ROOT}/ops/run_manager_brief.sh"; then
|
||||
echo "warning: manager brief refresh failed after ingest" >&2
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
CREATE TABLE IF NOT EXISTS analytics_1c.security_findings
|
||||
(
|
||||
ts DateTime64(3, 'UTC'),
|
||||
finding_id String,
|
||||
host String,
|
||||
user String,
|
||||
ip String,
|
||||
department LowCardinality(String),
|
||||
state LowCardinality(String),
|
||||
severity LowCardinality(String),
|
||||
confidence LowCardinality(String),
|
||||
score UInt16,
|
||||
source LowCardinality(String),
|
||||
rule_id String,
|
||||
rule_title String,
|
||||
summary String,
|
||||
recommended_action LowCardinality(String),
|
||||
management_channel_checked UInt8,
|
||||
evidence_ref String,
|
||||
raw_json String,
|
||||
ingested_at DateTime64(3, 'UTC') DEFAULT now64(3)
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
PARTITION BY toYYYYMM(ts)
|
||||
ORDER BY (state, severity, host, ts, finding_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS analytics_1c.security_finding_workflow_events
|
||||
(
|
||||
ts DateTime64(3, 'UTC'),
|
||||
finding_id String,
|
||||
event_type LowCardinality(String),
|
||||
status LowCardinality(String),
|
||||
actor String,
|
||||
comment String,
|
||||
decision_status String,
|
||||
rollback_plan_id String,
|
||||
plan_id String,
|
||||
evidence_json String
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
PARTITION BY toYYYYMM(ts)
|
||||
ORDER BY (finding_id, ts, event_type);
|
||||
|
||||
DROP VIEW IF EXISTS analytics_1c.security_finding_inbox;
|
||||
|
||||
CREATE VIEW analytics_1c.security_finding_inbox AS
|
||||
SELECT
|
||||
f.finding_id AS finding_id,
|
||||
min(f.ts) AS first_seen,
|
||||
max(f.ts) AS last_seen,
|
||||
argMax(f.host, f.ingested_at) AS host,
|
||||
argMax(f.user, f.ingested_at) AS user,
|
||||
argMax(f.ip, f.ingested_at) AS ip,
|
||||
argMax(f.department, f.ingested_at) AS department,
|
||||
argMax(f.state, f.ingested_at) AS state,
|
||||
argMax(f.severity, f.ingested_at) AS severity,
|
||||
argMax(f.confidence, f.ingested_at) AS confidence,
|
||||
argMax(f.score, f.ingested_at) AS score,
|
||||
argMax(f.source, f.ingested_at) AS source,
|
||||
argMax(f.rule_id, f.ingested_at) AS rule_id,
|
||||
argMax(f.rule_title, f.ingested_at) AS rule_title,
|
||||
argMax(f.summary, f.ingested_at) AS summary,
|
||||
argMax(f.recommended_action, f.ingested_at) AS recommended_action,
|
||||
argMax(f.management_channel_checked, f.ingested_at) AS management_channel_checked,
|
||||
argMax(f.evidence_ref, f.ingested_at) AS evidence_ref,
|
||||
argMax(f.raw_json, f.ingested_at) AS raw_json,
|
||||
coalesce(nullIf(w.status, ''), 'new') AS workflow_status,
|
||||
coalesce(nullIf(w.event_type, ''), 'created') AS last_workflow_event,
|
||||
w.workflow_updated_at AS workflow_updated_at,
|
||||
coalesce(w.actor, '') AS workflow_actor,
|
||||
coalesce(w.decision_status, '') AS decision_status,
|
||||
coalesce(w.rollback_plan_id, '') AS rollback_plan_id,
|
||||
coalesce(w.plan_id, '') AS plan_id
|
||||
FROM analytics_1c.security_findings AS f
|
||||
LEFT JOIN
|
||||
(
|
||||
SELECT
|
||||
finding_id,
|
||||
argMax(event_type, ts) AS event_type,
|
||||
argMax(status, ts) AS status,
|
||||
argMax(actor, ts) AS actor,
|
||||
argMax(decision_status, ts) AS decision_status,
|
||||
argMax(rollback_plan_id, ts) AS rollback_plan_id,
|
||||
argMax(plan_id, ts) AS plan_id,
|
||||
max(ts) AS workflow_updated_at
|
||||
FROM analytics_1c.security_finding_workflow_events
|
||||
GROUP BY finding_id
|
||||
) AS w USING finding_id
|
||||
GROUP BY
|
||||
f.finding_id,
|
||||
w.status,
|
||||
w.event_type,
|
||||
w.workflow_updated_at,
|
||||
w.actor,
|
||||
w.decision_status,
|
||||
w.rollback_plan_id,
|
||||
w.plan_id;
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"host": "HOST-EXAMPLE",
|
||||
"host_role": "workstation",
|
||||
"state": "suspected_infected",
|
||||
"confidence": "high",
|
||||
"signals": [
|
||||
{
|
||||
"source": "hayabusa",
|
||||
"rule_id": "sigma-placeholder-critical",
|
||||
"confidence": "critical"
|
||||
},
|
||||
{
|
||||
"source": "velociraptor",
|
||||
"rule_id": "Windows.Hayabusa.Monitoring",
|
||||
"confidence": "high"
|
||||
}
|
||||
],
|
||||
"recommended_action": "windows_firewall_quarantine",
|
||||
"management_channel_checked": true,
|
||||
"manual_operator_flag": false
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"enabled": false,
|
||||
"mode": "shadow",
|
||||
"default_ttl_minutes": 60,
|
||||
"require_admin_channel_check": true,
|
||||
"allow_auto_for_servers": false,
|
||||
"allowed_actions": [
|
||||
"windows_firewall_quarantine",
|
||||
"pfsense_host_block"
|
||||
],
|
||||
"management_allowlist": [
|
||||
"aw_server",
|
||||
"velociraptor_server",
|
||||
"admin_jump_host"
|
||||
],
|
||||
"minimum_high_signals_for_auto": 2
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"ts": "2026-06-25T10:00:00Z",
|
||||
"host": "HOST-EXAMPLE",
|
||||
"user": "user-example",
|
||||
"ip": "10.10.20.42",
|
||||
"department": "demo",
|
||||
"state": "suspected_infected",
|
||||
"severity": "critical",
|
||||
"confidence": "high",
|
||||
"score": 95,
|
||||
"source": "hayabusa",
|
||||
"rule_id": "demo-sigma-critical",
|
||||
"rule_title": "Demo high-confidence suspicious workstation",
|
||||
"summary": "Demo finding for Security Finding Inbox validation.",
|
||||
"recommended_action": "windows_firewall_quarantine",
|
||||
"management_channel_checked": true,
|
||||
"evidence_ref": "demo://hayabusa/HOST-EXAMPLE/demo-sigma-critical",
|
||||
"metadata": {
|
||||
"sample": "true"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"target_host": "HOST-EXAMPLE",
|
||||
"plan_id": "rollback-host-example-001",
|
||||
"ttl_minutes": 60,
|
||||
"reason": "High-confidence Hayabusa and Velociraptor containment drill",
|
||||
"management_allowlist": [
|
||||
"10.10.10.10",
|
||||
"10.10.10.11",
|
||||
"10.10.10.12"
|
||||
],
|
||||
"blocked_remote_addresses": [
|
||||
"10.10.20.0/24",
|
||||
"10.10.30.0/24"
|
||||
],
|
||||
"profiles": [
|
||||
"Domain"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
# AWatch-rus containment operator runbook
|
||||
|
||||
Дата: 2026-06-25.
|
||||
|
||||
Runbook для безопасной проверки containment-логики. Текущая реализация не
|
||||
блокирует рабочие станции и не меняет сеть. Она только рассчитывает решение и
|
||||
показывает, был бы quarantine рекомендован или отказан.
|
||||
|
||||
## 1. Сборка
|
||||
|
||||
```bash
|
||||
cd /mnt/usb_hdd2/Projects/ActivityWatch-Russian
|
||||
export CARGO_TARGET_DIR=/home/igor/.cache/detmir-adk-rust-target
|
||||
cargo build --manifest-path adk-rust/Cargo.toml -p containment-engine
|
||||
```
|
||||
|
||||
## 2. Smoke в disabled/shadow режиме
|
||||
|
||||
```bash
|
||||
cd /mnt/usb_hdd2/Projects/ActivityWatch-Russian
|
||||
bash scripts/containment_shadow_smoke.sh
|
||||
```
|
||||
|
||||
Ожидаемо:
|
||||
|
||||
- JSON содержит `would_mutate=false`;
|
||||
- `decision_status=disabled` для default example policy;
|
||||
- нет изменений firewall, pfSense, AD, VLAN, routes.
|
||||
|
||||
## 3. Проверка shadow recommendation
|
||||
|
||||
Создайте временный policy с:
|
||||
|
||||
```json
|
||||
{
|
||||
"enabled": true,
|
||||
"mode": "shadow"
|
||||
}
|
||||
```
|
||||
|
||||
на базе `configs/containment-policy.example.json`, затем выполните:
|
||||
|
||||
```bash
|
||||
containment-engine decide \
|
||||
--policy /tmp/containment-policy-shadow.json \
|
||||
--finding configs/containment-finding.example.json \
|
||||
--pretty
|
||||
```
|
||||
|
||||
Ожидаемо:
|
||||
|
||||
- `decision_status=shadow_recommended`;
|
||||
- `would_mutate=false`;
|
||||
- `rollback_plan_id` заполнен;
|
||||
- `blockers=[]`.
|
||||
|
||||
## 4. Manual approval mode
|
||||
|
||||
`manual_approval` должен только поставить решение в состояние
|
||||
`manual_approval_required`. Он не применяет block сам.
|
||||
|
||||
## 5. Auto mode
|
||||
|
||||
В текущей реализации `auto` может вернуть `auto_ready`, но `would_mutate=false`.
|
||||
Это намеренно: decision layer сам не применяет блокировки.
|
||||
|
||||
Запрещено считать `auto_ready` фактической блокировкой. Это только решение
|
||||
control plane.
|
||||
|
||||
## 6. Windows Firewall executor dry-run
|
||||
|
||||
Security Finding Inbox показывает подозрительные станции и фиксирует workflow
|
||||
события. Портал не выполняет firewall apply. После `approved` и
|
||||
`apply_requested` отдельный процесс `security-finding-inbox executor` может
|
||||
выполнить контролируемый цикл `decide -> plan -> apply -> verify`, а при
|
||||
ошибке `rollback`. По умолчанию executor работает dry-run/fail-closed.
|
||||
|
||||
Сгенерируйте план:
|
||||
|
||||
```bash
|
||||
cd /mnt/usb_hdd2/Projects/ActivityWatch-Russian
|
||||
containment-engine windows-firewall plan \
|
||||
--request configs/windows-firewall-containment-request.example.json \
|
||||
--pretty > /tmp/windows-firewall-plan.json
|
||||
```
|
||||
|
||||
Проверьте `blockers`. Для корректного example они должны быть пустыми.
|
||||
|
||||
Dry-run apply:
|
||||
|
||||
```bash
|
||||
containment-engine windows-firewall apply \
|
||||
--plan /tmp/windows-firewall-plan.json \
|
||||
--confirm-apply YES \
|
||||
--pretty
|
||||
```
|
||||
|
||||
Ожидаемо:
|
||||
|
||||
- `execution_status=dry_run_commands_ready`;
|
||||
- `would_mutate=false`;
|
||||
- в JSON есть PowerShell-команды `New-NetFirewallRule`;
|
||||
- реальные firewall-правила не создаются.
|
||||
|
||||
Verify dry-run:
|
||||
|
||||
```bash
|
||||
containment-engine windows-firewall verify \
|
||||
--plan /tmp/windows-firewall-plan.json \
|
||||
--pretty
|
||||
```
|
||||
|
||||
Rollback dry-run:
|
||||
|
||||
```bash
|
||||
containment-engine windows-firewall rollback \
|
||||
--plan /tmp/windows-firewall-plan.json \
|
||||
--confirm-rollback YES \
|
||||
--pretty
|
||||
```
|
||||
|
||||
## 7. Real Windows execution rules
|
||||
|
||||
Dry-run polling из центрального контура:
|
||||
|
||||
```bash
|
||||
security-finding-inbox executor \
|
||||
--once \
|
||||
--dry-run \
|
||||
--containment-engine-bin /usr/local/bin/containment-engine \
|
||||
--policy /etc/activitywatch/containment-policy.json \
|
||||
--management-allowlist 10.10.10.10,10.10.10.11 \
|
||||
--blocked-remote-addresses 10.10.20.0/24,10.10.30.0/24
|
||||
```
|
||||
|
||||
Реальный Windows Firewall apply допускается только на целевой Windows-станции:
|
||||
|
||||
```powershell
|
||||
security-finding-inbox.exe executor `
|
||||
--once `
|
||||
--execute-local `
|
||||
--confirm-execute YES `
|
||||
--executor-host HOST-EXAMPLE `
|
||||
--containment-engine-bin C:\ProgramData\AWatch-rus\containment-engine.exe `
|
||||
--policy C:\ProgramData\AWatch-rus\containment-policy.json `
|
||||
--management-allowlist 10.10.10.10,10.10.10.11 `
|
||||
--blocked-remote-addresses 10.10.20.0/24,10.10.30.0/24
|
||||
```
|
||||
|
||||
Executor откажется, если нет `approved` перед `apply_requested`, finding не
|
||||
`suspected_infected`/`confirmed_infected`, management channel не проверен,
|
||||
allowlist/block ranges пустые, host finding не совпадает с executor host для
|
||||
local apply, containment policy возвращает blocker или Windows Firewall plan
|
||||
содержит blockers.
|
||||
|
||||
`--execute-local` разрешён только для отдельного lab Windows host, где заранее
|
||||
проверены:
|
||||
|
||||
- доступ с admin jump host;
|
||||
- доступ к AWatch/Velociraptor management адресам;
|
||||
- rollback command;
|
||||
- out-of-band доступ, если firewall rule ошибочен;
|
||||
- TTL и оператор, ответственный за возврат.
|
||||
|
||||
Не использовать широкие блокировки `Any`/`LocalSubnet`: Windows Firewall
|
||||
block-правила могут перекрыть allow-правила и отрезать управление.
|
||||
|
||||
## 8. Когда можно расширять real containment executor
|
||||
|
||||
Только после выполнения условий:
|
||||
|
||||
- есть lab host;
|
||||
- подтвержден management allowlist;
|
||||
- есть rollback command;
|
||||
- есть TTL rollback;
|
||||
- есть audit log;
|
||||
- `plan`, `apply`, `verify`, `rollback` покрыты тестами;
|
||||
- auto-containment для серверов остается disabled.
|
||||
|
||||
## 9. Проверки перед commit
|
||||
|
||||
```bash
|
||||
cd /mnt/usb_hdd2/Projects/ActivityWatch-Russian
|
||||
python3 scripts/public_secret_pattern_check.py
|
||||
bash -n scripts/containment_shadow_smoke.sh
|
||||
bash scripts/containment_shadow_smoke.sh
|
||||
git diff --check
|
||||
|
||||
cd adk-rust
|
||||
export CARGO_TARGET_DIR=/home/igor/.cache/detmir-adk-rust-target
|
||||
cargo fmt --all --check
|
||||
cargo test -p containment-engine
|
||||
cargo clippy -p containment-engine --all-targets -- -D warnings
|
||||
```
|
||||
@@ -0,0 +1,146 @@
|
||||
# AWatch-rus containment policy
|
||||
|
||||
Дата: 2026-06-25.
|
||||
|
||||
Этот документ описывает безопасную политику автоматической/полуавтоматической
|
||||
изоляции рабочих станций. Containment нужен для быстрого ограничения
|
||||
распространения заражения, но не является автоматическим лечением,
|
||||
remediation, EDR/XDR или сертифицированной СЗИ.
|
||||
|
||||
## Default posture
|
||||
|
||||
По умолчанию containment выключен:
|
||||
|
||||
```text
|
||||
AW_CONTAINMENT_ENABLED=false
|
||||
AW_CONTAINMENT_MODE=shadow
|
||||
```
|
||||
|
||||
`shadow` означает: система рассчитывает рекомендацию и audit, но не меняет
|
||||
firewall, pfSense, AD, VLAN, маршруты или состояние рабочих станций.
|
||||
|
||||
## Policy file
|
||||
|
||||
Default path:
|
||||
|
||||
```text
|
||||
/etc/activitywatch/containment-policy.json
|
||||
```
|
||||
|
||||
Repo example:
|
||||
|
||||
```text
|
||||
configs/containment-policy.example.json
|
||||
```
|
||||
|
||||
Критичные поля:
|
||||
|
||||
- `enabled`: глобальный opt-in;
|
||||
- `mode`: `shadow`, `manual_approval`, `auto`;
|
||||
- `default_ttl_minutes`: срок quarantine до rollback/review;
|
||||
- `require_admin_channel_check`: запрещает блокировку, если управляемый канал
|
||||
не проверен;
|
||||
- `allow_auto_for_servers`: по умолчанию `false`;
|
||||
- `allowed_actions`: whitelist containment-действий;
|
||||
- `management_allowlist`: каналы, которые должны оставаться доступными;
|
||||
- `minimum_high_signals_for_auto`: минимальный порог high/critical signals.
|
||||
|
||||
## Safety rules
|
||||
|
||||
- Не включать `auto` до успешного shadow burn-in.
|
||||
- Не включать auto-containment для серверов и domain controllers.
|
||||
- Не запускать containment без rollback record.
|
||||
- Не запускать containment, если будет потерян admin/management channel.
|
||||
- Не применять широкие AD/OU/domain actions.
|
||||
- Не удалять файлы, registry keys или процессы как часть containment.
|
||||
- Не заявлять, что containment гарантированно остановил заражение.
|
||||
|
||||
## Decision threshold
|
||||
|
||||
Automatic quarantine допускается только если:
|
||||
|
||||
- host role is `workstation`;
|
||||
- host не входит в critical infrastructure denylist;
|
||||
- есть один `critical` signal или несколько `high` signals;
|
||||
- management-channel precheck passed;
|
||||
- action есть в `allowed_actions`;
|
||||
- rollback record создан успешно.
|
||||
|
||||
## Security Finding Inbox handoff
|
||||
|
||||
Security Finding Inbox (`docs/SECURITY_FINDING_INBOX_RU.md`) является входной
|
||||
очередью для подозрительных рабочих станций. Он хранит findings и workflow
|
||||
events в ClickHouse, показывает их в DetMir Portal. Портал не выполняет
|
||||
containment самостоятельно.
|
||||
|
||||
Workflow `apply_requested` означает только операторский запрос на применение.
|
||||
Фактическое применение идет через отдельный процесс
|
||||
`security-finding-inbox executor`, который повторно проверяет `approved`,
|
||||
запускает `containment-engine decide`, строит Windows Firewall plan, затем
|
||||
выполняет `apply`, `verify` и при ошибке `rollback`. Реальная мутация firewall
|
||||
разрешена только на целевой Windows-станции при `--execute-local`,
|
||||
`--confirm-execute YES` и совпадении `--executor-host` с finding host.
|
||||
|
||||
## Current implementation status
|
||||
|
||||
Реализован первый безопасный слой:
|
||||
|
||||
- Rust CLI `containment-engine`;
|
||||
- strict JSON policy/finding parsing;
|
||||
- `disabled`, `shadow`, `manual_approval`, `auto` decision states;
|
||||
- server/unknown host roles refused for auto mode by default;
|
||||
- `would_mutate=false` for current implementation;
|
||||
- separate Windows Firewall executor interface:
|
||||
`plan`, `apply`, `verify`, `rollback`;
|
||||
- Windows Firewall executor defaults to dry-run command generation unless
|
||||
`--execute-local` and explicit confirmation are used.
|
||||
|
||||
pfSense/AD/VLAN mutation paths are not implemented.
|
||||
|
||||
## Windows Firewall executor
|
||||
|
||||
Executor input example:
|
||||
|
||||
```text
|
||||
configs/windows-firewall-containment-request.example.json
|
||||
```
|
||||
|
||||
The executor is deliberately separate from decision making:
|
||||
|
||||
```bash
|
||||
containment-engine windows-firewall plan \
|
||||
--request configs/windows-firewall-containment-request.example.json \
|
||||
--pretty > /tmp/windows-firewall-plan.json
|
||||
|
||||
containment-engine windows-firewall apply \
|
||||
--plan /tmp/windows-firewall-plan.json \
|
||||
--confirm-apply YES \
|
||||
--pretty
|
||||
|
||||
containment-engine windows-firewall verify \
|
||||
--plan /tmp/windows-firewall-plan.json \
|
||||
--pretty
|
||||
|
||||
containment-engine windows-firewall rollback \
|
||||
--plan /tmp/windows-firewall-plan.json \
|
||||
--confirm-rollback YES \
|
||||
--pretty
|
||||
```
|
||||
|
||||
Without `--execute-local`, `apply` and `rollback` return generated PowerShell
|
||||
commands and `would_mutate=false`.
|
||||
|
||||
With `--execute-local`, execution is allowed only on a Windows host and only
|
||||
after explicit confirmation. On non-Windows hosts the executor fails closed.
|
||||
|
||||
## Windows Firewall guardrails
|
||||
|
||||
- `management_allowlist` is mandatory.
|
||||
- `blocked_remote_addresses` must be explicit IPs/subnets.
|
||||
- Broad block targets such as `Any`, `*`, `LocalSubnet`, `Internet`,
|
||||
`Intranet` are refused.
|
||||
- The executor does not change Windows Firewall profile defaults.
|
||||
- The executor does not disable interfaces, routes, users, services or
|
||||
processes.
|
||||
- Every plan includes rollback through `Remove-NetFirewallRule -Group ...`.
|
||||
- A successful dry-run is not evidence that the workstation has been isolated.
|
||||
@@ -0,0 +1,813 @@
|
||||
# Low-cost Sigma/Hayabusa/Velociraptor containment addon
|
||||
|
||||
Дата: 2026-06-25.
|
||||
|
||||
Цель: добавить в AWatch-rus дешевый, воспроизводимый и отключаемый слой
|
||||
security containment + forensics для организаций без зрелого SIEM/EDR. Главный
|
||||
смысл модуля - быстро ограничить дальнейшее распространение заражения или
|
||||
подозрительной активности с рабочей станции, сохранив управляемый канал
|
||||
расследования и восстановления.
|
||||
|
||||
Это дополнение не делает AWatch-rus сертифицированной DLP/SIEM/EDR/XDR/СЗИ и
|
||||
не заменяет штатные средства защиты. Автоматическая блокировка здесь означает
|
||||
policy-approved containment/quarantine, а не автоматическое лечение системы.
|
||||
|
||||
## Upstream basis
|
||||
|
||||
- Hayabusa: fast Windows event log forensics timeline generator and threat
|
||||
hunting tool, written in Rust, using Sigma-compatible Hayabusa rules.
|
||||
- Hayabusa supports single-host/live analysis, offline analysis of collected
|
||||
logs, and enterprise-wide use through a Velociraptor artifact.
|
||||
- Hayabusa outputs timeline/results suitable for CSV, JSON/JSONL and HTML
|
||||
reports.
|
||||
- `Windows.Hayabusa.Monitoring` in Velociraptor Curated Sigma is an artifact
|
||||
intended to triage a Windows host and is based on `Windows.Sigma.BaseEvents`.
|
||||
- Velociraptor is an endpoint visibility and collection tool using VQL
|
||||
artifacts. Its normal deployment is server + clients, but it also supports
|
||||
offline collectors and command-line artifact execution.
|
||||
|
||||
Primary references:
|
||||
|
||||
- https://github.com/Yamato-Security/hayabusa
|
||||
- https://github.com/Yamato-Security/hayabusa/wiki/About-Hayabusa
|
||||
- https://github.com/Yamato-Security/hayabusa-rules
|
||||
- https://sigma.velocidex.com/docs/artifacts/windows.hayabusa.monitoring/
|
||||
- https://github.com/Velocidex/velociraptor
|
||||
- https://docs.velociraptor.app/docs/deployment/
|
||||
|
||||
## Product positioning
|
||||
|
||||
Рабочее название модуля:
|
||||
|
||||
```text
|
||||
AWatch-rus Low-Cost Containment Pack
|
||||
```
|
||||
|
||||
Назначение:
|
||||
|
||||
- быстро получить полезный containment + DFIR/threat-hunting слой там, где
|
||||
нет SIEM/EDR;
|
||||
- автоматически или полуавтоматически изолировать подозрительно зараженную
|
||||
рабочую станцию от критичных сегментов;
|
||||
- сохранить минимальный управляемый канал: AWatch-rus/Velociraptor server,
|
||||
администраторский jump/VPN, DNS/NTP при необходимости;
|
||||
- запускать Hayabusa/Sigma-анализ EVTX и Velociraptor artifact collection;
|
||||
- давать владельцу и администратору понятные findings, timeline и evidence;
|
||||
- связывать findings с AWatch-rus cases и operator/forensics views;
|
||||
- оставаться optional и выключаемым без деградации Workforce core.
|
||||
|
||||
Запрещенные claims:
|
||||
|
||||
- не писать, что это SIEM replacement;
|
||||
- не писать, что это DLP replacement;
|
||||
- не писать, что это EDR/XDR;
|
||||
- не писать, что это сертифицированная СЗИ;
|
||||
- не писать, что автоматическое remediation включено;
|
||||
- не писать, что automatic containment гарантированно остановит заражение;
|
||||
- не писать, что threat detection ML/LLM-based;
|
||||
- не писать, что найденные события являются доказанной атакой без ручной
|
||||
проверки.
|
||||
|
||||
Допустимая формулировка:
|
||||
|
||||
```text
|
||||
Optional low-cost containment, security analytics and forensics layer based on
|
||||
open-source Hayabusa/Sigma/Velociraptor workflows.
|
||||
```
|
||||
|
||||
## Containment objective
|
||||
|
||||
Модуль должен отвечать на вопрос:
|
||||
|
||||
```text
|
||||
Как максимально быстро ограничить рабочую станцию, которая выглядит зараженной,
|
||||
чтобы она не заражала соседние машины и не продолжала утечку/распространение?
|
||||
```
|
||||
|
||||
Необходимо разделять:
|
||||
|
||||
- `suspected_infected` - есть правила/сигналы/аномалии, достаточные для
|
||||
карантина по политике организации;
|
||||
- `confirmed_infected` - есть ручное подтверждение администратора/ИБ;
|
||||
- `contained` - станция технически ограничена;
|
||||
- `released` - карантин снят вручную или по документированному rollback.
|
||||
|
||||
Containment actions должны быть обратимыми, журналируемыми и ограниченными по
|
||||
blast radius. По умолчанию допускается `shadow` или `manual_approval`; fully
|
||||
automatic quarantine включается только отдельным флагом и только после
|
||||
allowlist/rollback проверки.
|
||||
|
||||
## Architecture
|
||||
|
||||
### Modes
|
||||
|
||||
1. `disabled`
|
||||
- default для conservative deployment;
|
||||
- все readiness checks возвращают disabled-state;
|
||||
- Workforce/ActivityWatch core не зависит от модуля.
|
||||
|
||||
2. `hayabusa_offline`
|
||||
- текущий базовый режим;
|
||||
- Windows scheduled task экспортирует EVTX zip;
|
||||
- серверный `aw-hayabusa-drop.path` принимает package;
|
||||
- `aw-hayabusa-autoprocess` валидирует zip, process-inbox, quarantine.
|
||||
|
||||
3. `velociraptor_offline_collector`
|
||||
- для бедных/малых контуров без постоянно работающего Velociraptor server;
|
||||
- AWatch-rus собирает/хранит signed offline collector bundle;
|
||||
- запуск collector выполняется вручную или scheduled task;
|
||||
- результаты импортируются как artifact bundle.
|
||||
|
||||
4. `velociraptor_server_clients`
|
||||
- optional managed mode;
|
||||
- Linux server рядом с AW/Proxmox или отдельной VM;
|
||||
- Windows clients ставятся только явным Ansible-флагом;
|
||||
- используется для управляемого запуска `Windows.Hayabusa.Monitoring`.
|
||||
|
||||
5. `containment_shadow`
|
||||
- decision engine считает, что сделал бы, но ничего не блокирует;
|
||||
- безопасный default для пилота;
|
||||
- используется для настройки правил и false-positive анализа.
|
||||
|
||||
6. `containment_manual_approval`
|
||||
- система формирует containment recommendation;
|
||||
- администратор подтверждает действие в CLI/портале;
|
||||
- все действия пишутся в audit trail.
|
||||
|
||||
7. `containment_auto`
|
||||
- система сама применяет заранее разрешенные quarantine-действия;
|
||||
- включается только явным флагом;
|
||||
- требует allowlist, rollback TTL и проверку сохранения admin channel.
|
||||
|
||||
### Boundaries
|
||||
|
||||
Core remains:
|
||||
|
||||
- ActivityWatch server;
|
||||
- Workforce reports;
|
||||
- RDP/window/AFK/worktime collectors;
|
||||
- 1C/ClickHouse analytics;
|
||||
- portal health/readiness;
|
||||
- Hayabusa drop quarantine hardening.
|
||||
|
||||
Optional containment/forensics layer:
|
||||
|
||||
- Hayabusa binary and rules;
|
||||
- Sigma/Hayabusa curated rules cache;
|
||||
- Velociraptor binary/config/artifacts;
|
||||
- Velociraptor clients/offline collectors;
|
||||
- artifact result import;
|
||||
- findings summary and case links;
|
||||
- containment decision engine;
|
||||
- containment executor for approved channels.
|
||||
|
||||
Containment channels:
|
||||
|
||||
- Windows host firewall quarantine:
|
||||
allow only AWatch-rus/Velociraptor server, DNS/NTP if required, and admin
|
||||
jump/VPN;
|
||||
- pfSense/network gateway block:
|
||||
block workstation IP/MAC from lateral/internal segments, keep management
|
||||
exception;
|
||||
- switch/VLAN quarantine when supported:
|
||||
move port/client to quarantine VLAN through explicit integration;
|
||||
- Windows local containment:
|
||||
stop risky shares/services, disable outbound SMB/RDP to peers, collect
|
||||
evidence;
|
||||
- Active Directory actions, if configured:
|
||||
disable only the workstation account or user session by policy, never broad
|
||||
OU/domain actions by default.
|
||||
|
||||
Non-goals:
|
||||
|
||||
- deleting malware;
|
||||
- cleaning registry/files;
|
||||
- killing arbitrary processes based on weak signal;
|
||||
- disabling domain-wide accounts;
|
||||
- blocking servers/shared infrastructure automatically;
|
||||
- hiding the host from administrators.
|
||||
|
||||
No hot-path dependency:
|
||||
|
||||
- portal first screen must not wait for Velociraptor;
|
||||
- Workforce reports must not query Velociraptor;
|
||||
- readiness must not fail when module is disabled;
|
||||
- heavy artifact execution must be timer/manual/background only.
|
||||
|
||||
## Proposed configuration
|
||||
|
||||
Ansible group vars:
|
||||
|
||||
```yaml
|
||||
aw_forensics_pack_enabled: false
|
||||
aw_hayabusa_enabled: true
|
||||
aw_hayabusa_rules_enabled: true
|
||||
aw_hayabusa_rules_version: "pinned"
|
||||
aw_hayabusa_rules_update_enabled: false
|
||||
|
||||
aw_velociraptor_enabled: false
|
||||
aw_velociraptor_mode: "disabled" # disabled|offline_collector|server_clients
|
||||
aw_velociraptor_version: "pinned"
|
||||
aw_velociraptor_server_bind_host: "127.0.0.1"
|
||||
aw_velociraptor_public_enabled: false
|
||||
aw_velociraptor_artifact_pack_enabled: true
|
||||
aw_velociraptor_hayabusa_artifact_enabled: true
|
||||
|
||||
aw_forensics_store_raw_artifacts: false
|
||||
aw_forensics_raw_retention_days: 7
|
||||
aw_forensics_result_retention_days: 90
|
||||
aw_forensics_max_parallel_jobs: 1
|
||||
aw_forensics_max_job_minutes: 30
|
||||
aw_forensics_cpu_quota_pct: 25
|
||||
aw_forensics_io_nice: true
|
||||
|
||||
aw_containment_enabled: false
|
||||
aw_containment_mode: "shadow" # shadow|manual_approval|auto
|
||||
aw_containment_default_ttl_minutes: 60
|
||||
aw_containment_require_admin_channel_check: true
|
||||
aw_containment_allow_auto_for_servers: false
|
||||
aw_containment_allowed_actions:
|
||||
- windows_firewall_quarantine
|
||||
- pfsense_host_block
|
||||
aw_containment_management_allowlist:
|
||||
- "aw_server"
|
||||
- "velociraptor_server"
|
||||
- "admin_jump_host"
|
||||
```
|
||||
|
||||
Runtime env:
|
||||
|
||||
```text
|
||||
AW_FORENSICS_PACK_ENABLED=false
|
||||
AW_HAYABUSA_ENABLED=true
|
||||
AW_VELOCIRAPTOR_ENABLED=false
|
||||
AW_VELOCIRAPTOR_MODE=disabled
|
||||
AW_FORENSICS_STORE_RAW_ARTIFACTS=false
|
||||
AW_CONTAINMENT_ENABLED=false
|
||||
AW_CONTAINMENT_MODE=shadow
|
||||
```
|
||||
|
||||
## Data flow
|
||||
|
||||
### Existing Hayabusa path
|
||||
|
||||
```text
|
||||
Windows EVTX export
|
||||
-> zip + sidecars
|
||||
-> /opt/activitywatch/aw-rus-ops/drop
|
||||
-> aw-hayabusa-autoprocess
|
||||
-> validate package
|
||||
-> accept/process-inbox
|
||||
-> result_dir/latest-intake.json
|
||||
-> case link / portal summary
|
||||
-> quarantine on bad package
|
||||
```
|
||||
|
||||
### New Velociraptor path
|
||||
|
||||
```text
|
||||
Velociraptor artifact run
|
||||
-> Windows.Hayabusa.Monitoring / custom artifact
|
||||
-> Velociraptor result export
|
||||
-> AWatch-rus import directory
|
||||
-> schema validation
|
||||
-> derived findings JSON/SQLite
|
||||
-> optional case link
|
||||
-> portal forensics summary
|
||||
```
|
||||
|
||||
### Containment path
|
||||
|
||||
```text
|
||||
Finding/signals
|
||||
-> confidence and policy evaluation
|
||||
-> containment decision record
|
||||
-> admin-channel precheck
|
||||
-> shadow/manual/auto execution
|
||||
-> verify containment
|
||||
-> case/audit record
|
||||
-> TTL/rollback queue
|
||||
```
|
||||
|
||||
Raw artifacts and derived results must be separated:
|
||||
|
||||
- raw EVTX/result bundles: restricted evidence storage;
|
||||
- derived findings: sanitized AWatch-rus views;
|
||||
- operator notes/case links: case database;
|
||||
- public/demo exports: no raw hostnames, users, IPs, paths or secrets.
|
||||
|
||||
## Security and privacy guardrails
|
||||
|
||||
- Store no secrets in repo, docs, demo data or screenshots.
|
||||
- Do not commit generated Velociraptor config with private keys/client secrets.
|
||||
- Do not expose Velociraptor GUI publicly by default.
|
||||
- Default server bind should be loopback or private VPN-only address.
|
||||
- Require explicit operator action for client deployment.
|
||||
- Require retention policy for raw artifacts.
|
||||
- Require redaction for export/demo packs.
|
||||
- Require audit log for artifact imports, deletes and case links.
|
||||
- Treat Velociraptor outputs as untrusted input: validate schema, size, paths
|
||||
and timestamps before import.
|
||||
- Never execute arbitrary downloaded artifacts without pinning/checksums.
|
||||
- Never run containment if management channel would be lost.
|
||||
- Never auto-contain servers unless explicitly allowed and tested.
|
||||
- Always create rollback record before applying a block.
|
||||
- Always include TTL or manual release path.
|
||||
- Always log who/what triggered containment, which signals were used and which
|
||||
network paths remain allowed.
|
||||
|
||||
## Containment decision model
|
||||
|
||||
Inputs:
|
||||
|
||||
- high/critical Hayabusa/Sigma rule hits;
|
||||
- suspicious Windows event sequence from Velociraptor artifact;
|
||||
- AWatch-rus endpoint signals such as mass file changes, unusual process/file
|
||||
behavior, DLP/security signal spikes;
|
||||
- administrator manual flag.
|
||||
|
||||
Decision fields:
|
||||
|
||||
```json
|
||||
{
|
||||
"host": "HOST",
|
||||
"host_role": "workstation",
|
||||
"state": "suspected_infected",
|
||||
"confidence": "medium|high|critical",
|
||||
"signals": ["hayabusa:rule-id", "velociraptor:artifact"],
|
||||
"recommended_action": "windows_firewall_quarantine",
|
||||
"mode": "shadow|manual_approval|auto",
|
||||
"ttl_minutes": 60,
|
||||
"management_channel_checked": true,
|
||||
"rollback_plan_id": "opaque-id"
|
||||
}
|
||||
```
|
||||
|
||||
Minimum threshold for automatic quarantine:
|
||||
|
||||
- host role is workstation;
|
||||
- host is not in denylist of critical infrastructure;
|
||||
- at least one critical signal or multiple high-confidence signals;
|
||||
- management channel precheck passed;
|
||||
- containment action is in allowlist;
|
||||
- rollback record successfully written.
|
||||
|
||||
## Current implementation status
|
||||
|
||||
Implemented first safe layer:
|
||||
|
||||
- Rust CLI `containment-engine`;
|
||||
- strict JSON parsing for policy/finding input;
|
||||
- example files:
|
||||
`configs/containment-policy.example.json`,
|
||||
`configs/containment-finding.example.json`,
|
||||
`configs/windows-firewall-containment-request.example.json`;
|
||||
- disabled-by-default Ansible/env configuration;
|
||||
- `shadow`, `manual_approval` and `auto` decision states;
|
||||
- automatic containment refused for non-workstation roles by default;
|
||||
- `would_mutate=false` in current implementation;
|
||||
- Windows Firewall executor interface:
|
||||
`plan`, `apply`, `verify`, `rollback`;
|
||||
- Windows Firewall dry-run generates PowerShell `New-NetFirewallRule`,
|
||||
`Get-NetFirewallRule` and `Remove-NetFirewallRule` commands;
|
||||
- Windows Firewall execution is fail-closed without explicit confirmation and
|
||||
`--execute-local`;
|
||||
- Security Finding Inbox:
|
||||
ClickHouse schema, Rust ingest CLI, Hayabusa/Velociraptor source adapters,
|
||||
portal page `Подозрительные станции` and separate executor process for
|
||||
approved `apply_requested` workflow;
|
||||
- smoke script:
|
||||
`bash scripts/containment_shadow_smoke.sh`;
|
||||
- operator/policy docs:
|
||||
`docs/CONTAINMENT_OPERATOR_RUNBOOK_RU.md`,
|
||||
`docs/CONTAINMENT_POLICY_RU.md`.
|
||||
|
||||
Not implemented yet:
|
||||
|
||||
- production-verified Windows Firewall mutation on lab/real workstations;
|
||||
- real pfSense alias/table mutation;
|
||||
- AD/VLAN executor;
|
||||
- TTL rollback service;
|
||||
- portal containment action execution. The current portal records workflow
|
||||
events only and does not mutate firewall/network state; mutation is reserved
|
||||
for `security-finding-inbox executor` with explicit local Windows
|
||||
confirmation.
|
||||
|
||||
## Codex implementation plan
|
||||
|
||||
### Phase 0. Architecture and docs only
|
||||
|
||||
Files:
|
||||
|
||||
- `docs/LOW_COST_SIGMA_HAYABUSA_VELOCIRAPTOR_ADDON_RU.md`;
|
||||
- `docs/PROJECT_STATUS_RU.md`;
|
||||
- `docs/REGISTRY_FUNCTIONAL_SCOPE_RU.md`;
|
||||
- `README.md`.
|
||||
|
||||
Tasks:
|
||||
|
||||
- record addon scope and non-goals;
|
||||
- document upstream references and license/supply-chain review requirement;
|
||||
- state that module is planned/optional until implemented;
|
||||
- keep forbidden SIEM/DLP/СЗИ claims blocked.
|
||||
|
||||
Acceptance:
|
||||
|
||||
- docs mention optional low-cost containment/forensics layer;
|
||||
- no runtime/API/UI/product code change;
|
||||
- secret scan and diff check pass.
|
||||
|
||||
### Phase 1. Inventory current Hayabusa implementation
|
||||
|
||||
Files:
|
||||
|
||||
- `aw-server/hayabusa/README.md`;
|
||||
- `aw-server/hayabusa/aw-hayabusa.sh`;
|
||||
- `adk-rust/crates/hayabusa-tools/`;
|
||||
- `windows/export-evtx-for-hayabusa.ps1`;
|
||||
- `windows/export-upload-hayabusa-to-aw-server.ps1`;
|
||||
- `ansible/deploy_aw_server.yml`;
|
||||
- `ansible/deploy_aw_windows.yml`.
|
||||
|
||||
Tasks:
|
||||
|
||||
- document installed binaries, units, timers, directories and retention;
|
||||
- verify current drop/inbox/quarantine behavior;
|
||||
- add a manifest file for current Hayabusa server bundle;
|
||||
- add a read-only status command if missing.
|
||||
|
||||
Acceptance:
|
||||
|
||||
- `aw-hayabusa doctor` remains green;
|
||||
- bad zip quarantine behavior remains intact;
|
||||
- no change to DLP disabled runtime state.
|
||||
|
||||
### Phase 2. Supply-chain manifest and pinned downloads
|
||||
|
||||
New files:
|
||||
|
||||
- `third_party/forensics/manifest.json`;
|
||||
- `scripts/prepare_forensics_binaries.sh`;
|
||||
- `docs/FORENSICS_SUPPLY_CHAIN_RU.md`.
|
||||
|
||||
Tasks:
|
||||
|
||||
- define pinned versions for Hayabusa, Hayabusa rules and Velociraptor;
|
||||
- define SHA256 checksums and source URLs;
|
||||
- support offline cache directory;
|
||||
- fail closed if checksum mismatch;
|
||||
- never auto-update rules in production unless explicitly enabled.
|
||||
|
||||
Acceptance:
|
||||
|
||||
- dry-run prints planned downloads only;
|
||||
- checksum verification works on cached fixture;
|
||||
- no network required for deploy when cache exists.
|
||||
|
||||
### Phase 3. Optional Velociraptor server install
|
||||
|
||||
New/changed files:
|
||||
|
||||
- `ansible/group_vars/all.yml`;
|
||||
- `ansible/group_vars/all.example.yml`;
|
||||
- `ansible/deploy_aw_server.yml`;
|
||||
- `ops/systemd/velociraptor.service`;
|
||||
- `docs/VELOCIRAPTOR_DEPLOYMENT_RU.md`.
|
||||
|
||||
Tasks:
|
||||
|
||||
- add `aw_velociraptor_enabled=false` default;
|
||||
- install Velociraptor binary only when enabled;
|
||||
- generate config only on target host, not in repo;
|
||||
- bind to loopback/private address by default;
|
||||
- store datastore under `/var/lib/velociraptor`;
|
||||
- store config under `/etc/velociraptor`;
|
||||
- add systemd service with resource limits;
|
||||
- avoid public exposure unless explicitly configured.
|
||||
|
||||
Acceptance:
|
||||
|
||||
- disabled mode creates no running service;
|
||||
- enabled mode installs service and returns local health;
|
||||
- generated config is not committed;
|
||||
- Ansible syntax check passes.
|
||||
|
||||
### Phase 4. Velociraptor client/offline collector packaging
|
||||
|
||||
Files:
|
||||
|
||||
- `ansible/deploy_aw_windows.yml`;
|
||||
- `windows/ActivityWatch.Windows.Common.psm1`;
|
||||
- `windows/validate-deployment.ps1`;
|
||||
- optional `windows/install-velociraptor-client.ps1`.
|
||||
|
||||
Tasks:
|
||||
|
||||
- add explicit deployment mode:
|
||||
`disabled|offline_collector|client_service`;
|
||||
- package client installer/offline collector from pinned binary/config;
|
||||
- install client service only when explicitly enabled;
|
||||
- keep scheduled/manual offline collector for low-cost mode;
|
||||
- log to `C:\ProgramData\AWatch-rus\logs\velociraptor-*.log`;
|
||||
- include service/task checks in validation only when enabled.
|
||||
|
||||
Acceptance:
|
||||
|
||||
- disabled mode leaves Windows host untouched;
|
||||
- offline collector can run and produce an export bundle;
|
||||
- service mode reports healthy enrollment without exposing credentials.
|
||||
|
||||
### Phase 5. Hayabusa/Sigma artifact integration
|
||||
|
||||
Files:
|
||||
|
||||
- `third_party/forensics/artifacts/`;
|
||||
- `scripts/import_velociraptor_artifact_pack.sh`;
|
||||
- `docs/HAYABUSA_SIGMA_RULES_RU.md`.
|
||||
|
||||
Tasks:
|
||||
|
||||
- import/prepare `Windows.Hayabusa.Monitoring` artifact pack;
|
||||
- document mapping to Hayabusa rules;
|
||||
- create curated profile:
|
||||
`low-cost-default`, `incident`, `full`;
|
||||
- add noisy-rule tuning file;
|
||||
- require version metadata in every run.
|
||||
|
||||
Acceptance:
|
||||
|
||||
- artifact pack import is reproducible;
|
||||
- rules profile can be listed without running collection;
|
||||
- config supports small-host low-resource default.
|
||||
|
||||
### Phase 6. AWatch-rus result import
|
||||
|
||||
Prefer Rust.
|
||||
|
||||
New crate or extension:
|
||||
|
||||
- `adk-rust/crates/forensics-importer`;
|
||||
or extend `adk-rust/crates/hayabusa-tools`.
|
||||
|
||||
Tasks:
|
||||
|
||||
- import Hayabusa JSON/JSONL/CSV summary;
|
||||
- import Velociraptor artifact result export;
|
||||
- normalize to derived finding schema:
|
||||
`source`, `host`, `time`, `rule`, `level`, `mitre`, `summary`,
|
||||
`evidence_ref`, `case_id`, `tool_version`, `rules_version`;
|
||||
- reject oversized, malformed and path-traversal payloads;
|
||||
- write derived SQLite/JSON under `/var/lib/activitywatch/forensics`;
|
||||
- do not copy raw artifacts unless `AW_FORENSICS_STORE_RAW_ARTIFACTS=true`.
|
||||
|
||||
Acceptance:
|
||||
|
||||
- unit tests cover malformed JSON, oversized file, path traversal, empty result;
|
||||
- fixture import produces stable output;
|
||||
- raw-sensitive data is not rendered in default portal view.
|
||||
|
||||
### Phase 7. Containment control plane
|
||||
|
||||
Prefer Rust.
|
||||
|
||||
New crate or extension:
|
||||
|
||||
- `adk-rust/crates/containment-engine`;
|
||||
or extend `adk-rust/crates/forensics-importer` with a separate module.
|
||||
|
||||
Tasks:
|
||||
|
||||
- define containment decision schema and audit log;
|
||||
- add policy file:
|
||||
`/etc/activitywatch/containment-policy.json`;
|
||||
- add host role model:
|
||||
`workstation|server|domain_controller|unknown`;
|
||||
- add safe defaults:
|
||||
`enabled=false`, `mode=shadow`, server auto-containment disabled;
|
||||
- implement decision evaluation from imported findings;
|
||||
- implement dry-run/shadow output;
|
||||
- implement manual approval queue;
|
||||
- implement rollback record format.
|
||||
|
||||
Acceptance:
|
||||
|
||||
- unit tests cover workstation/server/unknown host roles;
|
||||
- automatic action is refused for server/unknown role by default;
|
||||
- no action runs if management channel precheck fails;
|
||||
- shadow mode produces audit record and does not mutate host/network.
|
||||
|
||||
### Phase 8. Containment executors
|
||||
|
||||
Executor targets:
|
||||
|
||||
- Windows firewall quarantine through PowerShell/Rust Windows helper;
|
||||
- pfSense alias/table block through explicit API/SSH integration;
|
||||
- optional switch/VLAN integration only behind feature flag.
|
||||
|
||||
Tasks:
|
||||
|
||||
- implement executor interface:
|
||||
`plan`, `apply`, `verify`, `rollback`;
|
||||
- first implemented executor: Windows Firewall explicit management allowlist
|
||||
plus explicit block ranges, without broad `Any`/`LocalSubnet` block and
|
||||
without default firewall profile changes;
|
||||
- apply pfSense host block using IP/MAC only after current lease/identity
|
||||
verification;
|
||||
- store rollback before mutation;
|
||||
- add TTL-based rollback timer;
|
||||
- add emergency release command.
|
||||
|
||||
Acceptance:
|
||||
|
||||
- fixture mode shows exact firewall/pfSense plan;
|
||||
- apply refuses empty allowlist;
|
||||
- verify confirms blocked lateral path and allowed management path;
|
||||
- rollback restores previous rules;
|
||||
- logs contain no secrets.
|
||||
|
||||
### Phase 9. Portal and API integration
|
||||
|
||||
Files:
|
||||
|
||||
- `adk-rust/crates/detmir-portal/`;
|
||||
- `docs/PORTAL_API_CONTRACTS_RU.md`;
|
||||
- `docs/DETMIR_CURRENT_STATE_RU.md`.
|
||||
|
||||
Tasks:
|
||||
|
||||
- add optional forensics module state:
|
||||
`disabled|not_configured|ready|degraded`;
|
||||
- show derived findings count, latest run, severity histogram;
|
||||
- show containment state:
|
||||
`disabled|shadow|recommended|contained|rollback_pending|released`;
|
||||
- show clear action buttons only for authorized admin/security roles;
|
||||
- link to case/evidence only by opaque ID;
|
||||
- do not block Workforce first screen;
|
||||
- do not include raw artifacts in frontend payload.
|
||||
|
||||
Acceptance:
|
||||
|
||||
- with module disabled, portal shows disabled-state and remains fast;
|
||||
- with fixture findings, portal renders summary;
|
||||
- with fixture containment recommendation, portal renders action state without
|
||||
applying action;
|
||||
- Playwright smoke confirms no endless loading and no raw sensitive fields.
|
||||
|
||||
### Phase 10. Health/readiness/checks
|
||||
|
||||
Files:
|
||||
|
||||
- `adk-rust/crates/detmir-check/`;
|
||||
- `adk-rust/crates/detmir-readiness/`;
|
||||
- `scripts/detmir-full-diagnostics/aw-contour-diag.sh`;
|
||||
- `scripts/aw-contour-diag.sh`;
|
||||
- `check-aw-full.sh`.
|
||||
|
||||
Tasks:
|
||||
|
||||
- add optional forensics status checks;
|
||||
- disabled mode must be OK/Skipped, not fail;
|
||||
- add optional containment status checks;
|
||||
- enabled mode checks:
|
||||
Velociraptor service, artifact pack, latest run age, importer health,
|
||||
queue/quarantine counts, containment executor health;
|
||||
- add resource pressure checks for long-running scans.
|
||||
|
||||
Acceptance:
|
||||
|
||||
- disabled mode produces `forensics:mode=disabled`;
|
||||
- disabled containment mode produces `containment:mode=disabled`;
|
||||
- enabled mode fails closed on stale/broken artifact importer;
|
||||
- containment auto mode fails closed if rollback store or admin-channel precheck
|
||||
is unavailable;
|
||||
- checks do not restart services unless explicit autoheal mode exists.
|
||||
|
||||
### Phase 11. Runtime safety and resource budgets
|
||||
|
||||
Files:
|
||||
|
||||
- systemd units/timers;
|
||||
- Ansible vars;
|
||||
- docs runbooks.
|
||||
|
||||
Tasks:
|
||||
|
||||
- enforce `Nice`, `IOSchedulingClass`, CPU quota and timeout for heavy scans;
|
||||
- serialize jobs through lock file;
|
||||
- add cancellation/timeout behavior;
|
||||
- quarantine failed artifact runs;
|
||||
- keep `aw-server-rust`, worktime API, ClickHouse and portal out of the scan
|
||||
critical path.
|
||||
- enforce containment mutation lock so two block/unblock actions cannot race.
|
||||
|
||||
Acceptance:
|
||||
|
||||
- two concurrent scan requests do not run two heavy jobs;
|
||||
- timeout leaves a clear failed run record;
|
||||
- core health remains green under disabled mode.
|
||||
- rollback timer is tested and idempotent.
|
||||
|
||||
### Phase 12. Documentation and operator runbooks
|
||||
|
||||
New docs:
|
||||
|
||||
- `docs/VELOCIRAPTOR_DEPLOYMENT_RU.md`;
|
||||
- `docs/FORENSICS_SUPPLY_CHAIN_RU.md`;
|
||||
- `docs/FORENSICS_OPERATOR_RUNBOOK_RU.md`;
|
||||
- `docs/FORENSICS_RETENTION_POLICY_RU.md`;
|
||||
- `docs/FORENSICS_PRIVACY_GUARDRAILS_RU.md`.
|
||||
- `docs/CONTAINMENT_OPERATOR_RUNBOOK_RU.md`;
|
||||
- `docs/CONTAINMENT_POLICY_RU.md`.
|
||||
|
||||
Tasks:
|
||||
|
||||
- describe installation modes;
|
||||
- describe offline collector workflow;
|
||||
- describe artifact run, import, case link and cleanup;
|
||||
- describe forbidden data in screenshots/demo packs;
|
||||
- document rollback and disable commands.
|
||||
- describe quarantine policy, management allowlist, manual approval, emergency
|
||||
release and TTL rollback.
|
||||
|
||||
Acceptance:
|
||||
|
||||
- admin can install disabled/offline/server modes from docs;
|
||||
- admin can test shadow containment safely before auto mode;
|
||||
- docs clearly say GitHub/public demo is not evidence storage;
|
||||
- no claim of SIEM/DLP/EDR/СЗИ replacement.
|
||||
|
||||
### Phase 13. Tests and gates
|
||||
|
||||
Required checks:
|
||||
|
||||
```bash
|
||||
python3 scripts/public_secret_pattern_check.py
|
||||
bash -n scripts/prepare_forensics_binaries.sh
|
||||
ansible-playbook -i ansible/inventory.ini ansible/deploy_aw_server.yml --syntax-check
|
||||
ansible-playbook -i ansible/inventory.ini ansible/deploy_aw_windows.yml --syntax-check
|
||||
|
||||
cd adk-rust
|
||||
export CARGO_TARGET_DIR=/home/igor/.cache/detmir-adk-rust-target
|
||||
cargo fmt --all --check
|
||||
cargo test -p hayabusa-tools
|
||||
cargo test -p forensics-importer
|
||||
cargo test -p containment-engine
|
||||
cargo clippy -p hayabusa-tools -p forensics-importer -p containment-engine --all-targets -- -D warnings
|
||||
|
||||
cd ..
|
||||
git diff --check
|
||||
```
|
||||
|
||||
Manual/live checks:
|
||||
|
||||
- disabled mode on clean install;
|
||||
- Hayabusa current drop-zone smoke;
|
||||
- Velociraptor offline collector fixture run;
|
||||
- Velociraptor server health if enabled;
|
||||
- containment shadow run with fixture critical finding;
|
||||
- manual approval containment in isolated lab host;
|
||||
- rollback verification;
|
||||
- portal browser smoke with module disabled and with fixture findings;
|
||||
- no public exposure of Velociraptor GUI unless explicitly configured.
|
||||
|
||||
## Codex guardrails
|
||||
|
||||
Codex must not:
|
||||
|
||||
- change Workforce core behavior while adding this module;
|
||||
- re-enable heavy DLP runtime by accident;
|
||||
- expose Velociraptor or Hayabusa outputs publicly;
|
||||
- commit generated secrets, private configs or raw evidence;
|
||||
- auto-block hosts before policy, allowlist, rollback and admin-channel checks
|
||||
exist;
|
||||
- auto-block servers/domain infrastructure by default;
|
||||
- claim completed integration before live/manual evidence exists;
|
||||
- change Rust/API/UI runtime outside the planned files without documenting why.
|
||||
|
||||
Codex should:
|
||||
|
||||
- start with docs/config disabled mode;
|
||||
- implement supply-chain pinning before service deployment;
|
||||
- prefer Rust for import/validation/parsing;
|
||||
- treat containment as a separate audited control plane, not as generic
|
||||
remediation;
|
||||
- keep PowerShell only for Windows install/run wrappers;
|
||||
- add small fixtures and negative tests before live deployment;
|
||||
- update project status after each successfully verified phase.
|
||||
|
||||
## Expected result
|
||||
|
||||
After implementation AWatch-rus should have:
|
||||
|
||||
- installed/pinned Hayabusa and rules workflow;
|
||||
- optional bundled Velociraptor server/client/offline collector modes;
|
||||
- reproducible artifact pack handling for `Windows.Hayabusa.Monitoring`;
|
||||
- derived findings importer into AWatch-rus forensics views;
|
||||
- policy-controlled automated/manual quarantine of suspected infected
|
||||
workstations;
|
||||
- rollback and emergency release path for every containment action;
|
||||
- disabled-by-default safety;
|
||||
- resource-bounded scans;
|
||||
- clear runbooks for poor/small organizations;
|
||||
- honest positioning as low-cost containment, security analytics and forensics, not
|
||||
SIEM/DLP/EDR/СЗИ.
|
||||
@@ -0,0 +1,279 @@
|
||||
# Security Finding Inbox
|
||||
|
||||
Дата: 2026-06-25.
|
||||
|
||||
Security Finding Inbox - это очередь подозрительных рабочих станций для
|
||||
связки Hayabusa/Sigma, Velociraptor, AWatch context и ручных ИБ-сигналов.
|
||||
Очередь нужна для контролируемого процесса:
|
||||
|
||||
```text
|
||||
finding -> triage -> decide -> plan -> approve -> apply_requested -> executor -> verify/rollback
|
||||
```
|
||||
|
||||
Важно: портал inbox сам не применяет Windows Firewall, pfSense, AD или VLAN
|
||||
изменения. Он фиксирует findings и workflow-события. Реальное применение
|
||||
делается отдельным процессом `security-finding-inbox executor`, который
|
||||
вызывает `containment-engine windows-firewall plan/apply/verify/rollback`.
|
||||
По умолчанию executor работает безопасно: dry-run/fail-closed, без локального
|
||||
изменения firewall.
|
||||
|
||||
## Компоненты
|
||||
|
||||
- ClickHouse schema:
|
||||
`clickhouse-1c/security/security_finding_inbox.sql`
|
||||
- normalized finding example:
|
||||
`configs/security/security-finding.example.json`
|
||||
- ingest/workflow CLI:
|
||||
`adk-rust/crates/security-finding-inbox`
|
||||
- executor CLI:
|
||||
`security-finding-inbox executor`
|
||||
- portal API:
|
||||
`/api/security/findings`
|
||||
`/api/security/findings/workflow`
|
||||
- portal page:
|
||||
`Подозрительные станции`
|
||||
|
||||
## ClickHouse tables
|
||||
|
||||
`security_findings`
|
||||
|
||||
- normalized finding records;
|
||||
- source: `hayabusa`, `sigma`, `velociraptor`, `awatch`, `manual`, `dlp`;
|
||||
- states: `new`, `suspected_infected`, `confirmed_infected`, `contained`,
|
||||
`released`, `false_positive`;
|
||||
- recommended action remains a recommendation, not a mutation.
|
||||
|
||||
`security_finding_workflow_events`
|
||||
|
||||
- append-only workflow audit;
|
||||
- event types: `decide_requested`, `plan_requested`, `approved`,
|
||||
`apply_requested`, `verify_requested`, `rollback_requested`, `rejected`,
|
||||
`false_positive`, plus executor audit events:
|
||||
`executor_plan_ready`, `executor_apply_succeeded`,
|
||||
`executor_apply_failed`, `executor_verify_succeeded`,
|
||||
`executor_verify_failed`, `executor_refused`,
|
||||
`executor_rollback_succeeded`, `executor_rollback_failed`;
|
||||
- portal writes only workflow events.
|
||||
|
||||
`security_finding_inbox`
|
||||
|
||||
- latest-state view for portal/dashboard;
|
||||
- filters released/rejected/false-positive rows out of the active queue.
|
||||
|
||||
## Ingest
|
||||
|
||||
Build:
|
||||
|
||||
```bash
|
||||
cd /mnt/usb_hdd2/Projects/ActivityWatch-Russian
|
||||
export CARGO_TARGET_DIR=/home/igor/.cache/detmir-adk-rust-target
|
||||
cargo build --manifest-path adk-rust/Cargo.toml -p security-finding-inbox
|
||||
```
|
||||
|
||||
Validate sample:
|
||||
|
||||
```bash
|
||||
security-finding-inbox validate \
|
||||
--input configs/security/security-finding.example.json
|
||||
```
|
||||
|
||||
Dry-run ingest:
|
||||
|
||||
```bash
|
||||
security-finding-inbox ingest \
|
||||
--input configs/security/security-finding.example.json \
|
||||
--dry-run
|
||||
```
|
||||
|
||||
Apply schema and ingest into ClickHouse:
|
||||
|
||||
```bash
|
||||
security-finding-inbox ingest \
|
||||
--input configs/security/security-finding.example.json \
|
||||
--clickhouse-url http://10.10.10.2:8123 \
|
||||
--database analytics_1c \
|
||||
--user "$CLICKHOUSE_USER" \
|
||||
--password "$CLICKHOUSE_PASSWORD" \
|
||||
--apply-schema
|
||||
```
|
||||
|
||||
The CLI accepts a single JSON object, JSON array, or JSONL.
|
||||
|
||||
### Real Hayabusa source
|
||||
|
||||
После `aw-hayabusa process-inbox` реальный источник находится в
|
||||
`/opt/hayabusa/state/latest-intake.json`. CLI читает `report_dir`, анализирует
|
||||
`timeline.jsonl`, logon summaries и строит normalized finding:
|
||||
|
||||
```bash
|
||||
security-finding-inbox ingest-hayabusa \
|
||||
--intake /opt/hayabusa/state/latest-intake.json \
|
||||
--min-severity medium \
|
||||
--clickhouse-url http://127.0.0.1:8123 \
|
||||
--database analytics_1c
|
||||
```
|
||||
|
||||
Для автоматического подключения Hayabusa drop/autoprocess:
|
||||
|
||||
```bash
|
||||
AW_SECURITY_FINDING_INBOX_ENABLED=true
|
||||
AW_SECURITY_FINDING_INBOX_BIN=/usr/local/bin/security-finding-inbox
|
||||
AW_SECURITY_FINDING_INBOX_MIN_SEVERITY=medium
|
||||
```
|
||||
|
||||
`AW_SECURITY_FINDING_INBOX_REQUIRED=false` оставляет forensic pipeline живым,
|
||||
если ClickHouse или inbox CLI временно недоступны. В `true`-режиме ошибка
|
||||
ingest считается operational failure.
|
||||
|
||||
### Real Velociraptor source
|
||||
|
||||
Velociraptor artifact JSON/JSONL можно загрузить через generic adapter:
|
||||
|
||||
```bash
|
||||
security-finding-inbox ingest-velociraptor-json \
|
||||
--input /path/to/velociraptor-artifact.jsonl \
|
||||
--default-severity high \
|
||||
--clickhouse-url http://127.0.0.1:8123 \
|
||||
--database analytics_1c
|
||||
```
|
||||
|
||||
Adapter ищет стандартные поля `Hostname`, `Artifact`, `Severity`, `Message`,
|
||||
`User`, `IP`. Если формат артефакта отличается, используйте normalized
|
||||
`security-finding-inbox ingest --input ...`.
|
||||
|
||||
## Portal workflow
|
||||
|
||||
Open:
|
||||
|
||||
```text
|
||||
DetMir Portal -> Подозрительные станции
|
||||
```
|
||||
|
||||
The page shows:
|
||||
|
||||
- host/user/IP/department;
|
||||
- severity/confidence/score;
|
||||
- source/rule;
|
||||
- state and latest workflow status;
|
||||
- recommended action;
|
||||
- workflow buttons.
|
||||
|
||||
Portal buttons record only workflow events:
|
||||
|
||||
- `decide`: request decision calculation;
|
||||
- `plan`: request containment plan;
|
||||
- `approve`: operator approval record;
|
||||
- `apply`: request to perform apply outside the portal;
|
||||
- `rollback`: rollback request record.
|
||||
|
||||
The portal does not run `containment-engine`, PowerShell, firewall commands or
|
||||
network changes.
|
||||
|
||||
## Executor handoff
|
||||
|
||||
Executor читает из ClickHouse только те findings, где:
|
||||
|
||||
- последний workflow event: `apply_requested`;
|
||||
- status: `apply_pending`;
|
||||
- ранее есть `approved`;
|
||||
- еще нет `executor_apply_succeeded`, `executor_apply_failed`,
|
||||
`executor_refused` или rollback terminal event.
|
||||
|
||||
Dry-run executor:
|
||||
|
||||
```bash
|
||||
security-finding-inbox executor \
|
||||
--once \
|
||||
--dry-run \
|
||||
--containment-engine-bin /usr/local/bin/containment-engine \
|
||||
--policy /etc/activitywatch/containment-policy.json \
|
||||
--management-allowlist 10.10.10.10,10.10.10.11 \
|
||||
--blocked-remote-addresses 10.10.20.0/24,10.10.30.0/24
|
||||
```
|
||||
|
||||
Linux systemd example for central dry-run/polling mode:
|
||||
|
||||
```text
|
||||
ops/systemd/aw-security-finding-executor.service
|
||||
```
|
||||
|
||||
Real local Windows apply is allowed only when all conditions are true:
|
||||
|
||||
- executor runs on the target Windows workstation;
|
||||
- `--execute-local` is set;
|
||||
- `--confirm-execute YES` is set;
|
||||
- `--executor-host` or local `COMPUTERNAME` matches finding `host`;
|
||||
- containment policy returns `manual_approval_required` or `auto_ready`;
|
||||
- management allowlist and blocked remote ranges are explicit;
|
||||
- generated Windows Firewall plan has no blockers.
|
||||
|
||||
Example on the target Windows host:
|
||||
|
||||
```powershell
|
||||
security-finding-inbox.exe executor `
|
||||
--once `
|
||||
--execute-local `
|
||||
--confirm-execute YES `
|
||||
--executor-host HOST-EXAMPLE `
|
||||
--containment-engine-bin C:\ProgramData\AWatch-rus\containment-engine.exe `
|
||||
--policy C:\ProgramData\AWatch-rus\containment-policy.json `
|
||||
--management-allowlist 10.10.10.10,10.10.10.11 `
|
||||
--blocked-remote-addresses 10.10.20.0/24,10.10.30.0/24
|
||||
```
|
||||
|
||||
Executor writes `executor_*` workflow events back into ClickHouse. It does not
|
||||
update or delete source findings.
|
||||
|
||||
## Manual containment handoff
|
||||
|
||||
After a finding is approved:
|
||||
|
||||
1. Build or review a containment policy/finding.
|
||||
2. Run:
|
||||
|
||||
```bash
|
||||
containment-engine decide \
|
||||
--policy /etc/activitywatch/containment-policy.json \
|
||||
--finding /path/to/finding.json \
|
||||
--pretty
|
||||
```
|
||||
|
||||
3. Build Windows Firewall request with explicit management allowlist.
|
||||
4. Run:
|
||||
|
||||
```bash
|
||||
containment-engine windows-firewall plan \
|
||||
--request /path/to/windows-firewall-request.json \
|
||||
--pretty > /tmp/fw-plan.json
|
||||
```
|
||||
|
||||
5. Confirm `blockers=[]`.
|
||||
6. Dry-run:
|
||||
|
||||
```bash
|
||||
containment-engine windows-firewall apply \
|
||||
--plan /tmp/fw-plan.json \
|
||||
--confirm-apply YES \
|
||||
--pretty
|
||||
```
|
||||
|
||||
7. Real apply only on the target Windows host:
|
||||
|
||||
```powershell
|
||||
containment-engine.exe windows-firewall apply `
|
||||
--plan C:\Temp\fw-plan.json `
|
||||
--confirm-apply YES `
|
||||
--execute-local `
|
||||
--pretty
|
||||
```
|
||||
|
||||
## Guardrails
|
||||
|
||||
- Do not place raw employee logs, secrets, passwords or customer identifiers in
|
||||
findings.
|
||||
- Do not treat `apply_requested` as successful containment.
|
||||
- Do not run broad `Any`/`LocalSubnet` firewall blocks.
|
||||
- Do not enable automatic action for servers/domain controllers.
|
||||
- Keep GitHub/portal evidence separate from Russian registry release evidence.
|
||||
- Keep DLP optional: Hayabusa/Velociraptor findings can continue while heavy DLP
|
||||
runtime is disabled.
|
||||
@@ -31,7 +31,7 @@ journalctl -u aw-hayabusa-drop.service -n 80 --no-pager
|
||||
curl -fsS http://127.0.0.1:5602/api/0/dlp/cases/30
|
||||
```
|
||||
|
||||
Ожидаемо: `drop` и `incoming` пустые, `latest-intake.json` имеет `status=ok`, `host=SHARKON2025`, а `LastTaskResult` Windows-задачи равен `0`.
|
||||
Ожидаемо: `drop` и `incoming` пустые, `latest-intake.json` имеет `status=ok`, `host=<stable-aw-logical-host-id>`, а `LastTaskResult` Windows-задачи равен `0`. Для текущего DetMir production historical logical id может оставаться `SHARKON2025`, даже если физический `COMPUTERNAME` RDP-сервера изменён.
|
||||
|
||||
## Что получает оператор
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
[Unit]
|
||||
Description=AWatch-rus Security Finding Inbox executor
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
EnvironmentFile=-/etc/activitywatch/aw-server.env
|
||||
ExecStart=/usr/local/bin/security-finding-inbox executor \
|
||||
--poll-seconds 30 \
|
||||
--dry-run
|
||||
Restart=on-failure
|
||||
RestartSec=10
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectSystem=full
|
||||
ProtectHome=true
|
||||
ReadWritePaths=/var/lib/activitywatch /var/lock
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
ENGINE="${CONTAINMENT_ENGINE_BIN:-}"
|
||||
POLICY="${1:-$ROOT_DIR/configs/containment-policy.example.json}"
|
||||
FINDING="${2:-$ROOT_DIR/configs/containment-finding.example.json}"
|
||||
FIREWALL_REQUEST="${3:-$ROOT_DIR/configs/windows-firewall-containment-request.example.json}"
|
||||
TMP_DIR="$(mktemp -d /tmp/containment-shadow-smoke.XXXXXX)"
|
||||
trap 'rm -rf "$TMP_DIR"' EXIT
|
||||
|
||||
if [[ -z "$ENGINE" ]]; then
|
||||
for candidate in \
|
||||
"${CARGO_TARGET_DIR:-}/debug/containment-engine" \
|
||||
"${CARGO_TARGET_DIR:-}/release/containment-engine" \
|
||||
"$ROOT_DIR/adk-rust/target/debug/containment-engine" \
|
||||
"$ROOT_DIR/adk-rust/target/release/containment-engine" \
|
||||
"/usr/local/bin/containment-engine"; do
|
||||
if [[ -n "$candidate" && -x "$candidate" ]]; then
|
||||
ENGINE="$candidate"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ -z "$ENGINE" ]]; then
|
||||
printf 'containment-engine binary not found. Build: cargo build --manifest-path adk-rust/Cargo.toml -p containment-engine\n' >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
validate_payload() {
|
||||
local expected_status="$1"
|
||||
python3 -c '
|
||||
import json
|
||||
import sys
|
||||
|
||||
expected_status = sys.argv[1]
|
||||
payload = json.load(sys.stdin)
|
||||
if payload.get("would_mutate") is not False:
|
||||
raise SystemExit("containment smoke failed: would_mutate must be false")
|
||||
status = payload.get("decision_status")
|
||||
if status != expected_status:
|
||||
raise SystemExit(f"containment smoke failed: expected {expected_status!r}, got {status!r}")
|
||||
print(f"containment_shadow_smoke=ok status={status}")
|
||||
' "$expected_status"
|
||||
}
|
||||
|
||||
disabled_out="$("$ENGINE" decide --policy "$POLICY" --finding "$FINDING" --pretty)"
|
||||
printf '%s\n' "$disabled_out"
|
||||
validate_payload "disabled" <<<"$disabled_out"
|
||||
|
||||
shadow_policy="$TMP_DIR/containment-policy-shadow.json"
|
||||
python3 - "$POLICY" "$shadow_policy" <<'PY'
|
||||
import json
|
||||
import sys
|
||||
|
||||
payload = json.load(open(sys.argv[1], encoding="utf-8"))
|
||||
payload["enabled"] = True
|
||||
payload["mode"] = "shadow"
|
||||
json.dump(payload, open(sys.argv[2], "w", encoding="utf-8"), ensure_ascii=False, indent=2)
|
||||
PY
|
||||
|
||||
shadow_out="$("$ENGINE" decide --policy "$shadow_policy" --finding "$FINDING" --pretty)"
|
||||
printf '%s\n' "$shadow_out"
|
||||
validate_payload "shadow_recommended" <<<"$shadow_out"
|
||||
|
||||
firewall_plan="$TMP_DIR/windows-firewall-plan.json"
|
||||
"$ENGINE" windows-firewall plan --request "$FIREWALL_REQUEST" --pretty >"$firewall_plan"
|
||||
cat "$firewall_plan"
|
||||
|
||||
python3 - "$firewall_plan" <<'PY'
|
||||
import json
|
||||
import sys
|
||||
|
||||
payload = json.load(open(sys.argv[1], encoding="utf-8"))
|
||||
if payload.get("executor") != "windows_firewall":
|
||||
raise SystemExit("firewall smoke failed: executor must be windows_firewall")
|
||||
if payload.get("blockers"):
|
||||
raise SystemExit(f"firewall smoke failed: unexpected blockers {payload['blockers']!r}")
|
||||
if not payload.get("apply_commands") or not payload.get("rollback_commands"):
|
||||
raise SystemExit("firewall smoke failed: apply/rollback commands must exist")
|
||||
print("windows_firewall_plan_smoke=ok")
|
||||
PY
|
||||
|
||||
firewall_apply_out="$("$ENGINE" windows-firewall apply --plan "$firewall_plan" --confirm-apply YES --pretty)"
|
||||
printf '%s\n' "$firewall_apply_out"
|
||||
|
||||
python3 -c '
|
||||
import json
|
||||
import sys
|
||||
|
||||
payload = json.load(sys.stdin)
|
||||
if payload.get("execution_status") != "dry_run_commands_ready":
|
||||
raise SystemExit("firewall apply smoke failed: expected dry_run_commands_ready")
|
||||
if payload.get("would_mutate") is not False:
|
||||
raise SystemExit("firewall apply smoke failed: dry-run must not mutate")
|
||||
print("windows_firewall_apply_dry_run_smoke=ok")
|
||||
' <<<"$firewall_apply_out"
|
||||
@@ -0,0 +1,110 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
BIN="${SECURITY_FINDING_INBOX_BIN:-}"
|
||||
SAMPLE="${1:-$ROOT_DIR/configs/security/security-finding.example.json}"
|
||||
TMP_DIR="$(mktemp -d /tmp/security-finding-inbox-smoke.XXXXXX)"
|
||||
trap 'rm -rf "$TMP_DIR"' EXIT
|
||||
|
||||
if [[ -z "$BIN" ]]; then
|
||||
for candidate in \
|
||||
"${CARGO_TARGET_DIR:-}/debug/security-finding-inbox" \
|
||||
"${CARGO_TARGET_DIR:-}/release/security-finding-inbox" \
|
||||
"$ROOT_DIR/adk-rust/target/debug/security-finding-inbox" \
|
||||
"$ROOT_DIR/adk-rust/target/release/security-finding-inbox" \
|
||||
"/usr/local/bin/security-finding-inbox"; do
|
||||
if [[ -n "$candidate" && -x "$candidate" ]]; then
|
||||
BIN="$candidate"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ -z "$BIN" ]]; then
|
||||
printf 'security-finding-inbox binary not found. Build: cargo build --manifest-path adk-rust/Cargo.toml -p security-finding-inbox\n' >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
"$BIN" schema | grep -q 'CREATE TABLE IF NOT EXISTS analytics_1c.security_findings'
|
||||
"$BIN" validate --input "$SAMPLE" | python3 -c '
|
||||
import json
|
||||
import sys
|
||||
payload = json.load(sys.stdin)
|
||||
assert payload["ok"] is True
|
||||
assert payload["rows"] == 1
|
||||
assert payload["finding_ids"][0].startswith("sf-")
|
||||
print("security_finding_validate=ok")
|
||||
'
|
||||
|
||||
"$BIN" ingest --input "$SAMPLE" --dry-run | python3 -c '
|
||||
import json
|
||||
import sys
|
||||
payload = json.load(sys.stdin)
|
||||
assert payload["ok"] is True
|
||||
assert payload["dry_run"] is True
|
||||
assert payload["rows"] == 1
|
||||
print("security_finding_ingest_dry_run=ok")
|
||||
'
|
||||
|
||||
mkdir -p "$TMP_DIR/hayabusa-report"
|
||||
cat >"$TMP_DIR/hayabusa-report/timeline.jsonl" <<'EOF'
|
||||
{"Level":"high","RuleTitle":"PowerShell Credential Dump","Timestamp":"2026-06-25T10:00:00Z"}
|
||||
{"Level":"crit","RuleTitle":"Suspicious Credential Access","Timestamp":"2026-06-25T10:01:00Z"}
|
||||
EOF
|
||||
cat >"$TMP_DIR/hayabusa-report/logon-summary-failed.csv" <<'EOF'
|
||||
header
|
||||
1
|
||||
2
|
||||
EOF
|
||||
cat >"$TMP_DIR/latest-intake.json" <<EOF
|
||||
{
|
||||
"host": "HOST-EXAMPLE",
|
||||
"status": "ok",
|
||||
"intake_id": "smoke-intake-001",
|
||||
"package_path": "$TMP_DIR/HOST-EXAMPLE.zip",
|
||||
"sha256": "demo",
|
||||
"report_dir": "$TMP_DIR/hayabusa-report"
|
||||
}
|
||||
EOF
|
||||
"$BIN" ingest-hayabusa --intake "$TMP_DIR/latest-intake.json" --min-severity low --dry-run | python3 -c '
|
||||
import json
|
||||
import sys
|
||||
payload = json.load(sys.stdin)
|
||||
assert payload["ok"] is True
|
||||
assert payload["dry_run"] is True
|
||||
assert payload["rows"] == 1
|
||||
print("security_finding_hayabusa_ingest_dry_run=ok")
|
||||
'
|
||||
|
||||
cat >"$TMP_DIR/velociraptor.jsonl" <<'EOF'
|
||||
{"Hostname":"HOST-EXAMPLE","Artifact":"Windows.Hayabusa.Monitoring","Severity":"high","Message":"Velociraptor smoke finding","User":"user-example"}
|
||||
EOF
|
||||
"$BIN" ingest-velociraptor-json --input "$TMP_DIR/velociraptor.jsonl" --dry-run | python3 -c '
|
||||
import json
|
||||
import sys
|
||||
payload = json.load(sys.stdin)
|
||||
assert payload["ok"] is True
|
||||
assert payload["dry_run"] is True
|
||||
assert payload["rows"] == 1
|
||||
print("security_finding_velociraptor_ingest_dry_run=ok")
|
||||
'
|
||||
|
||||
"$BIN" workflow \
|
||||
--finding-id sf-demo \
|
||||
--event-type approved \
|
||||
--actor smoke \
|
||||
--comment "dry-run approval" \
|
||||
--dry-run | python3 -c '
|
||||
import json
|
||||
import sys
|
||||
payload = json.load(sys.stdin)
|
||||
assert payload["ok"] is True
|
||||
assert payload["dry_run"] is True
|
||||
assert payload["event_type"] == "approved"
|
||||
print("security_finding_workflow_dry_run=ok")
|
||||
'
|
||||
|
||||
"$BIN" executor --help >/dev/null
|
||||
printenv SECURITY_FINDING_INBOX_SKIP_EXECUTOR_SMOKE >/dev/null 2>&1 || \
|
||||
printf 'security_finding_executor_cli=ok\n'
|
||||
Reference in New Issue
Block a user