functions.asciidoc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. [[eql-function-ref]]
  2. == EQL function reference
  3. ++++
  4. <titleabbrev>Function reference</titleabbrev>
  5. ++++
  6. experimental::[]
  7. {es} supports the following EQL functions:
  8. * <<eql-fn-between>>
  9. * <<eql-fn-cidrmatch>>
  10. * <<eql-fn-endswith>>
  11. * <<eql-fn-indexof>>
  12. * <<eql-fn-length>>
  13. * <<eql-fn-startswith>>
  14. * <<eql-fn-string>>
  15. * <<eql-fn-stringcontains>>
  16. * <<eql-fn-substring>>
  17. * <<eql-fn-wildcard>>
  18. [discrete]
  19. [[eql-fn-between]]
  20. === `between`
  21. Extracts a substring that's between a provided `left` and `right` text in a
  22. source string.
  23. [%collapsible]
  24. ====
  25. *Example*
  26. [source,eql]
  27. ----
  28. // file.path = "C:\\Windows\\System32\\cmd.exe"
  29. between(file.path, "system32\\\\", ".exe") // returns "cmd"
  30. between(file.path, "workspace\\\\", ".exe") // returns ""
  31. // Greedy matching defaults to false.
  32. between(file.path, "\\\\", "\\\\", false) // returns "Windows"
  33. // Sets greedy matching to true
  34. between(file.path, "\\\\", "\\\\", true) // returns "Windows\\System32"
  35. // Case sensitivity defaults to false.
  36. between(file.path, "system32\\\\", ".exe", false, false) // returns "cmd"
  37. // Sets case sensitivity to true
  38. between(file.path, "system32\\\\", ".exe", false, true) // returns ""
  39. between(file.path, "System32\\\\", ".exe", false, true) // returns "cmd"
  40. // empty source string
  41. between("", "system32\\\\", ".exe") // returns ""
  42. between("", "", "") // returns ""
  43. // null handling
  44. between(null, "system32\\\\", ".exe") // returns null
  45. ----
  46. *Syntax*
  47. [source,txt]
  48. ----
  49. between(<source>, <left>, <right>[, <greedy_matching>, <case_sensitive>])
  50. ----
  51. *Parameters*
  52. `<source>`::
  53. +
  54. --
  55. (Required, string or `null`)
  56. Source string. Empty strings return an empty string (`""`), regardless of the
  57. `<left>` or `<right>` parameters. If `null`, the function returns `null`.
  58. If using a field as the argument, this parameter supports only the following
  59. field datatypes:
  60. * <<keyword,`keyword`>>
  61. * <<constant-keyword,`constant_keyword`>>
  62. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  63. <<constant-keyword,`constant_keyword`>> sub-field
  64. Fields containing <<array,array values>> use the first array item only.
  65. --
  66. `<left>`::
  67. +
  68. --
  69. (Required, string)
  70. Text to the left of the substring to extract. This text should include
  71. whitespace.
  72. If using a field as the argument, this parameter supports only the following
  73. field datatypes:
  74. * <<keyword,`keyword`>>
  75. * <<constant-keyword,`constant_keyword`>>
  76. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  77. <<constant-keyword,`constant_keyword`>> sub-field
  78. <<array,Array values>> are not supported.
  79. --
  80. `<right>`::
  81. +
  82. --
  83. (Required, string)
  84. Text to the right of the substring to extract. This text should include
  85. whitespace.
  86. If using a field as the argument, this parameter supports only the following
  87. field datatypes:
  88. * <<keyword,`keyword`>>
  89. * <<constant-keyword,`constant_keyword`>>
  90. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  91. <<constant-keyword,`constant_keyword`>> sub-field
  92. <<array,Array values>> are not supported.
  93. --
  94. `<greedy_matching>`::
  95. (Optional, boolean)
  96. If `true`, match the longest possible substring, similar to `.*` in regular
  97. expressions. If `false`, match the shortest possible substring, similar to `.*?`
  98. in regular expressions. Defaults to `false`.
  99. `<case_sensitive>`::
  100. (Optional, boolean)
  101. If `true`, matching is case-sensitive. Defaults to `false`.
  102. *Returns:* string or `null`
  103. ====
  104. [discrete]
  105. [[eql-fn-cidrmatch]]
  106. === `cidrMatch`
  107. Returns `true` if an IP address is contained in one or more provided
  108. https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing[CIDR] blocks.
  109. [%collapsible]
  110. ====
  111. *Example*
  112. [source,eql]
  113. ----
  114. // source.address = "192.168.152.12"
  115. cidrMatch(source.address, "192.168.0.0/16") // returns true
  116. cidrMatch(source.address, "192.168.0.0/16", "10.0.0.0/8") // returns true
  117. cidrMatch(source.address, "10.0.0.0/8") // returns false
  118. cidrMatch(source.address, "10.0.0.0/8", "10.128.0.0/9") // returns false
  119. // null handling
  120. cidrMatch(null, "10.0.0.0/8") // returns null
  121. cidrMatch(source.address, null) // returns null
  122. ----
  123. *Syntax*
  124. [source,txt]
  125. ----
  126. `cidrMatch(<ip_address>, <cidr_block>[, ...])`
  127. ----
  128. *Parameters*
  129. `<ip_address>`::
  130. (Required, string or `null`)
  131. IP address. Supports
  132. https://en.wikipedia.org/wiki/IPv4[IPv4] and
  133. https://en.wikipedia.org/wiki/IPv6[IPv6] addresses. If `null`, the function
  134. returns `null`.
  135. +
  136. If using a field as the argument, this parameter supports only the <<ip,`ip`>>
  137. field datatype.
  138. `<cidr_block>`::
  139. (Required{multi-arg}, string or `null`)
  140. CIDR block you wish to search. If `null`, the function returns `null`.
  141. *Returns:* boolean or `null`
  142. ====
  143. [discrete]
  144. [[eql-fn-endswith]]
  145. === `endsWith`
  146. Returns `true` if a source string ends with a provided substring.
  147. [%collapsible]
  148. ====
  149. *Example*
  150. [source,eql]
  151. ----
  152. endsWith("regsvr32.exe", ".exe") // returns true
  153. endsWith("regsvr32.exe", ".dll") // returns false
  154. endsWith("", "") // returns true
  155. // file.name = "regsvr32.exe"
  156. endsWith(file.name, ".exe") // returns true
  157. endsWith(file.name, ".dll") // returns false
  158. // file.extension = ".exe"
  159. endsWith("regsvr32.exe", file.extension) // returns true
  160. endsWith("ntdll.dll", file.name) // returns false
  161. // file.name = [ "ntdll.dll", "regsvr32.exe" ]
  162. endsWith(file.name, ".dll") // returns true
  163. endsWith(file.name, ".exe") // returns false
  164. // null handling
  165. endsWith("regsvr32.exe", null) // returns null
  166. endsWith("", null) // returns null
  167. endsWith(null, ".exe") // returns null
  168. endsWith(null, null) // returns null
  169. ----
  170. *Syntax*
  171. [source,txt]
  172. ----
  173. endsWith(<source>, <substring>)
  174. ----
  175. *Parameters*
  176. `<source>`::
  177. +
  178. --
  179. (Required, string or `null`)
  180. Source string. If `null`, the function returns `null`.
  181. If using a field as the argument, this parameter supports only the following
  182. field datatypes:
  183. * <<keyword,`keyword`>>
  184. * <<constant-keyword,`constant_keyword`>>
  185. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  186. <<constant-keyword,`constant_keyword`>> sub-field
  187. Fields containing <<array,array values>> use the first array item only.
  188. --
  189. `<substring>`::
  190. +
  191. --
  192. (Required, string or `null`)
  193. Substring to search for. If `null`, the function returns `null`.
  194. If using a field as the argument, this parameter supports only the following
  195. field datatypes:
  196. * <<keyword,`keyword`>>
  197. * <<constant-keyword,`constant_keyword`>>
  198. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  199. <<constant-keyword,`constant_keyword`>> sub-field
  200. --
  201. *Returns:* boolean or `null`
  202. ====
  203. [discrete]
  204. [[eql-fn-indexof]]
  205. === `indexOf`
  206. Returns the first position of a provided substring in a source string.
  207. If an optional start position is provided, this function returns the first
  208. occurrence of the substring at or after the start position.
  209. [%collapsible]
  210. ====
  211. *Example*
  212. [source,eql]
  213. ----
  214. // url.domain = "subdomain.example.com"
  215. indexOf(url.domain, ".") // returns 9
  216. indexOf(url.domain, ".", 9) // returns 9
  217. indexOf(url.domain, ".", 10) // returns 17
  218. indexOf(url.domain, ".", -6) // returns 9
  219. // empty strings
  220. indexOf("", "") // returns 0
  221. indexOf(url.domain, "") // returns 0
  222. indexOf(url.domain, "", 9) // returns 9
  223. indexOf(url.domain, "", 10) // returns 10
  224. indexOf(url.domain, "", -6) // returns 0
  225. // missing substrings
  226. indexOf(url.domain, "z") // returns null
  227. indexOf(url.domain, "z", 9) // returns null
  228. // start position is higher than string length
  229. indexOf(url.domain, ".", 30) // returns null
  230. // null handling
  231. indexOf(null, ".", 9) // returns null
  232. indexOf(url.domain, null, 9) // returns null
  233. indexOf(url.domain, ".", null) // returns null
  234. ----
  235. *Syntax*
  236. [source,txt]
  237. ----
  238. indexOf(<source>, <substring>[, <start_pos>])
  239. ----
  240. *Parameters*
  241. `<source>`::
  242. +
  243. --
  244. (Required, string or `null`)
  245. Source string. If `null`, the function returns `null`.
  246. If using a field as the argument, this parameter supports only the following
  247. field datatypes:
  248. * <<keyword,`keyword`>>
  249. * <<constant-keyword,`constant_keyword`>>
  250. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  251. <<constant-keyword,`constant_keyword`>> sub-field
  252. --
  253. `<substring>`::
  254. +
  255. --
  256. (Required, string or `null`)
  257. Substring to search for.
  258. If this argument is `null` or the `<source>` string does not contain this
  259. substring, the function returns `null`.
  260. If the `<start_pos>` is positive, empty strings (`""`) return the `<start_pos>`.
  261. Otherwise, empty strings return `0`.
  262. If using a field as the argument, this parameter supports only the following
  263. field datatypes:
  264. * <<keyword,`keyword`>>
  265. * <<constant-keyword,`constant_keyword`>>
  266. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  267. <<constant-keyword,`constant_keyword`>> sub-field
  268. --
  269. `<start_pos>`::
  270. +
  271. --
  272. (Optional, integer or `null`)
  273. Starting position for matching. The function will not return positions before
  274. this one. Defaults to `0`.
  275. Positions are zero-indexed. Negative offsets are treated as `0`.
  276. If this argument is `null` or higher than the length of the `<source>` string,
  277. the function returns `null`.
  278. If using a field as the argument, this parameter supports only the following
  279. <<number,numeric>> field datatypes:
  280. * `long`
  281. * `integer`
  282. * `short`
  283. * `byte`
  284. --
  285. *Returns:* integer or `null`
  286. ====
  287. [discrete]
  288. [[eql-fn-length]]
  289. === `length`
  290. Returns the character length of a provided string, including whitespace and
  291. punctuation.
  292. [%collapsible]
  293. ====
  294. *Example*
  295. [source,eql]
  296. ----
  297. length("explorer.exe") // returns 12
  298. length("start explorer.exe") // returns 18
  299. length("") // returns 0
  300. length(null) // returns null
  301. // process.name = "regsvr32.exe"
  302. length(process.name) // returns 12
  303. ----
  304. *Syntax*
  305. [source,txt]
  306. ----
  307. length(<string>)
  308. ----
  309. *Parameters*
  310. `<string>`::
  311. +
  312. --
  313. (Required, string or `null`)
  314. String for which to return the character length. If `null`, the function returns
  315. `null`. Empty strings return `0`.
  316. If using a field as the argument, this parameter supports only the following
  317. field datatypes:
  318. * <<keyword,`keyword`>>
  319. * <<constant-keyword,`constant_keyword`>>
  320. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  321. <<constant-keyword,`constant_keyword`>> sub-field
  322. <<array,Array values>> are not supported.
  323. --
  324. *Returns:* integer or `null`
  325. ====
  326. [discrete]
  327. [[eql-fn-startswith]]
  328. === `startsWith`
  329. Returns `true` if a source string begins with a provided substring.
  330. [%collapsible]
  331. ====
  332. *Example*
  333. [source,eql]
  334. ----
  335. startsWith("regsvr32.exe", "regsvr32") // returns true
  336. startsWith("regsvr32.exe", "explorer") // returns false
  337. startsWith("", "") // returns true
  338. // process.name = "regsvr32.exe"
  339. startsWith(process.name, "regsvr32") // returns true
  340. startsWith(process.name, "explorer") // returns false
  341. // process.name = "regsvr32"
  342. startsWith("regsvr32.exe", process.name) // returns true
  343. startsWith("explorer.exe", process.name) // returns false
  344. // process.name = [ "explorer.exe", "regsvr32.exe" ]
  345. startsWith(process.name, "explorer") // returns true
  346. startsWith(process.name, "regsvr32") // returns false
  347. // null handling
  348. startsWith("regsvr32.exe", null) // returns null
  349. startsWith("", null) // returns null
  350. startsWith(null, "regsvr32") // returns null
  351. startsWith(null, null) // returns null
  352. ----
  353. *Syntax*
  354. [source,txt]
  355. ----
  356. startsWith(<source>, <substring>)
  357. ----
  358. *Parameters*
  359. `<source>`::
  360. +
  361. --
  362. (Required, string or `null`)
  363. Source string. If `null`, the function returns `null`.
  364. If using a field as the argument, this parameter supports only the following
  365. field datatypes:
  366. * <<keyword,`keyword`>>
  367. * <<constant-keyword,`constant_keyword`>>
  368. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  369. <<constant-keyword,`constant_keyword`>> sub-field
  370. Fields containing <<array,array values>> use the first array item only.
  371. --
  372. `<substring>`::
  373. +
  374. --
  375. (Required, string or `null`)
  376. Substring to search for. If `null`, the function returns `null`.
  377. If using a field as the argument, this parameter supports only the following
  378. field datatypes:
  379. * <<keyword,`keyword`>>
  380. * <<constant-keyword,`constant_keyword`>>
  381. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  382. <<constant-keyword,`constant_keyword`>> sub-field
  383. --
  384. *Returns:* boolean or `null`
  385. ====
  386. [discrete]
  387. [[eql-fn-string]]
  388. === `string`
  389. Converts a value to a string.
  390. [%collapsible]
  391. ====
  392. *Example*
  393. [source,eql]
  394. ----
  395. string(42) // returns "42"
  396. string(42.5) // returns "42.5"
  397. string("regsvr32.exe") // returns "regsvr32.exe"
  398. string(true) // returns "true"
  399. // null handling
  400. string(null) // returns null
  401. ----
  402. *Syntax*
  403. [source,txt]
  404. ----
  405. string(<value>)
  406. ----
  407. *Parameters*
  408. `<value>`::
  409. (Required)
  410. Value to convert to a string. If `null`, the function returns `null`.
  411. +
  412. If using a field as the argument, this parameter does not support the
  413. <<text,`text`>> field datatype.
  414. *Returns:* string or `null`
  415. ====
  416. [discrete]
  417. [[eql-fn-stringcontains]]
  418. === `stringContains`
  419. Returns `true` if a source string contains a provided substring.
  420. [%collapsible]
  421. ====
  422. *Example*
  423. [source,eql]
  424. ----
  425. // process.command_line = "start regsvr32.exe"
  426. stringContains(process.command_line, "regsvr32") // returns true
  427. stringContains(process.command_line, "start ") // returns true
  428. stringContains(process.command_line, "explorer") // returns false
  429. // process.name = "regsvr32.exe"
  430. stringContains(command_line, process.name) // returns true
  431. // empty strings
  432. stringContains("", "") // returns false
  433. stringContains(process.command_line, "") // returns false
  434. // null handling
  435. stringContains(null, "regsvr32") // returns null
  436. stringContains(process.command_line, null) // returns null
  437. ----
  438. *Syntax*
  439. [source,txt]
  440. ----
  441. stringContains(<source>, <substring>)
  442. ----
  443. *Parameters*
  444. `<source>`::
  445. (Required, string or `null`)
  446. Source string to search. If `null`, the function returns `null`.
  447. If using a field as the argument, this parameter supports only the following
  448. field datatypes:
  449. * <<keyword,`keyword`>>
  450. * <<constant-keyword,`constant_keyword`>>
  451. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  452. <<constant-keyword,`constant_keyword`>> sub-field
  453. `<substring>`::
  454. (Required, string or `null`)
  455. Substring to search for. If `null`, the function returns `null`.
  456. If using a field as the argument, this parameter supports only the following
  457. field datatypes:
  458. * <<keyword,`keyword`>>
  459. * <<constant-keyword,`constant_keyword`>>
  460. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  461. <<constant-keyword,`constant_keyword`>> sub-field
  462. *Returns:* boolean or `null`
  463. ====
  464. [discrete]
  465. [[eql-fn-substring]]
  466. === `substring`
  467. Extracts a substring from a source string at provided start and end positions.
  468. If no end position is provided, the function extracts the remaining string.
  469. [%collapsible]
  470. ====
  471. *Example*
  472. [source,eql]
  473. ----
  474. substring("start regsvr32.exe", 6) // returns "regsvr32.exe"
  475. substring("start regsvr32.exe", 0, 5) // returns "start"
  476. substring("start regsvr32.exe", 6, 14) // returns "regsvr32"
  477. substring("start regsvr32.exe", -4) // returns ".exe"
  478. substring("start regsvr32.exe", -4, -1) // returns ".ex"
  479. ----
  480. *Syntax*
  481. [source,txt]
  482. ----
  483. substring(<source>, <start_pos>[, <end_pos>])
  484. ----
  485. *Parameters*
  486. `<source>`::
  487. (Required, string)
  488. Source string.
  489. `<start_pos>`::
  490. +
  491. --
  492. (Required, integer)
  493. Starting position for extraction.
  494. If this position is higher than the `<end_pos>` position or the length of the
  495. `<source>` string, the function returns an empty string.
  496. Positions are zero-indexed. Negative offsets are supported.
  497. --
  498. `<end_pos>`::
  499. (Optional, integer)
  500. Exclusive end position for extraction. If this position is not provided, the
  501. function returns the remaining string.
  502. +
  503. Positions are zero-indexed. Negative offsets are supported.
  504. *Returns:* string
  505. ====
  506. [discrete]
  507. [[eql-fn-wildcard]]
  508. === `wildcard`
  509. Returns `true` if a source string matches one or more provided wildcard
  510. expressions.
  511. [%collapsible]
  512. ====
  513. *Example*
  514. [source,eql]
  515. ----
  516. // The two following expressions are equivalent.
  517. process.name == "*regsvr32*" or process.name == "*explorer*"
  518. wildcard(process.name, "*regsvr32*", "*explorer*")
  519. // process.name = "regsvr32.exe"
  520. wildcard(process.name, "*regsvr32*") // returns true
  521. wildcard(process.name, "*regsvr32*", "*explorer*") // returns true
  522. wildcard(process.name, "*explorer*") // returns false
  523. wildcard(process.name, "*explorer*", "*scrobj*") // returns false
  524. // empty strings
  525. wildcard("", "*start*") // returns false
  526. wildcard("", "*") // returns true
  527. wildcard("", "") // returns true
  528. // null handling
  529. wildcard(null, "*regsvr32*") // returns null
  530. wildcard(process.name, null) // returns null
  531. ----
  532. *Syntax*
  533. [source,txt]
  534. ----
  535. wildcard(<source>, <wildcard_exp>[, ...])
  536. ----
  537. *Parameters*
  538. `<source>`::
  539. +
  540. --
  541. (Required, string)
  542. Source string. If `null`, the function returns `null`.
  543. If using a field as the argument, this parameter supports only the following
  544. field datatypes:
  545. * <<keyword,`keyword`>>
  546. * <<constant-keyword,`constant_keyword`>>
  547. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  548. <<constant-keyword,`constant_keyword`>> sub-field
  549. --
  550. `<wildcard_exp>`::
  551. +
  552. --
  553. (Required{multi-arg-ref}, string)
  554. Wildcard expression used to match the source string. If `null`, the function
  555. returns `null`. Fields are not supported as arguments.
  556. --
  557. *Returns:* boolean
  558. ====