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

Wildcard netmask support in aliases and firewall rules #4952

Closed
OleSta opened this issue Apr 28, 2021 · 32 comments
Closed

Wildcard netmask support in aliases and firewall rules #4952

OleSta opened this issue Apr 28, 2021 · 32 comments
Assignees
Labels
feature Adding new functionality
Milestone

Comments

@OleSta
Copy link

OleSta commented Apr 28, 2021

Important notices
Before you add a new report, we ask you kindly to acknowledge the following:

[x] I have read the contributing guide lines at https://github.com/opnsense/plugins/blob/master/CONTRIBUTING.md

[x] I have searched the existing issues and I'm convinced that mine is new.

[x] When the request is meant for an existing plugin, I've added its name to the title.

Is your feature request related to a problem? Please describe.
Yes, we have to create MANY firewall rules instead one.

Describe the solution you'd like
I would like to create firewall rules and aliases that gives access/define IP's which ends at e.g. x.y.z.64-67
Using another firewall provider we could do this by using wildcard netmasks as this 0.0.0.64/0.0.0.252

Describe alternatives you've considered
Cannot handle it in OPNsense right now without creating a lot of firewall rules.

Additional context
Cisco example syntax:
Match all 192.168.x.1 addresses:
permit 192.168.0.1 0.0.255.0

Barracuda inplementation:
https://campus.barracuda.com/product/cloudgenfirewall/doc/79462985/how-to-create-wildcard-network-objects/

Watchguard implementation:
https://www.watchguard.com/help/docs/help-center/en-US/Content/en-US/Fireware/networksetup/wildcard_ip_addresses_about.html

@AdSchellevis AdSchellevis transferred this issue from opnsense/plugins Apr 28, 2021
@AdSchellevis AdSchellevis added the feature Adding new functionality label Apr 28, 2021
@AdSchellevis AdSchellevis self-assigned this Apr 28, 2021
@AdSchellevis
Copy link
Member

no promises, but at a first glance the trick shouldn't be very complicated to calculated networks from a mask.

@OleSta
Copy link
Author

OleSta commented Apr 28, 2021

Sounds great. Let me know if I can help testing or something.
How fast should I expect it to be implemented if done?

@AdSchellevis
Copy link
Member

Will do, we have some other alias changes scheduled to be merged (#4941), so I wasn't planning on starting with this one before it's merged, so if I can spare a bit of free time before the 21.7 in July that would be nice, but as mentioned before, no promises.

@OleSta
Copy link
Author

OleSta commented Apr 28, 2021

ok,
Here is a link more that explain the wildcard system more complex.
https://networklessons.com/security/create-complex-wildcard-masks/

@AdSchellevis
Copy link
Member

The trick is to calculate them upfront, if we can do that (easily), we can add it. The filter itself doesn't support this type of matching for as far as I know.

@fichtner fichtner added this to the Community milestone Apr 29, 2021
@AdSchellevis
Copy link
Member

It's a work in progress (needs ui/api code), but 05d3224 calculates the wildcard netmasks when provided in /usr/local/etc/filter_tables.conf.

For the record, support for wildcards will only be provided via aliases, pf doesn't support this format natively.

@marjohn56
Copy link
Member

Is this to be added as an alias? I have some time today, I could take a crack at it if you've not started it.

@AdSchellevis
Copy link
Member

@marjohn56 it should be valid input for the network alias type, you can easily try it out manually when changing an alias in /usr/local/etc/filter_tables.conf (e.g. 192.168.0.1/0.0.255.0) I think it only needs the validation extended, but haven't looked at the php code yet. If you want to give it a shot, go ahead, I'm not going to work on it today.

@marjohn56
Copy link
Member

Interesting... Not sure what validation it needs... worked perfectly. We have a nice aliastables entry which looks spot on.

@AdSchellevis
Copy link
Member

hmm, it seems to validate indeed, but it doesn't look intended. we might need to be careful then what it did before adding this.

@marjohn56
Copy link
Member

Your obviously so good at this that things work without thinking about it. 😉

@OleSta
Copy link
Author

OleSta commented May 4, 2021

I would be good if it was able to show the subnets calculated when validating the wildcard netmask

@AdSchellevis
Copy link
Member

you can use the table view for that (Firewall -> Diagnostics -> pfTables), at this point the interface doesn't know (and is generic behaviour for all alias types)

@AdSchellevis
Copy link
Member

@marjohn56 I really doubt that ;) if it smells like a bug, it usually is. The question is what 192.168.1.0/255.255.255.0 produced in table output before this patch. if it's an empty table, no problem, we can just make sure to fix the validation (which can't be right now), if it's not empty we risk people using undocumented "features"

@marjohn56
Copy link
Member

Well I don't use network aliases but if I enter the network 192.168.4.1/24 then I get an aliastable entry of that. Not sure the wiki is correct as it sort of suggests entering !192.168.1.0/24 - which is not accepted, that would just require inverse of the alias in the rule creation, correct?

@AdSchellevis
Copy link
Member

the ! is a valid pf keyword #4318 which should indeed exclude the specified range.

@marjohn56
Copy link
Member

Sorry.. my typo. If I enter !192.168.5.0/24 - that works.. I can sort of break it by doing something stupid like !10.5.1.4/0.0.255.0 - which gives me an empty aliastable entry.

@marjohn56
Copy link
Member

So the only validation I think might be needed is if a user did enter something !192.168.0.1/0.0.255.0 - which results in an empty aliastable, unless you think that the user should be able to enter !192.168.0.1/0.0.255.0? Sort of confusing myself now!

@AdSchellevis
Copy link
Member

@marjohn56 if it smells like a bug, it usually is 611304a ;)

AdSchellevis added a commit that referenced this issue May 9, 2021
@fichtner fichtner removed this from the Community milestone Jun 15, 2021
@fichtner fichtner added this to the 21.7 milestone Jun 15, 2021
fichtner pushed a commit that referenced this issue Jun 15, 2021
…ked code.

(cherry picked from commit 05d3224)
(cherry picked from commit 611304a)
(cherry picked from commit 714ad52)
@OleSta
Copy link
Author

OleSta commented Jun 18, 2021

Updated to 21.1.7 and if I use "192.168.0.0/0.0.255.0" it does list correct in pfTables. But if I use "192.168.0.0/0.0.252.0" it lists 64 entries (e.g. 192.168.232.0) which is not correct. I would expect 192.168.0.0/24,192.168.1.0/24, 192.168.2.0/24 and 192.168.3.0/24

@OleSta
Copy link
Author

OleSta commented Jun 18, 2021

If I use 192.168.0.0/0.0.3.255 pfTables lists 192.168.0.0/22

@OleSta
Copy link
Author

OleSta commented Jun 18, 2021

image

@AdSchellevis
Copy link
Member

@OleSta wilcard calculation is rather complex, in case of the 192.168.0.0/0.0.252.0 I would expect it to return 64 addresses, since 255 equals 256 addresses, cisco's examples look quite similar to the output we produce on the same test cases https://www.ciscopress.com/articles/article.asp?p=3089353&seqNum=5

@OleSta
Copy link
Author

OleSta commented Jun 18, 2021

Not sure how to use this.
I had hoped for this:
https://campus.barracuda.com/product/cloudgenfirewall/doc/79462985/how-to-create-wildcard-network-objects/

https://www.watchguard.com/help/docs/help-center/en-US/Content/en-US/Fireware/networksetup/wildcard_ip_addresses_about.html

I would like to create firewall rules and aliases that gives access/define IP's which ends at e.g. x.y.z.64-67
Using another firewall provider we could do this by using wildcard netmasks as this 0.0.0.64/0.0.0.252
How do I get that done with the implemented system?

@AdSchellevis
Copy link
Member

0.0.0.64/0.0.0.3 ? which translates to0.0.0.64/30, to me it looks like "wildcard" and "netmask" are swapped in some of the documents (https://en.wikipedia.org/wiki/Wildcard_mask)

@OleSta
Copy link
Author

OleSta commented Jun 18, 2021

would 0.0.0.64/30 work with the firewall rules? Guess I have to test next week.

@OleSta
Copy link
Author

OleSta commented Jun 22, 2021

using the 0.0.0.64/0.0.0.3 does not match any packets in the firewall rules I tested with.
Had to use 0.0.0.64/255.255.255.3

Did a test with 10.0.0.64/0.255.255.3
Loading pfTables work fine from Chrome (Remote Desktop Manager Free fails to load them).
Loaded 65536 entries :)

@OleSta
Copy link
Author

OleSta commented Jun 22, 2021

Why does both 0.0.0.64/255.255.255.3 and 10.0.0.64/0.255.255.3 give 65536 entries in pfTables?

@AdSchellevis
Copy link
Member

safety limit :

for idx, item in enumerate(net_wildcard_iterator(address.lstrip('!'))):
if idx > 65535:
# overflow
syslog.syslog(syslog.LOG_ERR, 'alias table %s overflow' % self._name)
break

@OleSta
Copy link
Author

OleSta commented Jun 22, 2021

Why do I get one more than the limit?

Yes 0.0.0.64/255.255.255.3 fails with overflow I see.

Why do I get this in my log:
unable to resolve 10.0.0.64/0.255.255.3 for alias test_wildcard

@OleSta
Copy link
Author

OleSta commented Jun 22, 2021

If I add many wildcards to an alias I get: Invalid argument. [test_wildcard]

@OleSta
Copy link
Author

OleSta commented Jun 24, 2021

Looks like its working with a few bugs and a limit of 65536.
I need to get used to the notation form as the other firewalls I have done use an almost reverse notation:
https://www.routerfreak.com/understanding-wild-card-masks/

AdSchellevis added a commit to opnsense/docs that referenced this issue Jul 24, 2021
AdSchellevis added a commit that referenced this issue Aug 15, 2021
oshogbo pushed a commit to DynFi/opnsense-core that referenced this issue Mar 3, 2022
oshogbo pushed a commit to DynFi/opnsense-core that referenced this issue Mar 3, 2022
oshogbo pushed a commit to DynFi/opnsense-core that referenced this issue Mar 3, 2022
…and make sure to obey ! when being provided.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Adding new functionality
Development

No branches or pull requests

4 participants