Skip to content

Commit 1892854

Browse files
committed
fix send_v6packet, icmpv6, add tests
1 parent e2348db commit 1892854

File tree

7 files changed

+378
-375
lines changed

7 files changed

+378
-375
lines changed

rust/Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ serde = { version = "1.0", features = ["derive"] }
6666
serde_json = "1.0.96"
6767
sha1 = "0.10.5"
6868
sha2 = "0.10.7"
69-
socket2 = "0.5.7"
69+
socket2 = "0.5.8"
7070
sysinfo = "0.30.5"
7171
thiserror = "1.0.62"
7272
time = { version = "0", features = ["parsing"] }

rust/examples/forge_icmp_v6.nasl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# SPDX-FileCopyrightText: 2023 Greenbone AG
2+
#
3+
# SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception
4+
5+
if(description) {
6+
script_oid("1.2.3");
7+
exit(0);
8+
}
9+
10+
include("misc_func.inc");
11+
12+
# ICMPv6
13+
IP6_v = 0x60;
14+
IP6_P = 0x3a;#ICMPv6
15+
IP6_HLIM = 0x40;
16+
ICMP_ID = rand() % 65536;
17+
18+
ori = "5858::1";
19+
dst = "5858::1";
20+
21+
ip6_packet = forge_ip_v6_packet( ip6_v: 6, # IP6_v,
22+
ip6_p: IP6_P,
23+
ip6_plen:40,
24+
ip6_hlim:IP6_HLIM,
25+
ip6_src: ori,
26+
ip6_dst: dst );
27+
28+
dump_ip_v6_packet(ip6_packet);
29+
30+
d = "123456";
31+
icmp = forge_icmp_v6_packet( ip6:ip6_packet,
32+
icmp_type:128,
33+
icmp_code:1,
34+
icmp_seq:2,
35+
icmp_id:ICMP_ID,
36+
icmp_cksum: 0
37+
);
38+
dump_icmp_v6_packet(icmpv6);
39+
filter = string("icmp6");
40+
ret = send_v6packet( icmp, pcap_active:TRUE, pcap_filter:filter, pcap_timeout: 2);
41+
display(ret);

rust/examples/forge_tcp_v6.nasl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# SPDX-FileCopyrightText: 2023 Greenbone AG
2+
#
3+
# SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception
4+
5+
# This script forges an IPv6 packet with a TCP segment including data. Sends it and captures the packet.
6+
# For running with openvas-nasl and scannerctl, run the following commands respectively
7+
# sudo openvas-nasl -X -d -i $PLUGINSPATH ~/my_nasl/forge_tcp_v6.nasl -t 5858::2
8+
# sudo target/debug/scannerctl execute script ~/my_nasl/forge_tcp_v6.nasl -t 5858::2
9+
#
10+
# Set the correct IPv6 addresses and routes in the orgin and destination hosts with the right address on each.
11+
# sudo ip addr add 5858::1/64 dev wlp6s0
12+
# sudo ip -6 route add 5858::1 dev wlp6s0
13+
14+
if(description) {
15+
script_oid("1.2.3");
16+
exit(0);
17+
}
18+
19+
include("misc_func.inc");
20+
21+
22+
src = "5858::1";
23+
dst = "5858::2";
24+
sport = 63321;
25+
dport = 63322;
26+
27+
filter = string("tcp and src ", src, " and dst ", dst);
28+
29+
ip6 = forge_ip_v6_packet( ip6_v: 6, # IP6_v,
30+
ip6_p: 6, #IP6_P,
31+
ip6_plen:40,
32+
ip6_hlim:IP6_HLIM,
33+
ip6_src: src,
34+
ip6_dst: dst);
35+
36+
37+
tcp = forge_tcp_v6_packet(ip6 : ip6,
38+
th_ack : 0,
39+
th_dport : dport,
40+
th_flags : TH_SYN,
41+
#th_seq : tcp_seq + 1024,
42+
th_sport : sport,
43+
th_x2 : 0,
44+
th_off : 5,
45+
th_win : 1024,
46+
th_urp : 0,
47+
tcp_opt : 3,
48+
tcp_opt_val : 7,
49+
data: "123456",
50+
update_ip_len: TRUE
51+
);
52+
53+
dump_tcp_v6_packet(tcp);
54+
55+
res = send_v6packet(tcp, pcap_filter: filter, pcap_timeout: 20, pcap_active: TRUE);
56+
display(res);

0 commit comments

Comments
 (0)