/src/ndpi/src/lib/protocols/json-rpc.c
Line | Count | Source |
1 | | /* |
2 | | * json-rpc.c |
3 | | * |
4 | | * Copyright (C) 2023 - ntop.org |
5 | | * Copyright (C) 2023 - V.G <v.gavrilov@securitycode.ru> |
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 | | #include "ndpi_protocol_ids.h" |
26 | | |
27 | | #define NDPI_CURRENT_PROTO NDPI_PROTOCOL_JSON_RPC |
28 | | |
29 | | #include "ndpi_api.h" |
30 | | #include "ndpi_private.h" |
31 | | |
32 | | static void ndpi_search_json_rpc(struct ndpi_detection_module_struct *ndpi_struct, |
33 | | struct ndpi_flow_struct *flow) |
34 | 2.83M | { |
35 | 2.83M | struct ndpi_packet_struct const * const packet = &ndpi_struct->packet; |
36 | | |
37 | 2.83M | NDPI_LOG_DBG(ndpi_struct, "search JSON-RPC\n"); |
38 | | |
39 | 2.83M | if (flow->detected_protocol_stack[0] == NDPI_PROTOCOL_HTTP || |
40 | 2.27M | flow->detected_protocol_stack[1] == NDPI_PROTOCOL_HTTP) |
41 | 605k | { |
42 | 605k | if ((packet->content_line.ptr != NULL) && |
43 | 47.9k | (LINE_ENDS(packet->content_line, "application/json-rpc") != 0)) |
44 | 212 | { |
45 | 212 | NDPI_LOG_INFO(ndpi_struct, "found JSON-RPC over HTTP\n"); |
46 | 212 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_JSON_RPC, |
47 | 212 | NDPI_PROTOCOL_HTTP, NDPI_CONFIDENCE_DPI); |
48 | 212 | } |
49 | 605k | return; |
50 | 605k | } |
51 | | |
52 | 2.22M | if ((packet->payload_packet_len > 30) && (packet->payload[0] == '{') && |
53 | 2.48k | (ndpi_strnstr((const char *)packet->payload, "\"jsonrpc\":", packet->payload_packet_len))) |
54 | 329 | { |
55 | 329 | NDPI_LOG_INFO(ndpi_struct, "found JSON-RPC over TCP\n"); |
56 | 329 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_JSON_RPC, |
57 | 329 | NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); |
58 | 329 | return; |
59 | 329 | } |
60 | | |
61 | 2.22M | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
62 | 2.22M | } |
63 | | |
64 | | void init_json_rpc_dissector(struct ndpi_detection_module_struct *ndpi_struct) |
65 | 8.35k | { |
66 | 8.35k | register_dissector("JSON-RPC", ndpi_struct, |
67 | 8.35k | ndpi_search_json_rpc, |
68 | 8.35k | NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION, |
69 | 8.35k | 1, NDPI_PROTOCOL_JSON_RPC); |
70 | 8.35k | } |