Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql: add tests #2067

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/mysql-command/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Description
Test sql query statement like `select * from xxx where xxx = yyy` args contents.
Binary file added tests/mysql-command/input.pcap
Binary file not shown.
15 changes: 15 additions & 0 deletions tests/mysql-command/suricata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%YAML 1.1
---

outputs:
- eve-log:
enabled: yes
filetype: regular
filename: eve.json
types:
- alert

app-layer:
protocols:
mysql:
enabled: yes
1 change: 1 addition & 0 deletions tests/mysql-command/test.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alert mysql any any -> any any (msg:"test mysql";mysql.command; content:"33030219971120201X"; metadata: mysql command; sid:1;)
25 changes: 25 additions & 0 deletions tests/mysql-command/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
requires:
min-version: 8

args:
QianKaiLin marked this conversation as resolved.
Show resolved Hide resolved
- -k none

checks:
- filter:
count: 1
match:
pcap_cnt: 40
src_ip: 172.18.0.1
src_port: 35316
dest_ip: 172.18.0.3
dest_port: 3306
proto: "TCP"
direction: "to_server"
event_type: alert
alert.signature: "test mysql"
alert.signature_id: 1
alert.severity: 3
alert.metadata.mysql[0]: "command"
mysql.command: "select * from test.identify where identify = 33030219971120201X"
mysql.rows[0]: "1,33030219971120201X"

QianKaiLin marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions tests/mysql-multi-queries/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Test Description

TODO: Simple description of what this test is for.

## PCAP

TODO: What is the source of this PCAP.

## Related issues

TODO: Issue numbers or links to related issues.
Binary file added tests/mysql-multi-queries/input.pcap
Binary file not shown.
15 changes: 15 additions & 0 deletions tests/mysql-multi-queries/suricata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%YAML 1.1
---

outputs:
- eve-log:
enabled: yes
filetype: regular
filename: eve.json
types:
- mysql

app-layer:
protocols:
mysql:
enabled: yes
61 changes: 61 additions & 0 deletions tests/mysql-multi-queries/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
requires:
min-version: 8

args:
- -k none

checks:
- filter:
count: 1
match:
dest_ip: 172.16.10.104
dest_port: 3306
pcap_cnt: 14
event_type: mysql
mysql.affected_rows: 0
mysql.command: SET NAMES utf8mb4
mysql.tls: false
mysql.version: 8.0.32
proto: TCP
src_ip: 172.16.10.222
src_port: 42074
- filter:
count: 1
match:
dest_ip: 172.16.10.104
dest_port: 3306
event_type: mysql
mysql.command: SELECT VERSION()
mysql.rows[0]: 8.0.32
mysql.tls: false
mysql.version: 8.0.32
proto: TCP
src_ip: 172.16.10.222
src_port: 42074
- filter:
count: 1
match:
dest_ip: 172.16.10.104
dest_port: 3306
pcap_cnt: 20
event_type: mysql
mysql.affected_rows: 0
mysql.command: ping
mysql.tls: false
mysql.version: 8.0.32
proto: TCP
src_ip: 172.16.10.222
src_port: 42074
- filter:
count: 1
match:
dest_ip: 172.16.10.104
dest_port: 3306
event_type: mysql
mysql.command: SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='sentinel_flow_admin'
mysql.rows[0]: sentinel_flow_admin
mysql.tls: false
mysql.version: 8.0.32
proto: TCP
src_ip: 172.16.10.222
src_port: 42074
6 changes: 6 additions & 0 deletions tests/mysql-prepare-statement/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Test Description

Test mysql prepare statement like `select * from xxx where id = ?`.

## PCAP
This PCAP was generated from flow in my workspace.
Binary file added tests/mysql-prepare-statement/input.pcap
Binary file not shown.
15 changes: 15 additions & 0 deletions tests/mysql-prepare-statement/suricata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%YAML 1.1
---

outputs:
- eve-log:
enabled: yes
filetype: regular
filename: eve.json
types:
- mysql

app-layer:
protocols:
mysql:
enabled: yes
73 changes: 73 additions & 0 deletions tests/mysql-prepare-statement/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
requires:
min-version: 8

args:
- -k none

checks:
- filter:
count: 1
match:
event_type: mysql
mysql.command: select * from requests WHERE id =1 limit 1
mysql.tls: false
QianKaiLin marked this conversation as resolved.
Show resolved Hide resolved
mysql.version: 8.4.0
- filter:
count: 1
match:
event_type: mysql
mysql.command: select * from requests WHERE id =2 limit 1
mysql.tls: false
mysql.version: 8.4.0
- filter:
count: 1
match:
event_type: mysql
mysql.command: select * from requests WHERE id=3 and client_code=client2 limit
1
mysql.tls: false
mysql.version: 8.4.0
- filter:
count: 1
match:
event_type: mysql
mysql.command: select * from requests WHERE id =4 limit 1
mysql.tls: false
mysql.version: 8.4.0
- filter:
count: 1
match:
event_type: mysql
mysql.command: select * from requests WHERE id =5 limit 1
mysql.tls: false
mysql.version: 8.4.0
- filter:
count: 1
match:
event_type: mysql
mysql.command: select * from requests WHERE id =6 limit 1
mysql.tls: false
mysql.version: 8.4.0
- filter:
count: 1
match:
event_type: mysql
mysql.command: select * from requests WHERE id =7 limit 1
mysql.tls: false
mysql.version: 8.4.0
- filter:
count: 1
match:
event_type: mysql
mysql.command: select * from requests WHERE id=8 and client_code=client2 limit
1
mysql.tls: false
mysql.version: 8.4.0
- filter:
count: 1
match:
event_type: mysql
mysql.command: select * from requests WHERE id=9 and client_code=client2 limit
1
mysql.tls: false
mysql.version: 8.4.0
6 changes: 6 additions & 0 deletions tests/mysql-query/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Test Description

Test mysql normal sql statement.

## PCAP
This PCAP was generated from flow in my workspace.
Binary file added tests/mysql-query/input.pcap
Binary file not shown.
15 changes: 15 additions & 0 deletions tests/mysql-query/suricata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%YAML 1.1
---

outputs:
- eve-log:
enabled: yes
filetype: regular
filename: eve.json
types:
- mysql

app-layer:
protocols:
mysql:
enabled: yes
22 changes: 22 additions & 0 deletions tests/mysql-query/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
requires:
min-version: 8

args:
- -k none

checks:
- filter:
count: 1
match:
event_type: mysql
mysql.version: 8.0.32
mysql.tls: false
mysql.command: "SELECT VERSION()"
mysql.rows[0]: "8.0.32"
- filter:
count: 1
match:
event_type: mysql
mysql.version: 8.0.32
mysql.tls: false
mysql.command: "ping"
2 changes: 2 additions & 0 deletions tests/mysql-rows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Description
Test sql query 's result like `id,1,2,3,4,5` content
Binary file added tests/mysql-rows/input.pcap
Binary file not shown.
15 changes: 15 additions & 0 deletions tests/mysql-rows/suricata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%YAML 1.1
---

outputs:
- eve-log:
enabled: yes
filetype: regular
filename: eve.json
types:
- alert

app-layer:
protocols:
mysql:
enabled: yes
1 change: 1 addition & 0 deletions tests/mysql-rows/test.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alert mysql any any -> any any (msg:"test mysql";mysql.rows; content:"33030219971120201X"; metadata: mysql rows; sid:1;)
50 changes: 50 additions & 0 deletions tests/mysql-rows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
requires:
min-version: 8

args:
- -k none

checks:
- filter:
count: 1
match:
tx_id: 1
pcap_cnt: 41
src_ip: 172.18.0.3
src_port: 3306
dest_port: 35318
dest_ip: 172.18.0.1
proto: "TCP"
event_type: alert
alert.action: "allowed"
alert.signature: "test mysql"
alert.signature_id: 1
alert.severity: 3
direction: "to_client"
alert.metadata.mysql[0]: "rows"
mysql.version: "9.0.1"
mysql.tls: false
mysql.command: "select * from test.identify where id = 1"
mysql.rows[0]: "1,33030219971120201X"
- filter:
count: 1
match:
tx_id: 3
pcap_cnt: 43
src_ip: 172.18.0.3
src_port: 3306
dest_port: 35316
dest_ip: 172.18.0.1
proto: "TCP"
direction: "to_client"
event_type: alert
alert.action: "allowed"
alert.signature: "test mysql"
alert.signature_id: 1
alert.severity: 3
alert.metadata.mysql[0]: "rows"
mysql.version: "9.0.1"
mysql.tls: false
mysql.command: "select * from test.identify where identify = 33030219971120201X"
mysql.rows[0]: "1,33030219971120201X"

6 changes: 6 additions & 0 deletions tests/mysql-tls/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Test Description

Check MySQL protocol upgrade to TLS protocol.

## PCAP
From my desktop's docker.
Binary file added tests/mysql-tls/input.pcap
Binary file not shown.
18 changes: 18 additions & 0 deletions tests/mysql-tls/suricata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
%YAML 1.1
---

outputs:
- eve-log:
enabled: yes
filetype: regular
filename: eve.json
types:
- mysql
- tls

app-layer:
protocols:
mysql:
enabled: yes
tls:
enabled: yes
Loading