
----

====== Référence QQL — Asset Inventory Tag Rule Engine ======

<WRAP round info>
**Source officielle :** https://docs.qualys.com/en/gav/latest/search_tips/tag_rules.htm\\
**Contexte :** ce qu'il faut pour écrire des règles Tag Rules (tags dynamiques) dans la console Qualys AssetView / GAV — tous les champs, syntaxe, pièges.
</WRAP>

===== 1. Filtrer "asset avec Cloud Agent" =====

Champ natif propre :

<code>asset.trackingMethod: QAGENT</code>

Valeurs possibles pour ''trackingMethod'' :
  * **QAGENT** : Cloud Agent
  * IP, DNSNAME, NETBIOS
  * INSTANCE_ID, OCA, VIRTUAL_MACHINE_ID, SEM, GCP_INSTANCE_ID

Alternative aussi valide :

<code>inventory:(source:`Cloud Agent`)</code>

===== 2. Chaîner des tags (tags.name) =====

''tags.name'' **est supporté** dans les règles Asset Inventory (même si pas dans l'autocomplete UI). Exemple officiel Qualys :

<code>tags.name: `Cloud Agent` AND software:(name: `Cisco AnyConnect Secure Mobility Client`)</code>

===== 3. Requête OS-LIN-SRV — 3 options valides =====

^ # ^ Requête ^ Reco ^
| 1 | ''operatingSystem.category1:Linux and operatingSystem.category2:Server and asset.trackingMethod:QAGENT'' | **À privilégier** — bas niveau, stable, indépendant de tout tag |
| 2 | ''operatingSystem.category1:Linux and operatingSystem.category2:Server and inventory:(source:`Cloud Agent`)'' | OK |
| 3 | ''operatingSystem.category1:Linux and operatingSystem.category2:Server and tags.name:`Cloud Agent`'' | OK mais chaîne sur un autre tag |

===== 4. Syntaxe et opérateurs =====

^ Élément ^ Règle ^
| Backticks '' ` ` '' | Match exact |
| Guillemets '' " " '' | Match partiel (substring) |
| Sans quote | Match exact sur un mot simple |
| AND / OR / NOT | Booleans (MAJUSCULES obligatoires) |
| Wildcards | ''*dev*'' (contient), ''dev*'' (commence), ''*dev'' (finit) |
| Range | ''[val1 ... val2]'' entre crochets, exact only |
| Null | ''fieldname is null'' |
| Date | yyyy-mm-dd, UTC |

<WRAP round important>
Comparaisons ''<'', ''>'', ''>='', ''<='' : **uniquement** sur ''asset.riskScore''. Pour les versions de softs → ranges ''[16.0 ... 20.0]''.
</WRAP>

===== 5. Hiérarchie Operating System =====

^ Champ ^ Valeurs / Usage ^
| ''operatingSystem'' | Nom complet (ex: ''Red Hat Enterprise Linux 9.7'') |
| ''operatingSystem.category'' | Windows, Unix, Linux, Mac, Embedded (racine) |
| ''operatingSystem.category1'' | Primary (Windows, Linux…) |
| ''operatingSystem.category2'' | Server, Client, Embedded… |
| ''operatingSystem.publisher'' | Microsoft, Red Hat, Canonical… |
| ''operatingSystem.name'' | Windows 10, RHEL… |
| ''operatingSystem.architecture'' | 32-Bit, 64-Bit |
| ''operatingSystem.edition'' | Enterprise, Professional… |
| ''operatingSystem.update'' | SP2… |
| ''operatingSystem.version'' / ''marketVersion'' | Version numérique |

<WRAP round tip>
La forme ''operatingSystem.category:"Linux / Server"'' marche par tolérance Qualys, mais la doc préconise ''category1'' + ''category2'' **séparés** pour une syntaxe propre.
</WRAP>

===== 6. Tokens utiles pour la taxonomie V3 =====

  * **Software installé** : ''software:(name:"Cloud Agent")'', ''software:(category:...)''
  * **Service tournant** : ''compute.service:(name:...) and compute.service:(status:RUNNING)''
  * **Domain role AD** : ''compute.domainRole'' — valeurs possibles :
    * Standalone Workstation
    * Member Workstation
    * Standalone Server
    * Member Server
    * Backup Domain Controller
    * Primary Domain Controller
  * **Ports ouverts** : ''asset.openPorts:(port:22)'' — utile pour tagguer "a SSH" ou "a RDP"
  * **RiskScore** : ''asset.riskScore:>800'' — pour un tag High Risk
  * **Hardware** : ''hardware.category1:Computer'', ''hardware.manufacturer:Dell''
  * **Interface** : ''asset.interface:(hostname:...)'', ''asset.interface:(address:...)''
  * **BIOS** : ''asset.biosDescription:"..."''

===== 7. Points clés à retenir =====

  - ''tags.name'' **fonctionne** dans les règles Asset Inventory, même si pas dans l'autocomplete UI
  - ''asset.trackingMethod:QAGENT'' est LE champ natif pour "a un agent" — à privilégier
  - Les Rule Engines autres qu'Asset Inventory (Asset Search legacy, Groovy, Regex OS, IP Range) existent mais ne sont **pas** couverts par cette doc QQL — ils ont leur propre syntaxe
  - OS category propre = ''category1'' + ''category2'' séparés, pas la concat ''"Linux / Server"''
  - Les comparaisons numériques (''<'', ''>'') ne marchent que sur ''asset.riskScore''

===== 8. Plan OS taxonomie (propositions QQL propres) =====

^ Tag ^ Règle QQL ^
| **OS-LIN-SRV** | ''operatingSystem.category1:Linux and operatingSystem.category2:Server and asset.trackingMethod:QAGENT'' |
| **OS-WIN-SRV** | ''operatingSystem.category1:Windows and operatingSystem.category2:Server and asset.trackingMethod:QAGENT'' |
| **OS-WIN-WKS** | ''operatingSystem.category1:Windows and operatingSystem.category2:Client and asset.trackingMethod:QAGENT'' |
| **OS-WIN-DC** | ''operatingSystem.category1:Windows and (compute.domainRole:"Primary Domain Controller" OR compute.domainRole:"Backup Domain Controller")'' |
| **OS-MAC** | ''operatingSystem.category1:Mac and asset.trackingMethod:QAGENT'' |

===== 9. Rule Engines disponibles (rappel) =====

Dans la console Tag Creation (vu UI SANEF) :
  * **Asset Inventory** ← QQL moderne, tout ce qui est décrit ci-dessus
  * Asset Name Contains
  * IP Address In Range(s) / IP Address In Range(s) + Network(s)
  * Network Addresses
  * Open Ports
  * Cloud Asset Search
  * Vuln(QID) Exist
  * Groovy Scriptlet
  * **Asset Search** ← legacy XML, **à éviter**, renvoie l'erreur ''Unexpected character 'o' in prolog''
  * Vulnerability Detection Searches
  * Container Security

<WRAP round important>
Pour toute règle basée OS / agent / software / service, **toujours prendre Asset Inventory**. Les autres moteurs sont pour des cas spécifiques (scan IP, vulns, containers).
</WRAP>

----

//— Source : Qualys GAV docs ''/gav/latest/search_tips/tag_rules.htm'' — synthèse consolidée 2026-04-22 //
