|
|
|
@ -22,9 +22,7 @@ use self::ipsec_parser::*;
|
|
|
|
|
|
|
|
|
|
use crate::applayer;
|
|
|
|
|
use crate::applayer::*;
|
|
|
|
|
use crate::core::{
|
|
|
|
|
self, AppProto, Flow, ALPROTO_FAILED, ALPROTO_UNKNOWN, STREAM_TOCLIENT, STREAM_TOSERVER,
|
|
|
|
|
};
|
|
|
|
|
use crate::core::{self, *};
|
|
|
|
|
use crate::ike::ikev1::{handle_ikev1, IkeV1Header, Ikev1Container};
|
|
|
|
|
use crate::ike::ikev2::{handle_ikev2, Ikev2Container};
|
|
|
|
|
use crate::ike::parser::*;
|
|
|
|
@ -201,7 +199,7 @@ impl IKEState {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn handle_input(&mut self, input: &[u8], direction: u8) -> AppLayerResult {
|
|
|
|
|
fn handle_input(&mut self, input: &[u8], direction: Direction) -> AppLayerResult {
|
|
|
|
|
// We're not interested in empty requests.
|
|
|
|
|
if input.len() == 0 {
|
|
|
|
|
return AppLayerResult::ok();
|
|
|
|
@ -259,13 +257,13 @@ impl IKEState {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Probe to see if this input looks like a request or response.
|
|
|
|
|
fn probe(input: &[u8], direction: u8, rdir: *mut u8) -> bool {
|
|
|
|
|
fn probe(input: &[u8], direction: Direction, rdir: *mut u8) -> bool {
|
|
|
|
|
match parse_isakmp_header(input) {
|
|
|
|
|
Ok((_, isakmp_header)) => {
|
|
|
|
|
if isakmp_header.maj_ver == 1 {
|
|
|
|
|
if isakmp_header.resp_spi == 0 && direction != STREAM_TOSERVER {
|
|
|
|
|
if isakmp_header.resp_spi == 0 && direction != Direction::ToServer {
|
|
|
|
|
unsafe {
|
|
|
|
|
*rdir = STREAM_TOSERVER;
|
|
|
|
|
*rdir = Direction::ToServer.into();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
@ -288,9 +286,9 @@ fn probe(input: &[u8], direction: u8, rdir: *mut u8) -> bool {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if isakmp_header.resp_spi == 0 && direction != STREAM_TOSERVER {
|
|
|
|
|
if isakmp_header.resp_spi == 0 && direction != Direction::ToServer {
|
|
|
|
|
unsafe {
|
|
|
|
|
*rdir = STREAM_TOSERVER;
|
|
|
|
|
*rdir = Direction::ToServer.into();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
@ -318,8 +316,8 @@ pub unsafe extern "C" fn rs_ike_probing_parser(
|
|
|
|
|
|
|
|
|
|
if !input.is_null() {
|
|
|
|
|
let slice = build_slice!(input, input_len as usize);
|
|
|
|
|
if probe(slice, direction, rdir) {
|
|
|
|
|
return ALPROTO_IKE ;
|
|
|
|
|
if probe(slice, direction.into(), rdir) {
|
|
|
|
|
return ALPROTO_IKE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ALPROTO_FAILED;
|
|
|
|
@ -354,7 +352,7 @@ pub unsafe extern "C" fn rs_ike_parse_request(
|
|
|
|
|
let state = cast_pointer!(state, IKEState);
|
|
|
|
|
let buf = build_slice!(input, input_len as usize);
|
|
|
|
|
|
|
|
|
|
return state.handle_input(buf, STREAM_TOSERVER);
|
|
|
|
|
return state.handle_input(buf, Direction::ToServer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
@ -364,7 +362,7 @@ pub unsafe extern "C" fn rs_ike_parse_response(
|
|
|
|
|
) -> AppLayerResult {
|
|
|
|
|
let state = cast_pointer!(state, IKEState);
|
|
|
|
|
let buf = build_slice!(input, input_len as usize);
|
|
|
|
|
return state.handle_input(buf, STREAM_TOCLIENT);
|
|
|
|
|
return state.handle_input(buf, Direction::ToClient);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
|