suricata
app-layer-htp.h
Go to the documentation of this file.
1/* Copyright (C) 2007-2020 Open Information Security Foundation
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.
11 *
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
18/**
19 * \defgroup httplayer HTTP layer support
20 *
21 * @{
22 */
23
24/**
25 * \file
26 *
27 * \author Gurvinder Singh <gurvindersinghdahiya@gmail.com>
28 * \author Pablo Rincon <pablo.rincon.crespo@gmail.com>
29 *
30 * This file provides a HTTP protocol support for the engine using HTP library.
31 */
32
33#ifndef SURICATA_APP_LAYER_HTP_H
34#define SURICATA_APP_LAYER_HTP_H
35
36#include "rust.h"
37#include "app-layer-frames.h"
38
39#include "htp/htp_rs.h"
40
41/* default request body limit */
42#define HTP_CONFIG_DEFAULT_REQUEST_BODY_LIMIT 4096U
43#define HTP_CONFIG_DEFAULT_RESPONSE_BODY_LIMIT 4096U
44#define HTP_CONFIG_DEFAULT_REQUEST_INSPECT_MIN_SIZE 32768U
45#define HTP_CONFIG_DEFAULT_REQUEST_INSPECT_WINDOW 4096U
46#define HTP_CONFIG_DEFAULT_RESPONSE_INSPECT_MIN_SIZE 32768U
47#define HTP_CONFIG_DEFAULT_RESPONSE_INSPECT_WINDOW 4096U
48#define HTP_CONFIG_DEFAULT_FIELD_LIMIT 18000U
49
50#define HTP_CONFIG_DEFAULT_LZMA_LAYERS 0U
51/* default libhtp lzma limit, taken from libhtp. */
52#define HTP_CONFIG_DEFAULT_LZMA_MEMLIMIT 1048576U
53#define HTP_CONFIG_DEFAULT_COMPRESSION_BOMB_LIMIT 1048576U
54// 100000 usec is 0.1 sec
55#define HTP_CONFIG_DEFAULT_COMPRESSION_TIME_LIMIT 100000
56
57#define HTP_CONFIG_DEFAULT_RANDOMIZE 1
58#define HTP_CONFIG_DEFAULT_RANDOMIZE_RANGE 10
59
60// 0x0001 not used
61#define HTP_FLAG_STATE_CLOSED_TS \
62 0x0002 /**< Flag to indicate that HTTP \
63 connection is closed */
64#define HTP_FLAG_STATE_CLOSED_TC \
65 0x0004 /**< Flag to indicate that HTTP \
66 connection is closed */
67
68enum {
71 HTP_BODY_REQUEST_POST, /* POST, no MP */
73};
74
75enum {
76 /* suricata errors/warnings */
80
85};
86
93
94typedef struct HTPCfgDir_ {
95 uint32_t body_limit;
99
100/** Need a linked list in order to keep track of these */
101typedef struct HTPCfgRec_ {
102 htp_cfg_t *cfg;
104
105 /** max size of the client body we inspect */
109
114
117
118 bool uri_include_all; /**< use all info in uri (bool) */
120
121/** Struct used to hold chunks of a body on a request */
123 struct HtpBodyChunk_ *next; /**< Pointer to the next chunk */
125 StreamingBufferSegment sbseg;
126} __attribute__((__packed__));
128
129/** Struct used to hold all the chunks of a body on a request */
130typedef struct HtpBody_ {
131 HtpBodyChunk *first; /**< Pointer to the first chunk */
132 HtpBodyChunk *last; /**< Pointer to the last chunk */
133
135
136 /* Holds the length of the htp request body seen so far */
138 /* parser tracker */
139 uint64_t body_parsed;
140 /* inspection tracker */
143
144#define HTP_BOUNDARY_SET BIT_U8(1) /**< We have a boundary string */
145#define HTP_FILENAME_SET BIT_U8(3) /**< filename is registered in the flow */
146#define HTP_DONTSTORE BIT_U8(4) /**< not storing this file */
147#define HTP_STREAM_DEPTH_SET BIT_U8(5) /**< stream-depth is set */
148
149/** Now the Body Chunks will be stored per transaction, at
150 * the tx user data */
180
181typedef struct HtpState_ {
182 /* Connection parser structure for each connection */
183 htp_connp_t *connp;
184 /* Connection structure for each connection */
185 htp_conn_t *conn;
186 Flow *f; /**< Needed to retrieve the original flow when using HTPLib callbacks */
188 const struct HTPCfgRec_ *cfg;
189 uint16_t flags;
190 uint16_t events;
191 uint16_t htp_messages_count; /**< Number of already logged messages */
192 uint32_t file_track_id; /**< used to assign file track ids to files */
200
201/** part of the engine needs the request body (e.g. http_client_body keyword) */
202#define HTP_REQUIRE_REQUEST_BODY (1 << 0)
203/** part of the engine needs the request file (e.g. log-file module) */
204#define HTP_REQUIRE_REQUEST_FILE (1 << 2)
205/** part of the engine needs the request body (e.g. file_data keyword) */
206#define HTP_REQUIRE_RESPONSE_BODY (1 << 3)
207
208SC_ATOMIC_EXTERN(uint32_t, htp_config_flags);
209
210void RegisterHTPParsers(void);
211void HTPAtExitPrintStats(void);
212void HTPFreeConfig(void);
213
214/* To free the state from unittests using app-layer-htp */
215void HTPStateFree(void *);
219void AppLayerHtpPrintStats(void);
220
221void HTPConfigure(void);
222
223void HtpConfigCreateBackup(void);
224void HtpConfigRestoreBackup(void);
225
226void *HtpGetTxForH2(void *);
227
228#endif /* SURICATA_APP_LAYER_HTP_H */
229
230/**
231 * @}
232 */
int64_t FrameId
struct AppLayerTxData AppLayerTxData
struct StreamSlice StreamSlice
struct AppLayerStateData AppLayerStateData
struct PrefilterEngineFlowbits __attribute__
DNP3 application header.
void AppLayerHtpEnableResponseBodyCallback(void)
Sets a flag that informs the HTP app layer that some module in the engine needs the http request body...
struct HtpState_ HtpState
void RegisterHTPParsers(void)
Register the HTTP protocol and state handling functions to APP layer of the engine.
struct HTPCfgRec_ HTPCfgRec
void HtpConfigRestoreBackup(void)
struct HtpTxUserData_ HtpTxUserData
void HTPStateFree(void *)
Function to frees the HTTP state memory and also frees the HTTP connection parser memory which was us...
enum HtpSwfCompressType_ HtpSwfCompressType
void HtpConfigCreateBackup(void)
struct HTPCfgDir_ HTPCfgDir
void HTPAtExitPrintStats(void)
Print the stats of the HTTP requests.
void HTPConfigure(void)
void HTPFreeConfig(void)
Clears the HTTP server configuration memory used by HTP library.
HtpSwfCompressType_
struct HtpBody_ HtpBody
void AppLayerHtpNeedFileInspection(void)
Sets a flag that informs the HTP app layer that some module in the engine needs the http request file...
void * HtpGetTxForH2(void *)
void AppLayerHtpEnableRequestBodyCallback(void)
Sets a flag that informs the HTP app layer that some module in the engine needs the http request body...
void AppLayerHtpPrintStats(void)
@ HTTP_DECODER_EVENT_RANGE_INVALID
@ HTTP_DECODER_EVENT_FILE_NAME_TOO_LONG
@ HTTP_DECODER_EVENT_MULTIPART_INVALID_HEADER
@ HTTP_DECODER_EVENT_MULTIPART_NO_FILEDATA
@ HTTP_DECODER_EVENT_FAILED_PROTOCOL_CHANGE
@ HTTP_DECODER_EVENT_TOO_MANY_WARNINGS
@ HTTP_DECODER_EVENT_MULTIPART_GENERIC_ERROR
@ HTTP_SWF_COMPRESSION_ZLIB
@ HTTP_SWF_COMPRESSION_NONE
@ HTTP_SWF_COMPRESSION_LZMA
@ HTTP_SWF_COMPRESSION_BOTH
@ HTP_BODY_REQUEST_NONE
@ HTP_BODY_REQUEST_PUT
@ HTP_BODY_REQUEST_POST
@ HTP_BODY_REQUEST_MULTIPART
Flow data structure.
Definition flow.h:356
uint32_t inspect_window
uint32_t inspect_min_size
uint32_t body_limit
HtpSwfCompressType swf_compression_type
HTPCfgDir request
struct HTPCfgRec_ * next
uint32_t swf_decompress_depth
int swf_decompression_enabled
bool uri_include_all
htp_cfg_t * cfg
HTPCfgDir response
uint32_t swf_compress_depth
StreamingBufferSegment sbseg
struct HtpBodyChunk_ * next
HtpBodyChunk * last
uint64_t content_len_so_far
HtpBodyChunk * first
uint64_t body_parsed
uint64_t body_inspected
StreamingBuffer * sb
uint64_t last_request_data_stamp
uint64_t last_response_data_stamp
uint64_t transaction_cnt
StreamSlice * slice
uint16_t events
uint16_t htp_messages_count
const struct HTPCfgRec_ * cfg
FrameId request_frame_id
AppLayerStateData state_data
htp_conn_t * conn
FrameId response_frame_id
uint16_t flags
uint32_t file_track_id
htp_connp_t * connp
uint32_t request_headers_raw_len
FileContainer files_ts
HttpRangeContainerBlock * file_range
MimeStateHTTP * mime_state
uint8_t request_has_trailers
uint8_t * request_headers_raw
HtpBody response_body
AppLayerTxData tx_data
uint8_t response_body_init
uint8_t * response_headers_raw
FileContainer files_tc
uint8_t request_body_type
uint8_t response_has_trailers
uint8_t request_body_init
uint32_t response_headers_raw_len
#define SC_ATOMIC_EXTERN(type, name)
wrapper for referencing an atomic variable declared on another file.