|
|
|
|
@ -55,9 +55,6 @@
|
|
|
|
|
#include "util-debug.h"
|
|
|
|
|
#include "util-print.h"
|
|
|
|
|
#include "util-memcmp.h"
|
|
|
|
|
#ifdef __SC_CUDA_SUPPORT__
|
|
|
|
|
#include "util-mpm-ac.h"
|
|
|
|
|
#endif
|
|
|
|
|
#include "util-validate.h"
|
|
|
|
|
|
|
|
|
|
const char *builtin_mpms[] = {
|
|
|
|
|
@ -253,549 +250,6 @@ uint16_t PatternMatchDefaultMatcher(void)
|
|
|
|
|
return mpm_algo_val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t PacketPatternSearchWithStreamCtx(DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
Packet *p)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret = 0;
|
|
|
|
|
const MpmCtx *mpm_ctx = NULL;
|
|
|
|
|
|
|
|
|
|
if (p->flowflags & FLOW_PKT_TOSERVER) {
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_stream_ctx_ts == NULL);
|
|
|
|
|
|
|
|
|
|
mpm_ctx = det_ctx->sgh->mpm_stream_ctx_ts;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_stream_ctx_tc == NULL);
|
|
|
|
|
|
|
|
|
|
mpm_ctx = det_ctx->sgh->mpm_stream_ctx_tc;
|
|
|
|
|
}
|
|
|
|
|
if (unlikely(mpm_ctx == NULL)) {
|
|
|
|
|
SCReturnInt(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[mpm_ctx->mpm_type].
|
|
|
|
|
Search(mpm_ctx, &det_ctx->mtc, &det_ctx->pmq,
|
|
|
|
|
p->payload, p->payload_len);
|
|
|
|
|
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \brief Pattern match -- searches for only one pattern per signature.
|
|
|
|
|
*
|
|
|
|
|
* \param det_ctx detection engine thread ctx
|
|
|
|
|
* \param p packet to inspect
|
|
|
|
|
*
|
|
|
|
|
* \retval ret number of matches
|
|
|
|
|
*/
|
|
|
|
|
uint32_t PacketPatternSearch(DetectEngineThreadCtx *det_ctx, Packet *p)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret;
|
|
|
|
|
const MpmCtx *mpm_ctx = NULL;
|
|
|
|
|
|
|
|
|
|
if (p->proto == IPPROTO_TCP) {
|
|
|
|
|
if (p->flowflags & FLOW_PKT_TOSERVER) {
|
|
|
|
|
mpm_ctx = det_ctx->sgh->mpm_proto_tcp_ctx_ts;
|
|
|
|
|
} else {
|
|
|
|
|
mpm_ctx = det_ctx->sgh->mpm_proto_tcp_ctx_tc;
|
|
|
|
|
}
|
|
|
|
|
} else if (p->proto == IPPROTO_UDP) {
|
|
|
|
|
if (p->flowflags & FLOW_PKT_TOSERVER) {
|
|
|
|
|
mpm_ctx = det_ctx->sgh->mpm_proto_udp_ctx_ts;
|
|
|
|
|
} else {
|
|
|
|
|
mpm_ctx = det_ctx->sgh->mpm_proto_udp_ctx_tc;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
mpm_ctx = det_ctx->sgh->mpm_proto_other_ctx;
|
|
|
|
|
}
|
|
|
|
|
if (unlikely(mpm_ctx == NULL))
|
|
|
|
|
SCReturnInt(0);
|
|
|
|
|
|
|
|
|
|
#ifdef __SC_CUDA_SUPPORT__
|
|
|
|
|
if (p->cuda_pkt_vars.cuda_mpm_enabled && p->pkt_src == PKT_SRC_WIRE) {
|
|
|
|
|
ret = SCACCudaPacketResultsProcessing(p, mpm_ctx, &det_ctx->pmq);
|
|
|
|
|
} else {
|
|
|
|
|
ret = mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
|
|
|
|
|
&det_ctx->mtc,
|
|
|
|
|
&det_ctx->pmq,
|
|
|
|
|
p->payload,
|
|
|
|
|
p->payload_len);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
ret = mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
|
|
|
|
|
&det_ctx->mtc,
|
|
|
|
|
&det_ctx->pmq,
|
|
|
|
|
p->payload,
|
|
|
|
|
p->payload_len);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \brief Uri Pattern match -- searches for one pattern per signature.
|
|
|
|
|
*
|
|
|
|
|
* \param det_ctx detection engine thread ctx
|
|
|
|
|
* \param p packet to inspect
|
|
|
|
|
*
|
|
|
|
|
* \retval ret number of matches
|
|
|
|
|
*/
|
|
|
|
|
uint32_t UriPatternSearch(DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
uint8_t *uri, uint16_t uri_len, uint8_t flags)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret;
|
|
|
|
|
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(flags & STREAM_TOCLIENT);
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_uri_ctx_ts == NULL);
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[det_ctx->sgh->mpm_uri_ctx_ts->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_uri_ctx_ts,
|
|
|
|
|
&det_ctx->mtcu, &det_ctx->pmq, uri, uri_len);
|
|
|
|
|
|
|
|
|
|
//PrintRawDataFp(stdout, uri, uri_len);
|
|
|
|
|
|
|
|
|
|
SCReturnUInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \brief Http client body pattern match -- searches for one pattern per
|
|
|
|
|
* signature.
|
|
|
|
|
*
|
|
|
|
|
* \param det_ctx Detection engine thread ctx.
|
|
|
|
|
* \param body The request body to inspect.
|
|
|
|
|
* \param body_len Body length.
|
|
|
|
|
*
|
|
|
|
|
* \retval ret Number of matches.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t HttpClientBodyPatternSearch(DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
uint8_t *body, uint32_t body_len, uint8_t flags)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret;
|
|
|
|
|
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(flags & STREAM_TOCLIENT);
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_hcbd_ctx_ts == NULL);
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[det_ctx->sgh->mpm_hcbd_ctx_ts->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_hcbd_ctx_ts, &det_ctx->mtcu,
|
|
|
|
|
&det_ctx->pmq, body, body_len);
|
|
|
|
|
|
|
|
|
|
SCReturnUInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \brief Http server body pattern match -- searches for one pattern per
|
|
|
|
|
* signature.
|
|
|
|
|
*
|
|
|
|
|
* \param det_ctx Detection engine thread ctx.
|
|
|
|
|
* \param body The request body to inspect.
|
|
|
|
|
* \param body_len Body length.
|
|
|
|
|
*
|
|
|
|
|
* \retval ret Number of matches.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t HttpServerBodyPatternSearch(DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
uint8_t *body, uint32_t body_len, uint8_t flags)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret;
|
|
|
|
|
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(!(flags & STREAM_TOCLIENT));
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_hsbd_ctx_tc == NULL);
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[det_ctx->sgh->mpm_hsbd_ctx_tc->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_hsbd_ctx_tc, &det_ctx->mtcu,
|
|
|
|
|
&det_ctx->pmq, body, body_len);
|
|
|
|
|
|
|
|
|
|
SCReturnUInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Http header match -- searches for one pattern per signature.
|
|
|
|
|
*
|
|
|
|
|
* \param det_ctx Detection engine thread ctx.
|
|
|
|
|
* \param headers Headers to inspect.
|
|
|
|
|
* \param headers_len Headers length.
|
|
|
|
|
*
|
|
|
|
|
* \retval ret Number of matches.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t HttpHeaderPatternSearch(DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
uint8_t *headers, uint32_t headers_len, uint8_t flags)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret;
|
|
|
|
|
if (flags & STREAM_TOSERVER) {
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_hhd_ctx_ts == NULL);
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[det_ctx->sgh->mpm_hhd_ctx_ts->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_hhd_ctx_ts, &det_ctx->mtcu,
|
|
|
|
|
&det_ctx->pmq, headers, headers_len);
|
|
|
|
|
} else {
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_hhd_ctx_tc == NULL);
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[det_ctx->sgh->mpm_hhd_ctx_tc->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_hhd_ctx_tc, &det_ctx->mtcu,
|
|
|
|
|
&det_ctx->pmq, headers, headers_len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCReturnUInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Http raw header match -- searches for one pattern per signature.
|
|
|
|
|
*
|
|
|
|
|
* \param det_ctx Detection engine thread ctx.
|
|
|
|
|
* \param headers Raw headers to inspect.
|
|
|
|
|
* \param headers_len Raw headers length.
|
|
|
|
|
*
|
|
|
|
|
* \retval ret Number of matches.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t HttpRawHeaderPatternSearch(DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
uint8_t *raw_headers, uint32_t raw_headers_len, uint8_t flags)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret;
|
|
|
|
|
if (flags & STREAM_TOSERVER) {
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_hrhd_ctx_ts == NULL);
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[det_ctx->sgh->mpm_hrhd_ctx_ts->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_hrhd_ctx_ts, &det_ctx->mtcu,
|
|
|
|
|
&det_ctx->pmq, raw_headers, raw_headers_len);
|
|
|
|
|
} else {
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_hrhd_ctx_tc == NULL);
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[det_ctx->sgh->mpm_hrhd_ctx_tc->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_hrhd_ctx_tc, &det_ctx->mtcu,
|
|
|
|
|
&det_ctx->pmq, raw_headers, raw_headers_len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCReturnUInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Http method match -- searches for one pattern per signature.
|
|
|
|
|
*
|
|
|
|
|
* \param det_ctx Detection engine thread ctx.
|
|
|
|
|
* \param method Method to inspect.
|
|
|
|
|
* \param method_len Method length.
|
|
|
|
|
*
|
|
|
|
|
* \retval ret Number of matches.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t HttpMethodPatternSearch(DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
uint8_t *raw_method, uint32_t raw_method_len, uint8_t flags)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret;
|
|
|
|
|
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(flags & STREAM_TOCLIENT);
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_hmd_ctx_ts == NULL);
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[det_ctx->sgh->mpm_hmd_ctx_ts->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_hmd_ctx_ts, &det_ctx->mtcu,
|
|
|
|
|
&det_ctx->pmq, raw_method, raw_method_len);
|
|
|
|
|
|
|
|
|
|
SCReturnUInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Http cookie match -- searches for one pattern per signature.
|
|
|
|
|
*
|
|
|
|
|
* \param det_ctx Detection engine thread ctx.
|
|
|
|
|
* \param cookie Cookie to inspect.
|
|
|
|
|
* \param cookie_len Cookie length.
|
|
|
|
|
*
|
|
|
|
|
* \retval ret Number of matches.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t HttpCookiePatternSearch(DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
uint8_t *cookie, uint32_t cookie_len, uint8_t flags)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret;
|
|
|
|
|
if (flags & STREAM_TOSERVER) {
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_hcd_ctx_ts == NULL);
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[det_ctx->sgh->mpm_hcd_ctx_ts->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_hcd_ctx_ts, &det_ctx->mtcu,
|
|
|
|
|
&det_ctx->pmq, cookie, cookie_len);
|
|
|
|
|
} else {
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_hcd_ctx_tc == NULL);
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[det_ctx->sgh->mpm_hcd_ctx_tc->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_hcd_ctx_tc, &det_ctx->mtcu,
|
|
|
|
|
&det_ctx->pmq, cookie, cookie_len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCReturnUInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Http raw uri match -- searches for one pattern per signature.
|
|
|
|
|
*
|
|
|
|
|
* \param det_ctx Detection engine thread ctx.
|
|
|
|
|
* \param uri Raw uri to inspect.
|
|
|
|
|
* \param uri_len Raw uri length.
|
|
|
|
|
*
|
|
|
|
|
* \retval ret Number of matches.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t HttpRawUriPatternSearch(DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
uint8_t *uri, uint32_t uri_len, uint8_t flags)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret;
|
|
|
|
|
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(flags & STREAM_TOCLIENT);
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_hrud_ctx_ts == NULL);
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[det_ctx->sgh->mpm_hrud_ctx_ts->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_hrud_ctx_ts, &det_ctx->mtcu,
|
|
|
|
|
&det_ctx->pmq, uri, uri_len);
|
|
|
|
|
|
|
|
|
|
SCReturnUInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Http stat msg match -- searches for one pattern per signature.
|
|
|
|
|
*
|
|
|
|
|
* \param det_ctx Detection engine thread ctx.
|
|
|
|
|
* \param stat_msg Stat msg to inspect.
|
|
|
|
|
* \param stat_msg_len Stat msg length.
|
|
|
|
|
*
|
|
|
|
|
* \retval ret Number of matches.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t HttpStatMsgPatternSearch(DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
uint8_t *stat_msg, uint32_t stat_msg_len, uint8_t flags)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret;
|
|
|
|
|
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(!(flags & STREAM_TOCLIENT));
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_hsmd_ctx_tc == NULL);
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[det_ctx->sgh->mpm_hsmd_ctx_tc->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_hsmd_ctx_tc, &det_ctx->mtcu,
|
|
|
|
|
&det_ctx->pmq, stat_msg, stat_msg_len);
|
|
|
|
|
|
|
|
|
|
SCReturnUInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Http stat code match -- searches for one pattern per signature.
|
|
|
|
|
*
|
|
|
|
|
* \param det_ctx Detection engine thread ctx.
|
|
|
|
|
* \param stat_code Stat code to inspect.
|
|
|
|
|
* \param stat_code_len Stat code length.
|
|
|
|
|
*
|
|
|
|
|
* \retval ret Number of matches.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t HttpStatCodePatternSearch(DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
uint8_t *stat_code, uint32_t stat_code_len, uint8_t flags)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret;
|
|
|
|
|
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(!(flags & STREAM_TOCLIENT));
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_hscd_ctx_tc == NULL);
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[det_ctx->sgh->mpm_hscd_ctx_tc->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_hscd_ctx_tc, &det_ctx->mtcu,
|
|
|
|
|
&det_ctx->pmq, stat_code, stat_code_len);
|
|
|
|
|
|
|
|
|
|
SCReturnUInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Http user agent match -- searches for one pattern per signature.
|
|
|
|
|
*
|
|
|
|
|
* \param det_ctx Detection engine thread ctx.
|
|
|
|
|
* \param cookie User-Agent to inspect.
|
|
|
|
|
* \param cookie_len User-Agent buffer length.
|
|
|
|
|
*
|
|
|
|
|
* \retval ret Number of matches.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t HttpUAPatternSearch(DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
uint8_t *ua, uint32_t ua_len, uint8_t flags)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret;
|
|
|
|
|
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(flags & STREAM_TOCLIENT);
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_huad_ctx_ts == NULL);
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[det_ctx->sgh->mpm_huad_ctx_ts->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_huad_ctx_ts, &det_ctx->mtcu,
|
|
|
|
|
&det_ctx->pmq, ua, ua_len);
|
|
|
|
|
|
|
|
|
|
SCReturnUInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \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
|
|
|
|
|
*
|
|
|
|
|
* \retval ret Number of matches.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t HttpHHPatternSearch(DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
uint8_t *hh, uint32_t hh_len, uint8_t flags)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret;
|
|
|
|
|
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(flags & STREAM_TOCLIENT);
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_hhhd_ctx_ts == NULL);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
SCReturnUInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Http raw host header match -- searches for one pattern per signature.
|
|
|
|
|
*
|
|
|
|
|
* \param det_ctx Detection engine thread ctx.
|
|
|
|
|
* \param hrh Raw hostname to inspect.
|
|
|
|
|
* \param hrh_len Raw hostname buffer length.
|
|
|
|
|
* \param flags Flags
|
|
|
|
|
*
|
|
|
|
|
* \retval ret Number of matches.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t HttpHRHPatternSearch(DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
uint8_t *hrh, uint32_t hrh_len, uint8_t flags)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret;
|
|
|
|
|
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(flags & STREAM_TOCLIENT);
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_hrhhd_ctx_ts == NULL);
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[det_ctx->sgh->mpm_hrhhd_ctx_ts->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_hrhhd_ctx_ts, &det_ctx->mtcu,
|
|
|
|
|
&det_ctx->pmq, hrh, hrh_len);
|
|
|
|
|
|
|
|
|
|
SCReturnUInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief DNS query match -- searches for one pattern per signature.
|
|
|
|
|
*
|
|
|
|
|
* \param det_ctx Detection engine thread ctx.
|
|
|
|
|
* \param hrh Buffer to inspect.
|
|
|
|
|
* \param hrh_len buffer length.
|
|
|
|
|
* \param flags Flags
|
|
|
|
|
*
|
|
|
|
|
* \retval ret Number of matches.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t DnsQueryPatternSearch(DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
uint8_t *buffer, uint32_t buffer_len,
|
|
|
|
|
uint8_t flags)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret = 0;
|
|
|
|
|
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(flags & STREAM_TOCLIENT);
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_dnsquery_ctx_ts == NULL);
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[det_ctx->sgh->mpm_dnsquery_ctx_ts->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_dnsquery_ctx_ts, &det_ctx->mtcu,
|
|
|
|
|
&det_ctx->pmq, buffer, buffer_len);
|
|
|
|
|
|
|
|
|
|
SCReturnUInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \brief Pattern match -- searches for only one pattern per signature.
|
|
|
|
|
*
|
|
|
|
|
* \param det_ctx detection engine thread ctx
|
|
|
|
|
* \param p packet
|
|
|
|
|
* \param smsg stream msg (reassembled stream data)
|
|
|
|
|
* \param flags stream flags
|
|
|
|
|
*
|
|
|
|
|
* \retval ret number of matches
|
|
|
|
|
*/
|
|
|
|
|
uint32_t StreamPatternSearch(DetectEngineThreadCtx *det_ctx, Packet *p,
|
|
|
|
|
StreamMsg *smsg, uint8_t flags)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret = 0;
|
|
|
|
|
uint8_t cnt = 0;
|
|
|
|
|
|
|
|
|
|
//PrintRawDataFp(stdout, smsg->data.data, smsg->data.data_len);
|
|
|
|
|
|
|
|
|
|
uint32_t r;
|
|
|
|
|
if (flags & STREAM_TOSERVER) {
|
|
|
|
|
for ( ; smsg != NULL; smsg = smsg->next) {
|
|
|
|
|
r = mpm_table[det_ctx->sgh->mpm_stream_ctx_ts->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_stream_ctx_ts, &det_ctx->mtcs,
|
|
|
|
|
&det_ctx->pmq, smsg->data, smsg->data_len);
|
|
|
|
|
if (r > 0) {
|
|
|
|
|
ret += r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cnt++;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for ( ; smsg != NULL; smsg = smsg->next) {
|
|
|
|
|
r = mpm_table[det_ctx->sgh->mpm_stream_ctx_tc->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_stream_ctx_tc, &det_ctx->mtcs,
|
|
|
|
|
&det_ctx->pmq, smsg->data, smsg->data_len);
|
|
|
|
|
if (r > 0) {
|
|
|
|
|
ret += r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cnt++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief SMTP Filedata match -- searches for one pattern per signature.
|
|
|
|
|
*
|
|
|
|
|
* \param det_ctx Detection engine thread ctx.
|
|
|
|
|
* \param buffer Buffer to inspect.
|
|
|
|
|
* \param buffer_len buffer length.
|
|
|
|
|
* \param flags Flags
|
|
|
|
|
*
|
|
|
|
|
* \retval ret Number of matches.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t SMTPFiledataPatternSearch(DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
uint8_t *buffer, uint32_t buffer_len,
|
|
|
|
|
uint8_t flags)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t ret = 0;
|
|
|
|
|
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(flags & STREAM_TOCLIENT);
|
|
|
|
|
DEBUG_VALIDATE_BUG_ON(det_ctx->sgh->mpm_smtp_filedata_ctx_ts == NULL);
|
|
|
|
|
|
|
|
|
|
ret = mpm_table[det_ctx->sgh->mpm_smtp_filedata_ctx_ts->mpm_type].
|
|
|
|
|
Search(det_ctx->sgh->mpm_smtp_filedata_ctx_ts, &det_ctx->mtcu,
|
|
|
|
|
&det_ctx->pmq, buffer, buffer_len);
|
|
|
|
|
|
|
|
|
|
SCReturnUInt(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \brief cleans up the mpm instance after a match */
|
|
|
|
|
void PacketPatternCleanup(ThreadVars *t, DetectEngineThreadCtx *det_ctx)
|
|
|
|
|
{
|
|
|
|
|
|