This document provides technical details about the Educational Remote Access Tool (RAT) for macOS, designed for CyberSec and Computer Science education.
The Educational RAT uses a simple client-server architecture:
┌─────────────────┐ Network ┌─────────────────┐
│ Server │ Protocol │ Client │
│ (C&C) │ (TCP) │ (Target) │
│ │ │ │
│ - Command │◄─────────────►│ - Command │
│ Processing │ │ Execution │
│ - Authentication│ │ - System Info │
│ - Client Mgmt │ │ - Response │
└─────────────────┘ └─────────────────┘
- Role: Command & Control center
- Responsibilities:
- Listen for client connections
- Authenticate clients
- Send commands to clients
- Receive and display responses
- Manage multiple client connections
- Role: Target machine agent
- Responsibilities:
- Connect to server
- Authenticate with server
- Execute received commands
- Send results back to server
- Maintain connection
- Shared key authentication
- Challenge-response mechanism
- Connection validation
Only safe, educational commands are allowed:
sysinfo- System information gatheringls- Directory listingpwd- Current directorywhoami- User informationps- Process listingnetstat- Network connectionsdf- Disk usageuptime- System uptimehelp- Command help
- No file modification commands
- No system configuration changes
- No destructive operations
- Command output limiting
- Timeout protection
- Client connects to server on specified port
- Authentication handshake:
- Server sends challenge:
AUTH:<key> - Client responds:
AUTH_OK:<key> - Server validates and confirms
- Server sends challenge:
- Information exchange:
- Server requests client info:
GET_INFO - Client sends JSON with system details
- Server requests client info:
- Command loop:
- Server sends command
- Client executes and responds
- Repeat until disconnect
- Text-based protocol
- UTF-8 encoding
- JSON for structured data
- Simple string commands
class RATServer:
def __init__(self, host, port):
self.clients = {} # Active connections
self.client_info = {} # Client metadata
self.allowed_commands = {...} # Whitelist
self.auth_key = self._generate_auth_key()Key Methods:
start()- Main server loophandle_client()- Client communication handlerauthenticate_client()- Authentication logicsend_command()- Command dispatchlist_clients()- Client management
class RATClient:
def __init__(self, server_host, server_port):
self.command_map = {...} # Command handlers
self.auth_key = None
self.running = FalseKey Methods:
connect_to_server()- Network connectionauthenticate()- Authentication processexecute_command()- Command executionstart()- Main client loop
def get_system_info(self) -> str:
info = {
'hostname': platform.node(),
'os': f"{platform.system()} {platform.release()}",
'architecture': platform.architecture()[0],
'processor': platform.processor(),
'python_version': platform.python_version(),
'current_user': getpass.getuser(),
'current_time': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
'platform': platform.platform()
}
return json.dumps(info, indent=2)def list_directory(self, path: str = None) -> str:
if path is None:
path = os.getcwd()
files = os.listdir(path)
result = f"Contents of {path}:\n"
for item in files:
item_path = os.path.join(path, item)
if os.path.isdir(item_path):
result += f"[DIR] {item}\n"
else:
size = os.path.getsize(item_path)
result += f"[FILE] {item} ({size} bytes)\n"
return resultdef list_processes(self) -> str:
result = subprocess.run(['ps', 'aux'],
capture_output=True,
text=True,
timeout=10)
lines = result.stdout.split('\n')
limited_lines = lines[:50] # Educational limit
return '\n'.join(limited_lines)- Connection events
- Authentication attempts
- Command execution
- Client management
- Error conditions
- Connection status
- Authentication results
- Command execution
- System information
- Error conditions
[2024-01-15 14:30:25] INFO: Server listening on 0.0.0.0:9999
[2024-01-15 14:30:30] INFO: New connection from 192.168.1.100:54321
[2024-01-15 14:30:31] INFO: Client 192.168.1.100:54321 authenticated successfully
[2024-01-15 14:30:35] INFO: Received command: sysinfo
- Connection timeouts
- Socket errors
- Authentication failures
- Data transmission errors
- Invalid commands
- Permission denied
- File not found
- Command execution failures
- Missing dependencies
- Platform incompatibility
- Resource limitations
- Network Programming: Understand TCP sockets and client-server communication
- System Administration: Learn system monitoring and information gathering
- Security Concepts: Study authentication, authorization, and security vulnerabilities
- Ethical Hacking: Practice responsible security testing principles
- Python Programming: Develop skills in network programming and system interaction
- Client-Server Architecture: How distributed systems communicate
- Network Protocols: TCP communication and data exchange
- Authentication: Secure connection establishment
- Command Execution: Safe system command handling
- Logging: System monitoring and debugging
- Error Handling: Robust system design
- Vulnerability Awareness: Understanding how remote access tools work
- Defense Strategies: Learning to detect and prevent unauthorized access
- Ethical Considerations: Importance of authorization and legal boundaries
- Security Best Practices: Authentication, whitelisting, and logging
- No Persistence: Tool doesn't install or persist on systems
- No Stealth: All activity is logged and visible
- Limited Commands: Only safe, educational commands allowed
- No Encryption: Traffic is not encrypted (for educational visibility)
- macOS Specific: Commands optimized for macOS systems
- Python Dependency: Requires Python 3.8+
- Network Access: Requires network connectivity between client and server
- Permissions: May require appropriate permissions for some commands
- Educational Use Only: Not for production or malicious use
- Authorization Required: Only use on systems you own or have permission to test
- Legal Compliance: Follow all applicable laws and regulations
- Ethical Use: Practice responsible security testing
- Encryption: Add SSL/TLS for secure communication
- GUI Interface: Create graphical interface for easier use
- Additional Commands: Add more educational commands
- Multi-Platform: Support Windows and Linux systems
- Advanced Authentication: Implement certificate-based authentication
- Command History: Log and display command history
- File Transfer: Safe file upload/download capabilities
- Input Validation: Enhanced command and input validation
- Rate Limiting: Prevent command flooding
- Audit Logging: Comprehensive audit trails
- Session Management: Advanced session handling
- Network Security: Firewall and network security integration
This Educational RAT provides a safe, controlled environment for learning about remote access tools, network programming, and security concepts. It demonstrates both offensive and defensive security principles while maintaining educational focus and ethical boundaries.
The implementation emphasizes safety, logging, and educational value over functionality, making it suitable for classroom use and security education.