From 73241fc86ca4529635166d5a885c202f71265451 Mon Sep 17 00:00:00 2001 From: Anoop Saldanha Date: Tue, 27 Jul 2010 10:00:11 +0530 Subject: [PATCH] support fragmented puds in dce + unittest --- src/app-layer-dcerpc.c | 159 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 158 insertions(+), 1 deletion(-) diff --git a/src/app-layer-dcerpc.c b/src/app-layer-dcerpc.c index 343690d0f6..2e5ef449d3 100644 --- a/src/app-layer-dcerpc.c +++ b/src/app-layer-dcerpc.c @@ -1342,7 +1342,6 @@ int32_t DCERPCParser(DCERPC *dcerpc, uint8_t *input, uint32_t input_len) { dcerpc->bytesprocessed = 0; break; } - dcerpc->bytesprocessed = 0; } SCReturnInt(parsed); } @@ -3612,12 +3611,170 @@ end: return result; } +/** + * \test DCERPC fragmented bind PDU(one PDU which is frag'ed) + */ +int DCERPCParserTest05(void) { + int result = 1; + Flow f; + int r = 0; + uint8_t bind1[] = { + 0x05, 0x00, 0x0b, 0x03, 0x10, 0x00, 0x00, 0x00, + 0xdc, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xd0, 0x16, 0xd0, 0x16, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0xc7, 0x70, 0x0d, 0x3e, 0x71, 0x37, 0x39, 0x0d, + 0x3a, 0x4f, 0xd3, 0xdc, 0xca, 0x49, 0xe8, 0xa3, + 0x05, 0x00, 0x00, 0x00, 0x04, 0x5d, 0x88, 0x8a, + 0xeb, 0x1c, 0xc9, 0x11, 0x9f, 0xe8, 0x08, 0x00, + 0x2b, 0x10, 0x48, 0x60, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x01, 0x00, 0x84, 0xb6, 0x55, 0x75, + 0xdb, 0x9e, 0xba, 0x54, 0x56, 0xd3, 0x45, 0x10, + 0xb7, 0x7a, 0x2a, 0xe2, 0x04, 0x00, 0x01, 0x00, + 0x04, 0x5d, 0x88, 0x8a, 0xeb, 0x1c, 0xc9, 0x11, + 0x9f, 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60, + 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x6e, 0x39, 0x21, 0x24, 0x70, 0x6f, 0x41, 0x57, + 0x54, 0x70, 0xb8, 0xc3, 0x5e, 0x89, 0x3b, 0x43, + 0x03, 0x00, 0x00, 0x00, 0x04, 0x5d, 0x88, 0x8a, + 0xeb, 0x1c, 0xc9, 0x11, 0x9f, 0xe8, 0x08, 0x00, + 0x2b, 0x10, 0x48, 0x60, 0x02, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x01, 0x00, 0x39, 0x6a, 0x86, 0x5d, + 0x24, 0x0f, 0xd2, 0xf7, 0xb6, 0xce, 0x95, 0x9c, + 0x54, 0x1d, 0x3a, 0xdb, 0x02, 0x00, 0x01, 0x00, + 0x04, 0x5d, 0x88, 0x8a, 0xeb, 0x1c, 0xc9, 0x11, + 0x9f, 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60, + 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x00, + 0x12, 0xa5, 0xdd, 0xc5, 0x55, 0xce, 0xc3, 0x46, + 0xbd, 0xa0, 0x94, 0x39, 0x3c, 0x0d, 0x9b, 0x5b, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x5d, 0x88, 0x8a, + 0xeb, 0x1c, 0xc9, 0x11, 0x9f, 0xe8, 0x08, 0x00, + 0x2b, 0x10, 0x48, 0x60, 0x02, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x01, 0x00, 0x87, 0x1c, 0x8b, 0x6e, + 0x11, 0xa8, 0x67, 0x98, 0xd4, 0x5d, 0xf6, 0x8a, + 0x2f, 0x33, 0x24, 0x7b, 0x05, 0x00, 0x03, 0x00, + 0x04, 0x5d, 0x88, 0x8a, 0xeb, 0x1c, 0xc9, 0x11, + 0x9f, 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60, + 0x02, 0x00, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, + 0x9b, 0x82, 0x13, 0xd1, 0x28, 0xe0, 0x63, 0xf3, + 0x62, 0xee, 0x76, 0x73, 0xf9, 0xac, 0x3d, 0x2e, + 0x03, 0x00, 0x00, 0x00, 0x04, 0x5d, 0x88, 0x8a, + 0xeb, 0x1c, 0xc9, 0x11, 0x9f, 0xe8, 0x08, 0x00, + 0x2b, 0x10, 0x48, 0x60, 0x02, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x01, 0x00, 0xa9, 0xd4, 0x73, 0xf2, + 0xed, 0xad, 0xe8, 0x82, 0xf8, 0xcf, 0x9d, 0x9f, + 0x66, 0xe6, 0x43, 0x37, 0x02, 0x00, 0x01, 0x00, + 0x04, 0x5d, 0x88, 0x8a, 0xeb, 0x1c, 0xc9, 0x11, + 0x9f, 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60, + 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, + 0x06, 0x2b, 0x85, 0x38, 0x4f, 0x73, 0x96, 0xb1, + 0x73, 0xe1, 0x59, 0xbe, 0x9d, 0xe2, 0x6c, 0x07, + 0x05, 0x00, 0x01, 0x00, 0x04, 0x5d, 0x88, 0x8a, + 0xeb, 0x1c, 0xc9, 0x11, 0x9f, 0xe8, 0x08, 0x00, + 0x2b, 0x10, 0x48, 0x60}; + uint32_t bind1_len = sizeof(bind1); + + uint8_t bind2[] = { + 0x02, 0x00, 0x00, 0x00, 0x09, 0x00, 0x01, 0x00, + 0xbf, 0xfa, 0xbb, 0xa4, 0x9e, 0x5c, 0x80, 0x61, + 0xb5, 0x8b, 0x79, 0x69, 0xa6, 0x32, 0x88, 0x77, + 0x01, 0x00, 0x01, 0x00, 0x04, 0x5d, 0x88, 0x8a, + 0xeb, 0x1c, 0xc9, 0x11, 0x9f, 0xe8, 0x08, 0x00, + 0x2b, 0x10, 0x48, 0x60, 0x02, 0x00, 0x00, 0x00, + 0x0a, 0x00, 0x01, 0x00, 0x39, 0xa8, 0x2c, 0x39, + 0x73, 0x50, 0x06, 0x8d, 0xf2, 0x37, 0x1e, 0x1e, + 0xa8, 0x8f, 0x46, 0x98, 0x02, 0x00, 0x02, 0x00, + 0x04, 0x5d, 0x88, 0x8a, 0xeb, 0x1c, 0xc9, 0x11, + 0x9f, 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60, + 0x02, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x01, 0x00, + 0x91, 0x13, 0xd0, 0xa7, 0xef, 0xc4, 0xa7, 0x96, + 0x0c, 0x4a, 0x0d, 0x29, 0x80, 0xd3, 0xfe, 0xbf, + 0x00, 0x00, 0x01, 0x00, 0x04, 0x5d, 0x88, 0x8a, + 0xeb, 0x1c, 0xc9, 0x11, 0x9f, 0xe8, 0x08, 0x00, + 0x2b, 0x10, 0x48, 0x60, 0x02, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x01, 0x00, 0xcc, 0x2b, 0x55, 0x1d, + 0xd4, 0xa4, 0x0d, 0xfb, 0xcb, 0x6f, 0x86, 0x36, + 0xa6, 0x57, 0xc3, 0x21, 0x02, 0x00, 0x01, 0x00, + 0x04, 0x5d, 0x88, 0x8a, 0xeb, 0x1c, 0xc9, 0x11, + 0x9f, 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60, + 0x02, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x01, 0x00, + 0x43, 0x7b, 0x07, 0xee, 0x85, 0xa8, 0xb9, 0x3a, + 0x0f, 0xf9, 0x83, 0x70, 0xe6, 0x0b, 0x4f, 0x33, + 0x02, 0x00, 0x02, 0x00, 0x04, 0x5d, 0x88, 0x8a, + 0xeb, 0x1c, 0xc9, 0x11, 0x9f, 0xe8, 0x08, 0x00, + 0x2b, 0x10, 0x48, 0x60, 0x02, 0x00, 0x00, 0x00, + 0x0e, 0x00, 0x01, 0x00, 0x9c, 0x6a, 0x15, 0x8c, + 0xd6, 0x9c, 0xa6, 0xc3, 0xb2, 0x9e, 0x62, 0x9f, + 0x3d, 0x8e, 0x47, 0x73, 0x02, 0x00, 0x02, 0x00, + 0x04, 0x5d, 0x88, 0x8a, 0xeb, 0x1c, 0xc9, 0x11, + 0x9f, 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60, + 0x02, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x01, 0x00, + 0xc8, 0x4f, 0x32, 0x4b, 0x70, 0x16, 0xd3, 0x01, + 0x12, 0x78, 0x5a, 0x47, 0xbf, 0x6e, 0xe1, 0x88, + 0x03, 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 bind2_len = sizeof(bind2); + + TcpSession ssn; + + memset(&f, 0, sizeof(f)); + memset(&ssn, 0, sizeof(ssn)); + + FLOW_INITIALIZE(&f); + f.protoctx = (void *)&ssn; + + StreamTcpInitConfig(TRUE); + FlowL7DataPtrInit(&f); + + r = AppLayerParse(&f, ALPROTO_DCERPC, STREAM_TOSERVER|STREAM_START, + bind1, bind1_len); + if (r != 0) { + printf("dcerpc header check returned %" PRId32 ", expected 0: ", r); + result = 0; + goto end; + } + + DCERPCState *dcerpc_state = f.aldata[AlpGetStateIdx(ALPROTO_DCERPC)]; + if (dcerpc_state == NULL) { + printf("no dcerpc state: "); + result = 0; + goto end; + } + + result &= (dcerpc_state->dcerpc.bytesprocessed == 420); + result &= (dcerpc_state->dcerpc.dcerpcbindbindack.ctxbytesprocessed == 40); + result &= (dcerpc_state->dcerpc.dcerpcbindbindack.numctxitems == 16); + result &= (dcerpc_state->dcerpc.dcerpcbindbindack.numctxitemsleft == 8); + + r = AppLayerParse(&f, ALPROTO_DCERPC, STREAM_TOSERVER, + bind2, bind2_len); + if (r != 0) { + printf("dcerpc header check returned %" PRId32 ", expected 0: ", r); + result = 0; + goto end; + } + + result &= (dcerpc_state->dcerpc.bytesprocessed == 0); + result &= (dcerpc_state->dcerpc.dcerpcbindbindack.ctxbytesprocessed == 0); + result &= (dcerpc_state->dcerpc.dcerpcbindbindack.numctxitems == 16); + result &= (dcerpc_state->dcerpc.dcerpcbindbindack.numctxitemsleft == 0); + +end: + FlowL7DataPtrFree(&f); + StreamTcpFreeConfig(TRUE); + FLOW_DESTROY(&f); + return result; +} + void DCERPCParserRegisterTests(void) { printf("DCERPCParserRegisterTests\n"); UtRegisterTest("DCERPCParserTest01", DCERPCParserTest01, 1); UtRegisterTest("DCERPCParserTest02", DCERPCParserTest02, 1); UtRegisterTest("DCERPCParserTest03", DCERPCParserTest03, 1); UtRegisterTest("DCERPCParserTest04", DCERPCParserTest04, 1); + UtRegisterTest("DCERPCParserTest05", DCERPCParserTest05, 1); } #endif