Commit graph

153 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
eb52af72e5 audit: exclude events from our pid at rule level
Do not exclude them by code, just don't receive them.
2020-03-09 19:51:06 +01:00
Gustavo Iñiguez Goia
27778c1fd6 Bump version to v1.0.0rc6 2020-03-08 20:59:57 +01:00
Gustavo Iñiguez Goia
6ebd6cca99 added a default configuration file
Some people has asked where they can change the daemon configuration.

As we can't change it from the GUI yet, and we're providing deb
packages, we need to distribute a default config.

That way the users will see it and will be able to customize it.
2020-03-08 20:25:05 +01:00
Gustavo Iñiguez Goia
0fb23bb588 audit: avoid to alloc unused map, reformatted code 2020-03-08 01:09:47 +01:00
Gustavo Iñiguez Goia
99b024e0de dns sources formatted and documented 2020-03-07 10:23:53 +01:00
Gustavo Iñiguez Goia
a3422e493b audit: sort events after update the cache 2020-03-07 00:57:43 +01:00
Gustavo Iñiguez Goia
ba770fdf0d audit: insert new processes at the top of the list.
And avoid to sort the list of known processes every time we add a new
one.

Code formatted and documented.
2020-03-07 00:23:33 +01:00
Gustavo Iñiguez Goia
ef04667cdb cache of pids: insert new processes at the top of the list
code formatted and documented a little bit.
2020-03-06 23:23:16 +01:00
Gustavo Iñiguez Goia
1c04e95fdc audit: search for a process using the ppid
auditd events provides the parent pid of a process which has created
a connection. If we don't find the socket inode under the pid of the
process, use the ppid.

This is normally the case when systemd-* spawns a new process which
creates a new connection.
2020-03-06 23:21:24 +01:00
Gustavo Iñiguez Goia
9e6860fe63 formatted connman/ 2020-03-06 21:44:47 +01:00
Gustavo Iñiguez Goia
6e3336258c firewall/rules.go formatted and documented. 2020-03-06 21:28:22 +01:00
Gustavo Iñiguez Goia
7cbcc4d736 reformatted netlink/ sources, fixed typo 2020-03-06 21:02:34 +01:00
Gustavo Iñiguez Goia
63b6ba6f94 added description for netlink/GetSocketInfo 2020-03-06 20:32:19 +01:00
Gustavo Iñiguez Goia
2137a395d1 audit: Fixed 32bits socket monitoring. 2020-03-05 20:57:37 +01:00
Gustavo Iñiguez Goia
461118e321 replace ReplaceAll() by Replace() to compile with go <= 11 2020-03-05 19:39:35 +01:00
Gustavo Iñiguez Goia
010a657f64 audit: get rid of mozilla/libaudit-go
mozilla/libaudit-go does not support i386/arm/etc, and we were using it
only for parsing audit messages.

So do not use it and parse raw messages directly. WIP.
2020-03-05 01:54:27 +01:00
Gustavo Iñiguez Goia
db22e83de1 pids cache: delete from cache non existent PIDs 2020-03-04 01:56:48 +01:00
Gustavo Iñiguez Goia
7ef15faf62 cache of known pids: update lastSeen field when we have a match 2020-03-04 01:31:36 +01:00
Gustavo Iñiguez Goia
3d6beb5ec3 Added new processes monitor method: audit
Use auditd events to keep a list of PIDs which open sockets, reading
them from the audisp af_unix plugin.

- Install auditd and audisp-plugins
- Enable the af_unix plugin (/etc/audisp-plugin/af_unix, active = yes)
- Start opensnitch with -process-monitor-method audit.

If the choosen method is audit but it's not active or not installed,
it'll fallback to /proc anyway.

If it's properly configured, a debug trace will be written to the logs:
"PID found via audit events ..."
2020-03-03 23:51:25 +01:00
Gustavo Iñiguez Goia
6a82cdbac1 Allow to select which log level to use
Let the user choose which level log to use. For now it must be set
manually and when starting the daemon.
2020-02-28 10:24:08 +01:00
Gustavo Iñiguez Goia
c5a3fb5132 Allow to select what process search method to use
Until now OpenSnitch used ftrace(debugfs) to search for running
processes (PIDs) and obtain the process path.

On some systems, this filesystem is not mounted or available, so we have
to rely on /proc.

After several weeks of use, I think that it's faster and more accurate
the 2nd method, search pids/cmdlines in /proc. So we offer the user to
choose which one to use.
2020-02-26 19:13:42 +01:00
Gustavo Iñiguez Goia
fe8789526a Apply default action in case of communication failure with the server
If we can't communicate with the server (UI), apply the default
configured action. For example, if the UI is doing too much work and it
reaches the timeout, or if there's a programming error (python exception
for instance).
2020-02-26 09:53:48 +01:00
Gustavo Iñiguez Goia
de956b1bf4 Fixed DNS responses firewall rule not deleted on exit
Sometimes the INPUT rule for to queue DNS responses was not deleted.
The code has also been reorganized.

And a minor tweak to make an if{} more idiomatic.
2020-02-25 01:30:24 +01:00
Gustavo Iñiguez Goia
7cb0a25119 Bump version to v1.0.0rc5 2020-02-24 20:07:22 +01:00
Gustavo Iñiguez Goia
2c7472f06d firewall: check rules every 5s
Every 5s check if our rules are loaded, and if they aren't, add them
again.
2020-02-22 00:27:35 +01:00
Gustavo Iñiguez Goia
8b579ece28 procmon: split cache functionality to a new file 2020-02-20 09:58:19 +01:00
Gustavo Iñiguez Goia
848f72de68 Fixed netlink socket querying
man sock_diag:
"If the nlmsg_flags field of the struct nlmsghdr header has the
NLM_F_DUMP flag set, it means that a list of sockets is being
requested; otherwise it is a query about an individual socket."
2020-02-20 01:45:02 +01:00
Gustavo Iñiguez Goia
d46d50a58d Bump version to v1.0.0rc3 2020-02-18 10:49:30 +01:00
Gustavo Iñiguez Goia
a13f42d98b netlink: fixed connections querying
also code simplified.
2020-02-18 02:05:15 +01:00
Gustavo Iñiguez Goia
25c27511e1 Improved PIDs searching and sorting
Accuracy and reliability improved.
2020-02-17 23:39:26 +01:00
Gustavo Iñiguez Goia
be7ffbc54b Improved PIDs searching in /proc
Improved and reorganized code.
2020-02-17 01:17:28 +01:00
Gustavo Iñiguez Goia
6646ee469a Accept response from netlink just if inode is valid
Sometimes we get wrong values for Uid field, so just check if the inode
field is valid to accept the response from netlink.
2020-02-15 00:22:37 +01:00
Gustavo Iñiguez Goia
9207465d58 Do not panic if we can't parse a Regex type rule
If for some reason a Regex type rule can not be parsed, opensnitchd
panics and exit. We drop regex.MustCompile() in favor of
regex.Compile(), and in case of failure we just drop the packet.

In either case, the daemon should not panic but it should not received
an invalid rule either, specially from the UI.

Closes #4
2020-02-14 23:15:14 +01:00
Gustavo Iñiguez Goia
a4a5637a22 Fixed errors
Typos were made.
2020-02-13 23:19:15 +01:00
Gustavo Iñiguez Goia
1e2f9aa124 Find pid of a process in /proc if debugfs is unavailable
debugfs is not always available due to different reasons:
https://github.com/evilsocket/opensnitch/issues/214
https://github.com/evilsocket/opensnitch/issues/276

Fallback to /proc parsing, although procfs could also be not available.

Easily testable by unmounting debugfs (umount debugfs) and launch
opensnitchd. It should work as expected.
2020-02-13 23:08:58 +01:00
Gustavo Iñiguez Goia
d5b7c597ae Fixed typo in netlink parameter
Thanks to @Ph0rk0z for pointing it out.
2020-02-13 10:01:22 +01:00
Gustavo Iñiguez Goia
54bb5dcca5 Fixed and improved netlink communications
Fixed invalid uid.
Fixed/improved netlink sockets querying.
2020-02-12 22:52:24 +01:00
Gustavo Iñiguez Goia
a6ff8d2c4f Prioritize cache pids with active connections
Processes with active connections are the most likely to be the latest
modified ones in /proc, thus sort cache pids by time speeds up pids cache
searching. From several ms to us.
2020-02-12 22:20:26 +01:00
Gustavo Iñiguez Goia
489b64730a Sort process descriptors by modified time
When parsing /proc/<pid>/fd/ looking for sockets, latest
modified/created descriptors are the most likely to have
generated connections.

This way we decrease the parsing time, system load and speed up process name
retrieval.
2020-02-11 21:32:48 +01:00
Gustavo Iñiguez Goia
8782b77625 Allow to compile the daemon with outdated libnetfilter-queue
On Ubuntu 18.04 the libnetfilter-queue is not the latest one (1.0.3) and
it doesn't have UID/GID support.
2020-02-09 19:28:27 +01:00
Gustavo Iñiguez Goia
7d330f24d9 Bump version to 1.0.0-rc2 2020-02-05 00:57:06 +01:00
Gustavo Iñiguez Goia
a978f405fc Fixed missing returned value 2020-02-05 00:26:32 +01:00
Gustavo Iñiguez Goia
5d92cbb893 Load nfq_get_uid dynamically
nfq_get_uid symbol does not exist on some systems.
2019-12-05 01:48:21 +01:00
Gustavo Iñiguez Goia
3e6520edad Version changed to 1.0.0-rc1 2019-12-04 23:16:35 +01:00
Gustavo Iñiguez Goia
996e9ad888 Added netlink IPv6 uid/inode lookup support 2019-12-02 23:53:41 +01:00
Gustavo Iñiguez Goia
d8ad8de6ef Lookup inode and uid via netlink
It has some advantages over parsing /proc, like performance and
reliability.
2019-12-01 20:10:49 +01:00
Gustavo Iñiguez Goia
4a30cc5b84 Reduced the pid cache sizes
It's somewhat arbitrary. It'll depend on each use case.
2019-12-01 20:05:20 +01:00
Gustavo Iñiguez Goia
cc27be2bae Added initial support for advanced rules (lists)
Probably not the best UI, just the one I came up with.
2019-11-20 10:27:28 +01:00
Gustavo Iñiguez Goia
912f85f5d1 Added more timeout options (30s, 5m, 15m, 30m, 1h)
Added 30s, 5m, 15m, 30m and 1h timeout options to deny or allow
connections.

It helps to avoid repetitive new connection dialogs, while at the same
time it allows you to deny/allow a connection for a short period of time,
and apply the default for the rest.
2019-11-09 01:35:13 +01:00
Gustavo Iñiguez Goia
93592b6b00 Allow to see which domain a process is trying to resolve
Ideally this information should go in a different Connection field, but
for now lets use DstHost.
2019-11-08 01:38:26 +01:00