@ -169,7 +169,8 @@ static int DoInspectDcePayload(DetectEngineCtx *de_ctx,
* matches after the first occurence . */
SCLogDebug ( " offset % " PRIu32 " , prev_offset % " PRIu32 , offset ,
prev_offset ) ;
offset + = prev_offset ;
if ( prev_offset ! = 0 )
offset = prev_offset ;
SCLogDebug ( " offset % " PRIu32 " , depth % " PRIu32 , offset , depth ) ;
@ -178,6 +179,8 @@ static int DoInspectDcePayload(DetectEngineCtx *de_ctx,
/* if offset is bigger than depth we can never match on a
* pattern . We can however , " match " on a negated pattern . */
/* \todo why isn't it >= ?. Same question applies for
* detect - engine - dcepayload . c and detect - engine - uri . c */
if ( offset > depth | | depth = = 0 ) {
if ( cd - > flags & DETECT_CONTENT_NEGATED ) {
goto match ;
@ -241,8 +244,7 @@ static int DoInspectDcePayload(DetectEngineCtx *de_ctx,
}
/* set the previous match offset to the start of this match + 1 */
prev_offset + = ( match_offset - ( cd - > content_len - 1 ) ) ;
prev_offset - = ( prev_payload_offset ) ;
prev_offset = ( match_offset - ( cd - > content_len - 1 ) ) ;
SCLogDebug ( " trying to see if there is another match after "
" prev_offset % " PRIu32 , prev_offset ) ;
}
@ -7706,6 +7708,105 @@ end:
return result ;
}
/**
* \ test Test the working of consecutive relative matches with offset .
*/
int DcePayloadTest24 ( void )
{
int result = 0 ;
uint8_t request1 [ ] = {
0x05 , 0x00 , 0x00 , 0x03 , 0x10 , 0x00 , 0x00 , 0x00 ,
0x68 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 ,
0x50 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x1a , 0x00 ,
0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , /* " " */
0x20 , 0x74 , 0x68 , 0x75 , 0x73 , 0x20 , 0x74 , 0x68 , /* " thus th" */
0x75 , 0x73 , 0x20 , 0x69 , 0x73 , 0x20 , 0x61 , 0x20 , /* "us is a " */
0x62 , 0x69 , 0x67 } ; /* "big" */
uint32_t request1_len = sizeof ( request1 ) ;
TcpSession ssn ;
Packet p ;
ThreadVars tv ;
DetectEngineCtx * de_ctx = NULL ;
DetectEngineThreadCtx * det_ctx = NULL ;
Flow f ;
int r ;
char * sig1 = " alert tcp any any -> any any "
" (msg: \" testing dce consecutive relative matches \" ; dce_stub_data; "
" content:thus; offset:8; content:is; within:6; "
" content:big; within:8; sid:1;) " ;
Signature * s ;
memset ( & tv , 0 , sizeof ( ThreadVars ) ) ;
memset ( & f , 0 , sizeof ( Flow ) ) ;
memset ( & ssn , 0 , sizeof ( TcpSession ) ) ;
memset ( & p , 0 , sizeof ( Packet ) ) ;
p . src . family = AF_INET ;
p . dst . family = AF_INET ;
p . payload = NULL ;
p . payload_len = 0 ;
p . proto = IPPROTO_TCP ;
p . flow = & f ;
p . flowflags | = FLOW_PKT_TOSERVER ;
p . flowflags | = FLOW_PKT_ESTABLISHED ;
FLOW_INITIALIZE ( & f ) ;
f . protoctx = ( void * ) & ssn ;
f . src . family = AF_INET ;
f . dst . family = AF_INET ;
f . alproto = ALPROTO_DCERPC ;
StreamTcpInitConfig ( TRUE ) ;
FlowL7DataPtrInit ( & f ) ;
de_ctx = DetectEngineCtxInit ( ) ;
if ( de_ctx = = NULL )
goto end ;
de_ctx - > flags | = DE_QUIET ;
de_ctx - > sig_list = SigInit ( de_ctx , sig1 ) ;
s = de_ctx - > sig_list ;
if ( s = = NULL )
goto end ;
SigGroupBuild ( de_ctx ) ;
DetectEngineThreadCtxInit ( & tv , ( void * ) de_ctx , ( void * ) & det_ctx ) ;
/* request 1 */
r = AppLayerParse ( & f , ALPROTO_DCERPC , STREAM_TOSERVER , request1 , request1_len ) ;
if ( r ! = 0 ) {
printf ( " toserver chunk 1 returned % " PRId32 " , expected 0: " , r ) ;
result = 0 ;
goto end ;
}
/* detection phase */
SigMatchSignatures ( & tv , de_ctx , det_ctx , & p ) ;
if ( ! ( PacketAlertCheck ( & p , 1 ) ) ) {
printf ( " sid 1 didn't match but should have for packet: " ) ;
goto end ;
}
result = 1 ;
end :
if ( de_ctx ! = NULL ) {
SigGroupCleanup ( de_ctx ) ;
SigCleanSignatures ( de_ctx ) ;
DetectEngineThreadCtxDeinit ( & tv , ( void * ) det_ctx ) ;
DetectEngineCtxFree ( de_ctx ) ;
}
FlowL7DataPtrFree ( & f ) ;
StreamTcpFreeConfig ( TRUE ) ;
return result ;
}
# endif /* UNITTESTS */
void DcePayloadRegisterTests ( void )
@ -7735,6 +7836,7 @@ void DcePayloadRegisterTests(void)
UtRegisterTest ( " DcePayloadTest21 " , DcePayloadTest21 , 1 ) ;
UtRegisterTest ( " DcePayloadTest22 " , DcePayloadTest22 , 1 ) ;
UtRegisterTest ( " DcePayloadTest23 " , DcePayloadTest23 , 1 ) ;
UtRegisterTest ( " DcePayloadTest24 " , DcePayloadTest24 , 1 ) ;
# endif /* UNITTESTS */
return ;