@ -759,313 +759,6 @@ end:
return result ;
}
/**
* \ test Test the working of consecutive relative matches .
*/
static int DcePayloadTest21 ( 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 ,
0x6e , 0x6f , 0x77 , 0x20 , 0x74 , 0x68 , 0x69 , 0x73 , /* "now this" */
0x20 , 0x69 , 0x73 , 0x20 , 0x69 , 0x73 , 0x20 , 0x62 , /* " is is b" */
0x69 , 0x67 , 0x20 , 0x62 , 0x69 , 0x67 , 0x20 , 0x73 , /* "ig big s" */
0x74 , 0x72 , 0x69 , 0x6e , 0x67 , 0x20 , 0x6e , 0x6f , /* "tring no" */
0x77 } ; /* "w" */
uint32_t request1_len = sizeof ( request1 ) ;
TcpSession ssn ;
Packet * p = NULL ;
ThreadVars tv ;
DetectEngineCtx * de_ctx = NULL ;
DetectEngineThreadCtx * det_ctx = NULL ;
Flow f ;
int r ;
const char * sig1 = " alert tcp any any -> any any "
" (msg: \" testing dce consecutive relative matches \" ; dce_stub_data; "
" content: \" this \" ; distance:0; content: \" is \" ; within:6; content: \" big \" ; within:8; "
" content: \" string \" ; within:8; sid:1;) " ;
Signature * s ;
AppLayerParserThreadCtx * alp_tctx = AppLayerParserThreadCtxAlloc ( ) ;
memset ( & tv , 0 , sizeof ( ThreadVars ) ) ;
memset ( & f , 0 , sizeof ( Flow ) ) ;
memset ( & ssn , 0 , sizeof ( TcpSession ) ) ;
p = UTHBuildPacket ( NULL , 0 , IPPROTO_TCP ) ;
p - > flow = & f ;
p - > flags | = PKT_HAS_FLOW | PKT_STREAM_EST ;
p - > flowflags | = FLOW_PKT_TOSERVER ;
p - > flowflags | = FLOW_PKT_ESTABLISHED ;
FLOW_INITIALIZE ( & f ) ;
f . protoctx = ( void * ) & ssn ;
f . proto = IPPROTO_TCP ;
f . flags | = FLOW_IPV4 ;
f . alproto = ALPROTO_DCERPC ;
StreamTcpInitConfig ( TRUE ) ;
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 */
FLOWLOCK_WRLOCK ( & f ) ;
r = AppLayerParserParse ( NULL , alp_tctx , & f , ALPROTO_DCERPC ,
STREAM_TOSERVER , request1 , request1_len ) ;
if ( r ! = 0 ) {
printf ( " toserver chunk 1 returned % " PRId32 " , expected 0: " , r ) ;
result = 0 ;
FLOWLOCK_UNLOCK ( & f ) ;
goto end ;
}
FLOWLOCK_UNLOCK ( & f ) ;
/* 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 ( alp_tctx ! = NULL )
AppLayerParserThreadCtxFree ( alp_tctx ) ;
if ( de_ctx ! = NULL ) {
SigGroupCleanup ( de_ctx ) ;
SigCleanSignatures ( de_ctx ) ;
DetectEngineThreadCtxDeinit ( & tv , ( void * ) det_ctx ) ;
DetectEngineCtxFree ( de_ctx ) ;
}
StreamTcpFreeConfig ( TRUE ) ;
UTHFreePackets ( & p , 1 ) ;
return result ;
}
/**
* \ test Test the working of consecutive relative matches .
*/
static int DcePayloadTest22 ( 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 ,
0x6e , 0x6f , 0x77 , 0x20 , 0x74 , 0x68 , 0x69 , 0x73 , /* "now this" */
0x20 , 0x69 , 0x73 , 0x20 , 0x69 , 0x73 , 0x20 , 0x69 , /* " is is i" */
0x73 , 0x20 , 0x62 , 0x69 , 0x67 , 0x20 , 0x62 , 0x69 , /* "s big bi" */
0x67 , 0x20 , 0x62 , 0x69 , 0x67 , 0x20 , 0x73 , 0x74 , /* "g big st" */
0x72 , 0x69 , 0x6e , 0x67 , 0x20 , 0x6e , 0x6f , 0x77 } ; /* "ring now" */
uint32_t request1_len = sizeof ( request1 ) ;
TcpSession ssn ;
Packet * p = NULL ;
ThreadVars tv ;
DetectEngineCtx * de_ctx = NULL ;
DetectEngineThreadCtx * det_ctx = NULL ;
Flow f ;
int r ;
const char * sig1 = " alert tcp any any -> any any "
" (msg: \" testing dce consecutive relative matches \" ; dce_stub_data; "
" content: \" this \" ; distance:0; content: \" is \" ; within:9; content: \" big \" ; within:12; "
" content: \" string \" ; within:8; sid:1;) " ;
Signature * s ;
AppLayerParserThreadCtx * alp_tctx = AppLayerParserThreadCtxAlloc ( ) ;
memset ( & tv , 0 , sizeof ( ThreadVars ) ) ;
memset ( & f , 0 , sizeof ( Flow ) ) ;
memset ( & ssn , 0 , sizeof ( TcpSession ) ) ;
p = UTHBuildPacket ( NULL , 0 , IPPROTO_TCP ) ;
p - > flow = & f ;
p - > flags | = PKT_HAS_FLOW | PKT_STREAM_EST ;
p - > flowflags | = FLOW_PKT_TOSERVER ;
p - > flowflags | = FLOW_PKT_ESTABLISHED ;
FLOW_INITIALIZE ( & f ) ;
f . protoctx = ( void * ) & ssn ;
f . proto = IPPROTO_TCP ;
f . flags | = FLOW_IPV4 ;
f . alproto = ALPROTO_DCERPC ;
StreamTcpInitConfig ( TRUE ) ;
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 */
FLOWLOCK_WRLOCK ( & f ) ;
r = AppLayerParserParse ( NULL , alp_tctx , & f , ALPROTO_DCERPC ,
STREAM_TOSERVER , request1 , request1_len ) ;
if ( r ! = 0 ) {
printf ( " toserver chunk 1 returned % " PRId32 " , expected 0: " , r ) ;
result = 0 ;
FLOWLOCK_UNLOCK ( & f ) ;
goto end ;
}
FLOWLOCK_UNLOCK ( & f ) ;
/* 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 ( alp_tctx ! = NULL )
AppLayerParserThreadCtxFree ( alp_tctx ) ;
if ( de_ctx ! = NULL ) {
SigGroupCleanup ( de_ctx ) ;
SigCleanSignatures ( de_ctx ) ;
DetectEngineThreadCtxDeinit ( & tv , ( void * ) det_ctx ) ;
DetectEngineCtxFree ( de_ctx ) ;
}
StreamTcpFreeConfig ( TRUE ) ;
UTHFreePackets ( & p , 1 ) ;
return result ;
}
/**
* \ test Test the working of consecutive relative matches .
*/
static int DcePayloadTest23 ( 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 ,
0x74 , 0x68 , 0x69 , 0x73 , 0x20 , 0x74 , 0x68 , 0x69 , /* "this thi" */
0x73 , 0x20 , 0x6e , 0x6f , 0x77 , 0x20 , 0x69 , 0x73 , /* "s now is" */
0x20 , 0x69 , 0x73 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , /* " is " */
0x62 , 0x69 , 0x67 , 0x20 , 0x73 , 0x74 , 0x72 , 0x69 , /* "big stri" */
0x6e , 0x67 , 0x20 , 0x6e , 0x6f , 0x77 } ; /* "ng now" */
uint32_t request1_len = sizeof ( request1 ) ;
TcpSession ssn ;
Packet * p = NULL ;
ThreadVars tv ;
DetectEngineCtx * de_ctx = NULL ;
DetectEngineThreadCtx * det_ctx = NULL ;
Flow f ;
int r ;
const char * sig1 = " alert tcp any any -> any any "
" (msg: \" testing dce consecutive relative matches \" ; dce_stub_data; "
" content: \" now \" ; distance:0; content: \" this \" ; distance:-20; "
" content: \" is \" ; within:12; content: \" big \" ; within:8; "
" content: \" string \" ; within:8; sid:1;) " ;
Signature * s ;
AppLayerParserThreadCtx * alp_tctx = AppLayerParserThreadCtxAlloc ( ) ;
memset ( & tv , 0 , sizeof ( ThreadVars ) ) ;
memset ( & f , 0 , sizeof ( Flow ) ) ;
memset ( & ssn , 0 , sizeof ( TcpSession ) ) ;
p = UTHBuildPacket ( NULL , 0 , IPPROTO_TCP ) ;
p - > flow = & f ;
p - > flags | = PKT_HAS_FLOW | PKT_STREAM_EST ;
p - > flowflags | = FLOW_PKT_TOSERVER ;
p - > flowflags | = FLOW_PKT_ESTABLISHED ;
FLOW_INITIALIZE ( & f ) ;
f . protoctx = ( void * ) & ssn ;
f . proto = IPPROTO_TCP ;
f . flags | = FLOW_IPV4 ;
f . alproto = ALPROTO_DCERPC ;
StreamTcpInitConfig ( TRUE ) ;
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 */
FLOWLOCK_WRLOCK ( & f ) ;
r = AppLayerParserParse ( NULL , alp_tctx , & f , ALPROTO_DCERPC ,
STREAM_TOSERVER , request1 , request1_len ) ;
if ( r ! = 0 ) {
printf ( " toserver chunk 1 returned % " PRId32 " , expected 0: " , r ) ;
result = 0 ;
FLOWLOCK_UNLOCK ( & f ) ;
goto end ;
}
FLOWLOCK_UNLOCK ( & f ) ;
/* 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 ( alp_tctx ! = NULL )
AppLayerParserThreadCtxFree ( alp_tctx ) ;
if ( de_ctx ! = NULL ) {
SigGroupCleanup ( de_ctx ) ;
SigCleanSignatures ( de_ctx ) ;
DetectEngineThreadCtxDeinit ( & tv , ( void * ) det_ctx ) ;
DetectEngineCtxFree ( de_ctx ) ;
}
StreamTcpFreeConfig ( TRUE ) ;
UTHFreePackets ( & p , 1 ) ;
return result ;
}
/**
* \ test Test content for dce sig .
*/
@ -3180,212 +2873,6 @@ static int DcePayloadParseTest41(void)
return result ;
}
/**
* \ test Test the working of consecutive relative matches with a negated content .
*/
static int DcePayloadTest42 ( 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 ,
0x77 , 0x65 , 0x20 , 0x6e , 0x65 , 0x65 , 0x64 , 0x20 , /* "we need " */
0x74 , 0x6f , 0x20 , 0x66 , 0x69 , 0x78 , 0x20 , 0x74 , /* "to fix t" */
0x68 , 0x69 , 0x73 , 0x20 , 0x61 , 0x6e , 0x64 , 0x20 , /* "his and " */
0x79 , 0x65 , 0x73 , 0x20 , 0x66 , 0x69 , 0x78 , 0x20 , /* "yes fix " */
0x74 , 0x68 , 0x69 , 0x73 , 0x20 , 0x6e , 0x6f , 0x77 /* "this now" */
} ;
uint32_t request1_len = sizeof ( request1 ) ;
TcpSession ssn ;
Packet * p = NULL ;
ThreadVars tv ;
DetectEngineCtx * de_ctx = NULL ;
DetectEngineThreadCtx * det_ctx = NULL ;
Flow f ;
int r ;
const char * sig1 = " alert tcp any any -> any any "
" (msg: \" testing dce consecutive relative matches \" ; dce_stub_data; "
" content: \" fix \" ; distance:0; content: \" this \" ; within:6; "
" content:! \" and \" ; distance:0; sid:1;) " ;
Signature * s ;
AppLayerParserThreadCtx * alp_tctx = AppLayerParserThreadCtxAlloc ( ) ;
memset ( & tv , 0 , sizeof ( ThreadVars ) ) ;
memset ( & f , 0 , sizeof ( Flow ) ) ;
memset ( & ssn , 0 , sizeof ( TcpSession ) ) ;
p = UTHBuildPacket ( NULL , 0 , IPPROTO_TCP ) ;
p - > flow = & f ;
p - > flags | = PKT_HAS_FLOW | PKT_STREAM_EST ;
p - > flowflags | = FLOW_PKT_TOSERVER ;
p - > flowflags | = FLOW_PKT_ESTABLISHED ;
FLOW_INITIALIZE ( & f ) ;
f . protoctx = ( void * ) & ssn ;
f . proto = IPPROTO_TCP ;
f . flags | = FLOW_IPV4 ;
f . alproto = ALPROTO_DCERPC ;
StreamTcpInitConfig ( TRUE ) ;
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 */
FLOWLOCK_WRLOCK ( & f ) ;
r = AppLayerParserParse ( NULL , alp_tctx , & f , ALPROTO_DCERPC ,
STREAM_TOSERVER , request1 , request1_len ) ;
if ( r ! = 0 ) {
printf ( " toserver chunk 1 returned % " PRId32 " , expected 0: " , r ) ;
result = 0 ;
FLOWLOCK_UNLOCK ( & f ) ;
goto end ;
}
FLOWLOCK_UNLOCK ( & f ) ;
/* detection phase */
SigMatchSignatures ( & tv , de_ctx , det_ctx , p ) ;
if ( ! ( PacketAlertCheck ( p , 1 ) ) ) {
printf ( " sid 1 matched but shouldn't have for packet: " ) ;
goto end ;
}
result = 1 ;
end :
if ( alp_tctx ! = NULL )
AppLayerParserThreadCtxFree ( alp_tctx ) ;
if ( de_ctx ! = NULL ) {
SigGroupCleanup ( de_ctx ) ;
SigCleanSignatures ( de_ctx ) ;
DetectEngineThreadCtxDeinit ( & tv , ( void * ) det_ctx ) ;
DetectEngineCtxFree ( de_ctx ) ;
}
StreamTcpFreeConfig ( TRUE ) ;
UTHFreePackets ( & p , 1 ) ;
return result ;
}
/**
* \ test Test the working of consecutive relative pcres .
*/
static int DcePayloadTest43 ( 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 ,
0x74 , 0x68 , 0x69 , 0x73 , 0x20 , 0x69 , 0x73 , 0x20 ,
0x61 , 0x20 , 0x73 , 0x75 , 0x70 , 0x65 , 0x72 , 0x20 ,
0x64 , 0x75 , 0x70 , 0x65 , 0x72 , 0x20 , 0x6e , 0x6f ,
0x76 , 0x61 , 0x20 , 0x69 , 0x6e , 0x20 , 0x73 , 0x75 ,
0x70 , 0x65 , 0x72 , 0x20 , 0x6e , 0x6f , 0x76 , 0x61 ,
0x20 , 0x6e , 0x6f , 0x77
} ;
uint32_t request1_len = sizeof ( request1 ) ;
TcpSession ssn ;
Packet * p = NULL ;
ThreadVars tv ;
DetectEngineCtx * de_ctx = NULL ;
DetectEngineThreadCtx * det_ctx = NULL ;
Flow f ;
int r ;
const char * sig1 = " alert tcp any any -> any any "
" (msg: \" testing dce consecutive relative matches \" ; dce_stub_data; "
" pcre:/super/R; content: \" nova \" ; within:7; sid:1;) " ;
Signature * s ;
AppLayerParserThreadCtx * alp_tctx = AppLayerParserThreadCtxAlloc ( ) ;
memset ( & tv , 0 , sizeof ( ThreadVars ) ) ;
memset ( & f , 0 , sizeof ( Flow ) ) ;
memset ( & ssn , 0 , sizeof ( TcpSession ) ) ;
p = UTHBuildPacket ( NULL , 0 , IPPROTO_TCP ) ;
p - > flow = & f ;
p - > flags | = PKT_HAS_FLOW | PKT_STREAM_EST ;
p - > flowflags | = FLOW_PKT_TOSERVER ;
p - > flowflags | = FLOW_PKT_ESTABLISHED ;
FLOW_INITIALIZE ( & f ) ;
f . protoctx = ( void * ) & ssn ;
f . proto = IPPROTO_TCP ;
f . flags | = FLOW_IPV4 ;
f . alproto = ALPROTO_DCERPC ;
StreamTcpInitConfig ( TRUE ) ;
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 */
FLOWLOCK_WRLOCK ( & f ) ;
r = AppLayerParserParse ( NULL , alp_tctx , & f , ALPROTO_DCERPC ,
STREAM_TOSERVER , request1 , request1_len ) ;
if ( r ! = 0 ) {
printf ( " toserver chunk 1 returned % " PRId32 " , expected 0: " , r ) ;
result = 0 ;
FLOWLOCK_UNLOCK ( & f ) ;
goto end ;
}
FLOWLOCK_UNLOCK ( & f ) ;
/* detection phase */
SigMatchSignatures ( & tv , de_ctx , det_ctx , p ) ;
if ( ! ( PacketAlertCheck ( p , 1 ) ) ) {
printf ( " sid 1 didn't match but should have: " ) ;
goto end ;
}
result = 1 ;
end :
if ( alp_tctx ! = NULL )
AppLayerParserThreadCtxFree ( alp_tctx ) ;
if ( de_ctx ! = NULL ) {
SigGroupCleanup ( de_ctx ) ;
SigCleanSignatures ( de_ctx ) ;
DetectEngineThreadCtxDeinit ( & tv , ( void * ) det_ctx ) ;
DetectEngineCtxFree ( de_ctx ) ;
}
StreamTcpFreeConfig ( TRUE ) ;
UTHFreePackets ( & p , 1 ) ;
return result ;
}
/**
* \ test Test content for dce sig .
*/
@ -3711,9 +3198,6 @@ void DcePayloadRegisterTests(void)
UtRegisterTest ( " DcePayloadTest18 " , DcePayloadTest18 ) ;
UtRegisterTest ( " DcePayloadTest19 " , DcePayloadTest19 ) ;
UtRegisterTest ( " DcePayloadTest20 " , DcePayloadTest20 ) ;
UtRegisterTest ( " DcePayloadTest21 " , DcePayloadTest21 ) ;
UtRegisterTest ( " DcePayloadTest22 " , DcePayloadTest22 ) ;
UtRegisterTest ( " DcePayloadTest23 " , DcePayloadTest23 ) ;
UtRegisterTest ( " DcePayloadParseTest25 " , DcePayloadParseTest25 ) ;
UtRegisterTest ( " DcePayloadParseTest26 " , DcePayloadParseTest26 ) ;
@ -3733,9 +3217,6 @@ void DcePayloadRegisterTests(void)
UtRegisterTest ( " DcePayloadParseTest40 " , DcePayloadParseTest40 ) ;
UtRegisterTest ( " DcePayloadParseTest41 " , DcePayloadParseTest41 ) ;
UtRegisterTest ( " DcePayloadTest42 " , DcePayloadTest42 ) ;
UtRegisterTest ( " DcePayloadTest43 " , DcePayloadTest43 ) ;
UtRegisterTest ( " DcePayloadParseTest44 " , DcePayloadParseTest44 ) ;
UtRegisterTest ( " DcePayloadParseTest45 " , DcePayloadParseTest45 ) ;
UtRegisterTest ( " DcePayloadParseTest46 " , DcePayloadParseTest46 ) ;