{"id":339,"date":"2015-02-22T19:13:19","date_gmt":"2015-02-22T19:13:19","guid":{"rendered":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=339"},"modified":"2017-11-25T18:11:23","modified_gmt":"2017-11-25T18:11:23","slug":"the-metaevent-module","status":"publish","type":"page","link":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=339","title":{"rendered":"The metaevent module"},"content":{"rendered":"<p>Events are records, composed of fields, that the various input and dissection modules provide to the Orchids detection engine. Those are ordinary, regular events.<\/p>\n<p>Orchids also allows you to create new events during the execution of a rule. Those events are called\u00a0<em>synthetic<\/em> events, or\u00a0<em>metaevents<\/em>. \u00a0It is the purpose of the <code>metaevent<\/code> module to provide primitives to post such synthetic events.<\/p>\n<p>Posting synthetic events is useful to make detection hierarchical. For an example, \u00a0imagine that attempting to unduly connect to some machine <code>$host<\/code> \u00a0is detected by a rule <code>connect_attempt.rule<\/code>, \u00a0and that you would like to detect when the same intruder tries to connect to two machines. \u00a0One possibility is to write <code>connect_attempt.rule<\/code> as a rule that, instead of reporting, would post a synthetic event containing the offending intruder identity and the <code>$host<\/code> it tried to connect to. \u00a0That can be done by writing:<\/p>\n<pre>inject_event (.{.meta.host = $host, .meta.intruder = $attacker});<\/pre>\n<p>in the\u00a0<code>connect_attempt.rule<\/code>\u00a0rule, posting the synthetic event given as argument to <code>inject_event<\/code>. \u00a0(Any list of records enclosed between <code>.{<\/code> and <code>}<\/code> is a synthetic event, see &#8220;synthetic event&#8221; in the <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=283\">expressions<\/a> page. \u00a0The <code>meta<\/code> module does not exist: this is a so-called <em>virtual<\/em> module, see below. Also the list of fields was kept minimal for the illustration.)<\/p>\n<p>Then a second rule that tries to detect two connection attempts by the same intruder might include code such as:<\/p>\n<pre>state first_connection {\r\n  expect (defined(.meta.host)) goto second_connection;\r\n}\r\nstate second_connection {\r\n  $host1 = .meta.host;\r\n  $attacker = .meta.intruder; \/\/ record data from first connection\r\n  expect (.meta.intruder==$attacker)\r\n    \/\/ wait for another meta event with the same $attacker\r\n    \/\/ (no need to check defined(.meta.host) here)\r\n    goto alert;\r\n}\r\nstate alert! {\r\n  $host2 = .meta.host;\r\n  report();\r\n}<\/pre>\n<h3>Virtual modules<\/h3>\n<p>So what is <code>meta<\/code> in that example?<\/p>\n<p>Just like the <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=628\"><code>generic<\/code><\/a> module, the <code>metaevent<\/code> module is a <em>meta<\/em>-module, one that allows you to define new, so-called <em>virtual<\/em> modules. \u00a0Any event field in Orchids is of the form <code>.<\/code><em>module-name<\/em><code>.<\/code><em>field-name<\/em>, so you cannot just write any random event field: either you use fields from some existing modules (which is not what we want to do here), or you create some fresh, specifically designed, virtual modules.<\/p>\n<p>Such virtual modules are declared inside the configuration options for the <code>metaevent<\/code> module. \u00a0Contrarily to\u00a0the <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=628\"><code>generic<\/code><\/a> module, we do not specify regular expressions here, just lists of fields with their types.<\/p>\n<h3>Configuration options<\/h3>\n<p><code>&lt;module metaevent&gt;<\/code><\/p>\n<p>contains a list of declarations of <em>virtual modules<\/em>.\u00a0 Virtual modules work exactly like actual modules, except you do not need to load any shared library at start-up time to start them. \u00a0You start each virtual module by a declaration of the form:<\/p>\n<p><code>&lt;vmod<\/code> <em>module-name<\/em><code>&gt;<\/code><\/p>\n<p>Inside such a declaration, you can declare fields with their names and types:<\/p>\n<ul>\n<li><code>str_field<\/code> <em>field-name description<\/em>: a field of type <code>str<\/code> (string)<\/li>\n<li><code>bstr_field<\/code> <em>field-name description<\/em>: a field of type <code>bstr<\/code> (binary string)<\/li>\n<li><code>int_field<\/code> <em>field-name description<\/em>: a field of type <code>int<\/code><\/li>\n<li><code>uint_field<\/code> <em>field-name description<\/em>: a field of type <code>uint<\/code> (unsigned int)<\/li>\n<li><code>float_field<\/code> <em>field-name description<\/em>: a field of type <code>float<\/code> (floating-point number)<\/li>\n<li><code>ipv4_field<\/code> <em>field-name description<\/em>: a field of type <code>ipv4<\/code> (IPv4 address)<\/li>\n<li><code>ipv6_field<\/code> <em>field-name description<\/em>: a field of type <code>ipv4<\/code> (IPv6 address)<\/li>\n<li><code>ctime_field<\/code> <em>field-name description<\/em>: a field of type <code>ctime<\/code> (Unix date)<\/li>\n<li><code>timeval_field<\/code> <em>field-name description<\/em>: a field of type <code>timeval<\/code> (duration)<\/li>\n<li><code>snmpoid_field<\/code>\u00a0<em>field-name description<\/em>: a field of type <code>snmpoid<\/code> (SNMP object identifier)<\/li>\n<\/ul>\n<p>Example:<\/p>\n<pre>&lt;vmod meta&gt;\r\n  str_field host \"The current host\"\r\n  str_field action \"A text description of the action done\"\r\n  ipv4_field intruder \"The attacker's IP address\"\r\n  ctime_field time \"The detection time\"\r\n&lt;\/vmod&gt;<\/pre>\n<p>Note that you are not forced to use\u00a0<em>all<\/em> the fields declared in a given virtual module. \u00a0It is perfectly fair to build events with only some of the fields, just as we did with the <code>meta<\/code> virtual module.<\/p>\n<p><code>&lt;\/vmod&gt;<\/code><\/p>\n<p><code>&lt;\/module&gt;<\/code><\/p>\n<h3>Primitives<\/h3>\n<ul>\n<li><strong><code>inject_event<\/code><\/strong> : <code>event<\/code> \u2192 <code>int<\/code><br \/>\ninject the given event into the Orchids event queue; the event can be a synthetic event, or one obtained by <code>current_event<\/code>, possibly enriched: see synthetic events on the <a title=\"Expressions\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=283\">expressions<\/a> page<\/p>\n<ul>\n<li>returns: 1 (true)<\/li>\n<\/ul>\n<\/li>\n<li><strong><code>current_event<\/code><\/strong> : \u2192 <code>event<\/code><br \/>\nthe current event<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Events are records, composed of fields, that the various input and dissection modules provide to the Orchids detection engine. Those are ordinary, regular events. Orchids also allows you to create new events during the execution of a rule. Those events are called\u00a0synthetic events, or\u00a0metaevents. \u00a0It is the purpose of the metaevent module to provide primitives &hellip; <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=339\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">The metaevent module<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-339","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=339"}],"version-history":[{"count":8,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/339\/revisions"}],"predecessor-version":[{"id":681,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/339\/revisions\/681"}],"wp:attachment":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}