|
1 | 1 | # EmbedIDS |
2 | | -Modern Intrusion Detection Systems (IDS) for Embedded Systems |
| 2 | + |
| 3 | +> **Modern Intrusion Detection System for Embedded Devices & IoT** |
| 4 | +
|
| 5 | +EmbedIDS is a lightweight, extensible intrusion detection library designed for embedded systems and IoT devices. It features user-managed memory, custom metrics, and pluggable detection algorithms with zero runtime overhead when disabled. |
| 6 | + |
| 7 | +## Quick Start |
| 8 | + |
| 9 | +```c |
| 10 | +#include <embedids.h> |
| 11 | + |
| 12 | +// Allocate history buffer (user-managed memory) |
| 13 | +static embedids_metric_datapoint_t cpu_history[50]; |
| 14 | + |
| 15 | +// Configure CPU monitoring with 80% threshold |
| 16 | +embedids_metric_config_t cpu_config = { |
| 17 | + .metric = { |
| 18 | + .name = "cpu_usage", |
| 19 | + .type = EMBEDIDS_METRIC_TYPE_PERCENTAGE, |
| 20 | + .history = cpu_history, |
| 21 | + .max_history_size = 50, |
| 22 | + .enabled = true |
| 23 | + }, |
| 24 | + .algorithms = {{ |
| 25 | + .type = EMBEDIDS_ALGORITHM_THRESHOLD, |
| 26 | + .enabled = true, |
| 27 | + .config.threshold = { |
| 28 | + .max_threshold.f32 = 80.0f, |
| 29 | + .check_max = true |
| 30 | + } |
| 31 | + }}, |
| 32 | + .num_algorithms = 1 |
| 33 | +}; |
| 34 | + |
| 35 | +// Initialize context and system |
| 36 | +embedids_context_t context; |
| 37 | +memset(&context, 0, sizeof(context)); |
| 38 | + |
| 39 | +embedids_system_config_t system = { |
| 40 | + .metrics = &cpu_config, |
| 41 | + .max_metrics = 1, |
| 42 | + .num_active_metrics = 1 |
| 43 | +}; |
| 44 | + |
| 45 | +embedids_init(&context, &system); |
| 46 | + |
| 47 | +// Monitor in real-time |
| 48 | +embedids_metric_value_t value = {.f32 = get_cpu_usage()}; |
| 49 | +embedids_add_datapoint(&context, "cpu_usage", value, timestamp_ms); |
| 50 | + |
| 51 | +if (embedids_analyze_metric(&context, "cpu_usage") != EMBEDIDS_OK) { |
| 52 | + handle_intrusion_detected(); |
| 53 | +} |
| 54 | +``` |
| 55 | +
|
| 56 | +## Architecture & Features |
| 57 | +
|
| 58 | +### **Extensible Design** |
| 59 | +- **User-Managed Memory**: No malloc/free - perfect for embedded systems |
| 60 | +- **Custom Metrics**: Support for float, int, percentage, boolean, enum types |
| 61 | +- **Pluggable Algorithms**: Threshold, trend analysis, statistical, and custom detection |
| 62 | +- **Multiple Algorithms per Metric**: Run several detection methods simultaneously |
| 63 | +- **Real-time Analysis**: Low-latency threat detection with configurable history |
| 64 | +
|
| 65 | +### **Detection Algorithms** |
| 66 | +| Algorithm | Description | Use Case | |
| 67 | +|-----------|-------------|----------| |
| 68 | +| **Threshold** | Min/max boundary checking | CPU usage, memory limits | |
| 69 | +| **Trend** | Slope-based anomaly detection | Memory leaks, performance degradation | |
| 70 | +| **Statistical** | Advanced statistical analysis | Complex pattern detection | |
| 71 | +| **Custom** | User-defined detection functions | Domain-specific threats | |
| 72 | +
|
| 73 | +### **Metric Types** |
| 74 | +- `EMBEDIDS_METRIC_TYPE_PERCENTAGE` - CPU usage, memory utilization (0-100%) |
| 75 | +- `EMBEDIDS_METRIC_TYPE_FLOAT` - Sensor readings, network traffic |
| 76 | +- `EMBEDIDS_METRIC_TYPE_UINT32/64` - Packet counts, process counts |
| 77 | +- `EMBEDIDS_METRIC_TYPE_BOOL` - System states, security flags |
| 78 | +- `EMBEDIDS_METRIC_TYPE_ENUM` - Custom enumerated values |
| 79 | +
|
| 80 | +## Installation |
| 81 | +
|
| 82 | +### **CMake (Recommended)** |
| 83 | +```bash |
| 84 | +mkdir build && cd build |
| 85 | +cmake .. -DBUILD_EXAMPLES=ON -DBUILD_TESTS=ON |
| 86 | +make -j$(nproc) |
| 87 | +sudo make install |
| 88 | +``` |
| 89 | + |
| 90 | +### **Integration Options** |
| 91 | +```cmake |
| 92 | +# Option 1: Installed package |
| 93 | +find_package(EmbedIDS REQUIRED) |
| 94 | +target_link_libraries(your_app EmbedIDS::embedids) |
| 95 | +
|
| 96 | +# Option 2: FetchContent (Git repository) |
| 97 | +include(FetchContent) |
| 98 | +FetchContent_Declare( |
| 99 | + EmbedIDS |
| 100 | + GIT_REPOSITORY https://github.com/samiralavi/EmbedIDS.git |
| 101 | + GIT_BRANCH main # Fetch the main branch |
| 102 | +) |
| 103 | +FetchContent_MakeAvailable(EmbedIDS) |
| 104 | +target_link_libraries(your_app embedids) |
| 105 | +``` |
| 106 | + |
| 107 | +### Build Options |
| 108 | + |
| 109 | +- `BUILD_TESTS=ON/OFF` - Unit tests with GoogleTest (default: ON) |
| 110 | +- `BUILD_EXAMPLES=ON/OFF` - Example applications (default: ON) |
| 111 | +- `ENABLE_COVERAGE=ON/OFF` - Code coverage reporting (default: OFF) |
| 112 | + |
| 113 | +## Testing & Coverage |
| 114 | + |
| 115 | +### Running Unit Tests |
| 116 | + |
| 117 | +There are multiple ways to run the test suites |
| 118 | + |
| 119 | +#### Method 1: Using CTest (Recommended) |
| 120 | +```bash |
| 121 | +# Build the project first |
| 122 | +mkdir build && cd build |
| 123 | +cmake .. -DBUILD_TESTS=ON |
| 124 | +make -j$(nproc) |
| 125 | + |
| 126 | +# Run all tests |
| 127 | +ctest |
| 128 | + |
| 129 | +# Run tests with detailed output |
| 130 | +ctest --verbose |
| 131 | + |
| 132 | +# List available tests |
| 133 | +ctest --list-tests |
| 134 | +``` |
| 135 | + |
| 136 | +#### Method 2: Direct Test Execution |
| 137 | +```bash |
| 138 | +# After building, run tests directly |
| 139 | +./tests/embedids_tests |
| 140 | + |
| 141 | +# Run specific test patterns (GoogleTest) |
| 142 | +./tests/embedids_tests --gtest_filter="*Threshold*" |
| 143 | +``` |
| 144 | + |
| 145 | +#### Method 3: Using make (if available) |
| 146 | +```bash |
| 147 | +make test # May not be available in all configurations |
| 148 | +``` |
| 149 | + |
| 150 | +### Code Coverage Analysis |
| 151 | + |
| 152 | +Generate detailed coverage reports to see test effectiveness: |
| 153 | + |
| 154 | +```bash |
| 155 | +# Configure with coverage enabled |
| 156 | +mkdir build && cd build |
| 157 | +cmake .. -DBUILD_TESTS=ON -DENABLE_COVERAGE=ON |
| 158 | +make -j$(nproc) |
| 159 | + |
| 160 | +# Generate coverage report |
| 161 | +make coverage |
| 162 | +``` |
| 163 | + |
| 164 | +## License |
| 165 | + |
| 166 | +Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) file for details. |
0 commit comments