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: support for nasl snmp getnext #1047

Merged
merged 33 commits into from
Mar 28, 2022
Merged

Conversation

Kraemii
Copy link
Member

@Kraemii Kraemii commented Feb 24, 2022

What:
Additional Nasle function to support GETNEXT for SNMP.
SC-443

Why:
This allows to iterate over OID trees

How:
Currently in testing phase

Used this script for testing:

########## begin script ####################
include("misc_func.inc");
include("dump.inc");


oid = '1.3.6.1.2.1.1.1.0';

## uncomment this line to test the error handling
#oid = '.1.3.6.1.2.1.1.1.0.3.3.3.3';
protocol = 'udp';
port = 161;
community = 'public';

display("Iterrate trough SNMP OID tree");
ret = snmpv1_get( port:port, oid:oid, protocol:protocol, community:community );
display (ret, "\n");
retry = 100;
while(ret[0] == 0 && retry > 0)
{
    retry = retry - 1;
    ret = snmpv1_getnext( port:port, oid:ret[2], protocol:protocol, community:community );
    display (ret, "\n");
}


############# end script ######################## 

Checklist:

  • Tests
  • PR merge commit message adjusted

@Kraemii Kraemii force-pushed the snmp-getnext branch 4 times, most recently from 52a8ed3 to 3144979 Compare February 28, 2022 08:21
@jjnicola jjnicola marked this pull request as ready for review March 9, 2022 10:13
@jjnicola jjnicola requested a review from a team as a code owner March 9, 2022 10:13
@jjnicola jjnicola enabled auto-merge (squash) March 14, 2022 07:11
/* Free request only, since members are pointers to the nasl lexic context
which will be free()'d later */
g_free (request);

return array_from_snmp_result (ret, result);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the result struct also has to free its memory after the array is created

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Result struct must not be free()'d, since the return nasl tree_cell structs does not have a copy of the result members, but points to them. You can see this in the array_from_snmp_result().
Once the script finishes, the memory used by tree_cells structures is released.

/* Free request only, since members are pointers to the nasl lexic context
which will be free()'d later */
g_free (request);

return array_from_snmp_result (ret, result);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

This fixes a segmentation fault in the original PR, because result didn't have allocated memory.
The first time the oid is requiered. The next time, the oid is optional for getnext

While snmpgetnext support mib descriptions instead of oids (like iso.3.6....), the older version
snmp v1 doesn't. Therfore the iso. is formated in the right place, so the oid can be saved once it is in the result.
…he result struct.

The oid can be used now for getnext. (See some commits above.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants