Skip to content
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

Add: nasl function support for IPv6 packet forgery, TCP and UDP over IPv6 and ICMPv6 #1661

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 orgin 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);
31 changes: 31 additions & 0 deletions rust/examples/packet_forgery_udp_v6.nasl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# SPDX-FileCopyrightText: 2023 Greenbone AG
#
# SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception

IP6_HLIM = 128;

src = "5858::1";
dst = "5858::2";

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

dump_ip_v6_packet (ip6);

udp6_packet = forge_udp_v6_packet(ip: ip6,
uh_sport: 5080,
uh_dport: 80,
uh_len: 12,
th_sum: 0,
data: "1234");
display(get_udp_v6_element(udp:udp6_packet, element:"uh_sport"));
udp6_packet = set_udp_v6_elements(udp: udp6_packet, uh_sport: 33000);
display(get_udp_v6_element(udp:udp6_packet, element:"uh_sport"));

dump_ip_v6_packet (udp6_packet);

send_v6packet(udp6_packet);
Loading
Loading