Protocol 71 of 81Layer 7FrameAssembly v3.1.2
llms-full.txt
mysqlMySQL & MariaDB Wire Protocol v10

Port 3306 Server Greetings, Logins & SQL Queries (app <-> db mysql)

Default Port / Protocol
TCP 3306
Host Endpoint Rule
Dual-Stack IPv4/IPv6
Wireshark Display Filter
mysql
Standards & Specs
MySQL Client/Server Protocol v10
Wire Stack:Ethernet II[802.1Q / QinQ / MPLS]IPv4 / IPv6TCP 3306MySQL / MariaDB

What It Does on the Wire

Need to test a database activity monitor or IDS rule against sql "SELECT * FROM users WHERE '1'='1';" without spinning up a live MySQL instance? mysql handles the 24-bit little-endian packet length and sequence byte automatically.

MySQL and MariaDB (mysql) communicate over TCP port 3306 using a binary packet framing where every message begins with a 3-byte little-endian payload length and a 1-byte packet sequence number (0, 1, 2...). Unlike HTTP, the MySQL server speaks first immediately after the TCP handshake by sending a Protocol v10 greeting banner.

FrameAssembly encodes valid MySQL v10 greeting handshakes (serverversion), login (HandshakeResponse41 carrying user and db), COM_QUERY (0x03, query + sql), ok (0x00), err (0xff, e.g. errcode 1045 Access Denied), and eof (0xfe) packets.

Database Activity Monitoring (DAM) & SQL Exfiltration Rules

Test Guardium, Imperva, Suricata, and Zeek mysql.log sensors against SELECT / DROP / INTO OUTFILE sql queries in cleartext lab captures.

Detect Exposed Port 3306 & errcode 1045 Brute-Force Attempts

Simulate root login attempts rejected with mysql err errcode 1045 (Access denied for user) to verify SIEM alerting.

App-Tier to Database Subnet Firewall Verification

Verify three-tier firewall rules permit TCP 3306 strictly from app servers and deny DMZ web servers.

Minimal Quickstart (mysql_quickstart.frasm)

Hit Preview Packets to compile in-browser and eyeball timestamps + wire byte lengths, or ship it straight to the Playground.

mysql_quickstart.frasm11 lines
Open in Playground
host app_srv { ip 10.50.1.20 }
host mysql_db { ip 10.50.2.33 }
compile {
app_srv -> mysql_db tcp syn srcport 53306 dstport 3306 wait 1ms
app_srv <- mysql_db tcp syn ack wait 1ms
app_srv -> mysql_db tcp ack wait 1ms
app_srv <- mysql_db mysql greeting serverversion "8.0.36" wait 2ms
app_srv -> mysql_db mysql login user "app_rw" db "orders" wait 2ms
app_srv <- mysql_db mysql ok
}

What the Compiler Calculates So You Don't Have To

  • Defaults to TCP destination port 3306 (psh ack) and computes the 3-byte little-endian MySQL packet length automatically.
  • Encodes NUL-terminated server version, thread ID, auth-plugin-data salt, and capability flags inside greeting so Wireshark recognizes the session as MySQL.
  • Prefixes sql strings with 0x03 (COM_QUERY) on query frames and encodes little-endian 16-bit error numbers on err frames.
Multi-Frame Lab · Ready to Compile

Blocked root Login (errcode 1045) + Authorized Application SQL Session

Shows a rejected root login returning MySQL Error 1045, followed by an authorized app_ro connection running a SELECT query.

mysql_dam_audit.frasm21 lines
Open in Playground
host web_node { ip 172.16.50.15 }
host db_main { ip 172.16.60.10 }
compile {
// 1. Unauthorized root login attempt -> MySQL Error 1045
web_node -> db_main tcp syn srcport 54306 dstport 3306 win 65535 mss 1460 wait 1ms
web_node <- db_main tcp syn ack win 65535 mss 1460 wait 1ms
web_node -> db_main tcp ack wait 1ms
web_node <- db_main mysql greeting serverversion "8.0.37-commercial" wait 2ms
web_node -> db_main mysql login user "root" db "mysql" wait 2ms
web_node <- db_main mysql err errcode 1045 wait 5ms
// 2. Authorized query on a second connection
web_node -> db_main tcp syn srcport 54307 dstport 3306 win 65535 mss 1460 wait 1ms
web_node <- db_main tcp syn ack win 65535 mss 1460 wait 1ms
web_node -> db_main tcp ack wait 1ms
web_node <- db_main mysql greeting serverversion "8.0.37-commercial" wait 1ms
web_node -> db_main mysql login user "app_ro" db "billing" wait 1ms
web_node <- db_main mysql ok wait 2ms
web_node -> db_main mysql query sql "SELECT invoice_id, total_cents FROM invoices WHERE paid = 0 LIMIT 25" wait 3ms
web_node <- db_main mysql ok
}
Terminal Commands (FrameAssembly CLI v3.1.2)
# 1. Eyeball relative timestamps, ports & wire lengths in your terminal
frameassembly show mysql_dam_audit.frasm

# 2. Compile .frasm -> classic .pcap (tcpdump/tcpreplay/Suricata) or nanosecond .pcapng
frameassembly mysql_dam_audit.frasm mysql_dam_audit.pcap
frameassembly mysql_dam_audit.frasm mysql_dam_audit.pcapng

# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture
frameassembly reverse mysql_dam_audit.pcap mysql_dam_audit_edited.frasm

All mysql Keywords & Header Options

Every sub-keyword and header option is lowercase [a-z0-9]+ with zero underscores — mix and match them in any order after mysql:

src_host -> dst_host mysql [greeting | login | query | ok | err | eof] [serverversion "<text>"] [user "<text>"] [db "<text>"] [sql "<text>"] [errcode <0..65535>]
Keyword / OptionAccepted ValueDefaultEffect on Packet
greeting | login | query | ok | err | eofMySQL packet type keywordquery (COM_QUERY 0x03)Selects Server Greeting v10 (greeting), Client HandshakeResponse41 (login), SQL Query (query), 0x00 OK (ok), 0xff Error (err), or 0xfe EOF (eof).
serverversion "<text>"Quoted version banner on greeting"8.0.36"Sets the NUL-terminated server version string in greeting packets.
user "<text>" | db "<text>"Quoted MySQL username and schema name on loginuser "root", db ""Populates username and initial database inside login packets.
sql "<text>"Quoted SQL statement on query"SELECT 1"Writes the SQL query string following COM_QUERY (0x03).
errcode <0..65535>16-bit MySQL error code (1045 Access denied, 1049 Unknown DB, 1064 Syntax error)1045 on errSets the 2-byte little-endian error code in err (0xff) packets.

Cross-Layer Wrappers Valid with mysql

802.1Q VLAN / QinQ / MPLS tags, IPv4/IPv6 QoS & TTL fields, wait gaps, and transport overrides allowed on this protocol

11 options
OptionRange / FormatDefaultEffect on Packet
wait <number><ns|us|ms|s|m>Time gap (ns, us, ms, s, m)10msAdvances the packet timestamp clock after sending this packet and before the next packet (wait 0ns sends back-to-back).
payload "<text>" | hexpayload "<hex>"Quoted text or hex bytes (choose one)OmittedAppends or overrides raw payload bytes ("deadbeef" or "de:ad:be:ef") and updates packet lengths and checksums.
srcmac <mac> | dstmac <mac>Colon, hyphen, or Cisco dot MACHost MAC / RFC multicast MACOverrides the 14-byte Ethernet II source or destination MAC address for this single packet.
vlan <0..4095> [pcp <0..7>] [dei <0|1>]VLAN ID 0..4095, PCP 0..7, DEI 0..1UntaggedWraps the packet in an IEEE 802.1Q VLAN tag (0x8100) with optional 802.1p QoS priority.
qinq <0..4095> [innervlan <0..4095>]Outer S-VLAN 0..4095, Inner C-VLAN 0..4095Untagged (innervlan 1 when qinq is set)Double-tags the packet with outer IEEE 802.1ad S-Tag (0x88a8) plus inner IEEE 802.1Q C-Tag (0x8100).
mpls <0..1048575> [exp|tc <0..7>] [bos <0|1>] [mplsttl <0..255>]Label 0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255Unlabeled (at most 1 mpls tag per packet)Inserts a 32-bit MPLS label header (0x8847) ahead of the Layer 3 header.
ttl <0..255> [dscp <0..63>] [ecn <0..3>]TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3ttl 64, dscp 0, ecn 0Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings.
ipid <0..65535> [df] [mf] [fragoffset <0..8191>]IPv4 ID, DF/MF flags, fragment offset 0..8191ipid 1, flags 0, fragoffset 0Sets IPv4 Identification, Do-Not-Fragment (df), More-Fragments (mf), and fragment offset (ignored over IPv6).
flowlabel <0..1048575>20-bit IPv6 Flow Label (0..1048575)0Sets the 20-bit IPv6 Flow Label for ECMP routing tests (ignored when running over IPv4 hosts).
srcport <0..65535> | dstport <0..65535>Port number 0..65535srcport 49152 (remembered), TCP 3306Overrides source or destination port and remembers the port pair automatically on <- replies.
seq <number> | acknum <number> | win <0..65535> | syn | ack | psh | fin | rstTCP sequence/ack numbers, window size, flags & RFC 7323 optionspsh ack, win 65535, automatic TCP seq/acknumOverrides automatic TCP sequence tracking, flags, or RFC 7323 options (mss, wscale, sackperm, tsval, tsecr).

Gotchas & Quick Fixes

Include Server greeting First for Full Wireshark Conversation State

Valid v3.1.2 Syntax
app_srv <- mysql_db mysql greeting serverversion "8.0.36"

Because MySQL is server-speaks-first, emitting mysql greeting from the server before mysql login helps Wireshark and Zeek classify the handshake phase accurately.

Field Guide 03
Poke Stateful Firewalls, Suricata, Zeek & OT Conduits