info: name: NATS Server - Enumeration author: pussycat0x severity: info description: | Detects and extracts detailed information from NATS (Neural Autonomic Transport System) servers. This template connects to NATS servers and retrieves server configuration details including server ID, version, cluster information, authentication settings, and other server properties. Useful for network enumeration and security assessment of NATS messaging infrastructure. impact: | Exposure of NATS server information can reveal system configuration, version details, and authentication requirements that may aid in further reconnaissance or exploitation. remediation: | Ensure NATS servers are properly configured with authentication, access controls, and are not exposed to untrusted networks unless necessary. reference: - https://docs.nats.io/ - https://github.com/nats-io/nats-server metadata: verified:true shodan-query: product:"NATS Server" max-request:1 tags: js,network,nats,tcp,enum
javascript: -pre-condition: | isPortOpen(Host,Port); code: | let packet = bytes.NewBuffer(); let prob ="\n" data= packet.Write(prob) const c = require("nuclei/net"); let conn = c.Open('tcp', `${Host}:${Port}`); conn.Send(data); let resp = conn.RecvFullString();
// Extract JSON from the response (between INFO and the error message) let jsonStart = resp.indexOf('{'); let jsonEnd = resp.lastIndexOf('}') +1; let jsonStr = resp.substring(jsonStart, jsonEnd);
try { let natsInfo = JSON.parse(jsonStr); let formatted = `NATS Server: Server ID: ${natsInfo.server_id} Server Name: ${natsInfo.server_name} Version: ${natsInfo.version} Proto: ${natsInfo.proto} Git Commit: ${natsInfo.git_commit} Go: ${natsInfo.go} Host: ${natsInfo.host} Port: ${natsInfo.port} Headers: ${natsInfo.headers} Auth Required: ${natsInfo.auth_required} Max Payload: ${natsInfo.max_payload} Jetstream: ${natsInfo.jetstream} Client ID: ${natsInfo.client_id} Client IP: ${natsInfo.ip} Cluster: ${natsInfo.cluster} Domain: ${natsInfo.domain}`;
if (natsInfo.compression) { formatted += ` Compression: ${natsInfo.compression}`; } if (natsInfo.info_on_connect) { formatted += ` Info On Connect: ${natsInfo.info_on_connect}`; } if (natsInfo.leafnode_urls && natsInfo.leafnode_urls.length >0) { formatted += ` Leafnode URLs: ${natsInfo.leafnode_urls.join(', ')}`; }
formatted; } catch (e) { resp; // Return original response if JSON parsing fails }