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
|
/*
* ajp.c
*
* Copyright (C) 2018 by Leonn Paiva <leonn.paiva@gmail.com>
*
* 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_protocol_ids.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_AJP
#include "ndpi_api.h"
#include "ndpi_private.h"
enum ajp_direction {
AJP_SERVER_TO_CONTAINER = 0x1234,
AJP_CONTAINER_TO_SERVER = 0x4142
};
enum ajp_packet_type {
AJP_UNKNOWN = 0,
/* packet types */
AJP_FORWARD_REQUEST = 2,
AJP_SEND_BODY_CHUNK = 3,
AJP_SEND_HEADERS = 4,
AJP_END_RESPONSE = 5,
AJP_GET_BODY_CHUNK = 6,
AJP_SHUTDOWN = 7,
AJP_PING = 8,
AJP_CPONG = 9,
AJP_CPING = 10,
AJP_BODY = 11
};
PACK_ON
struct ajp_header {
uint16_t magic;
uint16_t len;
uint8_t code;
} PACK_OFF;
static void set_ajp_detected(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
if(flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_AJP, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
}
}
/*************************************************************************************************/
static void ndpi_check_ajp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ajp_header ajp_hdr;
struct ndpi_packet_struct *packet = &ndpi_struct->packet;
if (packet->payload_packet_len < sizeof(ajp_hdr)) {
NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
return;
}
memcpy(&ajp_hdr, packet->payload, sizeof(struct ajp_header));
ajp_hdr.magic = ntohs(ajp_hdr.magic);
ajp_hdr.len = ntohs(ajp_hdr.len);
if (ajp_hdr.len > 0 && ajp_hdr.magic == AJP_SERVER_TO_CONTAINER) {
if (ajp_hdr.code == AJP_FORWARD_REQUEST || ajp_hdr.code == AJP_SHUTDOWN
|| ajp_hdr.code == AJP_PING || ajp_hdr.code == AJP_CPING) {
set_ajp_detected(ndpi_struct, flow);
} else {
NDPI_LOG_DBG(ndpi_struct, "Invalid AJP request type");
NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
}
} else if (ajp_hdr.len > 0 && ajp_hdr.magic == AJP_CONTAINER_TO_SERVER) {
if (ajp_hdr.code == AJP_SEND_BODY_CHUNK || ajp_hdr.code == AJP_SEND_HEADERS
|| ajp_hdr.code == AJP_END_RESPONSE || ajp_hdr.code == AJP_GET_BODY_CHUNK
|| ajp_hdr.code == AJP_CPONG) {
set_ajp_detected(ndpi_struct, flow);
} else {
NDPI_LOG_DBG(ndpi_struct, "Invalid AJP response type");
NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
}
} else {
NDPI_LOG_DBG(ndpi_struct,"Invalid AJP packet\n");
NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
}
}
static void ndpi_search_ajp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
{
NDPI_LOG_DBG(ndpi_struct, "search AJP\n");
ndpi_check_ajp(ndpi_struct, flow);
return;
}
/* ********************************* */
void init_ajp_dissector(struct ndpi_detection_module_struct *ndpi_struct)
{
register_dissector("AJP", ndpi_struct,
ndpi_search_ajp,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
1, NDPI_PROTOCOL_AJP);
}
|