Skip to content

Commit

Permalink
fix send_v6packet, icmpv6, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Dec 17, 2024
1 parent e2348db commit a372186
Show file tree
Hide file tree
Showing 7 changed files with 378 additions and 375 deletions.
14 changes: 7 additions & 7 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.96"
sha1 = "0.10.5"
sha2 = "0.10.7"
socket2 = "0.5.7"
socket2 = "0.5.8"
sysinfo = "0.30.5"
thiserror = "1.0.62"
time = { version = "0", features = ["parsing"] }
Expand Down
41 changes: 41 additions & 0 deletions rust/examples/forge_icmp_v6.nasl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# SPDX-FileCopyrightText: 2023 Greenbone AG
#
# SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception

if(description) {
script_oid("1.2.3");
exit(0);
}

include("misc_func.inc");

# ICMPv6
IP6_v = 0x60;
IP6_P = 0x3a;#ICMPv6
IP6_HLIM = 0x40;
ICMP_ID = rand() % 65536;

ori = "5858::1";
dst = "5858::1";

ip6_packet = forge_ip_v6_packet( ip6_v: 6, # IP6_v,
ip6_p: IP6_P,
ip6_plen:40,
ip6_hlim:IP6_HLIM,
ip6_src: ori,
ip6_dst: dst );

dump_ip_v6_packet(ip6_packet);

d = "123456";
icmp = forge_icmp_v6_packet( ip6:ip6_packet,
icmp_type:128,
icmp_code:1,
icmp_seq:2,
icmp_id:ICMP_ID,
icmp_cksum: 0
);
dump_icmp_v6_packet(icmpv6);
filter = string("icmp6");
ret = send_v6packet( icmp, pcap_active:TRUE, pcap_filter:filter, pcap_timeout: 2);
display(ret);
56 changes: 56 additions & 0 deletions rust/examples/forge_tcp_v6.nasl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# SPDX-FileCopyrightText: 2023 Greenbone AG
#
# SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception

# This script forges an IPv6 packet with a TCP segment including data. Sends it and captures the packet.
# For running with openvas-nasl and scannerctl, run the following commands respectively
# 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 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

if(description) {
script_oid("1.2.3");
exit(0);
}

include("misc_func.inc");


src = "5858::1";
dst = "5858::2";
sport = 63321;
dport = 63322;

filter = string("tcp and src ", src, " and dst ", dst);

ip6 = forge_ip_v6_packet( ip6_v: 6, # IP6_v,
ip6_p: 6, #IP6_P,
ip6_plen:40,
ip6_hlim:IP6_HLIM,
ip6_src: src,
ip6_dst: dst);


tcp = forge_tcp_v6_packet(ip6 : ip6,
th_ack : 0,
th_dport : dport,
th_flags : TH_SYN,
#th_seq : tcp_seq + 1024,
th_sport : sport,
th_x2 : 0,
th_off : 5,
th_win : 1024,
th_urp : 0,
tcp_opt : 3,
tcp_opt_val : 7,
data: "123456",
update_ip_len: TRUE
);

dump_tcp_v6_packet(tcp);

res = send_v6packet(tcp, pcap_filter: filter, pcap_timeout: 20, pcap_active: TRUE);
display(res);
Loading

0 comments on commit a372186

Please sign in to comment.