optimising the nagiosxi modules and also fixing the bug when autochec…#17820
Conversation
jheysel-r7
left a comment
There was a problem hiding this comment.
Thanks for all the fixes @manishkumarr1017! Just a couple of requests / questions.
| return 6, 'Unable to obtain the Nagios XI version from the dashboard' | ||
| end | ||
|
|
||
| # As affected versions are only 5.2.0 -> 5.8.4 |
There was a problem hiding this comment.
| # As affected versions are only 5.2.0 -> 5.8.4 | |
| # Versions of NagiosXI pre-5.2 have different formats (5r1.0, 2014r2.7, 2012r2.8b, etc.) that Rex cannot handle, | |
| # so we set pre-5.2 versions to 1.0.0 for easier Rex comparison because the module only works on post-5.2 versions. |
Please add the more detailed explanation given in the other modules here as well. I was confused as to why the version was being set to 1.0.0 until I read the above.
There was a problem hiding this comment.
Yeah sure. I will update this on all modules.
| end | ||
|
|
||
| # As affected versions are only 5.2.0 -> 5.8.4 | ||
| if /^\d{4}r\d(?:\.\d)?(?:(?:RC\d)|(?:[a-z]{1,3}))?$/.match(nagios_version) || nagios_version == '5r1.0' |
There was a problem hiding this comment.
I think it would make sense to add this regex string as a constant in: nagios_xi/version.rb, as it's being used by multiple modules and imo improves readability. Something like this:
# Versions of NagiosXI pre-5.2 have different formats (5r1.0, 2014r2.7, 2012r2.8b, etc.) that Rex cannot handle. The following regex is used to identify those versions.
PRE_5_2_VERSION_REGEX = '^\d{4}r\d(?:\.\d)?(?:(?:RC\d)|(?:[a-z]{1,3}))?$'
| if /^\d{4}r\d(?:\.\d)?(?:(?:RC\d)|(?:[a-z]{1,3}))?$/.match(nagios_version) || nagios_version == '5r1.0' | |
| if /#{PRE_5_2_VERSION_REGEX}/.match(nagios_version) || nagios_version == '5r1.0' |
Please update the other modules in this PR to use the constant as well, thanks!
There was a problem hiding this comment.
yeah sure. I will update this change in all modules.
| return login_result, res_array | ||
| end | ||
|
|
||
| def authenticate |
There was a problem hiding this comment.
Not asking you to do this as apart of this PR - however I've noticed now 3 out of the 4 authenticate methods in these 4 modules are now identical. With your knowledge of the different Nagios versions and their intricacies do you think moving the authenticate method to a mixin would make sense?
There was a problem hiding this comment.
Yeah I feel that it would be good having a single common method to reduce the code repetition I feel that adding this method to the nagios mixin would be a great idea. As I have 4 out of 5 authenticate methods are identical So I will try to find a way to incorporate into 1 authenticate method. I will try to update this in this PR.
| 'Stability' => [ CRASH_SAFE, ], | ||
| 'SideEffects' => [ ARTIFACTS_ON_DISK, IOC_IN_LOGS, CONFIG_CHANGES ] | ||
| 'SideEffects' => [ ARTIFACTS_ON_DISK, IOC_IN_LOGS, CONFIG_CHANGES ], | ||
| 'Reliability' => [] # fixing rubocop issues |
There was a problem hiding this comment.
| 'Reliability' => [] # fixing rubocop issues | |
| 'Reliability' => [] |
I see what you mean, although I think this comment belongs more on the github PR rather than in the module itself. Either way, thanks!
There was a problem hiding this comment.
Yeah sure. I apologise for this from next time I will add it in the PR comment rather than in the code comments. I will remove this.
| def authenticate | ||
| login_result, res_array = nagios_xi_login(datastore['USERNAME'], datastore['PASSWORD'], false) | ||
| case login_result | ||
| when 1..3 # An error occurred |
There was a problem hiding this comment.
While you're making changes to these module could you please refactor the login_result from an integer to an enum that better describes what the login result actually is? The team would really appreciate it, thank you.
There was a problem hiding this comment.
Yeah that would be great for readability. I will do this change.
|
@jheysel-r7 I will update this PR by today and will notify you after updating. @jheysel-r7 I have updated the PR. |
|
Hey @manishkumarr1017 thanks so much for making the requested changes. They look great. I've tested all the modules and will land this now. |
Release NotesThis PR fixes the nagiosxi authenticated modules to work with even when autocheck is disabled as well as refactors reusable code. |
Improving nagiosxi authenticated modules to work with even when autocheck is disabled. This Pull Request fixes #17606 and some improvements have been performed to the below nagios authenticated modules.
The improvements that are made for the above modules are
Verification that the exploit runs when the autocheck is disabled.
List the steps needed to make sure this thing works
msfconsoleuse exploit/linux/http/nagios_xi_plugins_check_plugin_authenticated_rceset RHOST <ip>set PASSWORD <nagios password>set LHOST <ip>set autocheck falserunHere is the output
Here is the previous output