-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
Fix incorrect scope condition when populating RHOSTS using services command #18411
Fix incorrect scope condition when populating RHOSTS using services command #18411
Conversation
231d8fb
to
76b23cf
Compare
76b23cf
to
4978610
Compare
Thanks for the PR! 👍 Is there replication steps on how to get empty strings for the scope into the database? When running a |
Sorry, I should have added more detailed steps to reproduce the database state. Here is how you could populate a database, assuming you already have a workspace with ID 1: insert into hosts (address, workspace_id, scope) values ('127.0.0.1', 1, ''); # the empty string in the scope field is the crucial part
insert into services (port, host_id, proto) values (1234, 1, 'tcp'); # assuming the newly added host has ID 1 Afterwards it can be reproduced as follows:
I understand that populating the database with 3rd party tools might not be officially supported, but I do think it would be better to handle empty (but not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a #present?
method that can be applied to strings to handle Nil, blank strings and empty strings that would be a better test here.
Even better might be to determine if the scope should be used at all because the address is an IPv6 address. Even if the field is populated for some reason I don't think it should be used for an IPv4 address.
Replication stepsOpen up console from msfconsole:
Create the database models:
BeforeError replicated:
AfterRHOSTS no longer has a trailing invalid
|
Release NotesFixes an edge-case where the |
When the database contains hosts with empty scope columns (where scope is an empty string), they are not correctly added to
RHOSTS
viaservices -R
because the command adds a trailing%
sign to each address. This can happen if the database is filled by an external program that setsscope
to an empty string instead ofNULL
.Fixes #18410.
Verification
Make sure you have less then 5 hosts in the database (or add a filter that reduces the number of hits to less than 5) and make sure that the hosts have empty strings in their
scope
column and notNULL
.msfconsole
services -R
Now you see that the addresses in
RHOSTS
have trailing%
signs. These are normally added to separate the address scope but in this case the scope is empty and they are added regardless.Fix
The reason why the ternary for adding or omitting the scope to the address fails is because empty strings (like
host.scope
in this case) are truthy in Ruby. Therefore, the conditional only works ifscope
isnil
. This is fixed by casting potentialnil
values to a string and performing a more explicit condition (host.scope.to_s != ""
).