fix padding calculation and stubdata parser for dcerpc

remotes/origin/master-1.0.x
Kirby Kuehl 17 years ago committed by Victor Julien
parent 811f2f605d
commit f15ca04889

@ -36,7 +36,7 @@ enum {
DCERPC_FIELD_MAX,
};
#if 0
#ifdef UNITTESTS
/* \brief hexdump function from libdnet, used for debugging only */
void hexdump(const void *buf, size_t len) {
/* dumps len bytes of *buf to stdout. Looks like:
@ -780,13 +780,15 @@ static uint32_t DCERPCParseREQUEST(Flow *f, void *dcerpc_state,
case 16:
sstate->numctxitems = 0;
if (input_len >= 8) {
if (sstate->dcerpc.packed_drep[0] == 0x10) {
sstate->opnum = *(p + 6);
sstate->opnum |= *(p + 7) << 8;
} else {
sstate->opnum = *(p + 6) << 8;
sstate->opnum |= *(p + 7);
}
if (sstate->dcerpc.type == REQUEST) {
if (sstate->dcerpc.packed_drep[0] == 0x10) {
sstate->opnum = *(p + 6);
sstate->opnum |= *(p + 7) << 8;
} else {
sstate->opnum = *(p + 6) << 8;
sstate->opnum |= *(p + 7);
}
}
sstate->bytesprocessed += 8;
SCReturnUInt(8U);
} else {
@ -821,14 +823,18 @@ static uint32_t DCERPCParseREQUEST(Flow *f, void *dcerpc_state,
if (!(--input_len))
break;
case 22:
sstate->opnum = *(p++);
if (sstate->dcerpc.type == REQUEST) {
sstate->opnum = *(p++);
}
if (!(--input_len))
break;
case 23:
sstate->opnum |= *(p++) << 8;
if (sstate->dcerpc.packed_drep[0] == 0x01) {
SCByteSwap16(sstate->opnum);
}
if (sstate->dcerpc.type == REQUEST) {
sstate->opnum |= *(p++) << 8;
if (sstate->dcerpc.packed_drep[0] == 0x01) {
SCByteSwap16(sstate->opnum);
}
}
--input_len;
break;
}
@ -989,6 +995,7 @@ static int DCERPCParse(Flow *f, void *dcerpc_state,
if (pstate == NULL)
SCReturnInt(-1);
while (sstate->bytesprocessed < DCERPC_HDR_LEN && input_len) {
retval = DCERPCParseHeader(f, dcerpc_state, pstate, input, input_len,
output);
@ -1083,8 +1090,10 @@ static int DCERPCParse(Flow *f, void *dcerpc_state,
if (sstate->bytesprocessed == DCERPC_HDR_LEN + 10
+ sstate->secondaryaddrlen) {
sstate->pad = sstate->bytesprocessed % 4;
sstate->padleft = sstate->pad;
if (sstate->bytesprocessed % 4) {
sstate->pad = (4 - sstate->bytesprocessed % 4);
sstate->padleft = sstate->pad;
}
}
while (sstate->bytesprocessed < DCERPC_HDR_LEN + 10
@ -1155,6 +1164,7 @@ static int DCERPCParse(Flow *f, void *dcerpc_state,
}
break;
case REQUEST:
case RESPONSE:
while (sstate->bytesprocessed < DCERPC_HDR_LEN + 8
&& sstate->bytesprocessed < sstate->dcerpc.frag_length
&& input_len) {
@ -1163,12 +1173,14 @@ static int DCERPCParse(Flow *f, void *dcerpc_state,
if (retval) {
parsed += retval;
input_len -= retval;
sstate->padleft = sstate->dcerpc.frag_length - sstate->bytesprocessed;
} else if (input_len) {
SCLogDebug("Error parsing DCERPC Request");
parsed -= input_len;
input_len = 0;
}
}
while (sstate->bytesprocessed >= DCERPC_HDR_LEN + 8
&& sstate->bytesprocessed < sstate->dcerpc.frag_length
&& input_len) {
@ -1181,21 +1193,21 @@ static int DCERPCParse(Flow *f, void *dcerpc_state,
SCLogDebug("Error parsing DCERPC Stub Data");
parsed -= input_len;
input_len = 0;
sstate->bytesprocessed = 0;
}
}
SCLogDebug("REQUEST processed %u/%u\n", sstate->bytesprocessed,
sstate->dcerpc.frag_length);
SCLogDebug("REQUEST processed %u frag length %u opnum %u input_len %u\n", sstate->bytesprocessed,
sstate->dcerpc.frag_length, sstate->opnum, input_len);
if (sstate->bytesprocessed == sstate->dcerpc.frag_length) {
sstate->bytesprocessed = 0;
}
break;
default:
SCLogDebug("DCERPC Type 0x%02x not implemented yet\n", sstate->dcerpc.type);
sstate->bytesprocessed = 0;
break;
}
pstate->parse_field = 0;
pstate->flags |= APP_LAYER_PARSER_DONE;
SCReturnInt(1);
}
@ -1241,7 +1253,7 @@ void RegisterDCERPCParsers(void) {
*/
/* set this to 1 to see problem */
#define KNOWNFAILURE 0
int DCERPCParserTest01(void) {
int result = 1;
Flow f;
@ -1463,7 +1475,7 @@ int DCERPCParserTest01(void) {
0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#if KNOWNFAILURE
uint8_t dcerpcrequest[] = {
0x05, 0x00, 0x00, 0x00, 0x10,
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
@ -1595,7 +1607,6 @@ int DCERPCParserTest01(void) {
0x00, 0x24, 0x00, 0x35, 0x00, 0x34, 0x00, 0x70,
0x00, 0x69, 0x00};
uint32_t requestlen = sizeof(dcerpcrequest);
#endif
uint32_t bindlen = sizeof(dcerpcbind);
uint32_t bindacklen = sizeof(dcerpcbindack);
@ -1660,10 +1671,9 @@ int DCERPCParserTest01(void) {
TAILQ_FOREACH(uuid_entry, &dcerpc_state->uuid_list, next) {
printUUID("BIND_ACK", uuid_entry);
}
#if KNOWNFAILURE
printf("Sending dcerpcrequest (%u)", requestlen);
hexdump(dcerpcrequest, requestlen);
r = AppLayerParse(&f, ALPROTO_DCERPC, STREAM_TOSERVER|STREAM_EOF, dcerpcrequest, requestlen, FALSE);
//hexdump(dcerpcrequest, requestlen);
r = AppLayerParse(&f, ALPROTO_DCERPC, STREAM_TOSERVER|STREAM_EOF, dcerpcrequest, requestlen);
if (r != 0) {
printf("dcerpc header check returned %" PRId32 ", expected 0: ", r);
result = 0;
@ -1674,7 +1684,6 @@ int DCERPCParserTest01(void) {
result = 0;
goto end;
}
#endif
end:
return result;
}

@ -5,9 +5,17 @@
#include "suricata-common.h"
#include "detect.h"
#include "detect-parse.h"
#include "detect-engine.h"
#include "detect-engine-mpm.h"
#include "detect-dce-iface.h"
#include "flow.h"
#include "flow-var.h"
#include "app-layer.h"
#include "app-layer-dcerpc.h"
#include "queue.h"
#include "stream-tcp-reassemble.h"
#include "util-debug.h"
#include "util-unittest.h"
@ -32,6 +40,7 @@ void DetectDceIfaceRegister(void)
int opts = 0;
sigmatch_table[DETECT_DCE_IFACE].name = "dce_iface";
sigmatch_table[DETECT_DCE_IFACE].alproto = ALPROTO_DCERPC;
sigmatch_table[DETECT_DCE_IFACE].Match = NULL;
sigmatch_table[DETECT_DCE_IFACE].AppLayerMatch = DetectDceIfaceMatch;
sigmatch_table[DETECT_DCE_IFACE].Setup = DetectDceIfaceSetup;
@ -94,12 +103,14 @@ static inline DetectDceIfaceData *DetectDceIfaceArgParse(const char *arg)
}
memset(did, 0, sizeof(DetectDceIfaceData));
/* retrieve the iface uuid string. iface uuid is a compulsion in the keyword */
res = pcre_get_substring(arg, ov, MAX_SUBSTRINGS, 1, &pcre_sub_str);
if (res < 0) {
SCLogError(SC_PCRE_GET_SUBSTRING_FAILED, "pcre_get_substring failed");
goto error;
}
/* parse the iface uuid string */
len = strlen(pcre_sub_str);
j = 0;
temp_str[2] = '\0';
@ -118,10 +129,32 @@ static inline DetectDceIfaceData *DetectDceIfaceArgParse(const char *arg)
j++;
}
/* if the regex has 3 or 5, any_frag option is present in the signature */
if (ret == 3 || ret == 5)
did->any_frag = 1;
/* if the regex has 4 or 5, version/operator is present in the signature */
if (ret == 4 || ret == 5) {
/* first handle the version number, so that we can do some additional
* validations of the version number, wrt. the operator */
res = pcre_get_substring(arg, ov, MAX_SUBSTRINGS, 3, &pcre_sub_str);
if (res < 0) {
SCLogError(SC_PCRE_GET_SUBSTRING_FAILED, "pcre_get_substring failed");
goto error;
}
version = atoi(pcre_sub_str);
if (version > UINT16_MAX) {
SCLogError(SC_ERR_INVALID_SIGNATURE, "DCE_IFACE interface version "
"invalid: %d\n", version);
goto error;
}
did->version = version;
/* free the substring */
pcre_free_substring(pcre_sub_str);
/* now let us handle the operator supplied with the version number */
res = pcre_get_substring(arg, ov, MAX_SUBSTRINGS, 2, &pcre_sub_str);
if (res < 0) {
SCLogError(SC_PCRE_GET_SUBSTRING_FAILED, "pcre_get_substring failed");
@ -130,9 +163,24 @@ static inline DetectDceIfaceData *DetectDceIfaceArgParse(const char *arg)
switch (pcre_sub_str[0]) {
case '<':
if (version == 0) {
SCLogError(SC_ERR_INVALID_SIGNATURE, "DCE_IFACE interface "
"version invalid: %d. Version can't be less"
"than 0, with \"<\" operator", version);
goto error;
}
did->op = DETECT_DCE_IFACE_OP_LT;
break;
case '>':
if (version == UINT16_MAX) {
SCLogError(SC_ERR_INVALID_SIGNATURE, "DCE_IFACE interface "
"version invalid: %d. Version can't be greater"
"than %d, with \">\" operator", version,
UINT16_MAX);
goto error;
}
did->op = DETECT_DCE_IFACE_OP_GT;
break;
case '=':
@ -143,19 +191,8 @@ static inline DetectDceIfaceData *DetectDceIfaceArgParse(const char *arg)
break;
}
res = pcre_get_substring(arg, ov, MAX_SUBSTRINGS, 3, &pcre_sub_str);
if (res < 0) {
SCLogError(SC_PCRE_GET_SUBSTRING_FAILED, "pcre_get_substring failed");
goto error;
}
version = atoi(pcre_sub_str);
if (version > 65535) {
SCLogError(SC_ERR_INVALID_SIGNATURE, "DCE_IFACE interface version "
"invalid: %d\n", version);
goto error;
}
did->version = version;
/* free the substring */
pcre_free_substring(pcre_sub_str);
}
return did;
@ -166,11 +203,53 @@ static inline DetectDceIfaceData *DetectDceIfaceArgParse(const char *arg)
return NULL;
}
/**
* \internal
* \brief Internal function that compares the dce interface version for this
* flow, to the signature's interface version specified using the
* dce_iface keyword.
*
* \param version The dce interface version for this flow.
* \param dce_data Pointer to the Signature's dce_iface keyword
* state(DetectDceIfaceData *).
*/
static inline int DetectDceIfaceMatchIfaceVersion(uint16_t version,
DetectDceIfaceData *dce_data)
{
switch (dce_data->op) {
case DETECT_DCE_IFACE_OP_LT:
return (version < dce_data->version);
case DETECT_DCE_IFACE_OP_GT:
return (version > dce_data->version);
case DETECT_DCE_IFACE_OP_EQ:
return (version == dce_data->version);
case DETECT_DCE_IFACE_OP_NE:
return (version != dce_data->version);
default:
return 1;
}
}
/**
* \brief App layer match function for the "dce_iface" 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 DetectDceIfaceMatch(ThreadVars *t, DetectEngineThreadCtx *det_ctx, Flow *f,
uint8_t flags, void *state, Signature *s, SigMatch *m)
{
int ret = 1;
struct uuid_entry *item = NULL;
int i = 0;
DetectDceIfaceData *dce_data = (DetectDceIfaceData *)m->ctx;
DCERPCState *dcerpc_state = (DCERPCState *)state;
if (dcerpc_state == NULL) {
@ -179,18 +258,46 @@ int DetectDceIfaceMatch(ThreadVars *t, DetectEngineThreadCtx *det_ctx, Flow *f,
}
SCMutexLock(&f->m);
int i = 0;
/* if any_frag is not enabled, we need to match only against the first
* fragment */
if (!dce_data->any_frag &&
!(dcerpc_state->dcerpc.pfc_flags & PFC_FIRST_FRAG)) {
/* any_frag has not been set, and apparently it's not the first fragment */
ret = 0;
goto end;
}
TAILQ_FOREACH(item, &dcerpc_state->uuid_list, next) {
ret = 1;
/* if the uuid has been rejected(item->result == 1), we skip to the
* next uuid */
if (item->result == 1)
continue;
/* check the interface uuid */
for (i = 0; i < 16; i++) {
if (dce_data->uuid[i] != item->uuid[i]) {
ret = 0;
break;
}
}
/* check the interface version */
if (dce_data->op != DETECT_DCE_IFACE_OP_NONE &&
!DetectDceIfaceMatchIfaceVersion(item->version, dce_data)) {
ret &= 0;
}
/* we have a match. Time to leave with a match */
if (ret == 1)
goto end;
}
return 1;
end:
SCMutexUnlock(&f->m);
return ret;
}
/**
@ -581,18 +688,549 @@ static int DetectDceIfaceTestParse11(void)
result &= (DetectDceIfaceSetup(NULL, s, NULL, "1234568-1234-1234-1234-123456789ABC,>1,any_frag") == -1);
result &= (DetectDceIfaceSetup(NULL, s, NULL, "12345678-1234-1234-1234-123456789ABC,>65536,any_frag") == -1);
result &= (DetectDceIfaceSetup(NULL, s, NULL, "12345678-1234-1234-1234-123456789ABC,>=1,any_frag") == -1);
result &= (DetectDceIfaceSetup(NULL, s, NULL, "12345678-1234-1234-1234-123456789ABC,<0,any_frag") == -1);
result &= (DetectDceIfaceSetup(NULL, s, NULL, "12345678-1234-1234-1234-123456789ABC,>65535,any_frag") == -1);
SigFree(s);
return result;
}
/**
* \test Test a valid dce_iface entry for a bind and bind_ack
*/
static int DetectDceIfaceTestParse12(void)
{
int result = 0;
Signature *s = NULL;
ThreadVars th_v;
Packet p;
Flow f;
TcpSession ssn;
DetectEngineThreadCtx *det_ctx = NULL;
DetectEngineCtx *de_ctx = NULL;
DCERPCState *dcerpc_state = NULL;
int r = 0;
uint8_t dcerpc_bind[] = {
0x05, 0x00, 0x0b, 0x03, 0x10, 0x00, 0x00, 0x00,
0x48, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0xb8, 0x10, 0xb8, 0x10, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
0x6a, 0x28, 0x19, 0x39, 0x0c, 0xb1, 0xd0, 0x11,
0x9b, 0xa8, 0x00, 0xc0, 0x4f, 0xd9, 0x2e, 0xf5,
0x00, 0x00, 0x00, 0x00, 0x04, 0x5d, 0x88, 0x8a,
0xeb, 0x1c, 0xc9, 0x11, 0x9f, 0xe8, 0x08, 0x00,
0x2b, 0x10, 0x48, 0x60, 0x02, 0x00, 0x00, 0x00,
};
uint8_t dcerpc_bindack[] = {
0x05, 0x00, 0x0c, 0x03, 0x10, 0x00, 0x00, 0x00,
0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0xb8, 0x10, 0xb8, 0x10, 0x26, 0x3d, 0x00, 0x00,
0x0c, 0x00, 0x5c, 0x50, 0x49, 0x50, 0x45, 0x5c,
0x6c, 0x73, 0x61, 0x73, 0x73, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x5d, 0x88, 0x8a, 0xeb, 0x1c, 0xc9, 0x11,
0x9f, 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60,
0x02, 0x00, 0x00, 0x00
};
uint32_t dcerpc_bind_len = sizeof(dcerpc_bind);
uint32_t dcerpc_bindack_len = sizeof(dcerpc_bindack);
memset(&th_v, 0, sizeof(th_v));
memset(&p, 0, sizeof(p));
memset(&f, 0, sizeof(f));
memset(&ssn, 0, sizeof(ssn));
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.payload = NULL;
p.payload_len = 0;
p.proto = IPPROTO_TCP;
StreamL7DataPtrInit(&ssn, StreamL7GetStorageSize());
f.protoctx = (void *)&ssn;
p.flow = &f;
p.flowflags |= FLOW_PKT_TOSERVER;
ssn.alproto = ALPROTO_DCERPC;
de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL)
goto end;
de_ctx->flags |= DE_QUIET;
s = de_ctx->sig_list = SigInit(de_ctx,
"alert tcp any any -> any any "
"(msg:\"DCERPC\"; "
"dce_iface:3919286a-b10c-11d0-9ba8-00c04fd92ef5,=0,any_frag; "
"sid:1;)");
if (s == NULL)
goto end;
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
r = AppLayerParse(&f, ALPROTO_DCERPC, STREAM_TOSERVER | STREAM_START,
dcerpc_bind, dcerpc_bind_len);
if (r != 0) {
SCLogDebug("AppLayerParse for dcerpc failed. Returned %" PRId32, r);
goto end;
}
dcerpc_state = ssn.aldata[AlpGetStateIdx(ALPROTO_DCERPC)];
if (dcerpc_state == NULL) {
SCLogDebug("no dcerpc state: ");
goto end;
}
/* do detect */
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
if (!PacketAlertCheck(&p, 1))
goto end;
r = AppLayerParse(&f, ALPROTO_DCERPC, STREAM_TOCLIENT, dcerpc_bindack,
dcerpc_bindack_len);
if (r != 0) {
SCLogDebug("AppLayerParse for dcerpc failed. Returned %" PRId32, r);
goto end;
}
/* do detect */
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
if (!PacketAlertCheck(&p, 1))
goto end;
result = 1;
end:
SigGroupCleanup(de_ctx);
SigCleanSignatures(de_ctx);
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}
/**
* \test Test a valid dce_iface entry with a bind, bind_ack and 3 request/responses.
*/
static int DetectDceIfaceTestParse13(void)
{
int result = 0;
Signature *s = NULL;
ThreadVars th_v;
Packet p;
Flow f;
TcpSession ssn;
DetectEngineThreadCtx *det_ctx = NULL;
DetectEngineCtx *de_ctx = NULL;
DCERPCState *dcerpc_state = NULL;
int r = 0;
uint8_t dcerpc_bind[] = {
0x05, 0x00, 0x0b, 0x03, 0x10, 0x00, 0x00, 0x00,
0x48, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0xb8, 0x10, 0xb8, 0x10, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
0x01, 0xd0, 0x8c, 0x33, 0x44, 0x22, 0xf1, 0x31,
0xaa, 0xaa, 0x90, 0x00, 0x38, 0x00, 0x10, 0x03,
0x01, 0x00, 0x00, 0x00, 0x04, 0x5d, 0x88, 0x8a,
0xeb, 0x1c, 0xc9, 0x11, 0x9f, 0xe8, 0x08, 0x00,
0x2b, 0x10, 0x48, 0x60, 0x02, 0x00, 0x00, 0x00,
};
uint8_t dcerpc_bindack[] = {
0x05, 0x00, 0x0c, 0x03, 0x10, 0x00, 0x00, 0x00,
0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0xb8, 0x10, 0xb8, 0x10, 0x65, 0x8e, 0x00, 0x00,
0x0d, 0x00, 0x5c, 0x50, 0x49, 0x50, 0x45, 0x5c,
0x77, 0x69, 0x6e, 0x72, 0x65, 0x67, 0x00, 0x6d,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x5d, 0x88, 0x8a, 0xeb, 0x1c, 0xc9, 0x11,
0x9f, 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60,
0x02, 0x00, 0x00, 0x00,
};
uint8_t dcerpc_request1[] = {
0x05, 0x00, 0x00, 0x03, 0x10, 0x00, 0x00, 0x00,
0x24, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
0x2c, 0xfd, 0xb5, 0x00, 0x40, 0xaa, 0x01, 0x00,
0x00, 0x00, 0x00, 0x02,
};
uint8_t dcerpc_response1[] = {
0x05, 0x00, 0x02, 0x03, 0x10, 0x00, 0x00, 0x00,
0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf6, 0x72, 0x28, 0x9c,
0xf0, 0x57, 0xd8, 0x11, 0xb0, 0x05, 0x00, 0x0c,
0x29, 0x87, 0xea, 0xe9, 0x00, 0x00, 0x00, 0x00,
};
uint8_t dcerpc_request2[] = {
0x05, 0x00, 0x00, 0x03, 0x10, 0x00, 0x00, 0x00,
0xa4, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf6, 0x72, 0x28, 0x9c,
0xf0, 0x57, 0xd8, 0x11, 0xb0, 0x05, 0x00, 0x0c,
0x29, 0x87, 0xea, 0xe9, 0x5c, 0x00, 0x5c, 0x00,
0xa8, 0xb9, 0x14, 0x00, 0x2e, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00,
0x53, 0x00, 0x4f, 0x00, 0x46, 0x00, 0x54, 0x00,
0x57, 0x00, 0x41, 0x00, 0x52, 0x00, 0x45, 0x00,
0x5c, 0x00, 0x4d, 0x00, 0x69, 0x00, 0x63, 0x00,
0x72, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x6f, 0x00,
0x66, 0x00, 0x74, 0x00, 0x5c, 0x00, 0x57, 0x00,
0x69, 0x00, 0x6e, 0x00, 0x64, 0x00, 0x6f, 0x00,
0x77, 0x00, 0x73, 0x00, 0x5c, 0x00, 0x43, 0x00,
0x75, 0x00, 0x72, 0x00, 0x72, 0x00, 0x65, 0x00,
0x6e, 0x00, 0x74, 0x00, 0x56, 0x00, 0x65, 0x00,
0x72, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6f, 0x00,
0x6e, 0x00, 0x5c, 0x00, 0x52, 0x00, 0x75, 0x00,
0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00,
};
uint8_t dcerpc_response2[] = {
0x05, 0x00, 0x02, 0x03, 0x10, 0x00, 0x00, 0x00,
0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf7, 0x72, 0x28, 0x9c,
0xf0, 0x57, 0xd8, 0x11, 0xb0, 0x05, 0x00, 0x0c,
0x29, 0x87, 0xea, 0xe9, 0x00, 0x00, 0x00, 0x00,
};
uint8_t dcerpc_request3[] = {
0x05, 0x00, 0x00, 0x03, 0x10, 0x00, 0x00, 0x00,
0x70, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf7, 0x72, 0x28, 0x9c,
0xf0, 0x57, 0xd8, 0x11, 0xb0, 0x05, 0x00, 0x0c,
0x29, 0x87, 0xea, 0xe9, 0x0c, 0x00, 0x0c, 0x00,
0x98, 0xda, 0x14, 0x00, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x4f, 0x00, 0x73, 0x00, 0x61, 0x00, 0x33, 0x00,
0x32, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x18, 0x00, 0x00, 0x00, 0x4e, 0x00, 0x54, 0x00,
0x4f, 0x00, 0x53, 0x00, 0x41, 0x00, 0x33, 0x00,
0x32, 0x00, 0x2e, 0x00, 0x45, 0x00, 0x58, 0x00,
0x45, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
};
uint8_t dcerpc_response3[] = {
0x05, 0x00, 0x02, 0x03, 0x10, 0x00, 0x00, 0x00,
0x1c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};
uint32_t dcerpc_bind_len = sizeof(dcerpc_bind);
uint32_t dcerpc_bindack_len = sizeof(dcerpc_bindack);
uint32_t dcerpc_request1_len = sizeof(dcerpc_request1_len);
uint32_t dcerpc_response1_len = sizeof(dcerpc_response1_len);
uint32_t dcerpc_request2_len = sizeof(dcerpc_request2_len);
uint32_t dcerpc_response2_len = sizeof(dcerpc_response2_len);
uint32_t dcerpc_request3_len = sizeof(dcerpc_request3_len);
uint32_t dcerpc_response3_len = sizeof(dcerpc_response3_len);
memset(&th_v, 0, sizeof(th_v));
memset(&p, 0, sizeof(p));
memset(&f, 0, sizeof(f));
memset(&ssn, 0, sizeof(ssn));
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.payload = NULL;
p.payload_len = 0;
p.proto = IPPROTO_TCP;
StreamL7DataPtrInit(&ssn, StreamL7GetStorageSize());
f.protoctx = (void *)&ssn;
p.flow = &f;
p.flowflags |= FLOW_PKT_TOSERVER;
ssn.alproto = ALPROTO_DCERPC;
de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL)
goto end;
de_ctx->flags |= DE_QUIET;
s = de_ctx->sig_list = SigInit(de_ctx,
"alert tcp any any -> any any "
"(msg:\"DCERPC\"; "
"dce_iface:338cd001-2244-31f1-aaaa-900038001003,=1,any_frag; "
"sid:1;)");
if (s == NULL)
goto end;
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
r = AppLayerParse(&f, ALPROTO_DCERPC, STREAM_TOSERVER | STREAM_START,
dcerpc_bind, dcerpc_bind_len);
if (r != 0) {
SCLogDebug("AppLayerParse for dcerpc failed. Returned %" PRId32, r);
goto end;
}
dcerpc_state = ssn.aldata[AlpGetStateIdx(ALPROTO_DCERPC)];
if (dcerpc_state == NULL) {
SCLogDebug("no dcerpc state: ");
goto end;
}
/* do detect */
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
if (!PacketAlertCheck(&p, 1))
goto end;
r = AppLayerParse(&f, ALPROTO_DCERPC, STREAM_TOCLIENT, dcerpc_bindack,
dcerpc_bindack_len);
if (r != 0) {
SCLogDebug("AppLayerParse for dcerpc failed. Returned %" PRId32, r);
goto end;
}
/* do detect */
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
if (!PacketAlertCheck(&p, 1))
goto end;
/* request1 */
r = AppLayerParse(&f, ALPROTO_DCERPC, STREAM_TOSERVER, dcerpc_request1,
dcerpc_request1_len);
if (r != 0) {
SCLogDebug("AppLayerParse for dcerpc failed. Returned %" PRId32, r);
goto end;
}
/* do detect */
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
if (!PacketAlertCheck(&p, 1))
goto end;
/* response1 */
r = AppLayerParse(&f, ALPROTO_DCERPC, STREAM_TOCLIENT, dcerpc_response1,
dcerpc_response1_len);
if (r != 0) {
SCLogDebug("AppLayerParse for dcerpc failed. Returned %" PRId32, r);
goto end;
}
/* do detect */
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
if (!PacketAlertCheck(&p, 1))
goto end;
/* request2 */
r = AppLayerParse(&f, ALPROTO_DCERPC, STREAM_TOSERVER, dcerpc_request2,
dcerpc_request2_len);
if (r != 0) {
SCLogDebug("AppLayerParse for dcerpc failed. Returned %" PRId32, r);
goto end;
}
/* do detect */
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
if (!PacketAlertCheck(&p, 1))
goto end;
/* response2 */
r = AppLayerParse(&f, ALPROTO_DCERPC, STREAM_TOCLIENT, dcerpc_response2,
dcerpc_response2_len);
if (r != 0) {
SCLogDebug("AppLayerParse for dcerpc failed. Returned %" PRId32, r);
goto end;
}
/* do detect */
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
if (!PacketAlertCheck(&p, 1))
goto end;
/* request3 */
r = AppLayerParse(&f, ALPROTO_DCERPC, STREAM_TOSERVER, dcerpc_request3,
dcerpc_request3_len);
if (r != 0) {
SCLogDebug("AppLayerParse for dcerpc failed. Returned %" PRId32, r);
goto end;
}
/* do detect */
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
if (!PacketAlertCheck(&p, 1))
goto end;
/* response3 */
r = AppLayerParse(&f, ALPROTO_DCERPC, STREAM_TOCLIENT | STREAM_EOF,
dcerpc_response3, dcerpc_response3_len);
if (r != 0) {
SCLogDebug("AppLayerParse for dcerpc failed. Returned %" PRId32, r);
goto end;
}
/* do detect */
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
if (!PacketAlertCheck(&p, 1))
goto end;
result = 1;
end:
SigGroupCleanup(de_ctx);
SigCleanSignatures(de_ctx);
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}
/**
* \test Test a valid dce_iface entry for a bind and bind_ack
*/
static int DetectDceIfaceTestParse14(void)
{
int result = 0;
Signature *s = NULL;
ThreadVars th_v;
Packet p;
Flow f;
TcpSession ssn;
DetectEngineThreadCtx *det_ctx = NULL;
DetectEngineCtx *de_ctx = NULL;
DCERPCState *dcerpc_state = NULL;
int r = 0;
uint8_t dcerpc_bind[] = {
0x05, 0x00, 0x0b, 0x03, 0x10, 0x00, 0x00, 0x00,
0x48, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0xb8, 0x10, 0xb8, 0x10, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
0x6a, 0x28, 0x19, 0x39, 0x0c, 0xb1, 0xd0, 0x11,
0x9b, 0xa8, 0x00, 0xc0, 0x4f, 0xd9, 0x2e, 0xf5,
0x00, 0x00, 0x00, 0x00, 0x04, 0x5d, 0x88, 0x8a,
0xeb, 0x1c, 0xc9, 0x11, 0x9f, 0xe8, 0x08, 0x00,
0x2b, 0x10, 0x48, 0x60, 0x02, 0x00, 0x00, 0x00,
};
uint8_t dcerpc_bindack[] = {
0x05, 0x00, 0x0c, 0x03, 0x10, 0x00, 0x00, 0x00,
0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0xb8, 0x10, 0xb8, 0x10, 0x26, 0x3d, 0x00, 0x00,
0x0c, 0x00, 0x5c, 0x50, 0x49, 0x50, 0x45, 0x5c,
0x6c, 0x73, 0x61, 0x73, 0x73, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x5d, 0x88, 0x8a, 0xeb, 0x1c, 0xc9, 0x11,
0x9f, 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60,
0x02, 0x00, 0x00, 0x00
};
uint32_t dcerpc_bind_len = sizeof(dcerpc_bind);
uint32_t dcerpc_bindack_len = sizeof(dcerpc_bindack);
memset(&th_v, 0, sizeof(th_v));
memset(&p, 0, sizeof(p));
memset(&f, 0, sizeof(f));
memset(&ssn, 0, sizeof(ssn));
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.payload = NULL;
p.payload_len = 0;
p.proto = IPPROTO_TCP;
StreamL7DataPtrInit(&ssn, StreamL7GetStorageSize());
f.protoctx = (void *)&ssn;
p.flow = &f;
p.flowflags |= FLOW_PKT_TOSERVER;
ssn.alproto = ALPROTO_DCERPC;
de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL)
goto end;
de_ctx->flags |= DE_QUIET;
s = de_ctx->sig_list = SigInit(de_ctx,
"alert tcp any any -> any any "
"(msg:\"DCERPC\"; "
"dce_iface:3919286a-b10c-11d0-9ba8-00c04fd92ef5,=0; "
"sid:1;)");
if (s == NULL)
goto end;
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
r = AppLayerParse(&f, ALPROTO_DCERPC, STREAM_TOSERVER | STREAM_START,
dcerpc_bind, dcerpc_bind_len);
if (r != 0) {
SCLogDebug("AppLayerParse for dcerpc failed. Returned %" PRId32, r);
goto end;
}
dcerpc_state = ssn.aldata[AlpGetStateIdx(ALPROTO_DCERPC)];
if (dcerpc_state == NULL) {
SCLogDebug("no dcerpc state: ");
goto end;
}
/* do detect */
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
if (!PacketAlertCheck(&p, 1))
goto end;
r = AppLayerParse(&f, ALPROTO_DCERPC, STREAM_TOCLIENT, dcerpc_bindack,
dcerpc_bindack_len);
if (r != 0) {
SCLogDebug("AppLayerParse for dcerpc failed. Returned %" PRId32, r);
goto end;
}
/* do detect */
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
if (!PacketAlertCheck(&p, 1))
goto end;
result = 1;
end:
SigGroupCleanup(de_ctx);
SigCleanSignatures(de_ctx);
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}
#endif
void DetectDceIfaceRegisterTests(void)
{
#ifdef UNITTESTS
UtRegisterTest("DetectDceIfaceTestParse01", DetectDceIfaceTestParse01, 1);
UtRegisterTest("DetectDceIfaceTestParse02", DetectDceIfaceTestParse02, 1);
UtRegisterTest("DetectDceIfaceTestParse03", DetectDceIfaceTestParse03, 1);
@ -604,7 +1242,10 @@ void DetectDceIfaceRegisterTests(void)
UtRegisterTest("DetectDceIfaceTestParse09", DetectDceIfaceTestParse09, 1);
UtRegisterTest("DetectDceIfaceTestParse10", DetectDceIfaceTestParse10, 1);
UtRegisterTest("DetectDceIfaceTestParse11", DetectDceIfaceTestParse11, 1);
UtRegisterTest("DetectDceIfaceTestParse12", DetectDceIfaceTestParse12, 1);
UtRegisterTest("DetectDceIfaceTestParse13", DetectDceIfaceTestParse13, 1);
UtRegisterTest("DetectDceIfaceTestParse14", DetectDceIfaceTestParse14, 1);
#endif
return;
}

@ -6,7 +6,8 @@
#define __DETECT_DCE_IFACE_H__
typedef enum DetectDceIfaceOperators_ {
DETECT_DCE_IFACE_OP_LT = 1,
DETECT_DCE_IFACE_OP_NONE = 0,
DETECT_DCE_IFACE_OP_LT,
DETECT_DCE_IFACE_OP_GT,
DETECT_DCE_IFACE_OP_EQ,
DETECT_DCE_IFACE_OP_NE,

File diff suppressed because it is too large Load Diff

@ -5,15 +5,15 @@
#ifndef __DETECT_DCE_OPNUM_H__
#define __DETECT_DCE_OPNUM_H__
#define DCE_OPNUM_RANGE_MAX 65535
#define DCE_OPNUM_RANGE_UNINITIALIZED 100000
typedef struct DetectDceOpnumRange_ {
uint32_t range1;
uint32_t range2;
struct DetectDceOpnumRange_ *next;
} DetectDceOpnumRange;
#define DCE_OPNUM_RANGE_MAX 65535
#define DCE_OPNUM_RANGE_UNINITIALIZED 100000
typedef struct DetectDceOpnumData_ {
DetectDceOpnumRange *range;
} DetectDceOpnumData;

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save