T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- mikrotik-api/scanner.py:120
- Finding
- Automatic Local-Network Reconnaissance and Default-Credential Authentication Attempts<![CDATA[ ## Vulnerability Details **File Location**: `mikrotik-api/scanner.py:120-199`, with subnet enumeration and concurrent scanning at `mikrotik-api/scanner.py:208-303` **Vulnerability Type**: Automatic network discovery, port scanning, and default-credential authentication **Risk Level**: High ### Vulnerable Code ```python def scan_ip(self, ip: str, arp_macs: Dict[str, str]) -> Optional[Dict]: try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(self.timeout) result = sock.connect_ex((ip, self.API_PORT)) if result == 0: mac = arp_macs.get(ip, 'Unknown') is_mikrotik = mac != 'Unknown' and any( mac.startswith(oui) for oui in self.MIKROTIK_OUIS ) device = { 'ip': ip, 'mac': mac, 'port': self.API_PORT, 'identity': 'Unknown', 'model': 'Unknown', 'version': '', 'source': 'api_port', 'is_mikrotik': is_mikrotik } if is_mikrotik: try: from client import MikroTikAPI api = MikroTikAPI(ip, 'admin', '', timeout=2) if api.connect(): if api.login(): result = api.run_command('/system/identity/print') if result: device['identity'] = result[0].get('name', 'Unknown') result = api.run_command('/system/resource/print') if result: device['version'] = result[0].get('version', '') api.disconnect() except: pass ``` The scan is applied to every usable address in locally discovered subnets: ```python for ip_int in range(network_masked + 1, broadcast): ip = socket. ...[truncated 2286 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove all authentication attempts from device discovery. Discovery should only report explicitly requested open ports. 2. Require the user to provide an authorized target CIDR instead of automatically scanning every local subnet. 3. Display the target range and require explicit confirmation before transmitting probe traffic. 4. Enforce a maximum address count, subnet-size limit, concurrency limit, and total scan timeout. 5. Maintain an allowlist of approved networks and reject multicast, public, cloud metadata, and other sensitive ranges. 6. Never try default or empty credentials automatically. Require credentials to be supplied for one explicitly selected device after discovery. 7. Log the authorization decision, requested range, start time, and scan volume. 8. Clearly separate passive inventory, active port scanning, and authenticated inspection into distinct operations. ]]>
