|
|
|
@ -52,8 +52,6 @@
|
|
|
|
|
#include "detect-http-raw-header.h"
|
|
|
|
|
#include "stream-tcp.h"
|
|
|
|
|
|
|
|
|
|
int DetectHttpRawHeaderMatch(ThreadVars *, DetectEngineThreadCtx *, Flow *,
|
|
|
|
|
uint8_t, void *, Signature *, SigMatch *);
|
|
|
|
|
int DetectHttpRawHeaderSetup(DetectEngineCtx *, Signature *, char *);
|
|
|
|
|
void DetectHttpRawHeaderRegisterTests(void);
|
|
|
|
|
void DetectHttpRawHeaderFree(void *);
|
|
|
|
@ -66,7 +64,6 @@ void DetectHttpRawHeaderRegister(void)
|
|
|
|
|
sigmatch_table[DETECT_AL_HTTP_RAW_HEADER].name = "http_raw_header";
|
|
|
|
|
sigmatch_table[DETECT_AL_HTTP_RAW_HEADER].Match = NULL;
|
|
|
|
|
sigmatch_table[DETECT_AL_HTTP_RAW_HEADER].AppLayerMatch = NULL;
|
|
|
|
|
//sigmatch_table[DETECT_AL_HTTP_RAW_HEADER].AppLayerMatch = DetectHttpRawHeaderMatch;
|
|
|
|
|
sigmatch_table[DETECT_AL_HTTP_RAW_HEADER].Setup = DetectHttpRawHeaderSetup;
|
|
|
|
|
sigmatch_table[DETECT_AL_HTTP_RAW_HEADER].Free = DetectHttpRawHeaderFree;
|
|
|
|
|
sigmatch_table[DETECT_AL_HTTP_RAW_HEADER].RegisterTests = DetectHttpRawHeaderRegisterTests;
|
|
|
|
@ -77,75 +74,6 @@ void DetectHttpRawHeaderRegister(void)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief App layer match function for the "http_raw_header" keyword.
|
|
|
|
|
*
|
|
|
|
|
* \param t Pointer to the ThreadVars instance.
|
|
|
|
|
* \param det_ctx Pointer to the DetectEngineThreadCtx.
|
|
|
|
|
* \param f Pointer to the flow.
|
|
|
|
|
* \param flags Pointer to the flags indicating the flow direction.
|
|
|
|
|
* \param state Pointer to the app layer state data.
|
|
|
|
|
* \param s Pointer to the Signature instance.
|
|
|
|
|
* \param m Pointer to the SigMatch.
|
|
|
|
|
*
|
|
|
|
|
* \retval 1 On Match.
|
|
|
|
|
* \retval 0 On no match.
|
|
|
|
|
*/
|
|
|
|
|
int DetectHttpRawHeaderMatch(ThreadVars *t, DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
Flow *f, uint8_t flags, void *state, Signature *s,
|
|
|
|
|
SigMatch *m)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
int result = 0;
|
|
|
|
|
DetectContentData *hrhd = (DetectContentData *)m->ctx;
|
|
|
|
|
HtpState *htp_state = (HtpState *)state;
|
|
|
|
|
|
|
|
|
|
SCMutexLock(&f->m);
|
|
|
|
|
|
|
|
|
|
if (htp_state == NULL || htp_state->connp == NULL ||
|
|
|
|
|
htp_state->connp->conn == NULL) {
|
|
|
|
|
SCLogDebug("No htp state, no match for http header data");
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
htp_tx_t *tx = NULL;
|
|
|
|
|
bstr *headers = NULL;
|
|
|
|
|
size_t idx = 0;
|
|
|
|
|
|
|
|
|
|
//htp_state->new_in_tx_index;
|
|
|
|
|
size_t l_size = list_size(htp_state->connp->conn->transactions);
|
|
|
|
|
for (idx = 0; idx < l_size; idx++) {
|
|
|
|
|
tx = list_get(htp_state->connp->conn->transactions, idx);
|
|
|
|
|
|
|
|
|
|
if (tx == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
headers = htp_tx_get_request_headers_raw(tx);
|
|
|
|
|
if (headers == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
SCLogDebug("inspecting tx %p", tx);
|
|
|
|
|
|
|
|
|
|
if (bstr_len(headers) > 0) {
|
|
|
|
|
/* call the case sensitive version if nocase has been specified in the sig */
|
|
|
|
|
if (hrhd->flags & DETECT_CONTENT_NOCASE) {
|
|
|
|
|
result = (SpmNocaseSearch((uint8_t *)bstr_ptr(headers), bstr_len(headers),
|
|
|
|
|
hrhd->content, hrhd->content_len) != NULL);
|
|
|
|
|
} else {
|
|
|
|
|
result = (SpmSearch((uint8_t *)bstr_ptr(headers), bstr_len(headers),
|
|
|
|
|
hrhd->content, hrhd->content_len) != NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCMutexUnlock(&f->m);
|
|
|
|
|
SCReturnInt(result ^ ((hrhd->flags & DETECT_CONTENT_NEGATED) ? 1 : 0));
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
SCMutexUnlock(&f->m);
|
|
|
|
|
SCReturnInt(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief this function clears the memory of http_raw_header modifier keyword
|
|
|
|
@ -157,6 +85,7 @@ void DetectHttpRawHeaderFree(void *ptr)
|
|
|
|
|
DetectContentData *cd = (DetectContentData *)ptr;
|
|
|
|
|
if (cd == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (cd->content != NULL)
|
|
|
|
|
SCFree(cd->content);
|
|
|
|
|
SCFree(cd);
|
|
|
|
|