Technical Documentation
Deep dive into the architecture, threading model, and security layers of RSC.
1. System Architecture
RSC uses a standard client-server architecture. The server listens on TCP port 4444 and is heavily multi-threaded:
- Accept Thread: Listens for new connections and spawns handler threads.
- Client Handler Thread: Handles the authentication handshake.
- Client Read Loop: The sole reader of the socket. Feeds data into a queue.
- Keepalive Thread: Sends newlines every 25s to prevent timeouts.
- Rotation Thread: Recalculates HMAC tokens every hour.
2. The Wire Protocol
Communication is line-based TCP. Authentication supports two formats:
# Legacy
AUTH:<token>
# Identity (Phase 8+)
AUTH:<server_uuid>:<payload_uuid>:<token>
Sentinel Framing: Because TCP is a stream, command responses are wrapped in explicit markers to prevent race conditions:
<<<RSC_BEGIN>>>
<actual output>
<<<RSC_END>>>
3. Server Implementation (Thread Race Fix)
Initially, both send_command and the read loop tried to call recv() on the socket, causing a race condition where keepalives were consumed as command output.
This was solved by making _client_read_loop the sole reader. It feeds raw bytes into session.response_queue.put(chunk). send_command then blocks on the queue until it sees the <<<RSC_END>>> sentinel.
4. Client Hibernation
If the server goes offline, the client does not crash. It enters a hibernation loop, logging [hibernate] <reason> — retry #N in 30s. It retries every 30 seconds until the server comes back online.
5. Security Architecture
- Rotating HMAC: Tokens expire every hour.
HMAC-SHA256(master_secret, window_num). - UUID Integrity Check: The payload checks if
_RSC_LAUNCHEDand the correct_RSC_UUIDare in the global scope. Extracted blobs exit silently. - Decoys: The payload contains two extra Base64 blobs.
_DECOY1prints fake version info._DECOY2connects to the server and sendsNice try dumbass, triggering the server's Tripwire log. - Persistent Registry: Payloads are tracked by UUID in
~/.config/reverse-shell/. Revoking a payload removes it, causing future auths to fail.
6. Exporter Wrappers
The Base64 payload is wrapped differently per format:
- py: Direct
exec(). - sh: Bash heredoc piping to
python3 -c. - bat: PowerShell
-EncodedCommand(UTF-16LE). - js: Node's
child_process.spawnpiping to Python stdin. - exe: Generates a PyInstaller
.specfile.
7. Web Dashboard (Flask + SSE)
Real-time updates are pushed using Server-Sent Events at /api/logs/stream. The server uses an EventBus singleton to broadcast logs, session additions, and disconnects to the frontend JavaScript.