Commit graph

25 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
ebac200642
ReadEnv() minor improvement
- Improved peformance parsing the environment variables of a process.
 - Added ReadEnv() test.

For a 4kb environ file:

Benchmark-Old    58070 ns/op   19264 B/op   68 allocs/op
Benchmark-New    49174 ns/op   17488 B/op   12 allocs/op
2024-10-18 01:08:43 +02:00
Gustavo Iñiguez Goia
f63a48deff
calculate the ram usage of a process in the daemon
- Calculate the ram usage of a process in the daemon, using the page
   size of the system.
 - Added new functions to read some details of a process, so we can use
   them in other parts of the code.
2024-10-15 00:49:58 +02:00
Gustavo Iñiguez Goia
01edd361fe
process tree improvements
- When discovering the hierarchy of a process, reuse components of
   the tree if they're already on cache, to improve speed and reduce
   mem allocs.
 - When building the tree of a proces, rebuild the tree if the first
   component doesn't have pid 1. Otherwise reuse the tree.
2024-01-18 13:35:29 +01:00
Gustavo Iñiguez Goia
96e62bf973
strings concatenation improvements
Use strings.Join() to concatenate strings, instead of Sprint*(), for
better performance.
2024-01-16 00:14:44 +01:00
Gustavo Iñiguez Goia
b2bd56d7e2
updated TestProcIOStats test
On this test we assumed that there would always be reading stats for our
own process /proc/self, but on restricted environments that might not
alwys be the case. Anyway, a value of 0 is not an error in itself.

Closes #1075
2024-01-05 15:31:00 +01:00
Gustavo Iñiguez Goia
290ed40e8d
procmon: fixed leak reading proc's environ vars 2023-12-17 23:29:27 +01:00
Gustavo Iñiguez Goia
431e2d3ed9
procmon/cache improvements
- Fixed several leaks.
 - Cache of events reorganized and improved.
   * items are added faster.
   * proc details are rebuilt if needed (checksums, proc tree, etc)
   * proc's tree is reused if we've got the parent in cache.

rel: #413
2023-12-12 14:48:17 +01:00
Gustavo Iñiguez Goia
17c8ec8484
fixed leak getting proc parents 2023-12-06 00:12:41 +01:00
Gustavo Iñiguez Goia
fb2c9893d0
replace /proc/self from bin paths
Sometimes we receive /proc/self/exe as the path of the process (electron
apps).
Since a couple of systemd versions ago, some processes spawned by
systemd are reported as /proc/self/fd/<number>.

In these cases reading the symbolic link /proc/<pid>/exe points to the
file on disk.
2023-12-03 01:13:55 +01:00
Gustavo Iñiguez Goia
19d376abf0
getparents code reorganization
Deoptimizing GetParents() until we figure out how to do it without
leaking mem.
2023-10-04 00:58:17 +02:00
Gustavo Iñiguez Goia
7f493e84a7
improved getting process's parents 2023-10-02 14:25:10 +02:00
Gustavo Iñiguez Goia
0556dc1c81
obtain process's parent hierarchy, checksums improvements
- Obtain the process's parent hierarchy.
 - Display the hierarchy on the pop-ups and the process dialog.
 - [pop-ups] Added a Detailed view with all the metadata of the
   process.
 - [cache-events] Improved the cache of processes.
 - [ruleseditor] Fixed enabling md5 checksum widget.

Related: #413, #406
2023-09-30 18:31:19 +02:00
Gustavo Iñiguez Goia
7a9bb17829
allow to filter connections by process checksum
Now you can create rules to filter processes by checksum. Only md5 is
available at the moment.

There's a global configuration option that you can use to enable or
disable this feature, from the config file or from the Preferences
dialog.

As part of this feature there have been more changes:

   - New proc monitor method (PROCESS CONNECTOR) that listens for
     exec/exit events from the kernel.
     This feature depends on CONFIG_PROC_EVENTS kernel option.

   - Only one cache of active processes for ebpf and proc monitor
     methods.

More info and details: #413.
2023-09-22 00:36:26 +02:00
Gustavo Iñiguez Goia
7cbfca6b1f
ebpf: increased ring buffer size, hook execveat
Increased perf map buffer size to avoid lose events under heavy loads.

Hook execveat to intercept executions from memory.
2022-10-13 01:44:23 +02:00
Gustavo Iñiguez Goia
8f70af47e2
resolve absolute path of a process if it's relative
We may receive relative paths from kernel (eBPF), so we need to resolve
the absolute path of the process in order to create valid rules.
2022-10-01 22:27:07 +02:00
Gustavo Iñiguez Goia
fc3d7382de ebpf: get cmdline arguments from kernel
- Get cmdline arguments from kernel along with the absolute path to the
  binary.
  If the cmdline has more than 20 arguments, or one of the arguments is
  longer than 256 bytes, get it from ProcFS.
- Improved stopping ebpf monitor method.
2022-07-12 15:40:01 +02:00
Gustavo Iñiguez Goia
7557faf3a6 prevent crash resolving /proc/self/exe 2022-07-09 22:17:17 +02:00
Gustavo Iñiguez Goia
45212db908 clean path of a process if it's needed
Sometimes the path of a path has " (deleted)" added or the path is
reported as "/proc/self/exe" which is a link and needs to be resolved.

 -> #694
2022-07-08 21:59:11 +02:00
Gustavo Iñiguez Goia
72483bdcde improved process detection
latest changes to detect short-lived processes caused undesired
behaviour (#694)

Closes #685
2022-07-08 17:15:57 +02:00
Gustavo Iñiguez Goia
4ce8b0e57c ebpf: improved process detection/new events module
Improved process detections by monitoring new processes execution.
It allow us to know the path of a process before a socket is opened.

Closes #617

Other improvements:
 - If we fail to retrieve the path of a process, then we'll use the comm
   name of the connection/process.
 - Better kernel connections detection.
 - If debugfs is not loaded, we'll try to mount it, to allow to use
   eBPF monitor method.

Future work (help wanted):
 - Extract command line arguments from the kernel (sys_execve, or mm
   struct).
 - Monitor other functions (execveat, clone*, fork, etc).
 - Send these events to the server (GUI), and display all the commands
   an application has executed.
2022-06-24 01:09:45 +02:00
Gustavo Iñiguez Goia
0526b84309
Allow to intercept more kernel connections (#513)
* Allow to intercept some kernel connections

Some connections are initiated from kernel space, like WireGuard
VPNs (#454), NFS or SMB connections (#502) and ip tunnels (#500).

Note: This feature is complete for x86_64, WIP for aarch64, and not supported for armhf and i386
https://github.com/evilsocket/opensnitch/pull/513#issuecomment-924400824

More information regarding this change: #493
2021-09-23 01:44:12 +02:00
Gustavo Iñiguez Goia
9b035ca66e added unit tests for process parsing and rules 2020-12-19 19:31:09 +01:00
Gustavo Iñiguez Goia
e13015ce67 updated import paths 2020-12-09 18:18:42 +01:00
Gustavo Iñiguez Goia
c1e8bc3156 netlink: de/serialize ipv6, dump socket list
- De/Serialize IPv6 connections.
- Added SocketsDump() to list all sockets currently in the kernel.
- [proc details] Resolve all the sockets an application has opened
  and translate them to network data, e.g:
  ```
  ls -l /proc/1234/fd/
    0  ... 25 -> socket[12345678]
  ```
  to
  ```
    0 .... 25 -> socket[12345678] - 54321:10.0.2.2 -> github.com:443,
  state: established
  ```
2020-11-20 00:53:29 +01:00
Gustavo Iñiguez Goia
c8d1161061 added dialog to inspect details of a process in realtime (procfs)
New dialog added to display details of a process in realtime, gathered
from ProcFS.
Process tab -> double click on an app -> click on the button with the
search icon.

We have also improved the discovery of apps icons and names. It should
work better on systems where the DE is not properly configured.

Tested, but not bulletproof, still in beta.
2020-11-16 17:09:52 +01:00