-
Notifications
You must be signed in to change notification settings - Fork 1.7k
rust/sip: register parser for tcp v9 #9893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
5451fdb
961a62d
add724d
a4f7db1
c49e208
96b34a7
fbb6c7a
769de02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -518,6 +518,59 @@ pub unsafe extern "C" fn rs_sip_parse_response_tcp( | |
| state.parse_response_tcp(flow, stream_slice) | ||
| } | ||
|
|
||
| fn register_pattern_probe(proto: u8) -> i8 { | ||
| let methods: Vec<&str> = vec![ | ||
| "REGISTER\0", | ||
| "INVITE\0", | ||
| "ACK\0", | ||
| "BYE\0", | ||
| "CANCEL\0", | ||
| "UPDATE\0", | ||
| "REFER\0", | ||
| "PRACK\0", | ||
| "SUBSCRIBE\0", | ||
| "NOTIFY\0", | ||
| "PUBLISH\0", | ||
| "MESSAGE\0", | ||
| "INFO\0", | ||
| "OPTIONS\0", | ||
| ]; | ||
| let mut r = 0; | ||
| unsafe { | ||
| for method in methods { | ||
| let depth = (method.len() - 1) as u16; | ||
| r |= AppLayerProtoDetectPMRegisterPatternCSwPP( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we really need probing after this pattern ? Plus this commit should reference https://redmine.openinfosecfoundation.org/issues/5047 right ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I think that probing it's not needed at this point and yes, the commit should point to the redmine ticket. (missed it.)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, I think it is rather |
||
| proto, | ||
| ALPROTO_SIP, | ||
| method.as_ptr() as *const std::os::raw::c_char, | ||
| depth, | ||
| 0, | ||
| core::Direction::ToServer as u8, | ||
| rs_sip_probing_parser_tcp_ts, | ||
| 0, | ||
| 0, | ||
| ); | ||
| } | ||
| r |= AppLayerProtoDetectPMRegisterPatternCSwPP( | ||
| proto, | ||
| ALPROTO_SIP, | ||
| b"SIP/2.0\0".as_ptr() as *const std::os::raw::c_char, | ||
| 8, | ||
| 0, | ||
| core::Direction::ToClient as u8, | ||
| rs_sip_probing_parser_tcp_tc, | ||
| 0, | ||
| 0, | ||
| ); | ||
| } | ||
|
|
||
| if r == 0 { | ||
| return 0; | ||
| } else { | ||
| return -1; | ||
| } | ||
| } | ||
|
|
||
| export_tx_data_get!(rs_sip_get_tx_data, SIPTransaction); | ||
| export_state_data_get!(rs_sip_get_state_data, SIPState); | ||
|
|
||
|
|
@@ -563,6 +616,9 @@ pub unsafe extern "C" fn rs_sip_register_parser() { | |
| if AppLayerProtoDetectConfProtoDetectionEnabled(ip_proto_str.as_ptr(), parser.name) != 0 { | ||
| let alproto = AppLayerRegisterProtocolDetection(&parser, 1); | ||
| ALPROTO_SIP = alproto; | ||
| if register_pattern_probe(core::IPPROTO_UDP) < 0 { | ||
| return; | ||
| } | ||
| if AppLayerParserConfParserEnabled(ip_proto_str.as_ptr(), parser.name) != 0 { | ||
| let _ = AppLayerRegisterParser(&parser, alproto); | ||
| } | ||
|
|
@@ -581,6 +637,9 @@ pub unsafe extern "C" fn rs_sip_register_parser() { | |
| if AppLayerProtoDetectConfProtoDetectionEnabled(ip_proto_str.as_ptr(), parser.name) != 0 { | ||
| let alproto = AppLayerRegisterProtocolDetection(&parser, 1); | ||
| ALPROTO_SIP = alproto; | ||
| if register_pattern_probe(core::IPPROTO_TCP) < 0 { | ||
| return; | ||
| } | ||
| if AppLayerParserConfParserEnabled(ip_proto_str.as_ptr(), parser.name) != 0 { | ||
| let _ = AppLayerRegisterParser(&parser, alproto); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think you need the final 0 in rust, do you ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you look at
register_pattern_probeinrust/src/smb/smb.rsyou'll see that the patterns contains\0.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks that SMB can be optimized as well then. We just use a buffer and its length, and you specify the
- 1for the length to get rid of this 0, right ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the same logic is applied in
bittorrent_dht.rsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://redmine.openinfosecfoundation.org/issues/6583 ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made some tests, and it looks like the null character is mandatory; otherwise, the pattern matching won't work.
Patterns (such as
BITTORRENT_DHT_PAYLOAD_PREFIX) are used in C functions, likeDetectContentDataParse, that takes a string as input.I believe it's not worth making changes around the code just to remove the null byte from the patterns.