suricata
app-layer-protos.h
Go to the documentation of this file.
1
/* Copyright (C) 2007-2021 Open Information Security Foundation
2
*
3
* You can copy, redistribute or modify this Program under the terms of
4
* the GNU General Public License version 2 as published by the Free
5
* Software Foundation.
6
*
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License
13
* version 2 along with this program; if not, write to the Free Software
14
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15
* 02110-1301, USA.
16
*/
17
18
/**
19
* \file
20
*
21
* \author Victor Julien <victor@inliniac.net>
22
* \author Anoop Saldanha <anoopsaldanha@gmail.com>
23
*/
24
25
#ifndef SURICATA_APP_LAYER_PROTOS_H
26
#define SURICATA_APP_LAYER_PROTOS_H
27
28
enum
AppProtoEnum
{
29
ALPROTO_UNKNOWN
= 0,
30
/* used by the probing parser when alproto detection fails
31
* permanently for that particular stream */
32
// Update of this value should be reflected in rust, where we also define it
33
ALPROTO_FAILED
= 1,
34
35
// Beginning of real/normal protocols
36
ALPROTO_HTTP1
,
37
ALPROTO_FTP
,
38
ALPROTO_SMTP
,
39
ALPROTO_TLS
,
/* SSLv2, SSLv3 & TLSv1 */
40
ALPROTO_SSH
,
41
ALPROTO_IMAP
,
42
ALPROTO_JABBER
,
43
ALPROTO_SMB
,
44
ALPROTO_DCERPC
,
45
ALPROTO_IRC
,
46
47
ALPROTO_DNS
,
48
ALPROTO_MODBUS
,
49
ALPROTO_ENIP
,
50
ALPROTO_DNP3
,
51
ALPROTO_NFS
,
52
ALPROTO_NTP
,
53
ALPROTO_FTPDATA
,
54
ALPROTO_TFTP
,
55
ALPROTO_IKE
,
56
ALPROTO_KRB5
,
57
ALPROTO_QUIC
,
58
ALPROTO_DHCP
,
59
ALPROTO_SNMP
,
60
ALPROTO_SIP
,
61
ALPROTO_RFB
,
62
ALPROTO_MQTT
,
63
ALPROTO_PGSQL
,
64
ALPROTO_TELNET
,
65
ALPROTO_WEBSOCKET
,
66
ALPROTO_LDAP
,
67
ALPROTO_DOH2
,
68
ALPROTO_TEMPLATE
,
69
ALPROTO_RDP
,
70
ALPROTO_HTTP2
,
71
ALPROTO_BITTORRENT_DHT
,
72
ALPROTO_POP3
,
73
74
// signature-only (ie not seen in flow)
75
// HTTP for any version (ALPROTO_HTTP1 (version 1) or ALPROTO_HTTP2)
76
ALPROTO_HTTP
,
77
78
/* keep last */
79
ALPROTO_MAX_STATIC
,
80
// After this ALPROTO_MAX_STATIC can come dynamic alproto ids
81
};
82
// NOTE: if ALPROTO's get >= 256, update SignatureNonPrefilterStore
83
84
/* not using the enum as that is a unsigned int, so 4 bytes */
85
typedef
uint16_t
AppProto
;
86
extern
AppProto
g_alproto_max
;
87
88
static
inline
bool
AppProtoIsValid(
AppProto
a)
89
{
90
return
((a >
ALPROTO_FAILED
&& a <
g_alproto_max
));
91
}
92
93
// whether a signature AppProto matches a flow (or signature) AppProto
94
static
inline
bool
AppProtoEquals(
AppProto
sigproto,
AppProto
alproto)
95
{
96
if
(sigproto == alproto) {
97
return
true
;
98
}
99
switch
(sigproto) {
100
case
ALPROTO_DNS
:
101
// a DNS signature matches on either DNS or DOH2 flows
102
return
(alproto ==
ALPROTO_DOH2
) || (alproto ==
ALPROTO_DNS
);
103
case
ALPROTO_HTTP2
:
104
// a HTTP2 signature matches on either HTTP2 or DOH2 flows
105
return
(alproto ==
ALPROTO_DOH2
) || (alproto ==
ALPROTO_HTTP2
);
106
case
ALPROTO_DOH2
:
107
// a DOH2 signature accepts dns, http2 or http generic keywords
108
return
(alproto ==
ALPROTO_DOH2
) || (alproto ==
ALPROTO_HTTP2
) ||
109
(alproto ==
ALPROTO_DNS
) || (alproto ==
ALPROTO_HTTP
);
110
case
ALPROTO_HTTP
:
111
return
(alproto ==
ALPROTO_HTTP1
) || (alproto ==
ALPROTO_HTTP2
);
112
case
ALPROTO_DCERPC
:
113
return
(alproto ==
ALPROTO_SMB
);
114
}
115
return
false
;
116
}
117
118
// whether a signature AppProto matches a flow (or signature) AppProto
119
static
inline
AppProto
AppProtoCommon(
AppProto
sigproto,
AppProto
alproto)
120
{
121
switch
(sigproto) {
122
case
ALPROTO_SMB
:
123
if
(alproto ==
ALPROTO_DCERPC
) {
124
// ok to have dcerpc keywords in smb sig
125
return
ALPROTO_SMB
;
126
}
127
break
;
128
case
ALPROTO_HTTP
:
129
// we had a generic http sig, now version specific
130
if
(alproto ==
ALPROTO_HTTP1
) {
131
return
ALPROTO_HTTP1
;
132
}
else
if
(alproto ==
ALPROTO_HTTP2
) {
133
return
ALPROTO_HTTP2
;
134
}
135
break
;
136
case
ALPROTO_HTTP1
:
137
// version-specific sig with a generic keyword
138
if
(alproto ==
ALPROTO_HTTP
) {
139
return
ALPROTO_HTTP1
;
140
}
141
break
;
142
case
ALPROTO_HTTP2
:
143
if
(alproto ==
ALPROTO_HTTP
) {
144
return
ALPROTO_HTTP2
;
145
}
146
break
;
147
case
ALPROTO_DOH2
:
148
// DOH2 accepts different protocol keywords
149
if
(alproto ==
ALPROTO_HTTP
|| alproto ==
ALPROTO_HTTP2
|| alproto ==
ALPROTO_DNS
) {
150
return
ALPROTO_DOH2
;
151
}
152
break
;
153
}
154
if
(sigproto != alproto) {
155
return
ALPROTO_FAILED
;
156
}
157
return
alproto;
158
}
159
160
/**
161
* \brief Maps the ALPROTO_*, to its string equivalent.
162
*
163
* \param alproto App layer protocol id.
164
*
165
* \retval String equivalent for the alproto.
166
*/
167
const
char
*
AppProtoToString
(
AppProto
alproto);
168
169
/**
170
* \brief Maps a string to its ALPROTO_* equivalent.
171
*
172
* \param String equivalent for the alproto.
173
*
174
* \retval alproto App layer protocol id, or ALPROTO_UNKNOWN.
175
*/
176
AppProto
StringToAppProto
(
const
char
*proto_name);
177
178
void
AppProtoRegisterProtoString
(
AppProto
alproto,
const
char
*proto_name);
179
180
#endif
/* SURICATA_APP_LAYER_PROTOS_H */
ALPROTO_IKE
@ ALPROTO_IKE
Definition:
app-layer-protos.h:55
ALPROTO_DCERPC
@ ALPROTO_DCERPC
Definition:
app-layer-protos.h:44
ALPROTO_DNS
@ ALPROTO_DNS
Definition:
app-layer-protos.h:47
ALPROTO_ENIP
@ ALPROTO_ENIP
Definition:
app-layer-protos.h:49
ALPROTO_TLS
@ ALPROTO_TLS
Definition:
app-layer-protos.h:39
ALPROTO_MODBUS
@ ALPROTO_MODBUS
Definition:
app-layer-protos.h:48
AppProto
uint16_t AppProto
Definition:
app-layer-protos.h:85
ALPROTO_QUIC
@ ALPROTO_QUIC
Definition:
app-layer-protos.h:57
ALPROTO_POP3
@ ALPROTO_POP3
Definition:
app-layer-protos.h:72
ALPROTO_JABBER
@ ALPROTO_JABBER
Definition:
app-layer-protos.h:42
ALPROTO_IRC
@ ALPROTO_IRC
Definition:
app-layer-protos.h:45
ALPROTO_SIP
@ ALPROTO_SIP
Definition:
app-layer-protos.h:60
ALPROTO_LDAP
@ ALPROTO_LDAP
Definition:
app-layer-protos.h:66
ALPROTO_FTP
@ ALPROTO_FTP
Definition:
app-layer-protos.h:37
g_alproto_max
AppProto g_alproto_max
Definition:
app-layer-protos.c:29
ALPROTO_SSH
@ ALPROTO_SSH
Definition:
app-layer-protos.h:40
ALPROTO_DHCP
@ ALPROTO_DHCP
Definition:
app-layer-protos.h:58
ALPROTO_KRB5
@ ALPROTO_KRB5
Definition:
app-layer-protos.h:56
ALPROTO_MAX_STATIC
@ ALPROTO_MAX_STATIC
Definition:
app-layer-protos.h:79
ALPROTO_SNMP
@ ALPROTO_SNMP
Definition:
app-layer-protos.h:59
ALPROTO_DNP3
@ ALPROTO_DNP3
Definition:
app-layer-protos.h:50
ALPROTO_SMTP
@ ALPROTO_SMTP
Definition:
app-layer-protos.h:38
StringToAppProto
AppProto StringToAppProto(const char *proto_name)
Maps a string to its ALPROTO_* equivalent.
Definition:
app-layer-protos.c:60
ALPROTO_IMAP
@ ALPROTO_IMAP
Definition:
app-layer-protos.h:41
ALPROTO_RDP
@ ALPROTO_RDP
Definition:
app-layer-protos.h:69
ALPROTO_TELNET
@ ALPROTO_TELNET
Definition:
app-layer-protos.h:64
ALPROTO_DOH2
@ ALPROTO_DOH2
Definition:
app-layer-protos.h:67
AppProtoRegisterProtoString
void AppProtoRegisterProtoString(AppProto alproto, const char *proto_name)
Definition:
app-layer-protos.c:74
ALPROTO_TFTP
@ ALPROTO_TFTP
Definition:
app-layer-protos.h:54
ALPROTO_HTTP2
@ ALPROTO_HTTP2
Definition:
app-layer-protos.h:70
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition:
app-layer-protos.h:36
ALPROTO_PGSQL
@ ALPROTO_PGSQL
Definition:
app-layer-protos.h:63
ALPROTO_FTPDATA
@ ALPROTO_FTPDATA
Definition:
app-layer-protos.h:53
ALPROTO_WEBSOCKET
@ ALPROTO_WEBSOCKET
Definition:
app-layer-protos.h:65
AppProtoToString
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its string equivalent.
Definition:
app-layer-protos.c:40
ALPROTO_MQTT
@ ALPROTO_MQTT
Definition:
app-layer-protos.h:62
ALPROTO_HTTP
@ ALPROTO_HTTP
Definition:
app-layer-protos.h:76
ALPROTO_UNKNOWN
@ ALPROTO_UNKNOWN
Definition:
app-layer-protos.h:29
ALPROTO_FAILED
@ ALPROTO_FAILED
Definition:
app-layer-protos.h:33
ALPROTO_TEMPLATE
@ ALPROTO_TEMPLATE
Definition:
app-layer-protos.h:68
ALPROTO_RFB
@ ALPROTO_RFB
Definition:
app-layer-protos.h:61
ALPROTO_BITTORRENT_DHT
@ ALPROTO_BITTORRENT_DHT
Definition:
app-layer-protos.h:71
ALPROTO_NTP
@ ALPROTO_NTP
Definition:
app-layer-protos.h:52
ALPROTO_SMB
@ ALPROTO_SMB
Definition:
app-layer-protos.h:43
AppProtoEnum
AppProtoEnum
Definition:
app-layer-protos.h:28
ALPROTO_NFS
@ ALPROTO_NFS
Definition:
app-layer-protos.h:51
src
app-layer-protos.h
Generated on Tue Jan 21 2025 23:30:27 for suricata by
1.8.18