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 functions for dumping icmp packets #609

Merged
merged 3 commits into from
Oct 20, 2020
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add support for TLSv1.3. [#588](https://github.com/greenbone/openvas/pull/588)
- Add alternative for supporting snmp during scans. [#594](https://github.com/greenbone/openvas/pull/594)
- Add resolve_hostname_to_multiple_ips() NASL function. [#596](https://github.com/greenbone/openvas/pull/596)
- Add dump_icmp_packet() and dump_icmp_v6_packet() nasl functions. [#609](https://github.com/greenbone/openvas/pull/609)

### Fixed
- Fork vhosts before creating the socket.[#576](https://github.com/greenbone/openvas/pull/576)
Expand Down
2 changes: 2 additions & 0 deletions nasl/nasl_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ static init_func libfuncs[] = {
{"forge_icmp_v6_packet", forge_icmp_v6_packet},
{"get_icmp_element", get_icmp_element},
{"get_icmp_v6_element", get_icmp_v6_element},
{"dump_icmp_packet", dump_icmp_packet},
{"dump_icmp_v6_packet", dump_icmp_v6_packet},
{"forge_igmp_packet", forge_igmp_packet},
{"forge_igmp_v6_packet", forge_igmp_v6_packet},
{"send_packet", nasl_send_packet},
Expand Down
28 changes: 28 additions & 0 deletions nasl/nasl_packet_forgery.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,34 @@ get_icmp_element (lex_ctxt *lexic)
return NULL;
}

/**
* @brief Dump the ICMP part of a IP Datagram.
*
* @param[in] lexic Lexical context of NASL interpreter.
* @param[in] ... IP datagrams to dump the ICMP part from.
*/
tree_cell *
dump_icmp_packet (lex_ctxt *lexic)
{
int i = 0;
u_char *pkt;
while ((pkt = (u_char *) get_str_var_by_num (lexic, i++)) != NULL)
{
struct ip *ip = (struct ip *) pkt;
struct icmp *icmp;
icmp = (struct icmp *) (pkt + ip->ip_hl * 4);
printf ("------\n");
printf ("\ticmp_id : %d\n", ntohs (icmp->icmp_id));
printf ("\ticmp_code : %d\n", icmp->icmp_code);
printf ("\ticmp_type : %u\n", icmp->icmp_type);
printf ("\ticmp_seq : %u\n", ntohs (icmp->icmp_seq));
printf ("\ticmp_cksum : %d\n", ntohs (icmp->icmp_cksum));
printf ("\tData : %s\n", icmp->icmp_data);
printf ("\n");
}
return NULL;
}

/*--------------[ IGMP ]--------------------------------------------*/

struct igmp
Expand Down
2 changes: 2 additions & 0 deletions nasl/nasl_packet_forgery.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ tree_cell *
forge_icmp_packet (lex_ctxt *);
tree_cell *
get_icmp_element (lex_ctxt *);
tree_cell *
dump_icmp_packet (lex_ctxt *);

tree_cell *
forge_igmp_packet (lex_ctxt *);
Expand Down
38 changes: 38 additions & 0 deletions nasl/nasl_packet_forgery_v6.c
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,44 @@ get_icmp_v6_element (lex_ctxt *lexic)
return NULL;
}

/**
* @brief Dump the ICMP part of a IP Datagram.
*
* @param[in] lexic Lexical context of NASL interpreter.
* @param[in] ... IP datagrams to dump the ICMP part from.
*/
tree_cell *
dump_icmp_v6_packet (lex_ctxt *lexic)
{
int i = 0;
u_char *pkt;
while ((pkt = (u_char *) get_str_var_by_num (lexic, i++)) != NULL)
{
unsigned int j;
unsigned int limit;
char *c;
struct ip6_hdr *ip6 = (struct ip6_hdr *) pkt;
struct icmp6_hdr *icmp;
icmp = (struct icmp6_hdr *) (pkt + 40);
limit = get_var_size_by_num (lexic, i - 1);
printf ("------\n");
printf ("\ticmp6_id : %d\n", ntohs (icmp->icmp6_id));
printf ("\ticmp6_code : %d\n", icmp->icmp6_code);
printf ("\ticmp6_type : %u\n", icmp->icmp6_type);
printf ("\ticmp6_seq : %u\n", ntohs (icmp->icmp6_seq));
printf ("\ticmp6_cksum : %d\n", ntohs (icmp->icmp6_cksum));
printf ("\tData : ");
c = (char *) ((char *) icmp + sizeof (struct icmp6_hdr));
if (UNFIX (ip6->ip6_plen) > (sizeof (struct icmp6_hdr)))
for (j = 0;
j < UNFIX (ip6->ip6_plen) - sizeof (struct icmp6_hdr) && j < limit;
j++)
printf ("%c", isprint (c[j]) ? c[j] : '.');
printf ("\n");
}
return NULL;
}

/*--------------[ IGMP ]--------------------------------------------*/
/*
* @brief Forge v6 IGMP packet.
Expand Down
2 changes: 2 additions & 0 deletions nasl/nasl_packet_forgery_v6.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ tree_cell *
forge_icmp_v6_packet (lex_ctxt *);
tree_cell *
get_icmp_v6_element (lex_ctxt *);
tree_cell *
dump_icmp_v6_packet (lex_ctxt *);

tree_cell *
forge_igmp_v6_packet (lex_ctxt *);
Expand Down