/src/zeek/src/analyzer/protocol/mysql/MySQL.cc
Line | Count | Source |
1 | | // See the file "COPYING" in the main distribution directory for copyright. |
2 | | |
3 | | #include "zeek/analyzer/protocol/mysql/MySQL.h" |
4 | | |
5 | | #include "zeek/Reporter.h" |
6 | | #include "zeek/analyzer/Manager.h" |
7 | | #include "zeek/analyzer/protocol/tcp/TCP_Reassembler.h" |
8 | | |
9 | | namespace zeek::analyzer::mysql { |
10 | | |
11 | 11.3k | MySQL_Analyzer::MySQL_Analyzer(Connection* c) : analyzer::tcp::TCP_ApplicationAnalyzer("MySQL", c) { |
12 | 11.3k | interp = new binpac::MySQL::MySQL_Conn(this); |
13 | 11.3k | had_gap = false; |
14 | 11.3k | tls_active = false; |
15 | 11.3k | } |
16 | | |
17 | 11.3k | MySQL_Analyzer::~MySQL_Analyzer() { delete interp; } |
18 | | |
19 | 11.3k | void MySQL_Analyzer::Done() { |
20 | 11.3k | analyzer::tcp::TCP_ApplicationAnalyzer::Done(); |
21 | | |
22 | 11.3k | interp->FlowEOF(true); |
23 | 11.3k | interp->FlowEOF(false); |
24 | 11.3k | } |
25 | | |
26 | 2.87k | void MySQL_Analyzer::EndpointEOF(bool is_orig) { |
27 | 2.87k | analyzer::tcp::TCP_ApplicationAnalyzer::EndpointEOF(is_orig); |
28 | | |
29 | 2.87k | if ( tls_active ) |
30 | 0 | ForwardEndOfData(is_orig); |
31 | | |
32 | 2.87k | interp->FlowEOF(is_orig); |
33 | 2.87k | } |
34 | | |
35 | 9.22k | void MySQL_Analyzer::StartTLS() { |
36 | 9.22k | tls_active = true; |
37 | | |
38 | 9.22k | Analyzer* ssl = analyzer_mgr->InstantiateAnalyzer("SSL", Conn()); |
39 | 9.22k | if ( ssl ) |
40 | 9.22k | AddChildAnalyzer(ssl); |
41 | 9.22k | } |
42 | | |
43 | 38.3k | void MySQL_Analyzer::DeliverStream(int len, const u_char* data, bool orig) { |
44 | 38.3k | analyzer::tcp::TCP_ApplicationAnalyzer::DeliverStream(len, data, orig); |
45 | | |
46 | 38.3k | if ( tls_active ) { |
47 | | // If TLS has been initiated, forward to child and |
48 | | // short-circuit further processing |
49 | 12.3k | ForwardStream(len, data, orig); |
50 | 12.3k | return; |
51 | 12.3k | } |
52 | | |
53 | 26.0k | if ( TCP() && TCP()->IsPartial() ) |
54 | 67 | return; |
55 | | |
56 | 26.0k | if ( had_gap ) |
57 | | // If only one side had a content gap, we could still try to |
58 | | // deliver data to the other side if the script layer can |
59 | | // handle this. |
60 | 35 | return; |
61 | | |
62 | 25.9k | try { |
63 | 25.9k | interp->NewData(orig, data, data + len); |
64 | 25.9k | } catch ( const binpac::Exception& e ) { |
65 | 1.77k | AnalyzerViolation(util::fmt("Binpac exception: %s", e.what())); |
66 | 1.77k | } |
67 | 25.9k | } |
68 | | |
69 | 73 | void MySQL_Analyzer::Undelivered(uint64_t seq, int len, bool orig) { |
70 | 73 | analyzer::tcp::TCP_ApplicationAnalyzer::Undelivered(seq, len, orig); |
71 | | |
72 | 73 | if ( tls_active ) |
73 | 0 | ForwardUndelivered(seq, len, orig); |
74 | | |
75 | 73 | had_gap = true; |
76 | 73 | interp->NewGap(orig, len); |
77 | 73 | } |
78 | | |
79 | | } // namespace zeek::analyzer::mysql |