/src/ndpi/src/lib/protocols/usenet.c
Line | Count | Source |
1 | | /* |
2 | | * usenet.c |
3 | | * |
4 | | * Copyright (C) 2009-11 - ipoque GmbH |
5 | | * Copyright (C) 2011-25 - ntop.org |
6 | | * |
7 | | * This file is part of nDPI, an open source deep packet inspection |
8 | | * library based on the OpenDPI and PACE technology by ipoque GmbH |
9 | | * |
10 | | * nDPI is free software: you can redistribute it and/or modify |
11 | | * it under the terms of the GNU Lesser General Public License as published by |
12 | | * the Free Software Foundation, either version 3 of the License, or |
13 | | * (at your option) any later version. |
14 | | * |
15 | | * nDPI is distributed in the hope that it will be useful, |
16 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | | * GNU Lesser General Public License for more details. |
19 | | * |
20 | | * You should have received a copy of the GNU Lesser General Public License |
21 | | * along with nDPI. If not, see <http://www.gnu.org/licenses/>. |
22 | | * |
23 | | */ |
24 | | |
25 | | |
26 | | #include "ndpi_protocol_ids.h" |
27 | | |
28 | | #define NDPI_CURRENT_PROTO NDPI_PROTOCOL_USENET |
29 | | |
30 | | #include "ndpi_api.h" |
31 | | #include "ndpi_private.h" |
32 | | |
33 | | static void ndpi_int_usenet_add_connection(struct ndpi_detection_module_struct |
34 | | *ndpi_struct, struct ndpi_flow_struct *flow) |
35 | 0 | { |
36 | 0 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_USENET, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); |
37 | 0 | } |
38 | | |
39 | | |
40 | | |
41 | | static void ndpi_search_usenet_tcp(struct ndpi_detection_module_struct *ndpi_struct, |
42 | | struct ndpi_flow_struct *flow) |
43 | 0 | { |
44 | 0 | struct ndpi_packet_struct *packet = &ndpi_struct->packet; |
45 | | |
46 | 0 | NDPI_LOG_DBG(ndpi_struct, "search usenet\n"); |
47 | |
|
48 | 0 | NDPI_LOG_DBG2(ndpi_struct, "STAGE IS %u\n", flow->l4.tcp.usenet_stage); |
49 | | |
50 | | // check for the first server replay |
51 | | /* |
52 | | 200 Service available, posting allowed |
53 | | 201 Service available, posting prohibited |
54 | | */ |
55 | 0 | if (flow->l4.tcp.usenet_stage == 0 && packet->payload_packet_len > 10 |
56 | 0 | && ((memcmp(packet->payload, "200 ", 4) == 0) |
57 | 0 | || (memcmp(packet->payload, "201 ", 4) == 0))) { |
58 | |
|
59 | 0 | NDPI_LOG_DBG2(ndpi_struct, "found 200 or 201\n"); |
60 | 0 | flow->l4.tcp.usenet_stage = 1 + packet->packet_direction; |
61 | |
|
62 | 0 | NDPI_LOG_DBG2(ndpi_struct, "maybe hit\n"); |
63 | 0 | return; |
64 | 0 | } |
65 | | |
66 | | /* |
67 | | [C] AUTHINFO USER fred |
68 | | [S] 381 Enter passphrase |
69 | | [C] AUTHINFO PASS flintstone |
70 | | [S] 281 Authentication accepted |
71 | | */ |
72 | | // check for client username |
73 | 0 | if (flow->l4.tcp.usenet_stage == 2 - packet->packet_direction) { |
74 | 0 | if (packet->payload_packet_len > 20 && (memcmp(packet->payload, "AUTHINFO USER ", 14) == 0)) { |
75 | 0 | NDPI_LOG_DBG2(ndpi_struct, "username found\n"); |
76 | 0 | flow->l4.tcp.usenet_stage = 3 + packet->packet_direction; |
77 | |
|
78 | 0 | NDPI_LOG_INFO(ndpi_struct, "found usenet\n"); |
79 | 0 | ndpi_int_usenet_add_connection(ndpi_struct, flow); |
80 | 0 | return; |
81 | 0 | } else if (packet->payload_packet_len == 13 && (memcmp(packet->payload, "MODE READER\r\n", 13) == 0)) { |
82 | 0 | NDPI_LOG_DBG2(ndpi_struct, |
83 | 0 | "no login necessary but we are a client.\n"); |
84 | |
|
85 | 0 | NDPI_LOG_INFO(ndpi_struct, "found usenet\n"); |
86 | 0 | ndpi_int_usenet_add_connection(ndpi_struct, flow); |
87 | 0 | return; |
88 | 0 | } else if (packet->payload_packet_len == 6 && (memcmp(packet->payload, "HELP\r\n", 6) == 0)) { |
89 | 0 | NDPI_LOG_INFO(ndpi_struct, "found usenet\n"); |
90 | 0 | ndpi_int_usenet_add_connection(ndpi_struct, flow); |
91 | 0 | return; |
92 | 0 | } |
93 | 0 | } |
94 | | |
95 | 0 | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
96 | 0 | } |
97 | | |
98 | | |
99 | | void init_usenet_dissector(struct ndpi_detection_module_struct *ndpi_struct) |
100 | 1 | { |
101 | 1 | register_dissector("Usenet", ndpi_struct, |
102 | 1 | ndpi_search_usenet_tcp, |
103 | 1 | NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION, |
104 | 1 | 1, NDPI_PROTOCOL_USENET); |
105 | 1 | } |