mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 17:48:21 +00:00
Get MySQL to compile and add basic v9 support.
This commit is contained in:
parent
101d340b18
commit
5929b635ab
3 changed files with 88 additions and 67 deletions
|
@ -21,6 +21,7 @@ add_subdirectory(irc)
|
||||||
add_subdirectory(login)
|
add_subdirectory(login)
|
||||||
add_subdirectory(mime)
|
add_subdirectory(mime)
|
||||||
add_subdirectory(modbus)
|
add_subdirectory(modbus)
|
||||||
|
add_subdirectory(mysql)
|
||||||
add_subdirectory(ncp)
|
add_subdirectory(ncp)
|
||||||
add_subdirectory(netbios)
|
add_subdirectory(netbios)
|
||||||
add_subdirectory(netflow)
|
add_subdirectory(netflow)
|
||||||
|
|
|
@ -11,8 +11,16 @@ refine flow MySQL_Flow += {
|
||||||
function proc_mysql_handshake_response_packet(msg: Handshake_Response_Packet): bool
|
function proc_mysql_handshake_response_packet(msg: Handshake_Response_Packet): bool
|
||||||
%{
|
%{
|
||||||
if ( mysql_handshake_response )
|
if ( mysql_handshake_response )
|
||||||
BifEvent::generate_mysql_handshake_response(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(),
|
{
|
||||||
bytestring_to_val(${msg.username}));
|
if ( ${msg.version} == 10 )
|
||||||
|
BifEvent::generate_mysql_handshake_response(connection()->bro_analyzer(),
|
||||||
|
connection()->bro_analyzer()->Conn(),
|
||||||
|
bytestring_to_val(${msg.v10_response.username}));
|
||||||
|
if ( ${msg.version} == 9 )
|
||||||
|
BifEvent::generate_mysql_handshake_response(connection()->bro_analyzer(),
|
||||||
|
connection()->bro_analyzer()->Conn(),
|
||||||
|
bytestring_to_val(${msg.v9_response.username}));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
|
@ -115,14 +115,10 @@ type Header = record {
|
||||||
|
|
||||||
type MySQL_PDU(is_orig: bool) = record {
|
type MySQL_PDU(is_orig: bool) = record {
|
||||||
hdr: Header;
|
hdr: Header;
|
||||||
# todo: bytestring &length=56;
|
|
||||||
msg: case is_orig of {
|
msg: case is_orig of {
|
||||||
false -> server_msg: Server_Message(hdr.seq_id);
|
false -> server_msg: Server_Message(hdr.seq_id);
|
||||||
true -> client_msg: Client_Message(state);
|
true -> client_msg: Client_Message(state);
|
||||||
} &requires(state);
|
} &requires(state);
|
||||||
|
|
||||||
# In case there is trash left over from not parsing something completely.
|
|
||||||
#blah: bytestring &restofdata;
|
|
||||||
} &let {
|
} &let {
|
||||||
state = $context.connection.get_state();
|
state = $context.connection.get_state();
|
||||||
} &length=hdr.len &byteorder=bigendian;
|
} &length=hdr.len &byteorder=bigendian;
|
||||||
|
@ -144,6 +140,8 @@ type Initial_Handshake_Packet = record {
|
||||||
9 -> handshake9 : Handshake_v9;
|
9 -> handshake9 : Handshake_v9;
|
||||||
default -> error : ERR_Packet;
|
default -> error : ERR_Packet;
|
||||||
};
|
};
|
||||||
|
} &let {
|
||||||
|
set_version: bool = $context.connection.set_version(protocol_version);
|
||||||
};
|
};
|
||||||
|
|
||||||
type Handshake_v10 = record {
|
type Handshake_v10 = record {
|
||||||
|
@ -160,17 +158,38 @@ type Handshake_v10 = record {
|
||||||
};
|
};
|
||||||
|
|
||||||
type Handshake_v9 = record {
|
type Handshake_v9 = record {
|
||||||
todo: bytestring &restofdata;
|
server_version : NUL_String;
|
||||||
|
connection_id : uint32;
|
||||||
|
scramble : NUL_String;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Handshake_Response_Packet = record {
|
type Handshake_Response_Packet = case $context.connection.get_version() of {
|
||||||
|
10 -> v10_response : Handshake_Response_Packet_v10;
|
||||||
|
9 -> v9_response : Handshake_Response_Packet_v9;
|
||||||
|
} &let {
|
||||||
|
version : uint8 = $context.connection.get_version();
|
||||||
|
} &byteorder=bigendian;
|
||||||
|
|
||||||
|
type Handshake_Response_Packet_v10 = record {
|
||||||
cap_flags : uint32;
|
cap_flags : uint32;
|
||||||
max_pkt_size : uint32;
|
max_pkt_size : uint32;
|
||||||
char_set : uint8;
|
char_set : uint8;
|
||||||
pad : padding[23];
|
pad : padding[23];
|
||||||
username : NUL_String;
|
username : NUL_String;
|
||||||
password : bytestring &restofdata;
|
password : bytestring &restofdata;
|
||||||
} &byteorder=bigendian;
|
};
|
||||||
|
|
||||||
|
type Handshake_Response_Packet_v9 = record {
|
||||||
|
cap_flags : uint16;
|
||||||
|
max_pkt_size : uint24le;
|
||||||
|
username : NUL_String;
|
||||||
|
auth_response : NUL_String;
|
||||||
|
have_db : case ( cap_flags & 0x8 ) of {
|
||||||
|
0x8 -> database : NUL_String;
|
||||||
|
0x0 -> none : empty;
|
||||||
|
};
|
||||||
|
password : bytestring &restofdata;
|
||||||
|
};
|
||||||
|
|
||||||
type Command_Request_Packet = record {
|
type Command_Request_Packet = record {
|
||||||
command: uint8;
|
command: uint8;
|
||||||
|
@ -183,7 +202,6 @@ type Command_Response = case $context.connection.get_expectation() of {
|
||||||
EXPECT_COLUMN_COUNT -> col_count : ColumnCount;
|
EXPECT_COLUMN_COUNT -> col_count : ColumnCount;
|
||||||
EXPECT_COLUMN_DEFINITION -> col_defs : ColumnDefinitions;
|
EXPECT_COLUMN_DEFINITION -> col_defs : ColumnDefinitions;
|
||||||
EXPECT_RESULTSET -> resultset : Resultset;
|
EXPECT_RESULTSET -> resultset : Resultset;
|
||||||
# EXPECT_RESULTSETROW -> resultsetrow : ResultsetRow;
|
|
||||||
EXPECT_STATUS -> status : Command_Response_Status;
|
EXPECT_STATUS -> status : Command_Response_Status;
|
||||||
EXPECT_EOF1 -> eof1 : EOF1;
|
EXPECT_EOF1 -> eof1 : EOF1;
|
||||||
EXPECT_EOF2 -> eof2 : EOF2;
|
EXPECT_EOF2 -> eof2 : EOF2;
|
||||||
|
@ -209,7 +227,6 @@ type ColumnCount = record {
|
||||||
};
|
};
|
||||||
|
|
||||||
type ColumnDefinitions = record {
|
type ColumnDefinitions = record {
|
||||||
# defs: ColumnDefinition41[$context.connection.get_col_count()];
|
|
||||||
defs: ColumnDefinition41[1];
|
defs: ColumnDefinition41[1];
|
||||||
} &let {
|
} &let {
|
||||||
update_expectation: bool = $context.connection.set_next_expected(EXPECT_EOF1);
|
update_expectation: bool = $context.connection.set_next_expected(EXPECT_EOF1);
|
||||||
|
@ -239,7 +256,6 @@ type ResultsetRow = record {
|
||||||
|
|
||||||
type ColumnDefinition41 = record {
|
type ColumnDefinition41 = record {
|
||||||
catalog : LengthEncodedString;
|
catalog : LengthEncodedString;
|
||||||
# todo: bytestring &length=2;
|
|
||||||
schema : LengthEncodedString;
|
schema : LengthEncodedString;
|
||||||
table : LengthEncodedString;
|
table : LengthEncodedString;
|
||||||
org_table: LengthEncodedString;
|
org_table: LengthEncodedString;
|
||||||
|
@ -252,10 +268,6 @@ type ColumnDefinition41 = record {
|
||||||
flags : uint16;
|
flags : uint16;
|
||||||
decimals : uint8;
|
decimals : uint8;
|
||||||
filler : padding[2];
|
filler : padding[2];
|
||||||
#if command was COM_FIELD_LIST {
|
|
||||||
# lenenc_int length of default-values
|
|
||||||
# string[$len] default values
|
|
||||||
#}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type ColumnDefinition320 = record {
|
type ColumnDefinition320 = record {
|
||||||
|
@ -265,19 +277,6 @@ type ColumnDefinition320 = record {
|
||||||
col_len : uint24le;
|
col_len : uint24le;
|
||||||
type_len : LengthEncodedInteger;
|
type_len : LengthEncodedInteger;
|
||||||
type : uint8;
|
type : uint8;
|
||||||
#if capabilities & CLIENT_LONG_FLAG {
|
|
||||||
#lenenc_int [03] length of flags+decimals fields
|
|
||||||
#2 flags
|
|
||||||
#1 decimals
|
|
||||||
# } else {
|
|
||||||
#1 [02] length of flags+decimals fields
|
|
||||||
#1 flags
|
|
||||||
#1 decimals
|
|
||||||
# }
|
|
||||||
# if command was COM_FIELD_LIST {
|
|
||||||
#lenenc_int length of default-values
|
|
||||||
#string[$len] default values
|
|
||||||
# }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type OK_Packet = record {
|
type OK_Packet = record {
|
||||||
|
@ -302,17 +301,30 @@ type EOF_Packet = record {
|
||||||
|
|
||||||
refine connection MySQL_Conn += {
|
refine connection MySQL_Conn += {
|
||||||
%member{
|
%member{
|
||||||
|
uint8 version_;
|
||||||
int state_;
|
int state_;
|
||||||
Expected expected_;
|
Expected expected_;
|
||||||
uint32 col_count_;
|
uint32 col_count_;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%init{
|
%init{
|
||||||
|
version_ = 0;
|
||||||
state_ = CONNECTION_PHASE;
|
state_ = CONNECTION_PHASE;
|
||||||
expected_ = EXPECT_STATUS;
|
expected_ = EXPECT_STATUS;
|
||||||
col_count_ = 0;
|
col_count_ = 0;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
function get_version(): uint8
|
||||||
|
%{
|
||||||
|
return version_;
|
||||||
|
%}
|
||||||
|
|
||||||
|
function set_version(v: uint8): bool
|
||||||
|
%{
|
||||||
|
version_ = v;
|
||||||
|
return true;
|
||||||
|
%}
|
||||||
|
|
||||||
function get_state(): int
|
function get_state(): int
|
||||||
%{
|
%{
|
||||||
return state_;
|
return state_;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue