Commit graph

37 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
f7114d95c4 delete inodes cache when a process exits 2020-04-03 00:42:46 +02:00
Gustavo Iñiguez Goia
0c6836539e audit: code reformatted, ALL_CAPS to mixedCaps
Also do not filter sockets by code, nor by pid/ppid (for now at least).
2020-03-10 10:16:32 +01:00
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
0fb23bb588 audit: avoid to alloc unused map, reformatted code 2020-03-08 01:09:47 +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
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
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
8b579ece28 procmon: split cache functionality to a new file 2020-02-20 09:58:19 +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
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
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
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
7eec749498 allow to configure unknown conns interception
/etc/opensnitchd/default-config.json can now contain
"intercept_unknown": true|false
2019-11-01 01:00:10 +01:00
Gustavo Iñiguez Goia
65c3790106 Prompt the user to allow/deny all outgoing connections
With the current implementation, it's not possible to know what
process/pid has created an outgoing connection, but there's still
valuable information that the user may want to know, so:

- display outgoing connections even if the process name/path is unknown.
 (src ip, dst ip, dst port, uid)
- get outgoing connection uid if kernel > 3.6.
2019-10-25 00:55:32 +02:00
Gustavo Iñiguez Goia
9cc3da6446 experimental cache of inodes and pids
Just an experimental cache of inodes and pids, which lowers the CPU
usage and improves user's experience.
2019-10-24 01:01:20 +02:00
Gustavo Iñiguez Goia
dea50635d5 Merge branch 'fix_process_finding' into main 2019-10-21 19:48:17 +02:00
Gustavo Iñiguez Goia
59a11a530c Workaroung process name lookup 2019-10-21 19:45:35 +02:00
Gustavo Iñiguez Goia
a7e9b5072f project import paths changed 2019-10-20 21:51:35 +02:00
Northern-Lights
f4162b9384
Update probed function sys_execve to do_execve 2018-08-12 13:02:33 -07:00
evilsocket
6962c19de2
fix: calling ftrace probe Reset in order to start from a clean state (fixes #159) 2018-04-18 02:00:12 +02:00
evilsocket
461e6b678e
using ftrace in order to track pids in realtime 2018-04-17 18:08:03 +02:00
evilsocket
96cc94180e
misc: small fix or general refactoring i did not bother commenting 2018-04-16 19:28:28 +02:00
evilsocket
d4cca89329
optimization 2018-04-16 19:12:46 +02:00
evilsocket
55e7ad9702
misc: small fix or general refactoring i did not bother commenting 2018-04-15 15:40:40 +02:00
evilsocket
b014a4069e
misc: small fix or general refactoring i did not bother commenting 2018-04-15 15:39:43 +02:00
evilsocket
534ec8cd73
misc: small fix or general refactoring i did not bother commenting 2018-04-02 05:25:32 +02:00