Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Dec 23, 2024
1 parent 475736d commit 8f898fe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 41 deletions.
2 changes: 1 addition & 1 deletion rust/examples/forge_tcp_v6.nasl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# sudo openvas-nasl -X -d -i $PLUGINSPATH ~/my_nasl/forge_tcp_v6.nasl -t 5858::2
# sudo target/debug/scannerctl execute script ~/my_nasl/forge_tcp_v6.nasl -t 5858::2
#
# Set the correct IPv6 addresses and routes in the orgin and destination hosts with the right address on each.
# Set the correct IPv6 addresses and routes in the origin and destination hosts with the right address on each.
# sudo ip addr add 5858::1/64 dev wlp6s0
# sudo ip -6 route add 5858::1 dev wlp6s0

Expand Down
1 change: 0 additions & 1 deletion rust/src/nasl/builtin/raw_ip/tests/frame_forgery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,3 @@ fn send_frame() {
NaslValue::Null,
);
}

63 changes: 24 additions & 39 deletions rust/src/nasl/builtin/raw_ip/tests/packet_forgery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use rustls::pki_types::{IpAddr, Ipv6Addr};

use crate::nasl::builtin::raw_ip;
use crate::nasl::{nasl_std_functions, test_prelude::*};
use crate::nasl::builtin::raw_ip::{PacketForgeryError, packet_forgery::safe_copy_from_slice};
use crate::nasl::builtin::raw_ip::{packet_forgery::safe_copy_from_slice, PacketForgeryError};
use crate::nasl::utils::context::Target;
use crate::nasl::{nasl_std_functions, test_prelude::*};
use crate::storage::DefaultDispatcher;
/// Copy from a slice in safe way, performing the necessary test to avoid panicking
Expand Down Expand Up @@ -72,8 +72,8 @@ fn forge_packet() {
th_sum: 0,
th_urp: 0);"#,
vec![
69u8, 0, 0, 40, 210, 4, 0, 0, 255, 6, 104, 109, 192, 168, 0, 1, 192, 168, 0, 12,
19, 216, 0, 80, 0, 0, 3, 232, 0, 0, 0, 0, 80, 33, 0, 0, 22, 86, 0, 0,
69u8, 0, 0, 40, 210, 4, 0, 0, 255, 6, 104, 109, 192, 168, 0, 1, 192, 168, 0, 12, 19,
216, 0, 80, 0, 0, 3, 232, 0, 0, 0, 0, 80, 33, 0, 0, 22, 86, 0, 0,
],
);
}
Expand Down Expand Up @@ -184,8 +184,8 @@ fn forge_udp() {
th_sum: 0,
data: "1234");"#,
vec![
69u8, 0, 0, 32, 210, 4, 0, 0, 255, 17, 104, 108, 192, 168, 0, 1, 192, 168, 0, 10,
19, 216, 0, 80, 0, 8, 5, 240, 49, 50, 51, 52,
69u8, 0, 0, 32, 210, 4, 0, 0, 255, 17, 104, 108, 192, 168, 0, 1, 192, 168, 0, 10, 19,
216, 0, 80, 0, 8, 5, 240, 49, 50, 51, 52,
],
);
}
Expand Down Expand Up @@ -213,8 +213,8 @@ fn forge_icmp() {
icmp_id: 1,
data: "1234");"#,
vec![
69u8, 0, 0, 32, 210, 4, 0, 0, 255, 1, 104, 124, 192, 168, 0, 1, 192, 168, 0, 10, 8,
0, 145, 153, 1, 0, 1, 0, 49, 50, 51, 52,
69u8, 0, 0, 32, 210, 4, 0, 0, 255, 1, 104, 124, 192, 168, 0, 1, 192, 168, 0, 10, 8, 0,
145, 153, 1, 0, 1, 0, 49, 50, 51, 52,
],
);
}
Expand Down Expand Up @@ -242,8 +242,8 @@ fn forge_igmp() {
group: 224.0.0.1,
);"#,
vec![
69u8, 0, 0, 28, 210, 4, 0, 0, 255, 2, 104, 127, 192, 168, 0, 1, 192, 168, 0, 10,
17, 10, 14, 244, 224, 0, 0, 1,
69u8, 0, 0, 28, 210, 4, 0, 0, 255, 2, 104, 127, 192, 168, 0, 1, 192, 168, 0, 10, 17,
10, 14, 244, 224, 0, 0, 1,
],
);
}
Expand All @@ -270,56 +270,42 @@ fn copy_from_slice_panic() {
// "Error copying from slice. Index out of range".to_string()
// ))
// );
//
//
// // different range size between origin and destination
// assert_eq!(
// safe_copy_from_slice(&mut a, 0, alen, &b, 0, 2),
// Err(error(
// "Error copying from slice. Index out of range".to_string()
// ))
// );
//
//
// // out of index in the destination range
// assert_eq!(
// safe_copy_from_slice(&mut a, 1, alen + 1, &b, 0, b.len()),
// Err(error(
// "Error copying from slice. Index out of range".to_string()
// ))
// );
//
//
// let _r = safe_copy_from_slice(&mut a, 0, 2, &b, 0, 2);
// assert_eq!(a, [b'a', b'b', 3u8, 4u8]);
//}

#[test]
fn forge_icmp_v6_packet() {
// let initial = vec![
// ("description".to_owned(), true.into()),
// ("OPENVAS_VERSION".to_owned(), "testus".into()),
// ];
// let storage = DefaultDispatcher::new();
// let register = Register::root_initial(&initial);
// let target = Target::default();
// let functions = nasl_std_functions();
// let loader = |_: &str| "".to_string();
// let key = crate::storage::ContextKey::Scan("1".to_string(), Some("::1".to_string()));
//
// let mut context = Context::new(key, target, &storage, &storage, &loader, &functions);
// context.set_target("5858::2".to_string());
//
// let mut t = TestBuilder::default().with_context(context);
// let dst = t.context();
// let a = dst.target();
// assert_eq!(a, "5858::2");
let mut t = TestBuilder::default();
let key = crate::storage::ContextKey::Scan(String::default(), Some("5858::2".to_string()));
let mut t = TestBuilder::default().with_context_key(key);
t.ok(
r#"ip6_packet = forge_ip_v6_packet( ip6_v: 6, # IP6_v,
ip6_p: 0x3a, #ICMPv6
r#"ip6_packet = forge_ip_v6_packet( ip6_v: 6,
ip6_p: 0x3a,
ip6_plen:40,
ip6_hlim:IP6_HLIM,
ip6_hlim: 128,
ip6_src: "5858::1",
ip6_dst: "5858::2");"#,
vec![6, 0, 0, 58, 40, 58, 58, 0, 0, 0, 0, 0, 1, 58,58, 0, 0, 0, 0, 0, 2],
vec![
96u8, 0, 0, 0, 0, 0, 58, 128, 88, 88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 88, 88,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2,
],
);
t.ok(
r#"icmp = forge_icmp_v6_packet( ip6:ip6_packet,
Expand All @@ -330,9 +316,8 @@ fn forge_icmp_v6_packet() {
icmp_cksum: 0
);"#,
vec![
6, 0, 0, 58, 40, 58, 58, 0, 0, 0, 0, 0, 1, 58, 58, 0, 0, 0, 0, 0, 2,
128, 1, 64, 38, 140, 227, 2, 0
96u8, 0, 0, 0, 0, 8, 58, 128, 88, 88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 88, 88,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 128, 1, 204, 8, 1, 0, 2, 0,
],
);
}

0 comments on commit 8f898fe

Please sign in to comment.