Commit graph

53 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
ad1cdd4015
tests: better sys-fw log,meta and ip tests 2023-07-12 12:53:13 +02:00
Gustavo Iñiguez Goia
eaec4a825c
tests: added sys-fw conntrack tests 2023-07-11 15:32:15 +02:00
Gustavo Iñiguez Goia
3ca5645c7e
tests: added quota tests 2023-07-11 13:53:01 +02:00
Gustavo Iñiguez Goia
7441aa2ccc
tests: rewritten nat tests
Move common nat checks to its own file.
2023-07-11 13:15:26 +02:00
Gustavo Iñiguez Goia
c2e6032a86
tests: added needed helpers 2023-07-11 01:16:23 +02:00
Gustavo Iñiguez Goia
dad8c0c65d
tests: added queue, nat tests
- Added queue, snat, dnat, redirect, tproxy and masquerade tests.
- Return errors if verdict parameters are not formatted as expected.
2023-07-11 00:57:15 +02:00
Gustavo Iñiguez Goia
6ddd4dcee6
tests: added meta tests, improved ip tests 2023-07-09 23:05:12 +02:00
Gustavo Iñiguez Goia
b1ebc0eb22
sys fw: fixed setting marks on packets
Fix for meta mark set 666
2023-07-09 23:03:50 +02:00
Gustavo Iñiguez Goia
a18404fba9
tests: added sys-fw ip and iface tests
- Added ip daddr, saddr tests.
- Added basic iface tests.
2023-07-08 21:50:46 +02:00
Gustavo Iñiguez Goia
603c4ab39a
tests: added sys-fw verdict tests
- Added accept, drop, return and jump tests.
- Added reject tests.
2023-07-07 13:56:25 +02:00
Gustavo Iñiguez Goia
1a063d10e2
tests: added new sys fw tests
- Added counter tests.
- Added ethernet addresses tests.

Added comments to some functions.
2023-07-07 00:46:09 +02:00
Gustavo Iñiguez Goia
e268a88cff
tests: added sys fw ports tests 2023-07-06 17:59:30 +02:00
Gustavo Iñiguez Goia
28fab440da
sys,fw: check for errors when adding ports rules
Verify that ports are correctly converted to int, for single and range
ports.
2023-07-06 17:58:17 +02:00
Gustavo Iñiguez Goia
84df5135ff
tests: added log and protocol expressions 2023-07-06 16:02:14 +02:00
Gustavo Iñiguez Goia
aa8e793dc4
sys,fw: fixed compilation 2023-07-06 14:33:56 +02:00
Gustavo Iñiguez Goia
18e583d20e
tests: updated sys fw tests 2023-07-06 14:27:54 +02:00
Gustavo Iñiguez Goia
344819eb30
sys,fw: export more internal funcs 2023-07-06 14:09:54 +02:00
Gustavo Iñiguez Goia
d474e7f57a
sys,fw: export some internal utils. 2023-07-06 13:36:57 +02:00
Gustavo Iñiguez Goia
f1ef00a5fd
tests: added nftables/system tests
- test add/delete system fw rules
- test fw config disabled.
2023-07-01 22:41:04 +02:00
Gustavo Iñiguez Goia
0a2dcf6406
tests: added basic nftables/rules tests 2023-06-30 16:19:50 +02:00
Gustavo Iñiguez Goia
e345d61076
tests: added nftables/monitor tests 2023-06-30 10:51:18 +02:00
Gustavo Iñiguez Goia
78ac6c0f6b
tests: disable some tests by default, added utils.go tests
- These tests require permissions for creating new namespaces.
  By default disable them for now.
- Added utils.go tests.
2023-06-29 16:19:47 +02:00
Gustavo Iñiguez Goia
d3b40108c7
tests: added sys fw basic tables/chains tests 2023-06-29 11:27:18 +02:00
Gustavo Iñiguez Goia
f7eec83367
sys fw: allow to add icmp types by commas
- Previously we only supported multiple ICMP types on the same rule
by adding multiple keys:
 Key: type
 Value: echo-request
 Key: type
 Value: echo-reply

Now it's possible to specify them using ',':
 Key: type
 Value: echo-request,echo-reply

- Validate ICMP types before adding them.
2023-06-20 01:14:57 +02:00
Gustavo Iñiguez Goia
9bad34bb16
changed default config permissions on saving
- Changed default permissions of default-config.json, system-fw.json
 - Changed bool values by constants.
2023-06-14 12:10:19 +02:00
Gustavo Iñiguez Goia
9c483b1a59
sys,fw: allow to create multiprotocol rules
Now you can add rules to allow multiple protocols.
For example you can add a rule to allow dport/sport for both TCP
and UDP.

There're two options to allow a port:

Statement {
 Name: tcp
 Values:
   Key: dport
   Value: 1234
}

Statement {
 Name: meta
 Values:
   Key: l4proto
   Value: tcp,udp

   Key: dport
   Value: 1234
}

Closes #951.
2023-05-27 22:02:14 +02:00
Gustavo Iñiguez Goia
810b785b3a
sys,fw: put dns rule always at the top of the chain
The DNS rule to intercept DNS responses must always be at the top of
the (input-filter) rules, otherwise we won't receive DNS resolutions.

Adding, removing or changing system fw rules was removing the rule from 1st
position.

Another approach to this problem could be to remove&&add only the dns rule,
instead of disable-enable interception+rules monitor.
2023-05-25 01:20:53 +02:00
Gustavo Iñiguez Goia
9f71c15e57
sys,fw: fixed race condition creating system rules
Hard to reproduce, but not impossible
2023-05-24 14:26:58 +02:00
Gustavo Iñiguez Goia
6c456aefba
sys fw: fixed race condition reloading rules 2023-05-19 01:35:20 +02:00
Gustavo Iñiguez Goia
fe88841640
sys fw: support ports range operators
Allow to use operators (==, !=) when adding firewall rules with port
ranges (444-555).
2023-04-15 00:33:47 +02:00
Gustavo Iñiguez Goia
e32881c03f
sys fw: allow to apply operators on Meta and Ct expressions
Allow to apply operators (==, !=) on Meta (mark, skuid, skgid, etc) and
Conntrack Mark expressions.
2023-04-13 01:36:59 +02:00
Gustavo Iñiguez Goia
b7c6c8b8db
fw: minor changes for better code reading 2023-01-30 13:43:44 +01:00
Gustavo Iñiguez Goia
b546fb9e7a
Bump nftables-go lib version to 0.1.0 2023-01-22 14:40:08 +01:00
Gustavo Iñiguez Goia
9dfcca295a
fixed adding interception chains on old kernels (4.x) 2023-01-07 22:28:52 +01:00
Gustavo Iñiguez Goia
d31c4e86bf
fixed adding interception rule on some kernels
On some kernels (4.19), adding the interception rule to the
inet-mangle-output chain failed.

According to the nftables wiki, the mangle-output chain have (must?) to
be of type Route:
"route type: ... mangle table ... for the output hook (for other
hooks use type filter instead)."

https://wiki.nftables.org/wiki-nftables/index.php/Configuring_chains#Base_chain_types

So if we fail adding the interception rule, we retry it with type Filter
instead of Route.

Related: #781 , ced9a24
2023-01-04 21:44:46 +01:00
Gustavo Iñiguez Goia
05e63e97a7
sys fw: improved chains creation
This is part of latest commit ced9a24933

 - When reusing a chain, configure the new policy.
 - Don't backup existing rules when reloading the configuration.
2022-12-23 00:50:22 +01:00
Gustavo Iñiguez Goia
ced9a24933
nftables: fixed adding interception rules
On some systems after disabling and enabling the interception, the
DNS rule was not being re-added, with error: chain already exists.

When the interception is disabled, we firstly remove the rules,
and secondly if the chain and table is empty we try to remove them
as well.

However, on some systems even if "nft list ruleset" didn't list the
chains to hold our rules, it failed with error "already exists".

Before adding a chain now we check if it exists, and if it does we
reuse it.

Closes #781
2022-12-22 00:19:16 +01:00
Gustavo Iñiguez Goia
afa23f5ac2
sys fw: improved rules, profiles policies
- Allow to use commas to define conntrack states:
  ("related,established")
- Remove profile's rules when switching from Deny to Allow.
- Fixed checking duplicated rules.

Closes #778
2022-12-19 10:59:43 +01:00
Gustavo Iñiguez Goia
23b1a6b75e
fw: restore chains policy where applicable
If the user configures chains' policy to Drop, we need to restore it to
Accept when exiting, otherwise we could block connections
unintentionally.
2022-12-11 14:15:17 +01:00
Gustavo Iñiguez Goia
2e2f1768f2
improved errors printing 2022-12-11 11:41:47 +01:00
Gustavo Iñiguez Goia
ec31ee0814
sys fw: added option to filter by MAC 2022-10-23 11:36:51 +02:00
Gustavo Iñiguez Goia
fc96b24000
sys fw: added more meta options (uid,gid,l4proto..
Added more options to match connections against packets metainformation:
 skuid, skgid, l4proto, protocol

Fixed setting mark on packets via meta (although it results in an error
-> [invalid type]).
2022-09-16 14:01:41 +02:00
Gustavo Iñiguez Goia
b8d6ead363
sys firewall: fixed matching ip protocols
Fixed using: ip protocol ah (or tcp, udp, gre, l2tp, etc)
2022-09-14 22:03:14 +02:00
Gustavo Iñiguez Goia
09ec8692f7
firewall: fixed adding rules with IPs
Instead of "ip daddr 1.1.1.1", "nh,128,32 16843009" was added.

Reproduced on ubuntu 20/22, manjaro, with different kernels (5.1x)
2022-09-13 21:58:52 +02:00
Gustavo Iñiguez Goia
5c7b1c1558
fw: allow to set rules log level
Allow to set log level in (system) firewall rules.

  "Statement": {
   "Op": "",
   "Name": "log",
   "Values": [
     {
       "Key": "prefix",
       "Value": "invalid-in-packet"
     },
     {
       "Key": "level",
       "Value": "emerg"
     }
   ]
  }

https://github.com/evilsocket/opensnitch/wiki/System-rules#examples-of-supported-statements
2022-09-12 01:14:39 +02:00
Gustavo Iñiguez Goia
f0a9d02e94 fw: fixed adding daddr/saddr to inet tables
If the table family where we're adding a daddr/saddr is inet, we need to
specify the protocol of the IP being added.

Otherwise, listing the rules they appear as:
@nh,128,32 3232235777 accept
instead of: daddr 192.168.1.111 accept

seen here: #704
2022-07-30 00:25:28 +02:00
Nico Berlee
5721ca9479
fw: support for icmpv6 nftables in system rules
- Add support for all available nftables ICMPv6 types (ip6tables -m icmpv6 --help)
- Build nftables ICMPv6 rules
- Create a default outbound ICMPv6 echo-request/reply rule
  (currently outbound echo-request ICMPv6 is by default denied)

Signed-off-by: Nico Berlee <nico.berlee@on2it.net>
2022-07-02 18:14:40 +02:00
Gustavo Iñiguez Goia
0ba5fc44c9 run tests on every change, fixed fw options
- Run unit tests on every push/pr.
- Silence gcc warnings, it doesn't seem to work and causes unit tests to
  fail:
  https://github.com/golang/go/issues/6883#issuecomment-383800123
- Improved firewall configuration contraints, to meet with this table:
  https://wiki.nftables.org/wiki-nftables/index.php/Netfilter_hooks#Hooks_by_family_and_chain_type
2022-05-18 17:47:39 +02:00
Gustavo Iñiguez Goia
d9e0c59158
Allow to configure firewall rules from the GUI (#660)
* Allow to configure firewall rules from the GUI (WIP)

New features:
- Configure and list system firewall rules from the GUI (nftables).
- Configure chains' policies.
- Add simple rules to allow incoming ports.
- Add simple rules to exclude apps (ports) from being intercepted.

This feature is only available for nftables. iptables is still supported,
you can add rules to the configuration file and they'll be loaded, but
you can't configure them from the GUI.

More information: #592
2022-05-03 22:05:12 +02:00
Gustavo Iñiguez Goia
1f79b3a8fd fw, nftables: better rules deletion on exit
We were not deleting our rules correctly on exit if another fw tool had
added rules to the nftables tables. This problem caused to detect that
our rules were not added, so we added them again.
2022-02-17 23:54:55 +01:00