An AI-powered black-box style debugger
ShadowTrace is a local tool that analyzes processes, files, and network connections in real time, generating explanatory reports with the help of language models (LLMs). It helps you understand the behavior of opaque binaries without access to their original source code.
- Intercepts processes executed on the system
- Monitors opened files (read/write)
- Detects network connections (sockets, IPs, ports)
- Produces structured JSON logs
- Uses a local LLM to analyze patterns and generate explanations
- Command-line interface (CLI)
# Clone the repository
git clone https://github.com/usuario/shadowtrace.git
cd shadowtrace
# Run the installer script
./install.shThe installer checks dependencies like Rust and Ollama (optional), then builds and installs ShadowTrace.
# Clone the repository
git clone https://github.com/usuario/shadowtrace.git
cd shadowtrace
# Build
cargo build --release
# Optional: install globally
sudo cp target/release/shadowtrace /usr/local/bin/- Rust (1.70+): Required to build the project
- Ollama (recommended): For LLM analysis functionality
- Recommended models: llama2, mistral, orca-mini
# Help and available options
shadowtrace --help
# Monitor a specific process
shadowtrace monitor --pid 1234
shadowtrace monitor --name firefox --duration 120
# Audit a binary
shadowtrace audit --binary /path/to/binary
# Monitor all system processes
shadowtrace system --watch
# Use a specific model
shadowtrace --model mistral monitor --name chromeShadowTrace automatically generates detailed reports in JSON and Markdown formats, stored at:
~/.shadowtrace/reports/
Reports include:
- Comprehensive process information
- Detected file events
- Established network connections
- Detailed LLM analysis
- Alerts and warnings
- Rust for performance and safety
- Ollama/llama.cpp for local LLM processing
- Clap for command-line interface
- Real interception of file and network operations is in progress
- Binary audit mode is partially implemented
- Detecting certain suspicious behaviors may require elevated privileges
Contributions are welcome! Check the issues to get started.
This project is licensed under the MIT License.
ShadowTrace TUI had issues capturing keyboard events, preventing normal navigation. The UI rendered correctly but did not respond to key presses.
The issue was identified in the event system implementation in src/ui/events.rs. The original code used a non-blocking approach (try_recv()) that did not wait properly for keyboard events.
Changes implemented:
-
Event reading method change:
- Added
event::poll()with a 100 ms timeout before attempting to read events - This avoids constant read attempts when there are no events
- Added
-
Improved handling of received events:
- Replaced
try_recv()withrecv_timeout()with a 50 ms timeout - This allows briefly waiting for events without fully blocking the thread
- Replaced
// Input event thread
thread::spawn(move || {
loop {
// Blockingly read events
if event::poll(Duration::from_millis(100)).unwrap_or(false) {
if let Ok(event) = event::read() {
if let Err(err) = event_tx.send(Event::Input(event)) {
eprintln!("Error sending event: {:?}", err);
break;
}
}
}
}
});
// ...
pub fn next(&self) -> Result<Option<CEvent>> {
// Use recv_timeout instead of try_recv to block with a time limit
match self.rx.recv_timeout(Duration::from_millis(50)) {
Ok(Event::Input(event)) => Ok(Some(event)),
Ok(Event::Tick) => Ok(None),
Err(mpsc::RecvTimeoutError::Timeout) => Ok(None),
Err(mpsc::RecvTimeoutError::Disconnected) => Err(anyhow::anyhow!("Event channel disconnected")),
}
}The problem originated in the event system implementation using try_recv(), a non-blocking method that returns immediately if there are no events. This caused many key events to be missed or not processed correctly.
- Improved efficiency: Reduced CPU usage by avoiding constant polling
- Better responsiveness: Improved key event capture by actively waiting
- More predictable behavior: Configurable timeouts for different environments
This solution has been tested on macOS, and should work on any platform supported by Rust and Crossterm.
p- Process Monitorf- File Monitorn- Network Monitorr- Reportsh- HelpqorEsc- Exit or Return to Main Menu
-
Process Monitor:
- Up/Down arrows - Navigate between processes
- Enter - Select a process for monitoring
r- Refresh list
-
Other Screens:
- Esc - Return to Dashboard
If you still experience keyboard input issues:
- Terminal focus: Ensure the terminal window is focused
- Keyboard drivers: Check for software conflicts that might capture keys
- Environment variables: Run with
TERM=xterm-256color cargo runto force a specific terminal type - Alternate terminal: Try a different terminal emulator (iTerm2, Alacritty, etc.)
This implementation uses the following libraries:
- crossterm: Event capture and terminal handling
- ratatui: TUI rendering
- tokio: Async runtime
Event handling uses separate threads with Rust MPSC channels (Multiple Producer, Single Consumer), enabling a decoupled architecture.