1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
/*
* manolito.c
*
* Copyright (C) 2009-11 - ipoque GmbH
* Copyright (C) 2011-21 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nDPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_MANOLITO
static void ndpi_int_manolito_add_connection(struct
ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
struct ndpi_id_struct *src = flow->src;
struct ndpi_id_struct *dst = flow->dst;
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MANOLITO, NDPI_CONFIDENCE_DPI);
if (src != NULL) {
if (packet->udp != NULL) {
src->manolito_last_pkt_arrival_time = packet->tick_timestamp;
}
}
if (dst != NULL) {
if (packet->udp != NULL) {
dst->manolito_last_pkt_arrival_time = packet->tick_timestamp;
}
}
}
/*
return 0 if nothing has been detected
return 1 if it is a megaupload packet
*/
u_int8_t search_manolito_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
u_int8_t search_manolito_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src = flow->src;
// struct ndpi_id_struct *dst = flow->dst;
NDPI_LOG(NDPI_PROTOCOL_MANOLITO, ndpi_struct, NDPI_LOG_DEBUG, "MANOLITO TCP DETECTION\n");
if (flow->l4.tcp.manolito_stage == 0 && packet->payload_packet_len > 6) {
if (memcmp(packet->payload, "SIZ ", 4) != 0)
goto end_manolito_nothing_found;
flow->l4.tcp.manolito_stage = 1 + packet->packet_direction;
NDPI_LOG(NDPI_PROTOCOL_MANOLITO, ndpi_struct, NDPI_LOG_DEBUG, "MANOLITO Stage 1.\n");
goto end_manolito_maybe_hit;
} else if ((flow->l4.tcp.manolito_stage == 2 - packet->packet_direction)
&& packet->payload_packet_len > 4) {
if (memcmp(packet->payload, "STR ", 4) != 0)
goto end_manolito_nothing_found;
NDPI_LOG(NDPI_PROTOCOL_MANOLITO, ndpi_struct, NDPI_LOG_DEBUG, "MANOLITO Stage 2.\n");
flow->l4.tcp.manolito_stage = 3 + packet->packet_direction;
goto end_manolito_maybe_hit;
} else if ((flow->l4.tcp.manolito_stage == 4 - packet->packet_direction) && packet->payload_packet_len > 5) {
if (memcmp(packet->payload, "MD5 ", 4) != 0)
goto end_manolito_nothing_found;
NDPI_LOG(NDPI_PROTOCOL_MANOLITO, ndpi_struct, NDPI_LOG_DEBUG, "MANOLITO Stage 3.\n");
flow->l4.tcp.manolito_stage = 5 + packet->packet_direction;
goto end_manolito_maybe_hit;
} else if ((flow->l4.tcp.manolito_stage == 6 - packet->packet_direction) && packet->payload_packet_len == 4) {
if (memcmp(packet->payload, "GO!!", 4) != 0)
goto end_manolito_nothing_found;
NDPI_LOG(NDPI_PROTOCOL_MANOLITO, ndpi_struct, NDPI_LOG_DEBUG, "MANOLITO Stage 4.\n");
goto end_manolito_found;
}
//NDPI_LOG(NDPI_PROTOCOL_MANOLITO,ndpi_struct, NDPI_LOG_DEBUG, "MANOLITO FLOW STAGE %d\n", flow->l4.tcp.manolito_stage);
goto end_manolito_nothing_found;
end_manolito_found:
NDPI_LOG(NDPI_PROTOCOL_MANOLITO, ndpi_struct, NDPI_LOG_DEBUG, "MANOLITO FOUND\n");
ndpi_int_manolito_add_connection(ndpi_struct, flow);
return 1;
end_manolito_maybe_hit:
NDPI_LOG(NDPI_PROTOCOL_MANOLITO, ndpi_struct, NDPI_LOG_DEBUG, "MANOLITO maybe hit.\n");
return 2;
end_manolito_nothing_found:
NDPI_LOG(NDPI_PROTOCOL_MANOLITO, ndpi_struct, NDPI_LOG_DEBUG, "MANOLITO NOTHING FOUND\n");
return 0;
}
void ndpi_search_manolito_tcp_udp(struct
ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
struct ndpi_id_struct *src = flow->src;
struct ndpi_id_struct *dst = flow->dst;
if (packet->tcp != NULL) {
if (search_manolito_tcp(ndpi_struct, flow) != 0)
return;
} else if (packet->udp != NULL) {
if (flow->detected_protocol_stack[0] == NDPI_PROTOCOL_MANOLITO) {
if (src != NULL) {
src->manolito_last_pkt_arrival_time = packet->tick_timestamp;
}
if (dst != NULL) {
dst->manolito_last_pkt_arrival_time = packet->tick_timestamp;
}
return;
} else if (packet->udp->source == htons(41170)
|| packet->udp->dest == htons(41170)) {
if (src != NULL && src->manolito_last_pkt_arrival_time != 0
&& (packet->tick_timestamp - src->manolito_last_pkt_arrival_time <
ndpi_struct->manolito_subscriber_timeout)) {
NDPI_LOG(NDPI_PROTOCOL_MANOLITO, ndpi_struct, NDPI_LOG_DEBUG, "MANOLITO: UDP detected \n");
ndpi_int_manolito_add_connection(ndpi_struct, flow);
return;
} else if (src != NULL
&& (packet->tick_timestamp - src->manolito_last_pkt_arrival_time) >=
ndpi_struct->manolito_subscriber_timeout) {
src->manolito_last_pkt_arrival_time = 0;
}
if (dst != NULL && dst->manolito_last_pkt_arrival_time != 0
&& (packet->tick_timestamp - dst->manolito_last_pkt_arrival_time <
ndpi_struct->manolito_subscriber_timeout)) {
NDPI_LOG(NDPI_PROTOCOL_MANOLITO, ndpi_struct, NDPI_LOG_DEBUG, "MANOLITO: UDP detected \n");
ndpi_int_manolito_add_connection(ndpi_struct, flow);
return;
} else if (dst != NULL
&& (packet->tick_timestamp - dst->manolito_last_pkt_arrival_time) >=
ndpi_struct->manolito_subscriber_timeout) {
dst->manolito_last_pkt_arrival_time = 0;
}
if ((packet->payload_packet_len == 20 && htons(0x3d4b) == get_u_int16_t(packet->payload, 0)
&& packet->payload[2] == 0xd9 && htons(0xedbb) == get_u_int16_t(packet->payload, 16))
|| (packet->payload_packet_len == 25 && htons(0x3e4a) == get_u_int16_t(packet->payload, 0)
&& htons(0x092f) == get_u_int16_t(packet->payload, 20) && packet->payload[22] == 0x20)
|| (packet->payload_packet_len == 20 && !get_u_int16_t(packet->payload, 2) && !get_u_int32_t(packet->payload, 8)
&& !get_u_int16_t(packet->payload, 18) && get_u_int16_t(packet->payload, 0))
) { //20B pkt is For PING
NDPI_LOG(NDPI_PROTOCOL_MANOLITO, ndpi_struct, NDPI_LOG_DEBUG, "MANOLITO: UDP detected \n");
ndpi_int_manolito_add_connection(ndpi_struct, flow);
return;
} else if (flow->packet_counter < 7) {
return;
}
}
}
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MANOLITO);
}
#endif
|