mysqlMySQL & MariaDB Wire Protocol v10Port 3306 Server Greetings, Logins & SQL Queries (app <-> db mysql)
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.
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
greetingso Wireshark recognizes the session as MySQL. - Prefixes
sqlstrings with0x03(COM_QUERY) onqueryframes and encodes little-endian 16-bit error numbers onerrframes.
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.
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}# 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.frasmAll 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 / Option | Accepted Value | Default | Effect on Packet |
|---|---|---|---|
| greeting | login | query | ok | err | eof | MySQL packet type keyword | query (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 login | user "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 err | Sets 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
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
| Option | Range / Format | Default | Effect on Packet |
|---|---|---|---|
| wait <number><ns|us|ms|s|m> | Time gap (ns, us, ms, s, m) | 10ms | Advances 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) | Omitted | Appends 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 MAC | Host MAC / RFC multicast MAC | Overrides 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..1 | Untagged | Wraps 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..4095 | Untagged (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..255 | Unlabeled (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..3 | ttl 64, dscp 0, ecn 0 | Sets 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..8191 | ipid 1, flags 0, fragoffset 0 | Sets 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) | 0 | Sets 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..65535 | srcport 49152 (remembered), TCP 3306 | Overrides source or destination port and remembers the port pair automatically on <- replies. |
| seq <number> | acknum <number> | win <0..65535> | syn | ack | psh | fin | rst | TCP sequence/ack numbers, window size, flags & RFC 7323 options | psh ack, win 65535, automatic TCP seq/acknum | Overrides 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
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.