]>
Commit | Line | Data |
---|---|---|
a0ee6ade | 1 | /* Copyright (C) 2007-2011 Open Information Security Foundation |
ce019275 WM |
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. | |
0165b3f0 | 11 | * |
ce019275 WM |
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 | ||
60a99915 EL |
18 | /** |
19 | * \defgroup httplayer HTTP layer support | |
20 | * | |
21 | * @{ | |
22 | */ | |
23 | ||
ce019275 WM |
24 | /** |
25 | * \file | |
0165b3f0 | 26 | * |
07f7ba55 | 27 | * \author Gurvinder Singh <gurvindersinghdahiya@gmail.com> |
0165b3f0 | 28 | * \author Pablo Rincon <pablo.rincon.crespo@gmail.com> |
07f7ba55 | 29 | * |
ce019275 | 30 | * This file provides a HTTP protocol support for the engine using HTP library. |
07f7ba55 GS |
31 | */ |
32 | ||
48248687 VJ |
33 | #ifndef __APP_LAYER_HTP_H__ |
34 | #define __APP_LAYER_HTP_H__ | |
07f7ba55 | 35 | |
a9cdd2bb BR |
36 | #include "util-radix-tree.h" |
37 | ||
07f7ba55 GS |
38 | #include <htp/htp.h> |
39 | ||
6ebe7b7c | 40 | /* default request body limit */ |
a0ee6ade VJ |
41 | #define HTP_CONFIG_DEFAULT_REQUEST_BODY_LIMIT 4096U |
42 | ||
43 | /** a boundary should be smaller in size */ | |
44 | #define HTP_BOUNDARY_MAX 200U | |
6ebe7b7c | 45 | |
50f7d0a8 | 46 | #define HTP_FLAG_STATE_OPEN 0x01 /**< Flag to indicate that HTTP |
0165b3f0 | 47 | connection is open */ |
50f7d0a8 | 48 | #define HTP_FLAG_STATE_CLOSED 0x02 /**< Flag to indicate that HTTP |
0165b3f0 | 49 | connection is closed */ |
50f7d0a8 | 50 | #define HTP_FLAG_STATE_DATA 0x04 /**< Flag to indicate that HTTP |
0165b3f0 | 51 | connection needs more data */ |
50f7d0a8 | 52 | #define HTP_FLAG_STATE_ERROR 0x08 /**< Flag to indicate that an error |
0165b3f0 PR |
53 | has been occured on HTTP |
54 | connection */ | |
50f7d0a8 | 55 | #define HTP_FLAG_NEW_BODY_SET 0x10 /**< Flag to indicate that HTTP |
0165b3f0 PR |
56 | has parsed a new body (for |
57 | pcre) */ | |
0165b3f0 PR |
58 | enum { |
59 | HTP_BODY_NONE, /**< Flag to indicate the current | |
60 | operation */ | |
61 | HTP_BODY_REQUEST, /**< Flag to indicate that the | |
62 | current operation is a request */ | |
403b2788 VJ |
63 | HTP_BODY_REQUEST_MULTIPART, |
64 | HTP_BODY_REQUEST_PUT, | |
0165b3f0 PR |
65 | HTP_BODY_RESPONSE /**< Flag to indicate that the current |
66 | * operation is a response */ | |
67 | }; | |
68 | ||
69 | #define HTP_PCRE_NONE 0x00 /**< No pcre executed yet */ | |
70 | #define HTP_PCRE_DONE 0x01 /**< Flag to indicate that pcre has | |
71 | done some inspection in the | |
72 | chunks */ | |
73 | #define HTP_PCRE_HAS_MATCH 0x02 /**< Flag to indicate that the chunks | |
74 | matched on some rule */ | |
75 | ||
76 | /** Struct used to hold chunks of a body on a request */ | |
7a8cd61f | 77 | typedef struct HtpBodyChunk_ { |
0165b3f0 PR |
78 | uint8_t *data; /**< Pointer to the data of the chunk */ |
79 | uint32_t len; /**< Length of the chunk */ | |
0165b3f0 | 80 | uint32_t id; /**< number of chunk of the current body */ |
a0ee6ade VJ |
81 | struct HtpBodyChunk_ *next; /**< Pointer to the next chunk */ |
82 | uint64_t stream_offset; | |
7a8cd61f | 83 | } HtpBodyChunk; |
0165b3f0 PR |
84 | |
85 | /** Struct used to hold all the chunks of a body on a request */ | |
7a8cd61f VJ |
86 | typedef struct HtpBody_ { |
87 | HtpBodyChunk *first; /**< Pointer to the first chunk */ | |
88 | HtpBodyChunk *last; /**< Pointer to the last chunk */ | |
0165b3f0 PR |
89 | uint32_t nchunks; /**< Number of chunks in the current operation */ |
90 | uint8_t operation; /**< This flag indicate if it's a request | |
91 | or a response */ | |
a0ee6ade VJ |
92 | |
93 | /* pahole: padding: 3 */ | |
0165b3f0 | 94 | } HtpBody; |
fc2f7f29 | 95 | |
a0ee6ade VJ |
96 | #define HTP_BODY_COMPLETE 0x01 /**< body is complete or limit is reached, |
97 | either way, this is it. */ | |
98 | #define HTP_CONTENTTYPE_SET 0x02 /**< We have the content type */ | |
99 | #define HTP_BOUNDARY_SET 0x04 /**< We have a boundary string */ | |
100 | #define HTP_BOUNDARY_OPEN 0x08 /**< We have a boundary string */ | |
101 | #define HTP_FILENAME_SET 0x10 /**< filename is registered in the flow */ | |
6ebe7b7c | 102 | |
06a65cb4 PR |
103 | /** Now the Body Chunks will be stored per transaction, at |
104 | * the tx user data */ | |
105 | typedef struct SCHtpTxUserData_ { | |
5c6a65dc AS |
106 | /* Body of the request (if any) */ |
107 | HtpBody body; | |
a0ee6ade | 108 | |
5c6a65dc | 109 | /* Holds the length of the htp request body */ |
a0ee6ade | 110 | uint64_t content_len; |
5c6a65dc | 111 | /* Holds the length of the htp request body seen so far */ |
a0ee6ade VJ |
112 | uint64_t content_len_so_far; |
113 | ||
114 | uint64_t body_parsed; | |
115 | ||
116 | /** Holds the boundary identificator string if any (used on | |
117 | * multipart/form-data only) | |
118 | */ | |
6d60b3a7 | 119 | uint8_t *boundary; |
a0ee6ade | 120 | uint8_t boundary_len; |
6d60b3a7 | 121 | |
6ebe7b7c | 122 | uint8_t flags; |
06a65cb4 PR |
123 | } SCHtpTxUserData; |
124 | ||
07f7ba55 | 125 | typedef struct HtpState_ { |
07f7ba55 | 126 | |
7a8cd61f VJ |
127 | htp_connp_t *connp; /**< Connection parser structure for |
128 | each connection */ | |
6d60b3a7 | 129 | Flow *f; /**< Needed to retrieve the original flow when usin HTPLib callbacks */ |
fc2f7f29 | 130 | uint8_t flags; |
70b32f73 VJ |
131 | uint16_t transaction_cnt; |
132 | uint16_t transaction_done; | |
6ebe7b7c | 133 | uint32_t request_body_limit; |
07f7ba55 GS |
134 | } HtpState; |
135 | ||
07f7ba55 GS |
136 | void RegisterHTPParsers(void); |
137 | void HTPParserRegisterTests(void); | |
fc2f7f29 GS |
138 | void HTPAtExitPrintStats(void); |
139 | void HTPFreeConfig(void); | |
48248687 | 140 | |
0165b3f0 PR |
141 | htp_tx_t *HTPTransactionMain(const HtpState *); |
142 | ||
143 | int HTPCallbackRequestBodyData(htp_tx_data_t *); | |
4e44073c | 144 | int HtpTransactionGetLoggableId(Flow *); |
0165b3f0 PR |
145 | void HtpBodyPrint(HtpBody *); |
146 | void HtpBodyFree(HtpBody *); | |
147 | void AppLayerHtpRegisterExtraCallbacks(void); | |
25a3a5c6 PR |
148 | /* To free the state from unittests using app-layer-htp */ |
149 | void HTPStateFree(void *); | |
97d49d8f | 150 | void AppLayerHtpEnableRequestBodyCallback(void); |
6d60b3a7 | 151 | void AppLayerHtpNeedFileInspection(void); |
6fca55e0 | 152 | void AppLayerHtpPrintStats(void); |
0165b3f0 | 153 | |
48248687 | 154 | #endif /* __APP_LAYER_HTP_H__ */ |
07f7ba55 | 155 | |
60a99915 EL |
156 | /** |
157 | * @} | |
158 | */ |