http_host: mpm prefilter engine

pull/2310/head
Victor Julien 9 years ago
parent 61c3748fc4
commit 5218849213

@ -1,4 +1,4 @@
/* Copyright (C) 2007-2013 Open Information Security Foundation
/* Copyright (C) 2007-2016 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
@ -25,6 +25,7 @@
/** \file
*
* \author Anoop Saldanha <anoopsaldanha@gmail.com>
* \author Victor Julien <victor@inliniac.net>
*
* \brief Handle HTTP host header.
* HHHD - Http Host Header Data
@ -41,6 +42,7 @@
#include "detect-parse.h"
#include "detect-engine-state.h"
#include "detect-engine-content-inspection.h"
#include "detect-engine-prefilter.h"
#include "flow-util.h"
#include "util-debug.h"
@ -60,49 +62,43 @@
#include "detect-engine-hhhd.h"
#include "util-validate.h"
/**
* \brief Http host header match -- searches for one pattern per signature.
*
* \param det_ctx Detection engine thread ctx.
* \param hh Host header to inspect.
* \param hh_len Host header buffer length.
* \param flags Flags
/** \brief HTTP Host Mpm prefilter callback
*
* \retval ret Number of matches.
* \param det_ctx detection engine thread ctx
* \param p packet to inspect
* \param f flow to inspect
* \param txv tx to inspect
* \param pectx inspection context
*/
static inline uint32_t HttpHHPatternSearch(DetectEngineThreadCtx *det_ctx,
const uint8_t *hh, const uint32_t hh_len)
static void PrefilterTxHostname(DetectEngineThreadCtx *det_ctx,
const void *pectx,
Packet *p, Flow *f, void *txv,
const uint64_t idx, const uint8_t flags)
{
SCEnter();
uint32_t ret = 0;
const MpmCtx *mpm_ctx = (MpmCtx *)pectx;
htp_tx_t *tx = (htp_tx_t *)txv;
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_hhhd_ctx_ts == NULL);
if (tx->request_hostname == NULL)
return;
if (hh_len >= det_ctx->sgh->mpm_hhhd_ctx_ts->minlen) {
ret = mpm_table[det_ctx->sgh->mpm_hhhd_ctx_ts->mpm_type].
Search(det_ctx->sgh->mpm_hhhd_ctx_ts, &det_ctx->mtcu,
&det_ctx->pmq, hh, hh_len);
}
const uint32_t buffer_len = bstr_len(tx->request_hostname);
const uint8_t *buffer = bstr_ptr(tx->request_hostname);
SCReturnUInt(ret);
if (buffer_len >= mpm_ctx->minlen) {
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtcu, &det_ctx->pmq, buffer, buffer_len);
}
}
int DetectEngineRunHttpHHMpm(DetectEngineThreadCtx *det_ctx, void *txv)
int PrefilterTxHostnameRegister(SigGroupHead *sgh, MpmCtx *mpm_ctx)
{
uint32_t cnt = 0;
htp_tx_t *tx = (htp_tx_t *)txv;
if (tx->request_hostname == NULL)
goto end;
const uint8_t *hname = (const uint8_t *)bstr_ptr(tx->request_hostname);
if (hname == NULL)
goto end;
const uint32_t hname_len = bstr_len(tx->request_hostname);
cnt = HttpHHPatternSearch(det_ctx, hname, hname_len);
SCEnter();
end:
return cnt;
return PrefilterAppendTxEngine(sgh, PrefilterTxHostname,
ALPROTO_HTTP, HTP_REQUEST_HEADERS,
mpm_ctx, NULL);
}
/**

@ -1,4 +1,4 @@
/* Copyright (C) 2007-2013 Open Information Security Foundation
/* Copyright (C) 2007-2016 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
@ -25,6 +25,8 @@
#include "app-layer-htp.h"
int PrefilterTxHostnameRegister(SigGroupHead *sgh, MpmCtx *mpm_ctx);
int DetectEngineInspectHttpHH(ThreadVars *tv,
DetectEngineCtx *de_ctx,
DetectEngineThreadCtx *det_ctx,
@ -32,8 +34,6 @@ int DetectEngineInspectHttpHH(ThreadVars *tv,
void *alstate,
void *tx, uint64_t tx_id);
int DetectEngineRunHttpHHMpm(DetectEngineThreadCtx *det_ctx, void *txv);
void DetectEngineHttpHHRegisterTests(void);
#endif /* __DETECT_ENGINE_HHHD_H__ */

@ -54,6 +54,7 @@
#include "detect-engine-hmd.h"
#include "detect-engine-hcd.h"
#include "detect-engine-hua.h"
#include "detect-engine-hhhd.h"
#include "detect-engine-dns.h"
#include "stream.h"
@ -112,7 +113,8 @@ AppLayerMpms app_mpms[] = {
{ "http_client_body", 0, SIG_FLAG_TOSERVER, DETECT_SM_LIST_HCBDMATCH, SIG_GROUP_HEAD_MPM_HCBD, NULL, 12},
{ "http_host", 0, SIG_FLAG_TOSERVER, DETECT_SM_LIST_HHHDMATCH, SIG_GROUP_HEAD_MPM_HHHD, NULL, 13},
{ "http_host", 0, SIG_FLAG_TOSERVER, DETECT_SM_LIST_HHHDMATCH,
SIG_GROUP_HEAD_MPM_HHHD, PrefilterTxHostnameRegister, 13},
{ "http_raw_host", 0, SIG_FLAG_TOSERVER, DETECT_SM_LIST_HRHHDMATCH, SIG_GROUP_HEAD_MPM_HRHHD, NULL, 14},
{ "http_cookie", 0, SIG_FLAG_TOSERVER, DETECT_SM_LIST_HCDMATCH,

@ -903,11 +903,6 @@ static inline void DetectMpmPrefilter(DetectEngineCtx *de_ctx,
tx_progress = AppLayerParserGetStateProgress(IPPROTO_TCP, ALPROTO_HTTP, tx, flags);
if (tx_progress >= HTP_REQUEST_HEADERS) {
if (det_ctx->sgh->flags & SIG_GROUP_HEAD_MPM_HHHD) {
PACKET_PROFILING_DETECT_START(p, PROF_DETECT_MPM_HHHD);
DetectEngineRunHttpHHMpm(det_ctx, tx);
PACKET_PROFILING_DETECT_END(p, PROF_DETECT_MPM_HHHD);
}
if (det_ctx->sgh->flags & SIG_GROUP_HEAD_MPM_HRHHD) {
PACKET_PROFILING_DETECT_START(p, PROF_DETECT_MPM_HRHHD);
DetectEngineRunHttpHRHMpm(det_ctx, tx);

Loading…
Cancel
Save