macOS apps last_opened_time reports all versions/installed paths as having been opened when only one has

Abierto
#8,677 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
42/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
cpp, macos

Línea de trabajo

Comienza rastreando la implementación de la tabla de apps de macOS y su consulta de Spotlight para kMDItemLastUsedDate. Reproduce el problema con dos rutas de bundle y compara sus valores de last_opened_time antes y después de abrir una app. Se considera terminado cuando solo la ruta del bundle abierto recibe una marca de tiempo, mientras que la otra permanece en -1.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug macOS triage virtual tables

Bug report

What operating system and version are you using?
+---------+-------+----------+
| version | build | platform |
+---------+-------+----------+
| 15.6    | 24G84 | darwin   |
+---------+-------+----------+
What version of osquery are you using?
+---------+
| version |
+---------+
| 5.18.1  |
+---------+
What steps did you take to reproduce the issue?
  1. Install two different versions of an app in two different paths on the host. For example, I installed:
    Firefox.app version 142.0 to /Applications/Firefox.app
    Firefox.app version 129.0 to /Users/admin/Desktop/Firefox.app
  2. Run SELECT * FROM apps WHERE bundle_identifier='org.mozilla.firefox' and see that both apps are returned as distinct results with different versions and different paths. Both have last_opened_time set to -1 since neither has been opened yet.
  3. Open ONLY ONE of the installed apps on the host. Then close the app. Do not open the other app.
  4. Run SELECT * FROM apps WHERE bundle_identifier='org.mozilla.firefox'
What did you expect to see?

I expected to see the last_opened_time to show a new value for the app that I opened, but not the other, as only one of the app versions at one of the paths was opened.

What did you see instead?

Both apps have been updated with a last_opened_at timestamp. They are not the exact same timestamp, they differ slightly.

Output of commands before and after opening only the app located in /Users/admin/Desktop/Firefox.app

osquery> SELECT * from apps where bundle_identifier='org.mozilla.firefox';
+-------------+----------------------------------+-------------------+---------------------+-------------+----------------------+----------------+---------------------+-------------+---------+----------+--------------------+--------------+---------------+------------------------+----------------------------------+---------------------+-----------+------------------+
| name        | path                             | bundle_executable | bundle_identifier   | bundle_name | bundle_short_version | bundle_version | bundle_package_type | environment | element | compiler | development_region | display_name | info_string   | minimum_system_version | category                         | applescript_enabled | copyright | last_opened_time |
+-------------+----------------------------------+-------------------+---------------------+-------------+----------------------+----------------+---------------------+-------------+---------+----------+--------------------+--------------+---------------+------------------------+----------------------------------+---------------------+-----------+------------------+
| Firefox.app | /Applications/Firefox.app        | firefox           | org.mozilla.firefox | Firefox     | 142.0                | 14225.8.11     | APPL                |             |         |          | English            |              | Firefox 142.0 | 10.15.0                | public.app-category.productivity | 1                   |           | -1.0             |
| Firefox.app | /Users/admin/Desktop/Firefox.app | firefox           | org.mozilla.firefox | Firefox     | 129.0                | 12924.8.1      | APPL                |             |         |          | English            |              | Firefox 129.0 | 10.15.0                | public.app-category.productivity | 1                   |           | -1.0             |
+-------------+----------------------------------+-------------------+---------------------+-------------+----------------------+----------------+---------------------+-------------+---------+----------+--------------------+--------------+---------------+------------------------+----------------------------------+---------------------+-----------+------------------+
osquery> SELECT * from apps where bundle_identifier='org.mozilla.firefox';
+-------------+----------------------------------+-------------------+---------------------+-------------+----------------------+----------------+---------------------+-------------+---------+----------+--------------------+--------------+---------------+------------------------+----------------------------------+---------------------+-----------+------------------+
| name        | path                             | bundle_executable | bundle_identifier   | bundle_name | bundle_short_version | bundle_version | bundle_package_type | environment | element | compiler | development_region | display_name | info_string   | minimum_system_version | category                         | applescript_enabled | copyright | last_opened_time |
+-------------+----------------------------------+-------------------+---------------------+-------------+----------------------+----------------+---------------------+-------------+---------+----------+--------------------+--------------+---------------+------------------------+----------------------------------+---------------------+-----------+------------------+
| Firefox.app | /Applications/Firefox.app        | firefox           | org.mozilla.firefox | Firefox     | 142.0                | 14225.8.11     | APPL                |             |         |          | English            |              | Firefox 142.0 | 10.15.0                | public.app-category.productivity | 1                   |           | 1756230542.73983 |
| Firefox.app | /Users/admin/Desktop/Firefox.app | firefox           | org.mozilla.firefox | Firefox     | 129.0                | 12924.8.1      | APPL                |             |         |          | English            |              | Firefox 129.0 | 10.15.0                | public.app-category.productivity | 1                   |           | 1756230539.79383 |
+-------------+----------------------------------+-------------------+---------------------+-------------+----------------------+----------------+---------------------+-------------+---------+----------+--------------------+--------------+---------------+------------------------+----------------------------------+---------------------+-----------+------------------+

Per https://github.com/osquery/osquery/issues/4470 it sounds like osquery is using spotlight to gather this information. It also states

this metadata item is only valid for this specific application bundle. If the application is replaced/updated, Spotlight considers it a "new" app (which it technically is), for which the kMDItemLastUsedDate is no longer defined.

which is particularly problematic when incorporating osquery into other applications (Such as Fleet) because:

  1. Any time an app is updated, the last_opened_time is cleared out, which signals the app has never been opened. If an admin is looking to revoke unused software and sees that an app has never been opened, when in fact, only the most recently updated version has not yet been opened, they may erroneously assume they can revoke that software without adverse effect.
  2. If software with the same application bundle exists across multiple versions/install paths for an application, it becomes impossible to differentiate between which version of the software is currently being used because all versions/paths are updated with a last_opened_time even when they weren't opened. This results in the misconception that older, potentially vulnerable versions of an application are being used/opened, even if they are not.
Lenguaje dominante
C++
Estrellas
23.8k
Forks
2.7k
Merge medio
6 d 11 h
PR fusionados (30 d)
69

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de osquery/osquery

Todos los issues de osquery/osquery

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.