Mssql — 2 vulnerability checks
noctis ships 2 vulnerability checks for Mssql, covering 3 CVEs; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
Microsoft SQL Server default credentials (TDS login)
| CVE | CVE-2021-33583, CVE-2024-6912 |
|---|---|
| Severity | critical · CVSS 9.8 |
| Category | default-credentials — Default credentials |
| Services | ms-sql-s, mssql |
| Detection | script, set_var, tcp_open, tcp_send, tcp_close, match · highest QoD 97 |
| Feed | tests/vulnerabilities/mssql/mssql-default-credentials.yaml |
The Microsoft SQL Server accepted a login with a common or vendor default credential (sa:sa, the Docker Hub example sa password, Milestone XProtect, Arcserve UDP, Lansweeper, Jira, PerkinElmer BioAssay accounts…) and ran a read-only query on the session, while a random password for the same login was rejected. Anyone who reaches the TDS port can read and change every database the login can reach and, with `sa`, run operating-system commands through xp_cmdshell.
How noctis detects it
- Parses / computes the next value with a Rhai script
- Parses / computes the next value with a Rhai script
- 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
- Sends a binary frame on the open socket
- Parses / computes the next value with a Rhai script
- Opens a persistent TCP/TLS socket
- Sends a binary frame on the open socket
- Sends a binary frame on the open socket
- Parses / computes the next value with a Rhai script
- Parses / computes the next value with a Rhai script
- … and 2 more steps — see the feed source below
References:
- https://nvd.nist.gov/vuln/detail/CVE-2021-33583
- https://nvd.nist.gov/vuln/detail/CVE-2024-6912
- https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/b46a581a-39de-4745-b076-ec4dbb7d13ec
- https://www.mdsec.co.uk/2023/06/cve-2023-26258-remote-code-execution-in-arcserve-udp-backup/
- https://cyberdanube.com/en/en-multiple-vulnerabilities-in-perten-processplus/
Feed source — tests/vulnerabilities/mssql/mssql-default-credentials.yaml
# Microsoft SQL Server — common / vendor default credentials (TDS login)
# (CVE-2021-33583 REINER timeCard, CVE-2024-6912 PerkinElmer ProcessPlus)
#
# Many products install SQL Server (often SQL Express) with a fixed `sa` or
# application-login password, and rushed installs keep `sa:sa` & co. Anyone who
# reaches TCP/1433 with one of these pairs gets the database — and, as `sa`, the
# host through xp_cmdshell.
#
# Ported from OpenVAS/Greenbone NVT pre2008/mssql_brute_force.nasl
# (OID 1.3.6.1.4.1.25623.1.0.10862, GPL-2.0-only) and its mssql.inc helpers:
# same credential list, in the same order, with the same lockout guard — by
# default at most 2 passwords are tried per account
# (DEFAULT_ACCOUNT_TEST_THRESHOLD = 2), so the pairs below are exactly those the
# NASL tries by default: the 14 first pairs whose account has not been tried
# twice yet. The product pairs further down the NASL list (REINER timeCard
# `sa:k+7&DG$pXNTy9h_8`, PerkinElmer ProcessPlus `sa:enilno`, Saleslogix, Act!,
# …) are all `sa` passwords that the NASL itself never reaches at its default
# threshold; they are kept out here for the same reason (account lockout on
# SQL logins with CHECK_POLICY=ON). The feed keeps the NASL's two CVE IDs for
# tracking, but every finding names no CVE (`cves: []`): none of the pairs tried
# is one of those two products' passwords.
#
# Deviations from the NASL (stronger detection, documented in the PR):
# * Protocol. The NASL sends a TDS 4.2 (Sybase-era) LOGIN packet with no
# PRELOGIN. This feed speaks TDS 7.1: PRELOGIN (encryption "not supported")
# then LOGIN7 with the password obfuscated as the protocol requires — what
# every SQL Server from 2000 to 2022 accepts. Verified against a real SQL
# Server 2022 (mcr.microsoft.com/mssql/server:2022-latest).
# * Success test. The NASL reports when byte 8 of the reply is 0xE3 (an
# ENVCHANGE token). Here the reply's token stream is walked and a LOGINACK
# token (0xAD) is required; an ERROR token (0xAA, e.g. 18456 "Login failed")
# ends the walk.
# * Benign post-login proof (QoD 97). On the logged-in session the feed runs
# the read-only `SELECT 'NOCTIS'+CAST(a+b AS varchar(16))` with two random
# numbers, and requires NOCTIS<a+b> (a value never sent) in the result row.
# A LOGINACK whose query did not return the marker still reports, at QoD 75.
# * Accept-any-password guard. After a successful login, one more login with
# the same user and a random password is made; when it is also accepted
# (honeypot, broken auth), nothing is reported.
# * A server that requires encryption (PRELOGIN answer ENCRYPT_REQ / ON) is
# not tested: TLS inside TDS is not supported by the engine, and the NASL's
# plain login fails there too.
# * The loop stops at the first working pair (fewer logins than the NASL,
# which keeps going to list every pair).
#
# Cyber-safety: only a constant SELECT runs after the login; nothing is read
# from or written to any table. Failed logins are logged by the server and may
# count toward a lockout policy — category default-credentials so operators can
# exclude credential logins.
uid: 62ec9cb7-594f-4bbf-aff3-8ddfa120e34c
name: "Microsoft SQL Server default credentials (TDS login)"
description: |
The Microsoft SQL Server accepted a login with a common or vendor default
credential (sa:sa, the Docker Hub example sa password, Milestone XProtect,
Arcserve UDP, Lansweeper, Jira, PerkinElmer BioAssay accounts…) and ran a
read-only query on the session, while a random password for the same login
was rejected. Anyone who reaches the TDS port can read and change every
database the login can reach and, with `sa`, run operating-system commands
through xp_cmdshell.
cves: [CVE-2021-33583, CVE-2024-6912]
cvss: 9.8
severity: critical
category: default-credentials
confidence_base: 0.30
tags: [mssql, sql-server, tds, database, default-credentials, weak-auth, intrusive]
services: [ms-sql-s, mssql]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2021-33583"
- "https://nvd.nist.gov/vuln/detail/CVE-2024-6912"
- "https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/b46a581a-39de-4745-b076-ec4dbb7d13ec"
- "https://www.mdsec.co.uk/2023/06/cve-2023-26258-remote-code-execution-in-arcserve-udp-backup/"
- "https://cyberdanube.com/en/en-multiple-vulnerabilities-in-perten-processplus/"
steps:
# Per-run marker: the query sends a and b, the row must carry NOCTIS<a+b>.
# Also builds the PRELOGIN / SQL batch frames and a random control password.
- id: setup
action: script
store_as: tds
code: |
fn u16hex(s) {
let h = "";
for c in s.chars() { h += hexstr(c.to_string()) + "00"; }
h
}
let a = rand_int(100000, 899999);
let b = rand_int(100000, 899999);
let q = u16hex("SELECT 'NOCTIS'+CAST(" + a + "+" + b + " AS varchar(16))");
// PRELOGIN: VERSION + ENCRYPTION=0x02 (ENCRYPT_NOT_SUP) + terminator.
let pre = "00000b0006" + "0100110001" + "ff" + "090000000000" + "02";
#{
prelogin: "1201" + p16be(8 + strlen(pre) / 2) + "00000100" + pre,
batch: "0101" + p16be(8 + strlen(q) / 2) + "00000100" + q,
marker: hexstr("NOCTIS" + (a + b)),
marker_txt: "NOCTIS" + (a + b),
ctl_pw: "Nx" + rand_str(14)
}
# ------------------------------------------- one iteration per pair
# The NASL's list in its order, at its default lockout threshold (at most
# 2 passwords per account). A finding (stop: true) ends the loop.
- id: init-login-ok
action: set_var
loop:
over:
- {user: "sa", pass: "sa"}
- {user: "sa", pass: "yourStrong(!)Password"}
- {user: "probe", pass: "probe"}
- {user: "probe", pass: "password"}
- {user: "sql", pass: "sql"}
- {user: "ELNAdmin", pass: "ELNAdmin"}
- {user: "msi", pass: "keyboa5"}
- {user: "arcserve_udp", pass: "@rcserveP@ssw0rd"}
- {user: "lansweeperuser", pass: "mysecretpassword0*"}
- {user: "lansweeperuser", pass: "Mysecretpassword0*"}
- {user: "jirauser", pass: "jirapasswd"}
- {user: "jirauser", pass: "jirauser"}
- {user: "admin", pass: "administrator"}
- {user: "admin", pass: "password"}
var: acct
var_name: login_ok
var_value: false
- id: init-enc-ok
action: set_var
var_name: enc_ok
var_value: false
- id: init-proof
action: set_var
var_name: proof
var_value: false
- id: init-ctl-ok
action: set_var
var_name: ctl_ok
var_value: false
- id: init-evidence
action: set_var
var_name: ev
var_value: ""
- id: init-pre
action: set_var
var_name: pre
var_value: {response_hex: ""}
- id: init-lg
action: set_var
var_name: lg
var_value: {response_hex: ""}
- id: init-bq
action: set_var
var_name: bq
var_value: {response_hex: ""}
- id: init-ctl-pre
action: set_var
var_name: c_pre
var_value: {response_hex: ""}
- id: init-ctl-lg
action: set_var
var_name: c_lg
var_value: {response_hex: ""}
# LOGIN7 (TDS 7.1) for this pair and for the control (random password).
# The password is UTF-16LE with every byte nibble-swapped then XORed 0xA5.
- id: build-login
action: script
store_as: lp
code: |
fn u16hex(s) {
let h = "";
for c in s.chars() { h += hexstr(c.to_string()) + "00"; }
h
}
fn scramble(s) {
let h = "";
for c in s.chars() {
let v = ord(c.to_string());
h += p8((((v << 4) & 0xF0) | (v >> 4)) ^ 0xA5) + "a5";
}
h
}
fn login7(user, pass) {
let fields = [u16hex("noctis"), u16hex(user), scramble(pass), u16hex("noctis"),
"", "", u16hex("noctis"), "", ""];
let fixed = p32le(0x71000001) + p32le(4096) + p32le(7) + p32le(0) + p32le(0)
+ "e0030000" + p32le(0) + p32le(0x409);
let off = 86;
let ptrs = "";
let data = "";
for f in fields {
let n = strlen(f) / 2;
ptrs += p16le(off) + p16le(n / 2);
data += f;
off += n;
}
let tail = "000000000000" + p16le(off) + p16le(0) + p16le(off) + p16le(0);
let body = fixed + ptrs + tail + data;
let msg = p32le(4 + strlen(body) / 2) + body;
"1001" + p16be(8 + strlen(msg) / 2) + "00000100" + msg
}
#{ real: login7(acct.user, acct.pass), ctl: login7(acct.user, tds.ctl_pw) }
- id: open
action: tcp_open
handle: ms
port: "{{port}}"
timeout_secs: 10
store_as: conn
- id: prelogin
action: tcp_send
handle: ms
condition: "conn.connected == true"
send_hex: "{{tds.prelogin}}"
timeout_secs: 10
store_as: pre
# PRELOGIN reply (packet type 0x04): find the ENCRYPTION option. With our
# ENCRYPT_NOT_SUP, a server that does not force encryption answers 0x00/0x02
# and the whole session stays in clear; 0x01/0x03 means TLS is required.
- id: check-prelogin
action: script
condition: "conn.connected == true"
store_as: enc_ok
code: |
let r = pre.response_hex;
let ok = false;
if type_of(r) == "string" && strlen(r) >= 26 && substr(r, 0, 1) == "04" {
let n = strlen(r) / 2;
let i = 8;
while i + 4 < n {
let t = u8(substr(r, i * 2, i * 2 + 1));
if t == 0xFF { break; }
let o = u16be(substr(r, (i + 1) * 2, (i + 1) * 2 + 3));
if t == 1 && 8 + o < n {
let e = u8(substr(r, (8 + o) * 2, (8 + o) * 2 + 1));
ok = e == 0 || e == 2;
break;
}
i += 5;
}
}
ok
- id: login
action: tcp_send
handle: ms
condition: "enc_ok == true"
send_hex: "{{lp.real}}"
timeout_secs: 10
store_as: lg
# Walk the reply's token stream: LOGINACK (0xAD) = authenticated; an
# ERROR (0xAA, 18456 Login failed) or any other token ends the walk.
- id: check-login
action: script
condition: "enc_ok == true"
store_as: login_ok
code: |
let r = lg.response_hex;
let ok = false;
if type_of(r) == "string" && strlen(r) >= 22 && substr(r, 0, 1) == "04" {
let n = strlen(r) / 2;
let i = 8;
while i + 2 < n {
let h = i * 2;
let t = u8(substr(r, h, h + 1));
if t == 0xAD { ok = true; break; }
if t in [0xE3, 0xAB, 0xA9, 0xA4, 0xA5] {
let len = u16le(substr(r, h + 2, h + 5));
i += 3 + len;
} else if t in [0xFD, 0xFE, 0xFF] {
i += 9;
} else {
break;
}
}
}
ok
- id: query
action: tcp_send
handle: ms
condition: "login_ok == true"
send_hex: "{{tds.batch}}"
timeout_secs: 10
store_as: bq
- id: check-query
action: script
condition: "login_ok == true"
store_as: proof
code: |
type_of(bq.response_hex) == "string" && strstr(bq.response_hex, tds.marker) != ""
- id: close
action: tcp_close
handle: ms
# ---------------------------------- control: same login, random password
- id: ctl-open
action: tcp_open
handle: ctl
port: "{{port}}"
condition: "login_ok == true"
timeout_secs: 10
store_as: c_conn
- id: ctl-prelogin
action: tcp_send
handle: ctl
condition: "login_ok == true && c_conn.connected == true"
send_hex: "{{tds.prelogin}}"
timeout_secs: 10
store_as: c_pre
- id: ctl-login
action: tcp_send
handle: ctl
condition: "login_ok == true && c_conn.connected == true"
send_hex: "{{lp.ctl}}"
timeout_secs: 10
store_as: c_lg
- id: ctl-close
action: tcp_close
handle: ctl
# The control counts as rejected only when its reply carries an ERROR token
# (0xAA, 18456 Login failed). A LOGINACK, no reply or a dropped connection
# keeps ctl_ok true and suppresses the finding. Same walk as check-login.
- id: ctl-check
action: script
condition: "login_ok == true"
store_as: ctl_ok
code: |
let r = c_lg.response_hex;
let rejected = false;
if type_of(r) == "string" && strlen(r) >= 22 && substr(r, 0, 1) == "04" {
let n = strlen(r) / 2;
let i = 8;
while i + 2 < n {
let h = i * 2;
let t = u8(substr(r, h, h + 1));
if t == 0xAA { rejected = true; break; }
if t == 0xAD { break; }
if t in [0xE3, 0xAB, 0xA9, 0xA4, 0xA5] {
let len = u16le(substr(r, h + 2, h + 5));
i += 3 + len;
} else if t in [0xFD, 0xFE, 0xFF] {
i += 9;
} else {
break;
}
}
}
!rejected
- id: evidence
action: script
condition: "login_ok == true && ctl_ok == false"
store_as: ev
code: |
if proof { "TDS login " + acct.user + " accepted (LOGINACK), query returned " + tds.marker_txt }
else { "TDS login " + acct.user + " accepted (LOGINACK)" }
# ------------------------------------------------------------- findings
- id: finding-query
action: match
source: ev
pattern: "returned NOCTIS\\d+"
condition: "proof == true && ctl_ok == false"
on_match:
finding:
title: "Microsoft SQL Server default credentials {{acct.user}}:{{acct.pass}}"
description: "SQL Server accepted the login '{{acct.user}}' with the well-known password '{{acct.pass}}' (LOGINACK) and ran a read-only SELECT on the session that returned a per-run computed marker, while a random password for the same login was rejected."
remediation: "Set a strong, unique password on this login (or disable it — `ALTER LOGIN [{{acct.user}}] DISABLE`), enforce CHECK_POLICY, prefer Windows authentication, and do not expose TCP/1433 to untrusted networks."
cves: []
confidence_delta: 0.65
qod: 97
evidence: "{{ev}} (random password rejected)"
stop: true
- id: finding-login
action: match
source: ev
pattern: "accepted \\(LOGINACK\\)$"
condition: "proof == false && login_ok == true && ctl_ok == false"
on_match:
finding:
title: "Microsoft SQL Server default credentials {{acct.user}}:{{acct.pass}}"
description: "SQL Server accepted the login '{{acct.user}}' with the well-known password '{{acct.pass}}' (LOGINACK token), while a random password for the same login was rejected. The post-login query did not return its marker."
remediation: "Set a strong, unique password on this login (or disable it — `ALTER LOGIN [{{acct.user}}] DISABLE`), enforce CHECK_POLICY, prefer Windows authentication, and do not expose TCP/1433 to untrusted networks."
cves: []
confidence_delta: 0.50
qod: 75
evidence: "{{ev}} (random password rejected)"
stop: trueMicrosoft SQL Server sa account with a blank password
| CVE | CVE-2000-1209 |
|---|---|
| Severity | critical · CVSS 10.0 |
| Category | default-credentials — Default credentials |
| Services | ms-sql-s, mssql |
| Detection | script, set_var, tcp_open, tcp_send, tcp_close, match · highest QoD 97 |
| Feed | tests/vulnerabilities/mssql/CVE-2000-1209.yaml |
Logs in to the SQL Server TDS port as `sa` with an empty password (TDS 7.1 PRELOGIN + LOGIN7, unencrypted session) and requires the server to acknowledge the login. On the logged-in session it runs a read-only `SELECT 'NOCTIS'+CAST(a+b AS varchar(16))` with two random numbers and confirms the row carries the computed sum, then checks that a random `sa` password is rejected so honeypots and servers that accept any password are not reported. A blank `sa` password gives anyone who reaches the port full control of every database and, through xp_cmdshell, of the host. The finding has high confidence when the query proof succeeds, and lower confidence when only the login was accepted. Servers that require an encrypted session are not tested.
How noctis detects it
- Parses / computes the next value with a Rhai script
- 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
- Sends a binary frame on the open socket
- Parses / computes the next value with a Rhai script
- Opens a persistent TCP/TLS socket
- Sends a binary frame on the open socket
- Sends a binary frame on the open socket
- Parses / computes the next value with a Rhai script
- Parses / computes the next value with a Rhai script
- Checks
evforreturned NOCTIS\d+→ finding QoD 97: Microsoft SQL Server sa account with a blank password - … and 1 more steps — see the feed source below
References:
- https://nvd.nist.gov/vuln/detail/CVE-2000-1209
- https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/b46a581a-39de-4745-b076-ec4dbb7d13ec
Feed source — tests/vulnerabilities/mssql/CVE-2000-1209.yaml
# Microsoft SQL Server — `sa` account with a blank password (CVE-2000-1209)
#
# SQL Server 7.0, SQL Server 2000 and MSDE 1.0 installed the `sa` login with a
# null password, and many third-party packages shipped that way (Compaq Insight
# Manager, Tumbleweed MMS, Visio 2000…). Worms such as Spida and Voyager Alpha
# Force spread through it. Later versions can still be set up this way
# (mixed-mode install with CHECK_POLICY=OFF and an empty sa password).
#
# Ported from OpenVAS/Greenbone NVT pre2008/mssql_blank_password.nasl
# (OID 1.3.6.1.4.1.25623.1.0.10673, GPL-2.0-only): one login as `sa` with an
# empty password. The TDS framing, token walk and post-login proof are shared
# with tests/vulnerabilities/mssql/mssql-default-credentials.yaml.
#
# Deviations from the NASL (stronger detection, documented in the PR):
# * Protocol. The NASL sends a TDS 4.2 (Sybase-era) LOGIN packet with no
# PRELOGIN. This feed speaks TDS 7.1: PRELOGIN (encryption "not supported")
# then LOGIN7 — what every SQL Server from 2000 to 2022 accepts. Verified
# against a real SQL Server 2022 whose sa password was set to ''.
# * Success test. The NASL reports when byte 8 of the reply is 0xE3 (any
# ENVCHANGE token). Here the token stream is walked and a LOGINACK (0xAD) is
# required; an ERROR token (0xAA, 18456 "Login failed") ends the walk.
# * Benign post-login proof (QoD 97): the read-only
# `SELECT 'NOCTIS'+CAST(a+b AS varchar(16))` with two random numbers must
# return NOCTIS<a+b> (a value never sent). LOGINACK without the marker
# still reports, at QoD 75.
# * Accept-any-password guard: after the blank-password login succeeds, one
# more `sa` login with a random password is made; it must be explicitly
# refused (ERROR 18456). When it is also accepted (honeypot, broken auth),
# gets no reply or the connection drops, nothing is reported.
# * A server that requires encryption (PRELOGIN answer ENCRYPT_REQ / ON) is
# not tested: TLS inside TDS is not supported by the engine, and the NASL's
# plain login fails there too.
#
# Cyber-safety: a single constant SELECT runs after the login; nothing is read
# from or written to any table. Exactly one failed login at most is logged
# against `sa` (the random-password control) — category default-credentials so
# operators can exclude credential logins.
uid: 5c40a4c1-a909-47d0-a7ec-c25a05d1201a
name: "Microsoft SQL Server sa account with a blank password"
description: |
Logs in to the SQL Server TDS port as `sa` with an empty password (TDS 7.1
PRELOGIN + LOGIN7, unencrypted session) and requires the server to
acknowledge the login. On the logged-in session it runs a read-only
`SELECT 'NOCTIS'+CAST(a+b AS varchar(16))` with two random numbers and
confirms the row carries the computed sum, then checks that a random `sa`
password is rejected so honeypots and servers that accept any password are
not reported. A blank `sa` password gives anyone who reaches the port full
control of every database and, through xp_cmdshell, of the host. The finding
has high confidence when the query proof succeeds, and lower confidence when
only the login was accepted. Servers that require an encrypted session are
not tested.
cves: [CVE-2000-1209]
cvss: 10.0
severity: critical
category: default-credentials
confidence_base: 0.30
tags: [mssql, sql-server, tds, database, default-credentials, blank-password, weak-auth, intrusive]
services: [ms-sql-s, mssql]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2000-1209"
- "https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/b46a581a-39de-4745-b076-ec4dbb7d13ec"
steps:
# Per-run marker: the query sends a and b, the row must carry NOCTIS<a+b>.
# Builds the PRELOGIN / SQL batch frames and the two LOGIN7 frames (blank
# password, random control password).
- id: setup
action: script
store_as: tds
code: |
fn u16hex(s) {
let h = "";
for c in s.chars() { h += hexstr(c.to_string()) + "00"; }
h
}
fn scramble(s) {
let h = "";
for c in s.chars() {
let v = ord(c.to_string());
h += p8((((v << 4) & 0xF0) | (v >> 4)) ^ 0xA5) + "a5";
}
h
}
fn login7(user, pass) {
let fields = [u16hex("noctis"), u16hex(user), scramble(pass), u16hex("noctis"),
"", "", u16hex("noctis"), "", ""];
let fixed = p32le(0x71000001) + p32le(4096) + p32le(7) + p32le(0) + p32le(0)
+ "e0030000" + p32le(0) + p32le(0x409);
let off = 86;
let ptrs = "";
let data = "";
for f in fields {
let n = strlen(f) / 2;
ptrs += p16le(off) + p16le(n / 2);
data += f;
off += n;
}
let tail = "000000000000" + p16le(off) + p16le(0) + p16le(off) + p16le(0);
let body = fixed + ptrs + tail + data;
let msg = p32le(4 + strlen(body) / 2) + body;
"1001" + p16be(8 + strlen(msg) / 2) + "00000100" + msg
}
let a = rand_int(100000, 899999);
let b = rand_int(100000, 899999);
let q = u16hex("SELECT 'NOCTIS'+CAST(" + a + "+" + b + " AS varchar(16))");
// PRELOGIN: VERSION + ENCRYPTION=0x02 (ENCRYPT_NOT_SUP) + terminator.
let pre = "00000b0006" + "0100110001" + "ff" + "090000000000" + "02";
#{
prelogin: "1201" + p16be(8 + strlen(pre) / 2) + "00000100" + pre,
batch: "0101" + p16be(8 + strlen(q) / 2) + "00000100" + q,
marker: hexstr("NOCTIS" + (a + b)),
marker_txt: "NOCTIS" + (a + b),
login: login7("sa", ""),
ctl: login7("sa", "Nx" + rand_str(14))
}
- id: init-enc-ok
action: set_var
var_name: enc_ok
var_value: false
- id: init-login-ok
action: set_var
var_name: login_ok
var_value: false
- id: init-proof
action: set_var
var_name: proof
var_value: false
- id: init-ctl-ok
action: set_var
var_name: ctl_ok
var_value: false
- id: init-evidence
action: set_var
var_name: ev
var_value: ""
- id: init-pre
action: set_var
var_name: pre
var_value: {response_hex: ""}
- id: init-lg
action: set_var
var_name: lg
var_value: {response_hex: ""}
- id: init-bq
action: set_var
var_name: bq
var_value: {response_hex: ""}
- id: init-ctl-lg
action: set_var
var_name: c_lg
var_value: {response_hex: ""}
- id: open
action: tcp_open
handle: ms
port: "{{port}}"
timeout_secs: 10
store_as: conn
- id: prelogin
action: tcp_send
handle: ms
condition: "conn.connected == true"
send_hex: "{{tds.prelogin}}"
timeout_secs: 10
store_as: pre
# PRELOGIN reply (packet type 0x04): find the ENCRYPTION option. With our
# ENCRYPT_NOT_SUP, a server that does not force encryption answers 0x00/0x02
# and the whole session stays in clear; 0x01/0x03 means TLS is required.
- id: check-prelogin
action: script
condition: "conn.connected == true"
store_as: enc_ok
code: |
let r = pre.response_hex;
let ok = false;
if type_of(r) == "string" && strlen(r) >= 26 && substr(r, 0, 1) == "04" {
let n = strlen(r) / 2;
let i = 8;
while i + 4 < n {
let t = u8(substr(r, i * 2, i * 2 + 1));
if t == 0xFF { break; }
let o = u16be(substr(r, (i + 1) * 2, (i + 1) * 2 + 3));
if t == 1 && 8 + o < n {
let e = u8(substr(r, (8 + o) * 2, (8 + o) * 2 + 1));
ok = e == 0 || e == 2;
break;
}
i += 5;
}
}
ok
- id: login
action: tcp_send
handle: ms
condition: "enc_ok == true"
send_hex: "{{tds.login}}"
timeout_secs: 10
store_as: lg
# Walk the reply's token stream: LOGINACK (0xAD) = authenticated; an
# ERROR (0xAA, 18456 Login failed) or any other token ends the walk.
- id: check-login
action: script
condition: "enc_ok == true"
store_as: login_ok
code: |
let r = lg.response_hex;
let ok = false;
if type_of(r) == "string" && strlen(r) >= 22 && substr(r, 0, 1) == "04" {
let n = strlen(r) / 2;
let i = 8;
while i + 2 < n {
let h = i * 2;
let t = u8(substr(r, h, h + 1));
if t == 0xAD { ok = true; break; }
if t in [0xE3, 0xAB, 0xA9, 0xA4, 0xA5] {
let len = u16le(substr(r, h + 2, h + 5));
i += 3 + len;
} else if t in [0xFD, 0xFE, 0xFF] {
i += 9;
} else {
break;
}
}
}
ok
- id: query
action: tcp_send
handle: ms
condition: "login_ok == true"
send_hex: "{{tds.batch}}"
timeout_secs: 10
store_as: bq
- id: check-query
action: script
condition: "login_ok == true"
store_as: proof
code: |
type_of(bq.response_hex) == "string" && strstr(bq.response_hex, tds.marker) != ""
- id: close
action: tcp_close
handle: ms
# ------------------------------------- control: sa with a random password
- id: ctl-open
action: tcp_open
handle: ctl
port: "{{port}}"
condition: "login_ok == true"
timeout_secs: 10
store_as: c_conn
- id: ctl-prelogin
action: tcp_send
handle: ctl
condition: "login_ok == true && c_conn.connected == true"
send_hex: "{{tds.prelogin}}"
timeout_secs: 10
store_as: c_pre
- id: ctl-login
action: tcp_send
handle: ctl
condition: "login_ok == true && c_conn.connected == true"
send_hex: "{{tds.ctl}}"
timeout_secs: 10
store_as: c_lg
- id: ctl-close
action: tcp_close
handle: ctl
# The control counts as rejected only when its reply carries an ERROR token
# (0xAA, 18456 Login failed). A LOGINACK, no reply or a dropped connection
# keeps ctl_ok true and suppresses the finding. Same walk as check-login.
- id: ctl-check
action: script
condition: "login_ok == true"
store_as: ctl_ok
code: |
let r = c_lg.response_hex;
let rejected = false;
if type_of(r) == "string" && strlen(r) >= 22 && substr(r, 0, 1) == "04" {
let n = strlen(r) / 2;
let i = 8;
while i + 2 < n {
let h = i * 2;
let t = u8(substr(r, h, h + 1));
if t == 0xAA { rejected = true; break; }
if t == 0xAD { break; }
if t in [0xE3, 0xAB, 0xA9, 0xA4, 0xA5] {
let len = u16le(substr(r, h + 2, h + 5));
i += 3 + len;
} else if t in [0xFD, 0xFE, 0xFF] {
i += 9;
} else {
break;
}
}
}
!rejected
- id: evidence
action: script
condition: "login_ok == true && ctl_ok == false"
store_as: ev
code: |
if proof { "TDS login sa with an empty password accepted (LOGINACK), query returned " + tds.marker_txt }
else { "TDS login sa with an empty password accepted (LOGINACK)" }
# ------------------------------------------------------------- findings
- id: finding-query
action: match
source: ev
pattern: "returned NOCTIS\\d+"
condition: "proof == true && ctl_ok == false"
on_match:
finding:
title: "Microsoft SQL Server sa account with a blank password"
description: "SQL Server accepted the login 'sa' with an empty password (LOGINACK) and ran a read-only SELECT on the session that returned a per-run computed marker, while a random password for 'sa' was rejected."
remediation: "Set a strong password on the sa login (`ALTER LOGIN [sa] WITH PASSWORD = '<strong>', CHECK_POLICY = ON`) or disable it (`ALTER LOGIN [sa] DISABLE`), prefer Windows authentication, and do not expose the SQL Server port to untrusted networks."
confidence_delta: 0.65
qod: 97
evidence: "{{ev}} (random password rejected)"
- id: finding-login
action: match
source: ev
pattern: "accepted \\(LOGINACK\\)$"
condition: "proof == false && login_ok == true && ctl_ok == false"
on_match:
finding:
title: "Microsoft SQL Server sa account with a blank password"
description: "SQL Server accepted the login 'sa' with an empty password (LOGINACK token), while a random password for 'sa' was rejected. The post-login query did not return its marker."
remediation: "Set a strong password on the sa login (`ALTER LOGIN [sa] WITH PASSWORD = '<strong>', CHECK_POLICY = ON`) or disable it (`ALTER LOGIN [sa] DISABLE`), prefer Windows authentication, and do not expose the SQL Server port to untrusted networks."
confidence_delta: 0.50
qod: 75
evidence: "{{ev}} (random password rejected)"