@@ -482,6 +482,359 @@ cargo doc --open
482482
483483### Project Structure
484484
485+ ## 🚀 Quick Start
486+
487+ ### Run as Binary
488+
489+ ``` bash
490+ # Clone repository
491+ git clone https://github.com/vsilent/stackdog
492+ cd stackdog
493+
494+ # Build and run
495+ cargo run
496+ ```
497+
498+ ### Use as Library
499+
500+ Add to your ` Cargo.toml ` :
501+
502+ ``` toml
503+ [dependencies ]
504+ stackdog = " 0.2"
505+ ```
506+
507+ Basic usage:
508+
509+ ``` rust
510+ use stackdog :: {RuleEngine , AlertManager , ThreatScorer };
511+
512+ let mut engine = RuleEngine :: new ();
513+ let mut alerts = AlertManager :: new ()? ;
514+ let scorer = ThreatScorer :: new ();
515+
516+ // Process security events
517+ for event in events {
518+ let score = scorer . calculate_score (& event );
519+ if score . is_high_or_higher () {
520+ alerts . generate_alert (... )? ;
521+ }
522+ }
523+ ```
524+
525+ ### Docker Development
526+
527+ ``` bash
528+ # Start development environment
529+ docker-compose up -d
530+
531+ # View logs
532+ docker-compose logs -f stackdog
533+ ```
534+
535+ ---
536+
537+ ## 🏗️ Architecture
538+
539+ ```
540+ ┌─────────────────────────────────────────────────────────────────┐
541+ │ Stackdog Security Core │
542+ ├─────────────────────────────────────────────────────────────────┤
543+ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │
544+ │ │ Collectors │ │ ML/AI │ │ Response Engine │ │
545+ │ │ │ │ Engine │ │ │ │
546+ │ │ • eBPF │ │ │ │ • nftables/iptables │ │
547+ │ │ • Auditd │ │ • Anomaly │ │ • Container quarantine │ │
548+ │ │ • Docker │ │ Detection │ │ • Auto-response │ │
549+ │ │ Events │ │ • Scoring │ │ • Alerting │ │
550+ │ └─────────────┘ └─────────────┘ └─────────────────────────┘ │
551+ └─────────────────────────────────────────────────────────────────┘
552+ ```
553+
554+ ### Components
555+
556+ | Component | Description | Status |
557+ | -----------| -------------| --------|
558+ | ** Events** | Security event types & validation | ✅ Complete |
559+ | ** Rules** | Rule engine & signature detection | ✅ Complete |
560+ | ** Alerting** | Alert management & notifications | ✅ Complete |
561+ | ** Firewall** | nftables/iptables integration | ✅ Complete |
562+ | ** Collectors** | eBPF syscall monitoring | ✅ Infrastructure |
563+ | ** ML** | Candle-based anomaly detection | 🚧 In progress |
564+
565+ ---
566+
567+ ## 🎯 Features
568+
569+ ### 1. Event Collection
570+
571+ ``` rust
572+ use stackdog :: {SyscallEvent , SyscallType };
573+
574+ let event = SyscallEvent :: builder ()
575+ . pid (1234 )
576+ . uid (1000 )
577+ . syscall_type (SyscallType :: Execve )
578+ . container_id (Some (" abc123" . to_string ()))
579+ . build ();
580+ ```
581+
582+ ** Supported Events:**
583+ - Syscall events (execve, connect, openat, ptrace, etc.)
584+ - Network events
585+ - Container lifecycle events
586+ - Alert events
587+
588+ ### 2. Rule Engine
589+
590+ ``` rust
591+ use stackdog :: RuleEngine ;
592+ use stackdog :: rules :: builtin :: {SyscallBlocklistRule , ProcessExecutionRule };
593+
594+ let mut engine = RuleEngine :: new ();
595+ engine . register_rule (Box :: new (SyscallBlocklistRule :: new (
596+ vec! [SyscallType :: Ptrace , SyscallType :: Setuid ]
597+ )));
598+
599+ let results = engine . evaluate (& event );
600+ ```
601+
602+ ** Built-in Rules:**
603+ - Syscall allowlist/blocklist
604+ - Process execution monitoring
605+ - Network connection tracking
606+ - File access monitoring
607+
608+ ### 3. Signature Detection
609+
610+ ``` rust
611+ use stackdog :: SignatureDatabase ;
612+
613+ let db = SignatureDatabase :: new ();
614+ println! (" Loaded {} signatures" , db . signature_count ());
615+
616+ let matches = db . detect (& event );
617+ for sig in matches {
618+ println! (" Threat: {} (Severity: {})" , sig . name (), sig . severity ());
619+ }
620+ ```
621+
622+ ** Built-in Signatures (10+):**
623+ - 🪙 Crypto miner detection
624+ - 🏃 Container escape attempts
625+ - 🌐 Network scanners
626+ - 🔐 Privilege escalation
627+ - 📤 Data exfiltration
628+
629+ ### 4. Threat Scoring
630+
631+ ``` rust
632+ use stackdog :: ThreatScorer ;
633+
634+ let scorer = ThreatScorer :: new ();
635+ let score = scorer . calculate_score (& event );
636+
637+ if score . is_critical () {
638+ println! (" Critical threat detected! Score: {}" , score . value ());
639+ }
640+ ```
641+
642+ ** Severity Levels:**
643+ - Info (0-19)
644+ - Low (20-39)
645+ - Medium (40-69)
646+ - High (70-89)
647+ - Critical (90-100)
648+
649+ ### 5. Alert System
650+
651+ ``` rust
652+ use stackdog :: AlertManager ;
653+
654+ let mut manager = AlertManager :: new ()? ;
655+
656+ let alert = manager . generate_alert (
657+ AlertType :: ThreatDetected ,
658+ AlertSeverity :: High ,
659+ " Suspicious activity detected" . to_string (),
660+ Some (event ),
661+ )? ;
662+
663+ manager . acknowledge_alert (& alert . id ())? ;
664+ ```
665+
666+ ** Notification Channels:**
667+ - Console (logging)
668+ - Slack webhooks
669+ - Email (SMTP)
670+ - Generic webhooks
671+
672+ ### 6. Firewall & Response
673+
674+ ``` rust
675+ use stackdog :: {QuarantineManager , ResponseAction , ResponseType };
676+
677+ // Quarantine container
678+ let mut quarantine = QuarantineManager :: new ()? ;
679+ quarantine . quarantine (" container_abc123" )? ;
680+
681+ // Automated response
682+ let action = ResponseAction :: new (
683+ ResponseType :: BlockIP (" 192.168.1.100" . to_string ()),
684+ " Block malicious IP" . to_string (),
685+ );
686+ ```
687+
688+ ** Response Actions:**
689+ - Block IP addresses
690+ - Block ports
691+ - Quarantine containers
692+ - Kill processes
693+ - Send alerts
694+ - Custom commands
695+
696+ ---
697+
698+ ## 📦 Installation
699+
700+ ### Prerequisites
701+
702+ - ** Rust** 1.75+ ([ install] ( https://rustup.rs/ ) )
703+ - ** SQLite3** + libsqlite3-dev
704+ - ** Linux** kernel 4.19+ (for eBPF features)
705+ - ** Clang/LLVM** (for eBPF compilation)
706+
707+ ### Install Dependencies
708+
709+ ** Ubuntu/Debian:**
710+ ``` bash
711+ apt-get install libsqlite3-dev libssl-dev clang llvm pkg-config
712+ ```
713+
714+ ** macOS:**
715+ ``` bash
716+ brew install sqlite openssl llvm
717+ ```
718+
719+ ** Fedora/RHEL:**
720+ ``` bash
721+ dnf install sqlite-devel openssl-devel clang llvm
722+ ```
723+
724+ ### Build from Source
725+
726+ ``` bash
727+ git clone https://github.com/vsilent/stackdog
728+ cd stackdog
729+ cargo build --release
730+ ```
731+
732+ ### Run Tests
733+
734+ ``` bash
735+ # Run all tests
736+ cargo test --lib
737+
738+ # Run specific module tests
739+ cargo test --lib -- events::
740+ cargo test --lib -- rules::
741+ cargo test --lib -- alerting::
742+ ```
743+
744+ ---
745+
746+ ## 💡 Usage Examples
747+
748+ ### Example 1: Detect Suspicious Syscalls
749+
750+ ``` rust
751+ use stackdog :: {RuleEngine , SyscallEvent , SyscallType };
752+ use stackdog :: rules :: builtin :: SyscallBlocklistRule ;
753+
754+ let mut engine = RuleEngine :: new ();
755+ engine . register_rule (Box :: new (SyscallBlocklistRule :: new (
756+ vec! [SyscallType :: Ptrace , SyscallType :: Setuid ]
757+ )));
758+
759+ let event = SyscallEvent :: new (
760+ 1234 , 1000 , SyscallType :: Ptrace , Utc :: now ()
761+ );
762+
763+ let results = engine . evaluate (& event );
764+ if results . iter (). any (| r | r . is_match ()) {
765+ println! (" ⚠️ Suspicious syscall detected!" );
766+ }
767+ ```
768+
769+ ### Example 2: Container Quarantine
770+
771+ ``` rust
772+ use stackdog :: QuarantineManager ;
773+
774+ let mut quarantine = QuarantineManager :: new ()? ;
775+
776+ // Quarantine compromised container
777+ quarantine . quarantine (" container_abc123" )? ;
778+
779+ // Check quarantine status
780+ let state = quarantine . get_state (" container_abc123" );
781+ println! (" Container state: {:?}" , state );
782+
783+ // Release after investigation
784+ quarantine . release (" container_abc123" )? ;
785+ ```
786+
787+ ### Example 3: Multi-Event Pattern Detection
788+
789+ ``` rust
790+ use stackdog :: {SignatureMatcher , PatternMatch , SyscallType };
791+
792+ let mut matcher = SignatureMatcher :: new ();
793+
794+ // Detect: execve followed by ptrace (suspicious)
795+ matcher . add_pattern (
796+ PatternMatch :: new ()
797+ . with_syscall (SyscallType :: Execve )
798+ . then_syscall (SyscallType :: Ptrace )
799+ . within_seconds (60 )
800+ );
801+
802+ let result = matcher . match_sequence (& events );
803+ if result . is_match () {
804+ println! (" ⚠️ Suspicious pattern detected!" );
805+ }
806+ ```
807+
808+ ### More Examples
809+
810+ See [ ` examples/usage_examples.rs ` ] ( examples/usage_examples.rs ) for complete working examples.
811+
812+ Run examples:
813+ ``` bash
814+ cargo run --example usage_examples
815+ ```
816+
817+ ---
818+
819+ ## 📚 Documentation
820+
821+ | Document | Description |
822+ | ----------| -------------|
823+ | [ DEVELOPMENT.md] ( DEVELOPMENT.md ) | Complete development plan (18 weeks) |
824+ | [ TESTING.md] ( TESTING.md ) | Testing guide and infrastructure |
825+ | [ TODO.md] ( TODO.md ) | Task tracking and roadmap |
826+ | [ CHANGELOG.md] ( CHANGELOG.md ) | Version history |
827+ | [ CONTRIBUTING.md] ( CONTRIBUTING.md ) | Contribution guidelines |
828+ | [ STATUS.md] ( STATUS.md ) | Current implementation status |
829+
830+ ### API Documentation
831+
832+ ``` bash
833+ # Generate docs
834+ cargo doc --open
835+
836+ # View online (after release)
837+ # https://docs.rs/stackdog
485838```
486839stackdog/
487840├── src/
0 commit comments