src/
├── main.rs CLI args, TLS setup, mDNS registration, server start
├── server.rs TCP listener, TLS accept, spawn per-client tasks
├── session.rs Per-client dispatch loop (auth + message handling)
├── pty.rs PTY session creation and I/O
└── file_ops.rs Directory operations with path validation
--listen, --daemon, --token)~/.config/parasite/config.toml (auto-generated on first run)~/.parasite/agent-cert.pem)~/.parasite/agent-token)config.network.agent_port)Each connected client gets its own handle_client task with:
HashMap<SessionId, ShellSession> for PTY sessions┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Network │────>│ Dispatch │────>│ PTY Sessions │
│ Reader Task │ │ Loop │ │ │
└──────────────┘ └──────┬───────┘ └──────────────┘
│
┌──────┴───────┐
│ File Ops │
│ (sync/async) │
└──────────────┘
The agent uses portable-pty for cross-platform PTY support:
pub struct PtySession {
master: Box<dyn MasterPty + Send>,
child: Box<dyn Child + Send + Sync>,
writer: Box<dyn Write + Send>,
}
$SHELL or /bin/bash)spawn_blocking task reads PTY output in configurable chunks (config.buffers.pty_read_buffer_size)Terminal type is set via config.terminal.term (default: xterm-256color).
All directory operations are in file_ops.rs with path validation:
| Handler | Validates | Operation |
|---|---|---|
handle_dir_list |
validate_path |
Read directory entries (dirs only) |
handle_dir_create |
validate_new_path |
Create a new directory |
handle_dir_rename |
Both old/new | Rename/move a directory |
handle_dir_delete |
validate_path |
Recursively delete a directory |
handle_dir_search |
validate_path |
DFS search by name (configurable depth/results) |
DirSearch runs in spawn_blocking since it performs recursive filesystem traversal.
Every file operation validates that the resolved path is within $HOME:
~ → $HOME.., symlinks)canonical.starts_with(home)$HOME itselfThe agent collects system information using the sysinfo crate:
The agent registers itself as a _parasite._tcp.local. service with properties:
agent_id — hostnamehostname — hostnametoken — auth tokenversion — service version string