|
|
|
@ -62,113 +62,6 @@
|
|
|
|
|
#include "detect-engine-hrhhd.h"
|
|
|
|
|
#include "util-validate.h"
|
|
|
|
|
|
|
|
|
|
/** \brief HTTP Host (Raw) Mpm prefilter callback
|
|
|
|
|
*
|
|
|
|
|
* \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 void PrefilterTxHostnameRaw(DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
const void *pectx,
|
|
|
|
|
Packet *p, Flow *f, void *txv,
|
|
|
|
|
const uint64_t idx, const uint8_t flags)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
const MpmCtx *mpm_ctx = (MpmCtx *)pectx;
|
|
|
|
|
htp_tx_t *tx = (htp_tx_t *)txv;
|
|
|
|
|
const uint8_t *hname = NULL;
|
|
|
|
|
uint32_t hname_len = 0;
|
|
|
|
|
|
|
|
|
|
if (tx->parsed_uri == NULL || tx->parsed_uri->hostname == NULL) {
|
|
|
|
|
if (tx->request_headers == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
htp_header_t *h = (htp_header_t *)htp_table_get_c(tx->request_headers,
|
|
|
|
|
"Host");
|
|
|
|
|
if (h == NULL || h->value == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
hname = (const uint8_t *)bstr_ptr(h->value);
|
|
|
|
|
hname_len = bstr_len(h->value);
|
|
|
|
|
} else {
|
|
|
|
|
hname = (const uint8_t *)bstr_ptr(tx->parsed_uri->hostname);
|
|
|
|
|
hname_len = bstr_len(tx->parsed_uri->hostname);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hname != NULL && hname_len >= mpm_ctx->minlen) {
|
|
|
|
|
(void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
|
|
|
|
|
&det_ctx->mtcu, &det_ctx->pmq, hname, hname_len);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int PrefilterTxHostnameRawRegister(DetectEngineCtx *de_ctx,
|
|
|
|
|
SigGroupHead *sgh, MpmCtx *mpm_ctx)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
return PrefilterAppendTxEngine(de_ctx, sgh, PrefilterTxHostnameRaw,
|
|
|
|
|
ALPROTO_HTTP, HTP_REQUEST_HEADERS,
|
|
|
|
|
mpm_ctx, NULL, "http_raw_host");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Do the http_header content inspection for a signature.
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Detection engine context.
|
|
|
|
|
* \param det_ctx Detection engine thread context.
|
|
|
|
|
* \param s Signature to inspect.
|
|
|
|
|
* \param f Flow.
|
|
|
|
|
* \param flags App layer flags.
|
|
|
|
|
* \param state App layer state.
|
|
|
|
|
*
|
|
|
|
|
* \retval 0 No match.
|
|
|
|
|
* \retval 1 Match.
|
|
|
|
|
*/
|
|
|
|
|
int DetectEngineInspectHttpHRH(ThreadVars *tv,
|
|
|
|
|
DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
const Signature *s, const SigMatchData *smd,
|
|
|
|
|
Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
|
|
|
|
|
{
|
|
|
|
|
uint8_t *hname;
|
|
|
|
|
uint32_t hname_len;
|
|
|
|
|
htp_tx_t *tx = (htp_tx_t *)txv;
|
|
|
|
|
if (tx->parsed_uri == NULL || tx->parsed_uri->hostname == NULL) {
|
|
|
|
|
htp_header_t *h = NULL;
|
|
|
|
|
h = (htp_header_t *)htp_table_get_c(tx->request_headers, "Host");
|
|
|
|
|
if (h == NULL) {
|
|
|
|
|
SCLogDebug("HTTP host header not present in this request");
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
hname = (uint8_t *)bstr_ptr(h->value);
|
|
|
|
|
hname_len = bstr_len(h->value);
|
|
|
|
|
} else {
|
|
|
|
|
hname = (uint8_t *)bstr_ptr(tx->parsed_uri->hostname);
|
|
|
|
|
if (hname == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
hname_len = bstr_len(tx->parsed_uri->hostname);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
det_ctx->buffer_offset = 0;
|
|
|
|
|
det_ctx->discontinue_matching = 0;
|
|
|
|
|
det_ctx->inspection_recursion_counter = 0;
|
|
|
|
|
int r = DetectEngineContentInspection(de_ctx, det_ctx, s, smd,
|
|
|
|
|
f,
|
|
|
|
|
hname, hname_len,
|
|
|
|
|
0, DETECT_CI_FLAGS_SINGLE,
|
|
|
|
|
DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE, NULL);
|
|
|
|
|
if (r == 1)
|
|
|
|
|
return DETECT_ENGINE_INSPECT_SIG_MATCH;
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
if (AppLayerParserGetStateProgress(IPPROTO_TCP, ALPROTO_HTTP, tx, flags) > HTP_REQUEST_HEADERS)
|
|
|
|
|
return DETECT_ENGINE_INSPECT_SIG_CANT_MATCH;
|
|
|
|
|
else
|
|
|
|
|
return DETECT_ENGINE_INSPECT_SIG_NO_MATCH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************Unittests**********************************/
|
|
|
|
|
|
|
|
|
|
#ifdef UNITTESTS
|
|
|
|
|