A WebSocket-based relay system that allows remote command execution through a central relay server.
- relay-server.js: Node.js relay server that handles WebSocket connections
- websocket_agent.py: Python agent that connects to the relay and executes commands
- websocket_client.py: Python client that sends commands to agents through the relay
-
Node.js (for relay server)
npm install express ws uuid
-
Python (for agent and client)
pip install websockets requests
-
Install websockets in python:
pip install websockets
-
Start the relay server:
node relay-server.js
-
Start an agent (on the target machine):
python websocket_agent.py <relay_server_ip> [port] [agent_id]
-
Start the client:
python websocket_client.py <relay_server_ip> [port]
list
- Show available agentsquit
- Exit the client<agent_id> <command>
- Execute command on specific agent
Example:
remote> list
Available agents: agent1, agent2
remote> agent1 dir
remote> agent1 cd /tmp
remote> agent1 pwd
Possible causes:
- Agent hasn't connected yet
- Agent connection failed
- Timing issue with registration
Debugging steps:
-
Check if relay server is running:
python check_server.py <relay_server_ip>
-
Test WebSocket connection:
python test_connection.py <relay_server_ip>
-
Check relay server logs for agent registration messages
-
Ensure agent is running and connected:
- Look for "Agent X registered" in relay server logs
- Check agent logs for connection success
Possible causes:
- Agent not receiving commands
- Agent not sending responses
- WebSocket connection issues
Debugging steps:
- Check relay server logs for command forwarding
- Check agent logs for command reception
- Verify WebSocket state in both agent and client
-
Restart all components in this order:
- Relay server
- Agent
- Client
-
Check network connectivity:
- Ensure relay server is accessible from agent and client
- Check firewall settings
-
Verify agent ID:
- Use the same agent ID consistently
- Check for typos in agent ID when sending commands
check_server.py
- Check relay server HTTP endpointstest_connection.py
- Test basic WebSocket connectivity
The system provides detailed logging:
- Relay server logs show connections, registrations, and command flow
- Agent logs show command execution and responses
- Client logs show command sending and response reception
Check these logs when troubleshooting issues.