├── .github
└── workflows
│ └── release.yml
├── .gitmodules
├── ELK_VERSIONS
├── LICENSE
├── README.md
├── agent
└── install-sysmon-beats.ps1
├── beaker
├── check_kibana
├── Dockerfile
└── check_kibana.py
├── docker-compose.yml
├── docs
└── Installation and Release Generation.md
├── elasticsearch
├── Dockerfile
├── elasticsearch.yml
├── export_day.sh
├── export_index.sh
├── import_index.sh
└── reset_elastic_password.sh
├── images
├── BeaKer_demo.gif
├── BeaKer_demo_bottom.png
└── BeaKer_demo_top.png
├── installer
├── .gitignore
├── generate_installer.sh
└── stage
│ └── BeaKer
│ ├── .gitignore
│ ├── ELK_VERSIONS
│ ├── beaker
│ ├── check_kibana
│ └── DO_NOT_DELETE
│ ├── docker-compose.yml
│ ├── elasticsearch
│ ├── DO_NOT_DELETE
│ ├── export_day.sh
│ ├── export_index.sh
│ ├── import_index.sh
│ └── templates
│ │ ├── DO_NOT_DELETE
│ │ ├── winlogbeat-7.17.9.template.json
│ │ ├── winlogbeat-8.7.0-powershell.json
│ │ ├── winlogbeat-8.7.0-powershell_operational.json
│ │ ├── winlogbeat-8.7.0-routing.json
│ │ ├── winlogbeat-8.7.0-security.json
│ │ ├── winlogbeat-8.7.0-sysmon.json
│ │ ├── winlogbeat-8.7.0.template.json
│ │ └── winlogbeat-ilm-policy.json
│ ├── install_beaker.sh
│ ├── kibana
│ ├── import_dashboards.sh
│ ├── kibana_dashboards-7.17.0.ndjson
│ └── kibana_dashboards-8.0.0.ndjson
│ └── shell-lib
└── kibana
├── Dockerfile
├── export_dashboards.sh
├── import_dashboards.sh
├── kibana.yml
├── kibana_dashboards-7.17.0.ndjson
└── kibana_dashboards-8.0.0.ndjson
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: Generate and upload a release assets
2 |
3 | on:
4 | release:
5 | types:
6 | - published
7 | #- unpublished
8 | - created
9 | - edited
10 | #- deleted
11 | - prereleased
12 | - released
13 |
14 | jobs:
15 | upload:
16 | name: Upload Artifacts
17 | runs-on: ubuntu-20.04
18 | steps:
19 | - uses: actions/checkout@v2
20 | with:
21 | submodules: true
22 | - run: shell-lib/docker/install_docker.sh
23 | - run: installer/generate_installer.sh
24 | - uses: actions/upload-release-asset@v1
25 | env:
26 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27 | with:
28 | upload_url: ${{ github.event.release.upload_url }}
29 | asset_path: installer/BeaKer.tar
30 | # Note: This will fail if the asset already exists
31 | # (e.g. editing a release w/o deleting the existing asset)
32 | asset_name: BeaKer.tar
33 | asset_content_type: application/x-tar
34 | - uses: actions/upload-release-asset@v1
35 | env:
36 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37 | with:
38 | upload_url: ${{ github.event.release.upload_url }}
39 | asset_path: agent/install-sysmon-beats.ps1
40 | # Note: This will fail if the asset already exists
41 | # (e.g. editing a release w/o deleting the existing asset)
42 | asset_name: install-sysmon-beats.ps1
43 | asset_content_type: text/plain
44 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "shell-lib"]
2 | path = shell-lib
3 | url = https://github.com/activecm/shell-lib.git
4 |
--------------------------------------------------------------------------------
/ELK_VERSIONS:
--------------------------------------------------------------------------------
1 | 7.17.9
2 | 8.7.0
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 |
624 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BeaKer - Beaconing Kibana Executable Report
2 |
3 | Brought to you by [Active Countermeasures](https://www.activecountermeasures.com/).
4 |
5 | ---
6 |
7 | BeaKer visualizes Microsoft Sysmon network data to help threat hunters track down the source of suspicious network connections. The custom dashboard presents which users and executables created connections between two given IPs, how many times they've connected, the protocols and ports used, and much more.
8 |
9 | ## Getting Started
10 |
11 | 
12 |
13 | After Sysmon starts sending data to ElasticSearch, Kibana will be ready to go. Filter by a source and destination IP and a time range to view what connections have been made between the two. The Program List will display which executables on the source machine made the connections to the destination. The actual Sysmon logs are displayed lower on the screen where you can investigate the events in greater detail.
14 |
15 | ## How it works
16 |
17 | - Microsoft Sysmon: Logs network connections to the Windows Event Log
18 | - WinLogBeats: Sends the network connection logs to Elasticsearch
19 | - Elasticsearch: Stores, indexes, and aggregates the network connection logs
20 | - Kibana: Displays logs stored in Elasticsearch and provides a user interface for Elasticsearch administration
21 | - Beacon Dashboard: Aggregates the network connections between two hosts
22 |
23 | ## Installation
24 |
25 | ### BeaKer Server System Requirements
26 | * Operating System: The preferred platform is x86 64-bit Ubuntu 20.04 LTS. The system should be patched and up to date using apt-get.
27 | * The automated installer will also support CentOS 7.
28 | * Processor: Two or more cores. Elasticsearch uses parallel processing and benefits from more CPU cores.
29 | * Memory: 8-64GB. Monitoring more hosts requires more RAM.
30 | * Storage: Ensure `/var/lib/docker/volumes` has free space for the incoming network logs.
31 |
32 | ### BeaKer Agent System Requirements
33 | * Operating System: Windows x86-64 bit OS
34 | * Powershell Version: 3+
35 | * Installed WinLogBeats version must be <= the Elasticsearch version installed on the BeaKer server, but at least the minimum supported wire version for the Elasticsearch version
36 | * Elasticsearch v8.6.2 supports WinLogBeats 7.17.0 through 8.6.2
37 | * Elasticsearch v7.17.9 supports WinLogBeats 6.8.0 through 7.17.9
38 |
39 | ### Automated Install: BeaKer Server
40 |
41 | Download the [latest release](https://github.com/activecm/BeaKer/releases/latest) tar file, extract it, and inside the `BeaKer` directory,
42 | run `./install_beaker.sh` on the Linux machine that will aggregate your Sysmon data and host Kibana.
43 |
44 | ** Note that existing BeaKer installations must be upgraded to v7.17 before they can be upgraded to v8.x.
45 | The automated installer will:
46 | - Install Docker and Docker-Compose
47 | - Create a configuration directory in `/etc/BeaKer`
48 | - Install Elasticsearch, Kibana, and load the dashboards
49 | - Set the Elasticsearch superuser password for the `elastic` account
50 | - Set the `sysmon-ingest` user password for connecting WinLogBeats
51 | - Set up index templates, ILM policy, data streams and ingest pipelines
52 |
53 | The `beaker` script installed to `/usr/local/bin/beaker` is a wrapper around `docker-compose` and can be used to manage BeaKer.
54 | - To stop BeaKer, run `beaker down`
55 | - To start Beaker, run `beaker up`
56 | - To view the logs of the Elasticsearch container, run `beaker logs -f elasticsearch`
57 | - To view the logs of the Kibana container, run `beaker logs -f kibana`
58 |
59 | After running `./install_beaker.sh` you should be able to access Kibana at `localhost:5601`. Note that Kibana is exposed on every network interface available on the Docker host.
60 |
61 | Use the `elastic` account to perform your initial login to Kibana. Additional user accounts can be created using the Kibana interface. The `sysmon-ingest` user account is not allowed to access Kibana.
62 |
63 | The Elasticsearch server will begin listening for connections on port 9200 using HTTPS. It expects Sysmon ID 3 Network Events to be published to:
64 | - WinLogBeats less than v7.17.9: ES index `sysmon-%{+YYYY.MM.dd}`
65 | - WinLogBeats v7.17.9: ES index `winlogbeat-%{[agent.version]}` via data stream
66 | - WinLogBeats v8.6.2: Ingest Pipeline `winlogbeat-%{[agent.version]}-routing`
67 | See the embedded `winlogbeat.yml` file in `./agent/install-sysmon-beats.ps1` for more info.
68 |
69 | The easiest way to begin sending data to the server is to use the automated BeaKer agent installer.
70 |
71 | ### Automated Install: BeaKer Agent
72 | The PowerShell script `./agent/install-sysmon-beats.ps1` will install Sysmon and WinLogBeats, and configure WinLogBeats to begin sending data to the BeaKer server.
73 |
74 | To install the agent, run the script as `.\install-sysmon-beats.ps1 ip.or.hostname.of.beaker.server 9200`.
75 |
76 | The script will then:
77 | - Ask for the credentials of the Elasticsearch user to connect with
78 | - These may be supplied using the parameters `ESUsername` and `ESPassword`
79 | - If using the automated BeaKer Server installer, use `sysmon-ingest`
80 | - Download Sysmon and install it with the default configuration in `%PROGRAMFILES%` if it doesn't exist
81 | - Ensures Sysmon is running as a service
82 | - Download WinLogBeat and install it in `%PROGRAMFILES%` and `%PROGRAMDATA%` if it doesn't exist
83 | - **Removes any existing winlogbeat configuration files (`winlogbeat.yml`)**
84 | - Installs a new `winlogbeat.yml` file to connect to the BeaKer server
85 | - Ensures WinLogBeat is running as a service
86 |
87 | ### BeaKer Agent uninstall
88 | As an administrator, run the following scripts to uninstall the beaker agent:
89 | - `C:\Program Files\winlogbeat-7.5.2-windows-x86_64\uninstall-service-winlogbeat.ps1
90 | - `C:\Program Files\Sysmon\Sysmon64.exe -u`
91 |
92 | ### Data Collected By Sysmon Per Network Connection
93 | - Source
94 | - IP Address
95 | - Hostname
96 | - Port
97 | - Destination
98 | - IP Address
99 | - Hostname
100 | - Port
101 | - Network
102 | - Transport Protocol
103 | - Application Protocol
104 | - Community ID
105 | - Process
106 | - PID
107 | - Executable
108 | - Entity ID
109 | - User
110 | - Domain
111 | - Name
112 | - Timestamp
113 |
114 | ## Developer Information
115 | When cloning the project, ensure that you have cloned the git submodules as well.
116 | Either pass `--recurse-submodules` to `git clone` when pulling down the project, or run the following commands afterwards:
117 | - `cd BeaKer`
118 | - `git submodule update --init --recursive`
119 |
120 | To generate a new release tarball, run `./installer/generate_installer.sh`.
121 |
122 | ## License
123 |
124 | GNU GPL V3 © Active Countermeasures ™
125 |
--------------------------------------------------------------------------------
/agent/install-sysmon-beats.ps1:
--------------------------------------------------------------------------------
1 | <#
2 |
3 | .SYNOPSIS
4 | This Powershell script installs and configures Microsoft Sysinternals Sysmon and Elastic Winlogbeat with the aim
5 | of shipping network connection events to a centralized Elasticsearch server.
6 |
7 | .DESCRIPTION
8 | This script install Microsoft Sysinternals Sysmon and Elastic Winlogbeat to the Windows Program Files directory.
9 | Sysmon is then configured to report network connections and Winlogbeat is configured to send connection logs to
10 | the desired Elasticsearch server.
11 |
12 | .PARAMETER ESHost
13 | The IP address or hostname of the Elasticsearch server to send connection logs. This should not contain a protocol descriptor such as "https://".
14 |
15 | .PARAMETER ESPort
16 | The port on which the Elasticsearch server is listening. Defaults to TCP 9200.
17 |
18 | .PARAMETER ESUsername
19 | Warning: Insecure!
20 | The username used to authenticate to the Elasticsearch server. If ESUsername is not specified,
21 | the script will ask for the username at runtime. In order to avoid recording the Elasticsearch
22 | username, consider editing this file. Change the line `[string]$ESUsername="",` to
23 | `[string]$ESUsername="YOUR_ELASTIC_USERNAME_HERE",.
24 |
25 | .PARAMETER ESPassword
26 | Warning: Insecure!
27 | The password used to authenticate to the Elasticsearch server. If ESPassword is not specified,
28 | the script will ask for the password at runtime. In order to avoid recording the Elasticsearch
29 | password, consider editing this file. Change the line `[string]$ESPassword="",` to
30 | `[string]$ESPassword="YOUR_ELASTIC_PASSWORD_HERE",.
31 |
32 | .PARAMETER BeatsVersion
33 | The version of Winlogbeat to install. This will override any logic that handles upgrading to an
34 | intermediate version of Winlogbeat before upgrading to a higher major version.
35 |
36 | .EXAMPLE
37 | # Asks for Elasticsearch authentication details at runtime
38 | .\install-sysmon-beats.ps1 my-es-host.com 9200
39 |
40 | # Reads Elasticsearch authentication details from the command line aguments
41 | .\install-sysmon-beats.ps1 my-es-host.com 9200 elastic elastic_password
42 |
43 | # Overrides the version of Winlogbeat to install
44 | .\install-sysmon-beats.ps1 my-es-host.com 9200 elastic elastic_password 8.6.2
45 |
46 | .NOTES
47 | The Elasticsearch credentials are stored locally using Elastic Winlogbeat's secure
48 | storage facilities. The ESUsername and ESPassword parameters should not be passed
49 | into the script in a secure environment. Instead, either leave the credentials blank and
50 | enter the credentials during the installation process, or edit the parameters' default values in the script.
51 | #>
52 |
53 | param (
54 | [Parameter(Mandatory = $true)][string]$ESHost,
55 | [string]$ESPort = "9200",
56 | [string]$ESUsername = "",
57 | [string]$ESPassword = "",
58 | [string]$BeatsVersion = ""
59 | )
60 |
61 | $ELK_STACK_VERSION = "8.7.0"
62 |
63 | if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
64 | # Use param values instead of $args because $args doesn't appear to get populated if param values are specified
65 | # Also set the ExecutionPolicy to Bypass otherwise this will likely fail as script
66 | # execution is disabled by default.
67 | $arguments = "-ExecutionPolicy", "Bypass", "-File", $myinvocation.mycommand.definition, $ESHost, $ESPort
68 | if ($ESUsername) {
69 | # Only add this argument if the user provided it, otherwise it will be blank and will cause an error
70 | $arguments += $ESUsername
71 | }
72 | if ($ESPassword) {
73 | # Only add this argument if the user provided it, otherwise it will be blank and will cause an error
74 | $arguments += $ESPassword
75 | }
76 | if ($BeatsVersion) {
77 | # Only add this argument if the user provided it, otherwise it will be blank and will cause an error
78 | $arguments += $BeatsVersion
79 | }
80 |
81 | Start-Process -FilePath powershell -Verb runAs -ArgumentList $arguments
82 | Break
83 | }
84 |
85 |
86 | [bool] $OverrideBeatsVersion = $false
87 | if ([string]::IsNullOrWhiteSpace("$BeatsVersion")) {
88 | $BeatsVersion = "$ELK_STACK_VERSION"
89 | }
90 | else {
91 | if ($null -eq ("$BeatsVersion" -as [System.Version])) {
92 | throw "Beats version $BeatsVersion is not a valid version, please provide a valid version number."
93 | }
94 | if ([System.Version]$BeatsVersion -lt [System.Version]"7.17.9") {
95 | throw "Minimum supported Beats version is 7.17.9, exiting"
96 | }
97 | $OverrideBeatsVersion = $true
98 | }
99 |
100 | # Check for existing winlogbeat installation via Espy
101 | if (Test-Path "$Env:programfiles\Winlogbeat-Espy" -PathType Container) {
102 | Write-Output "Detected existing winlogbeat installation performed by Espy. Continuing the install may result in a partially working Sysmon/winlogbeat setup."
103 | $installAnyway = Read-Host -Prompt "Are you sure you want to continue? [y/n]"
104 | if (($installAnyway -eq 'n') -or ($installAnyway -eq 'N')) {
105 | Exit
106 | }
107 | }
108 |
109 | if (-not (Test-Path "$Env:programfiles\Sysmon" -PathType Container)) {
110 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
111 | Invoke-WebRequest -OutFile Sysmon.zip https://download.sysinternals.com/files/Sysmon.zip
112 | Expand-Archive .\Sysmon.zip
113 | rm .\Sysmon.zip
114 | mv .\Sysmon\ "$Env:programfiles"
115 | }
116 |
117 | echo @"
118 |
119 | md5,sha256,IMPHASH
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 | "@ > "$Env:programfiles\Sysmon\sysmon-net-only.xml"
189 |
190 |
191 | & "$Env:programfiles\Sysmon\Sysmon64.exe" -accepteula -i "$Env:programfiles\Sysmon\sysmon-net-only.xml"
192 |
193 | $InstalledBeatsVersion = ""
194 | [bool] $DownloadWinlogbeat = $false
195 |
196 | # Check for fresh install or pre-7.17 install
197 | if (-not (Test-Path "$Env:programfiles\Winlogbeat-BeaKer\winlogbeat.exe" -PathType Leaf)) {
198 | $DownloadWinlogbeat = $true
199 |
200 | # Create install directory if it doesn't exist
201 | if (-not (Test-Path "$Env:programfiles\Winlogbeat-BeaKer" -PathType Container)) {
202 | mkdir "$Env:programfiles\Winlogbeat-BeaKer" > $null
203 | }
204 |
205 | # Check if this is a pre-7.17 upgrade install
206 | if ((Test-Path "$Env:programfiles\winlogbeat-7*" -PathType Container)) {
207 | ### Make sure that Beats is upgraded to 7.17 before installing v8.x
208 | # Install winlogbeat 7.17.9 if the current version is less than 8.x
209 | if (!$OverrideBeatsVersion) {
210 | $BeatsVersion = "7.17.9"
211 | }
212 | Copy-Item "$Env:programfiles\winlogbeat-7*\winlogbeat.yml" "$Env:programfiles\Winlogbeat-BeaKer"
213 | }
214 | }
215 | else {
216 | # Check if currently installed version is outdated
217 | $InstalledBeatsVersion = (& "$Env:programfiles\Winlogbeat-BeaKer\winlogbeat.exe" version | Select-String -Pattern "(?<=winlogbeat version )(\d+\.\d+\.\d+)").Matches.Value
218 | if ($null -eq ("$InstalledBeatsVersion" -as [System.Version])) {
219 |
220 | if (!$OverrideBeatsVersion) {
221 | throw "Unable to retrieve installed winlogbeat version"
222 | }
223 | else {
224 | Write-Output "Unable to retrieve installed winlogbeat version, continuing anyway"
225 | $DownloadWinlogbeat = $true
226 | }
227 | }
228 | else {
229 | if ([System.Version]"$InstalledBeatsVersion" -lt [System.Version]"$BeatsVersion") {
230 | $DownloadWinlogbeat = $true
231 | }
232 | }
233 | }
234 |
235 | # Download winlogbeat and move it to install directory
236 | if ($DownloadWinlogbeat) {
237 | Write-Output "######## Downloading winlogbeat version $BeatsVersion ########"
238 |
239 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
240 | Invoke-WebRequest -OutFile WinLogBeat.zip https://artifacts.elastic.co/downloads/beats/winlogbeat/winlogbeat-"$BeatsVersion"-windows-x86_64.zip
241 | Expand-Archive .\WinLogBeat.zip
242 | rm .\WinLogBeat.zip
243 | rm .\WinLogBeat\winlogbeat*\winlogbeat.yml
244 |
245 | # Stop winlogbeat service if it exists
246 | if (Get-Service winlogbeat -ErrorAction SilentlyContinue) {
247 | Stop-Service winlogbeat
248 | (Get-Service winlogbeat).WaitForStatus('Stopped')
249 | Start-Sleep -s 1
250 | }
251 | Copy-Item -Path .\WinLogBeat\winlogbeat*\* -Destination "$Env:programfiles\Winlogbeat-BeaKer\" -Recurse -Force
252 | rm .\Winlogbeat -Recurse
253 | }
254 |
255 | Write-Output "######## Installing winlogbeat version $BeatsVersion ########"
256 |
257 |
258 | # Begin winlogbeat configuration
259 | Set-Location "$Env:programfiles\Winlogbeat-BeaKer\"
260 |
261 | # Backup winlogbeat config if it exists
262 | if (Test-Path -PathType Leaf .\winlogbeat.yml) {
263 | if ($DownloadWinlogbeat) {
264 | # Backup config with its version in the name if upgrading to a new Beats version
265 | # so that the config isn't overwritten by subsequent upgrades. This is useful in case
266 | # breaking changes between configurations need to be referenced in the future for troubleshooting
267 | Copy-Item .\winlogbeat.yml .\winlogbeat-$InstalledBeatsVersion-old.yml.bak
268 | }
269 | else {
270 | Copy-Item .\winlogbeat.yml .\winlogbeat.yml.bak
271 | }
272 | }
273 |
274 | .\winlogbeat.exe --path.data "C:\ProgramData\winlogbeat" keystore create
275 | if ($ESUsername) {
276 | Write-Output "$ESUsername" | .\winlogbeat.exe --path.data "C:\ProgramData\winlogbeat" keystore add ES_USERNAME --stdin
277 | }
278 | else {
279 | .\winlogbeat.exe --path.data "C:\ProgramData\winlogbeat" keystore add ES_USERNAME
280 | }
281 | if ($ESPassword) {
282 | Write-Output "$ESPassword" | .\winlogbeat.exe --path.data "C:\ProgramData\winlogbeat" keystore add ES_PASSWORD --stdin
283 | }
284 | else {
285 | .\winlogbeat.exe --path.data "C:\ProgramData\winlogbeat" keystore add ES_PASSWORD
286 | }
287 |
288 | # Set ACL's of the $Env:ProgramData\winlogbeat folder to be the same as $Env:ProgramFiles\winlogbeat* (the main install path)
289 | # This helps ensure that "normal" users aren't able to access the $Env:ProgramData\winlogbeat folder
290 | Get-ACL -Path "$Env:ProgramFiles\\Winlogbeat-BeaKer*" | Set-ACL -Path "$Env:ProgramData\\winlogbeat"
291 |
292 | rm .\winlogbeat.yml
293 |
294 | if ([System.Version]$BeatsVersion -lt [System.Version]"8.0.0") {
295 | Write-Output @"
296 | winlogbeat.event_logs:
297 | - name: Microsoft-Windows-Sysmon/Operational
298 | event_id: 3
299 | processors:
300 | - script:
301 | lang: javascript
302 | id: sysmon
303 | file: ${path.home}/module/sysmon/config/winlogbeat-sysmon.js
304 |
305 | setup.ilm.enabled: false
306 | setup.template.name: `"winlogbeat-%{[agent.version]}`"
307 | setup.template.pattern: `"winlogbeat-%{[agent.version]}`"
308 |
309 | output.elasticsearch:
310 | hosts:
311 | - https://${ESHost}:${ESPort}
312 | index: `"winlogbeat-%{[agent.version]}`"
313 | username: `"`${ES_USERNAME}`"
314 | password: `"`${ES_PASSWORD}`"
315 | ssl:
316 | enabled: true
317 | verification_mode: none
318 | "@ > winlogbeat.yml
319 | }
320 | else {
321 | Write-Output @"
322 | winlogbeat.event_logs:
323 | - name: Microsoft-Windows-Sysmon/Operational
324 | event_id: 3
325 |
326 | setup.ilm.enabled: false
327 |
328 | output.elasticsearch:
329 | hosts:
330 | - https://${ESHost}:${ESPort}
331 | pipeline: winlogbeat-%{[agent.version]}-routing
332 | username: `"`${ES_USERNAME}`"
333 | password: `"`${ES_PASSWORD}`"
334 | ssl:
335 | enabled: true
336 | verification_mode: none
337 | "@ > winlogbeat.yml
338 | }
339 |
340 | PowerShell.exe -ExecutionPolicy UnRestricted -File .\install-service-winlogbeat.ps1
341 |
342 | Start-Service winlogbeat
343 |
--------------------------------------------------------------------------------
/beaker:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Change dir to script dir
4 | pushd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" > /dev/null
5 |
6 |
7 | # If the current user doesn't have docker permissions or
8 | # permission to open the env file, use sudo
9 | SUDO=
10 | if [ ! -w "/var/run/docker.sock" -o ! -r ".env" ]; then
11 | SUDO="sudo --preserve-env"
12 | fi
13 |
14 | # Check for pre-requisites
15 | shell-lib/docker/check_docker.sh || echo "You do not have a supported version of Docker installed."
16 | shell-lib/docker/check_docker-compose.sh || echo "You do not have a supported version of Docker-Compose installed."
17 |
18 | # Ensure docker-compose can write to a temporary directory and execute scripts there
19 | source ./shell-lib/acmlib.sh
20 | require_executable_tmp_dir
21 |
22 | # TMPDIR is erased even if -E is passed to sudo. https://serverfault.com/questions/478741/sudo-does-not-preserve-tmpdir
23 | # Need to explicitly pass tmpdir in if it exists.
24 | if [ -n "$TMPDIR" ]; then
25 | $SUDO env "TMPDIR=$TMPDIR" docker-compose -f "docker-compose.yml" "$@"
26 | else
27 | $SUDO docker-compose -f "docker-compose.yml" "$@"
28 | fi
29 |
30 | # Store the exit code from docker-compose to use later
31 | result=$?
32 |
33 | # Change back to original directory
34 | popd > /dev/null
35 |
36 | # Pass docker-compose's exit code through
37 | exit $result
38 |
--------------------------------------------------------------------------------
/check_kibana/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:3.9
2 | ADD check_kibana.py .
3 | CMD ["python3", "./check_kibana.py"]
4 |
--------------------------------------------------------------------------------
/check_kibana/check_kibana.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import json
3 |
4 | # check kibana status for v8.x
5 |
6 |
7 | def check_kibana_migrations_v8(status):
8 | if "core" in status:
9 | if "savedObjects" in status["core"]:
10 | if "summary" in status["core"]["savedObjects"]:
11 | if "completed migrations" in status["core"]["savedObjects"]["summary"] \
12 | and "available" in status["core"]["savedObjects"]["summary"]:
13 | sys.exit(0)
14 |
15 | sys.exit(2)
16 |
17 |
18 | def check_kibana_status_v8(status):
19 | if "overall" in status:
20 | if "level" in status["overall"]:
21 | if status["overall"]["level"] == "available":
22 | check_kibana_migrations_v8(status)
23 | sys.exit(1)
24 |
25 | # check kibana status for v7.17
26 |
27 |
28 | def check_kibana_status(status):
29 | if "overall" in status:
30 | if "state" in status["overall"]:
31 | if status["overall"]["state"] == "green":
32 | check_migration_status(status)
33 | check_kibana_status_v8(status)
34 |
35 |
36 | def check_migration_status(status):
37 | if "statuses" in status:
38 | for plugin in status["statuses"]:
39 | if "core:savedObjects" in plugin["id"]:
40 | if "message" in plugin:
41 | if "completed migrations" in plugin["message"] \
42 | and "available" in plugin["message"]:
43 | sys.exit(0)
44 | sys.exit(2)
45 |
46 |
47 | # takes piped in curl output from https://localhost:5601/api/status
48 | # and checks whether or not kibana is online and finished with data migrations (upgrades)
49 | try:
50 | response = json.load(sys.stdin)
51 | except ValueError:
52 | sys.exit(4)
53 |
54 | if "status" in response:
55 | status = response["status"]
56 | check_kibana_status(status)
57 |
58 | sys.exit(3)
59 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 | volumes:
3 | elasticsearch_persistent:
4 | elasticsearch_snapshots:
5 | driver: local
6 | driver_opts:
7 | type: 'none'
8 | device: /var/BeaKer/snapshots
9 | o: bind
10 | services:
11 | elasticsearch:
12 | image: activecm-beaker/elasticsearch:${ELK_STACK_VERSION:-latest}
13 | build: ./elasticsearch
14 | restart: unless-stopped
15 | environment:
16 | - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
17 | - "ES_JAVA_OPTS=-Xms3g -Xmx3g"
18 | ports:
19 | - "${ELASTIC_HTTP_PORT:-9200}:9200"
20 | volumes:
21 | - elasticsearch_persistent:/usr/share/elasticsearch/data
22 | - ${BEAKER_CONFIG_DIR:-/etc/BeaKer/}certificates:/usr/share/elasticsearch/config/certificates
23 | - elasticsearch_snapshots:/usr/share/elasticsearch/snapshots
24 | kibana:
25 | image: activecm-beaker/kibana:${ELK_STACK_VERSION:-latest}
26 | build: ./kibana
27 | restart: unless-stopped
28 | environment:
29 | - KIBANA_SERVICE_TOKEN=${KIBANA_SERVICE_TOKEN}
30 | - SAVED_OBJECTS_ENCRYPTION_KEY=${SAVED_OBJECTS_ENCRYPTION_KEY}
31 | - REPORTING_ENCRYPTION_KEY=${REPORTING_ENCRYPTION_KEY}
32 | - SECURITY_ENCRYPTION_KEY=${SECURITY_ENCRYPTION_KEY}
33 | ports:
34 | - "${KIBANA_HTTP_PORT:-5601}:5601"
35 | volumes:
36 | - ${BEAKER_CONFIG_DIR:-/etc/BeaKer/}certificates:/usr/share/kibana/config/certificates
37 | depends_on:
38 | - elasticsearch
39 | check_kibana:
40 | image: activecm-beaker/check_kibana:latest
41 | build: ./check_kibana
42 | restart: "no"
43 | depends_on:
44 | - kibana
45 | es-dump:
46 | image: taskrabbit/elasticsearch-dump:v6.28.0
47 | restart: "no"
48 | environment:
49 | - NODE_TLS_REJECT_UNAUTHORIZED=0
50 | depends_on:
51 | - elasticsearch
52 | entrypoint: ["/bin/true"]
53 |
54 |
--------------------------------------------------------------------------------
/docs/Installation and Release Generation.md:
--------------------------------------------------------------------------------
1 | # Installation and Release Generation
2 |
3 | ## Generating a Release on Github
4 |
5 | ### Updating ELK Components
6 | 1. Update `ELK_VERSION` with the ELK stack version(s) to include in the release, one per line. They must be in ascending order.
7 | 2. Update `ELK_STACK_VERSION` in `./agent/install-sysmon-beats.ps1`.
8 | 3. For each included ELK version, install WinLogBeat and export the index template and ingest pipelines for each version.
9 | - Run `.\winlogbeat.exe --path.data C:\ProgramData\winlogbeat export pipelines --es.version=7.16.0`
10 | - Refer to the [WinLogBeat Documentation](https://www.elastic.co/guide/en/beats/winlogbeat/current/load-ingest-pipelines.html) for which `--es.version` to pass into this command.
11 | - Run `.\winlogbeat.exe export template --es.version [winlogbeat-version] | Out-File -Encoding UTF8 winlogbeat-[winlogbeat-version].template.json`
12 | - Put each template & ingest pipeline in `./installer/stage/BeaKer/elasticsearch/templates`.
13 | - Delete templates and pipelines from older ELK versions that are no longer included in the release.
14 | - Edit each index template to:
15 | - Include `"winlogbeat-[winlogbeat-version]"` within the `index_patterns` array (if it doesn't already)
16 | - Include a top-level `data_stream` key
17 | - Include `"aliases":{ "winlogbeat": {} }` within the `template` object
18 | - Include `"lifecycle":{ "name": "beaker" }` within the `template.settings.index` object
19 |
20 | ### One-Time Release
21 |
22 | 1. Create a new [GitHub release](https://github.com/activecm/BeaKer/releases)
23 | - Name both the tag and the release with the version (e.g. `v1.0.0`)
24 | - Optionally upload assets to be included (*see below)
25 | 2. Publish the release. After a few minutes the assets will be automatically generated and attached to the release.
26 |
27 | *Optional manual asset generation
28 |
29 | Even if you do not attach any assets to a release they will be automatically generated and uploaded for you. If needed, you can upload `BeaKer.tar` manually before publishing the release. Run the script `installer/generate_installer.sh` on a clean working directory to generate `BeaKer.tar` (see the [`generate_installer.sh`](#generate_installersh) section below for more information on this script).
30 |
31 | ### Pre-Releases
32 |
33 | 1. Create a new [GitHub release](https://github.com/activecm/BeaKer/releases)
34 | - Name the tag with the current release candidate revision (e.g. `v1.0.0-rc1`)
35 | - Name the release with the version (e.g. `v1.0.0`)
36 | - Check the box to mark the release as a pre-release
37 |
38 | 
39 |
40 | 2. Publish the release. After a few minutes the assets will be automatically generated and attached to the release.
41 |
42 | 
43 |
44 | **For subsequent test releases:**
45 |
46 | 3. Edit the release and perform the following:
47 | - Edit the release message. This usually means adding the new change's summary to the changelog.
48 | - Increment the version tag to be the next rc revision (e.g. `v1.0.0-rc2`). This ensures new changes in master will be included.
49 | - Delete the existing `BeaKer.tar` asset that is attached (and any other assets). This ensures the asset will be regenerated.
50 | - Save the changes to the pre-release.
51 |
52 | 
53 |
54 | 4. Repeat step 3 as needed.
55 |
56 | **When ready to publish a final version:**
57 |
58 | 5. Edit the release. Since no further changes have been made there is no need to edit the release message or regenerate `BeaKer.tar` or other assets. The latest release candidate has now become the final version so all that remains is adding the final version tag.
59 | - Change the version tag and remove the rc revision (e.g. `v1.0.0-rc2` -> `v1.0.0`).
60 | - Uncheck the pre-release box and publish the release.
61 |
62 | 
63 |
64 | ### Notes
65 |
66 | The steps above were written with the following behaviors in mind. Use these as a reference if you need to troubleshoot, modify the workflow, or Github's behavior changes.
67 |
68 | - An installer `BeaKer.tar` is generated and uploaded as a release asset whenever a release is created or edited. This is triggered by the `release.yml` workflow.
69 | - This does not apply to "draft" releases. But it applies to pre-releases.
70 | - When you first create a release you make a tag from a specific branch. Even if you edit the content of a release later it keeps the original tag referencing the original commit. This means that if you add new commits to the branch, you will need to create a new tag in order to have the release inclued the new commits.
71 | - In order to trigger the "edited" event in the workflow you have to actually change the release message.
72 | - If the `BeaKer.tar` asset already exists in a release it will not be replaced. In order to have it regenerated and replaced you need to delete the `BeaKer.tar` file when editing the release.
73 | - Check https://github.com/activecm/BeaKer/actions/ if your release is not being automatically generated to troubleshoot.
74 | - Updating the `release.yml` workflow seems to only apply in the master branch. If you need to debug or make changes to the workflow it is best to fork the repository and test there first.
75 |
76 | ## Component Overview
77 |
78 | ### `install_beaker.sh`
79 |
80 | `install_beaker.sh` installs Docker, Docker-Compose, and the BeaKer server on the local machine.
81 |
82 | ```bash
83 | installer/stage/install_beaker.sh
84 | ```
85 |
86 | ### `stage`
87 |
88 | The stage folder holds exactly one folder which will be what the user sees when they unpack the corresponding tarball.
89 |
90 | In order to add a file to the release tarball, either create a file inside the `stage` directory, or symlink it in with `ln -s`.
91 |
92 | You can also modify the `generate_installer.sh` script to download or generate a file in the `stage` directory, but then be sure you add the name of this file to the `stage/.gitignore` file to avoid committing it.
93 |
94 | ### `generate_installer.sh`
95 |
96 | The stage directory is built into a corresponding tarball by the accompanying `generate_installer.sh` file.
97 |
98 | ```bash
99 | installer/generate_installer.sh
100 | ```
101 |
102 | #### Detailed Usage
103 |
104 | By default, the script will pull all latest base images from the remote container repos and then force a local rebuild from scratch (i.e. not using the cache). This reasonably ensures everything is up to date and there are no issues caused by caching. It doesn't (yet) prevent you from having uncomitted or untagged changes to your local source code so beware of this.
105 |
106 | Additionally, the installer script has options that can be used to speed up development or testing the installer archives generated.
107 |
108 | ```
109 | --use-cache Builds Docker images using the local cache.
110 | --no-pull Do not pull the latest base images from the container
111 | repository during the build process.
112 | --no-build Do not build Docker images from scratch. This requires
113 | you to have the images already built on your system. (Implies --no-pull)
114 | ```
115 |
116 | For instance, if you just finished manually building your images that you want to test you can generate an installer that uses those instead of rebuilding its own.
117 |
118 | ```bash
119 | scripts/installer/generate_installer.sh --no-build
120 | ```
121 |
122 | Or if you want to have the installer do a fresh build but you are fine speeding the process up by using the local build cache and don't care to fetch the latest remote images you can run it this way.
123 |
124 | ```bash
125 | scripts/installer/generate_installer.sh --use-cache --no-pull
126 | ```
127 |
--------------------------------------------------------------------------------
/elasticsearch/Dockerfile:
--------------------------------------------------------------------------------
1 | ARG ELK_STACK_VERSION
2 |
3 | FROM docker.elastic.co/elasticsearch/elasticsearch:${ELK_STACK_VERSION}
4 | ADD ./elasticsearch.yml /usr/share/elasticsearch/config/elasticsearch.yml
5 | RUN mkdir /usr/share/elasticsearch/snapshots
6 | # The elasticsearch container runs under the elasticsearch user
7 | # Make sure that the elasticsearch user has permission to read/save snapshots
8 | # Since this directory is a bind mount, give all users read/write permissions
9 | # in order to avoid flaky write permissions when creating snapshots
10 | RUN chmod -R 777 /usr/share/elasticsearch/snapshots
11 |
12 |
--------------------------------------------------------------------------------
/elasticsearch/elasticsearch.yml:
--------------------------------------------------------------------------------
1 | ---
2 | cluster.name: "AI-Hunter-Docker-Single-Node"
3 | network.host: 0.0.0.0
4 |
5 | discovery.type: single-node
6 |
7 | xpack.security.enabled: true
8 |
9 | xpack.security.transport.ssl.enabled: true
10 | xpack.security.transport.ssl.verification_mode: certificate
11 | xpack.security.transport.ssl.certificate_authorities: [ "/usr/share/elasticsearch/config/certificates/ca/ca.crt" ]
12 | xpack.security.transport.ssl.certificate: /usr/share/elasticsearch/config/certificates/Elasticsearch/Elasticsearch.crt
13 | xpack.security.transport.ssl.key: /usr/share/elasticsearch/config/certificates/Elasticsearch/Elasticsearch.key
14 |
15 | xpack.security.http.ssl.enabled: true
16 | xpack.security.http.ssl.certificate_authorities: [ "/usr/share/elasticsearch/config/certificates/ca/ca.crt" ]
17 | xpack.security.http.ssl.certificate: /usr/share/elasticsearch/config/certificates/Elasticsearch/Elasticsearch.crt
18 | xpack.security.http.ssl.key: /usr/share/elasticsearch/config/certificates/Elasticsearch/Elasticsearch.key
19 | path.repo: ["/usr/share/elasticsearch/snapshots"]
--------------------------------------------------------------------------------
/elasticsearch/export_day.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Grab input arguments
4 | if [ "$#" -ne 2 ]; then
5 | echo "Usage: ./export_day.sh day_to_save (format: YYYY-MM-DD) output/directory"
6 | exit 1
7 | fi
8 |
9 | day="$1"
10 | output_dir=`realpath "$2"`
11 | index_name="sysmon-$day"
12 |
13 | # Change dir to script parent dir after calling realpath on the output directory
14 | pushd "$(dirname "${BASH_SOURCE[0]}")/.." > /dev/null
15 |
16 | # Use main function for local vars to hold sensitive info
17 | main() {
18 |
19 | mkdir -p "$output_dir/$index_name"
20 |
21 |
22 | local username=""
23 | IFS="" read -es -p "Elasticsearch Username: " username
24 | echo ""
25 | local password=""
26 | IFS="" read -es -p "Elasticsearch Password: " password
27 | echo ""
28 |
29 | previous_day=$(date --date="${day} -1 day" +%Y-%m-%d)
30 |
31 | # Export winlogbeat-* data by matching on winlogbeat data stream ALIAS
32 | ./beaker run -v "$output_dir/$index_name:/exports:rw" \
33 | --entrypoint multielasticdump es-dump \
34 | --direction=dump \
35 | --input="https://$username:$password@elasticsearch:9200" \
36 | --output="/exports" \
37 | --includeType="data,mapping" \
38 | --match="^winlogbeat-.*$" \
39 | --searchBody="{\"query\":{\"range\":{\"@timestamp\": {\"gt\": \"${previous_day}\", \"lte\": \"${day}\"}}}}"
40 |
41 |
42 | tar -C "$output_dir" -czf "$output_dir/$index_name.tar.gz" "$index_name"
43 | rm -rf "$output_dir/$index_name"
44 | }
45 |
46 | main
47 |
48 | # Change back to original directory
49 | popd > /dev/null
50 |
--------------------------------------------------------------------------------
/elasticsearch/export_index.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Grab input arguments
4 | if [ "$#" -ne 2 ]; then
5 | echo "Usage: ./export_index.sh index_to_save output/directory"
6 | exit 1
7 | fi
8 |
9 | index_name="$1"
10 | output_dir=`realpath "$2"`
11 |
12 | # Change dir to script parent dir after calling realpath on the output directory
13 | pushd "$(dirname "${BASH_SOURCE[0]}")/.." > /dev/null
14 |
15 | # Use main function for local vars to hold sensitive info
16 | main() {
17 |
18 | mkdir -p "$output_dir/$index_name"
19 |
20 |
21 | local username=""
22 | IFS="" read -es -p "Elasticsearch Username: " username
23 | echo ""
24 | local password=""
25 | IFS="" read -es -p "Elasticsearch Password: " password
26 | echo ""
27 |
28 | ./beaker run -v "$output_dir/$index_name:/exports:rw" --entrypoint multielasticdump es-dump --input="https://$username:$password@elasticsearch:9200" --output="/exports" --includeType="data,mapping" --match="^$index_name\$"
29 |
30 | tar -C "$output_dir" -czf "$output_dir/$index_name.tar.gz" "$index_name"
31 | rm -rf "$output_dir/$index_name"
32 | }
33 |
34 | main
35 |
36 | # Change back to original directory
37 | popd > /dev/null
38 |
--------------------------------------------------------------------------------
/elasticsearch/import_index.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Grab input arguments
4 | if [ "$#" -ne 1 ]; then
5 | echo "Usage: ./import_index.sh path/to/archive.tar"
6 | exit 1
7 | fi
8 |
9 | input_tar=`realpath "$1"`
10 |
11 | # Change dir to script parent dir after calling realpath on the output directory
12 | pushd "$(dirname "${BASH_SOURCE[0]}")/.." > /dev/null
13 |
14 | # Use main function for local vars to hold sensitive info
15 | main() {
16 | local input_tar_dir=`dirname "$input_tar"`
17 | local index_name=`tar --exclude='*/*' -tf "$input_tar"`
18 |
19 | tar -xf "$input_tar" -C "$input_tar_dir"
20 | local index_dir="$input_tar_dir/$index_name"
21 |
22 | local username=""
23 | IFS="" read -es -p "Elasticsearch Username: " username
24 | echo ""
25 | local password=""
26 | IFS="" read -es -p "Elasticsearch Password: " password
27 | echo ""
28 | ./beaker run -v "$index_dir:/$index_name" --entrypoint multielasticdump es-dump --direction=load --input="/$index_name" --output="https://$username:$password@elasticsearch:9200"
29 |
30 | rm -rf "$index_dir"
31 | }
32 |
33 | main
34 |
35 | # Change back to original directory
36 | popd > /dev/null
37 |
--------------------------------------------------------------------------------
/elasticsearch/reset_elastic_password.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | # Change dir to script dir
5 | pushd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" > /dev/null
6 |
7 | main() {
8 | echo "Please enter a password for the admin Elasticsearch user account."
9 | echo "Username: elastic"
10 | local elastic_password=""
11 | local pw_confirmation="foobar"
12 | while [ "$elastic_password" != "$pw_confirmation" ]; do
13 | read -es -p "Password: " elastic_password
14 | echo ""
15 | read -es -p "Password (Confirmation): " pw_confirmation
16 | echo ""
17 | done
18 |
19 | echo "Creating temporary local admin to change the elastic account password" >&2
20 | local temp_pass=`apg -a 0 -m 12 -x 12 -M NCL -E '015|=' -n 1`
21 |
22 | beaker exec elasticsearch /usr/share/elasticsearch/bin/elasticsearch-users userdel temp_admin > /dev/null || true
23 | beaker exec elasticsearch /usr/share/elasticsearch/bin/elasticsearch-users useradd temp_admin -p "$temp_pass" -r superuser
24 |
25 | echo "Updating the elastic account password via REST interface" >&2
26 | sleep 5
27 |
28 | curl --fail -k -s -u temp_admin:"$temp_pass" -XPUT "https://localhost:9200/_xpack/security/user/elastic/_password?pretty" -H 'Content-Type: application/json' -d"
29 | {
30 | \"password\" : \"$elastic_password\"
31 | }
32 | "
33 |
34 | echo "Removing temporary local admin" >&2
35 | beaker exec elasticsearch /usr/share/elasticsearch/bin/elasticsearch-users userdel temp_admin
36 |
37 | local BEAKER_CONFIG_DIR=${BEAKER_CONFIG_DIR:-/etc/BeaKer}
38 | echo "Updating Kibana configuration in $BEAKER_CONFIG_DIR/env" >&2
39 | sudo sed --in-place=bak "s/^ELASTIC_PASSWORD=.*\$/ELASTIC_PASSWORD=$elastic_password/" "$BEAKER_CONFIG_DIR"/env
40 |
41 | beaker down
42 | beaker up -d
43 | }
44 |
45 | main
46 |
47 | # Change back to original directory
48 | popd > /dev/null
--------------------------------------------------------------------------------
/images/BeaKer_demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/activecm/BeaKer/f3b777e636ea1ff8d1ca133dfa6ff434bc3ae76f/images/BeaKer_demo.gif
--------------------------------------------------------------------------------
/images/BeaKer_demo_bottom.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/activecm/BeaKer/f3b777e636ea1ff8d1ca133dfa6ff434bc3ae76f/images/BeaKer_demo_bottom.png
--------------------------------------------------------------------------------
/images/BeaKer_demo_top.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/activecm/BeaKer/f3b777e636ea1ff8d1ca133dfa6ff434bc3ae76f/images/BeaKer_demo_top.png
--------------------------------------------------------------------------------
/installer/.gitignore:
--------------------------------------------------------------------------------
1 | *.tar
2 | *.tar.gz
3 |
--------------------------------------------------------------------------------
/installer/generate_installer.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | set -e
4 |
5 | # Store the absolute path of the script's dir and switch to the top dir
6 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7 | pushd "$SCRIPT_DIR/../" > /dev/null
8 |
9 | # Read in the versions that will be distributed with this release
10 | readarray elk_versions < ./ELK_VERSIONS
11 | # These images are exported in the deployment after running pulls/builds
12 | DOCKER_EXPORT_IMAGES="taskrabbit/elasticsearch-dump:v6.28.0\n"
13 | DOCKER_EXPORT_IMAGES="${DOCKER_EXPORT_IMAGES}activecm-beaker/check_kibana:latest\n"
14 |
15 | # Create elasticsearch & kibana images for each version defined in ELK_VERSIONS
16 | for version in "${elk_versions[@]}"; do
17 | DOCKER_EXPORT_IMAGES="${DOCKER_EXPORT_IMAGES}activecm-beaker/elasticsearch:$version"
18 | DOCKER_EXPORT_IMAGES="${DOCKER_EXPORT_IMAGES}activecm-beaker/kibana:$version"
19 | done
20 | DOCKER_EXPORT_IMAGES=$(echo -e "$DOCKER_EXPORT_IMAGES")
21 | echo "###### EXPORTING THE FOLLOWING IMAGES: ######"
22 | echo "$DOCKER_EXPORT_IMAGES"
23 |
24 | # These services are always built unless --no-build is passed in
25 | DOCKER_BUILD_SERVICES="elasticsearch kibana check_kibana"
26 | # These services are always pulled unless --no-pull is passsed in
27 | DOCKER_PULL_SERVICES="es-dump"
28 |
29 | __help() {
30 | cat <]
35 | Options:
36 | -h|--help Show this help message.
37 | --use-cache Builds Docker images using the local cache.
38 | --no-pull Do not pull the latest base images from the container
39 | repository during the build process.
40 | --no-build Do not build Docker images from scratch. This requires
41 | you to have the images already built on your system. (Implies --no-pull)
42 | HEREDOC
43 | }
44 |
45 | NO_CACHE="--no-cache"
46 |
47 | # Parse through command args
48 | while [[ $# -gt 0 ]]; do
49 | case $1 in
50 | -h|--help)
51 | # Display help and exit
52 | __help
53 | exit 0
54 | ;;
55 | --use-cache)
56 | NO_CACHE=""
57 | ;;
58 | --no-build)
59 | NO_BUILD="--no-build"
60 | ;;
61 | --no-pull)
62 | NO_PULL="--no-pull"
63 | ;;
64 | *)
65 | ;;
66 | esac
67 | shift
68 | done
69 |
70 | # File/ Directory Names
71 | DOCKER_IMAGE_OUT=images-latest
72 | BEAKER_ARCHIVE=BeaKer
73 |
74 | STAGE_DIR="$SCRIPT_DIR/stage/$BEAKER_ARCHIVE"
75 |
76 | # Make sure we can use docker-compose
77 | shell-lib/docker/check_docker.sh || {
78 | echo -e "\e[93mWARNING\e[0m: The generator did not detect a supported version of Docker."
79 | echo " A supported version of Docker can be installed by running"
80 | echo " the install_docker.sh script in the scripts directory."
81 | }
82 | shell-lib/docker/check_docker-compose.sh || {
83 | echo -e "\e[93mWARNING\e[0m: The generator did not detect a supported version of Docker-Compose."
84 | echo " A supported version of Docker-Compose can be installed by running"
85 | echo " the install_docker.sh script in the scripts directory."
86 | }
87 |
88 | export COMPOSE_FILE="docker-compose.yml"
89 |
90 | # If the current user doesn't have docker permissions run with sudo
91 | SUDO=
92 | SUDO_E=
93 | if [ ! -w "/var/run/docker.sock" ]; then
94 | SUDO="sudo"
95 | SUDO_E='sudo -E'
96 | fi
97 |
98 | if [ ! "$NO_BUILD" ]; then
99 | if [ "$NO_PULL" ]; then
100 | echo "The latest images will *not* be pulled from DockerHub for this build."
101 | $SUDO docker-compose build $NO_CACHE $DOCKER_BUILD_SERVICES
102 | else
103 | # Ensure we have the latest images
104 | echo "The latest images will be pulled from DockerHub for this build."
105 | $SUDO docker-compose pull $DOCKER_PULL_SERVICES
106 | for version in "${elk_versions[@]}"; do
107 | v=$(echo $version|tr -d '\n')
108 | export ELK_STACK_VERSION="$v"
109 | $SUDO_E docker-compose build --build-arg ELK_STACK_VERSION="$v" --pull $NO_CACHE $DOCKER_BUILD_SERVICES
110 | done
111 | fi
112 | fi
113 |
114 | echo "Exporting docker images... This may take a few minutes."
115 | $SUDO docker save $DOCKER_EXPORT_IMAGES | gzip -c - > "$STAGE_DIR/${DOCKER_IMAGE_OUT}.tar.gz"
116 |
117 | echo "Creating BeaKer installer archive..."
118 | # This has the result of only including the files we want
119 | # but putting them in a single directory so they extract nicely
120 | tar -C "$STAGE_DIR/.." --exclude '.*' -chf "$SCRIPT_DIR/${BEAKER_ARCHIVE}.tar" $BEAKER_ARCHIVE
121 |
122 | popd > /dev/null
123 |
--------------------------------------------------------------------------------
/installer/stage/BeaKer/.gitignore:
--------------------------------------------------------------------------------
1 | *.tar
2 | *.tar.gz
3 |
--------------------------------------------------------------------------------
/installer/stage/BeaKer/ELK_VERSIONS:
--------------------------------------------------------------------------------
1 | ../../../ELK_VERSIONS
--------------------------------------------------------------------------------
/installer/stage/BeaKer/beaker:
--------------------------------------------------------------------------------
1 | ../../../beaker
--------------------------------------------------------------------------------
/installer/stage/BeaKer/check_kibana/DO_NOT_DELETE:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/activecm/BeaKer/f3b777e636ea1ff8d1ca133dfa6ff434bc3ae76f/installer/stage/BeaKer/check_kibana/DO_NOT_DELETE
--------------------------------------------------------------------------------
/installer/stage/BeaKer/docker-compose.yml:
--------------------------------------------------------------------------------
1 | ../../../docker-compose.yml
--------------------------------------------------------------------------------
/installer/stage/BeaKer/elasticsearch/DO_NOT_DELETE:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/activecm/BeaKer/f3b777e636ea1ff8d1ca133dfa6ff434bc3ae76f/installer/stage/BeaKer/elasticsearch/DO_NOT_DELETE
--------------------------------------------------------------------------------
/installer/stage/BeaKer/elasticsearch/export_day.sh:
--------------------------------------------------------------------------------
1 | ../../../../elasticsearch/export_day.sh
--------------------------------------------------------------------------------
/installer/stage/BeaKer/elasticsearch/export_index.sh:
--------------------------------------------------------------------------------
1 | ../../../../elasticsearch/export_index.sh
--------------------------------------------------------------------------------
/installer/stage/BeaKer/elasticsearch/import_index.sh:
--------------------------------------------------------------------------------
1 | ../../../../elasticsearch/import_index.sh
--------------------------------------------------------------------------------
/installer/stage/BeaKer/elasticsearch/templates/DO_NOT_DELETE:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/activecm/BeaKer/f3b777e636ea1ff8d1ca133dfa6ff434bc3ae76f/installer/stage/BeaKer/elasticsearch/templates/DO_NOT_DELETE
--------------------------------------------------------------------------------
/installer/stage/BeaKer/elasticsearch/templates/winlogbeat-8.7.0-powershell.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "Pipeline for Windows Powershell events",
3 | "processors": [
4 | {
5 | "kv": {
6 | "field": "winlog.event_data.param2",
7 | "target_field": "winlog.event_data",
8 | "field_split": "\n\t",
9 | "trim_key": "\n\t",
10 | "trim_value": "\n\t",
11 | "value_split": "=",
12 | "if": "ctx?.winlog?.event_id == \"800\"",
13 | "description": "Split Event 800 event data fields."
14 | }
15 | },
16 | {
17 | "kv": {
18 | "value_split": "=",
19 | "if": "ctx?.winlog?.event_id != \"800\"",
20 | "description": "Split Events 4xx and 600 event data fields.",
21 | "field": "winlog.event_data.param3",
22 | "target_field": "winlog.event_data",
23 | "field_split": "\n\t",
24 | "trim_key": "\n\t",
25 | "trim_value": "\n\t"
26 | }
27 | },
28 | {
29 | "set": {
30 | "field": "ecs.version",
31 | "value": "1.12.0"
32 | }
33 | },
34 | {
35 | "set": {
36 | "copy_from": "winlog.level",
37 | "ignore_empty_value": true,
38 | "ignore_failure": true,
39 | "if": "ctx?.winlog?.level != \"\"",
40 | "field": "log.level"
41 | }
42 | },
43 | {
44 | "date": {
45 | "if": "ctx?.winlog?.time_created != null",
46 | "field": "winlog.time_created",
47 | "formats": [
48 | "ISO8601"
49 | ],
50 | "ignore_failure": true
51 | }
52 | },
53 | {
54 | "set": {
55 | "field": "event.module",
56 | "value": "powershell"
57 | }
58 | },
59 | {
60 | "set": {
61 | "value": "event",
62 | "field": "event.kind"
63 | }
64 | },
65 | {
66 | "set": {
67 | "value": "{{winlog.event_id}}",
68 | "field": "event.code"
69 | }
70 | },
71 | {
72 | "set": {
73 | "value": "process",
74 | "field": "event.category"
75 | }
76 | },
77 | {
78 | "set": {
79 | "if": "ctx?.event.code == \"400\"",
80 | "field": "event.type",
81 | "value": "start"
82 | }
83 | },
84 | {
85 | "set": {
86 | "field": "event.type",
87 | "value": "end",
88 | "if": "ctx?.event.code == \"403\""
89 | }
90 | },
91 | {
92 | "set": {
93 | "field": "event.type",
94 | "value": "info",
95 | "if": "ctx?.event?.type == null"
96 | }
97 | },
98 | {
99 | "convert": {
100 | "field": "winlog.event_data.SequenceNumber",
101 | "target_field": "event.sequence",
102 | "type": "long",
103 | "ignore_failure": true,
104 | "ignore_missing": true
105 | }
106 | },
107 | {
108 | "convert": {
109 | "field": "winlog.record_id",
110 | "type": "string",
111 | "ignore_failure": true,
112 | "ignore_missing": true
113 | }
114 | },
115 | {
116 | "rename": {
117 | "if": "ctx?.winlog?.event_data?.HostId != \"\"",
118 | "field": "winlog.event_data.HostId",
119 | "target_field": "process.entity_id",
120 | "ignore_failure": true,
121 | "ignore_missing": true
122 | }
123 | },
124 | {
125 | "rename": {
126 | "field": "winlog.event_data.HostApplication",
127 | "target_field": "process.command_line",
128 | "ignore_failure": true,
129 | "ignore_missing": true,
130 | "if": "ctx?.winlog?.event_data?.HostApplication != \"\""
131 | }
132 | },
133 | {
134 | "rename": {
135 | "field": "winlog.event_data.HostName",
136 | "target_field": "process.title",
137 | "ignore_failure": true,
138 | "ignore_missing": true,
139 | "if": "ctx?.winlog?.event_data?.HostName != \"\""
140 | }
141 | },
142 | {
143 | "split": {
144 | "field": "winlog.event_data.UserId",
145 | "target_field": "_temp.user_parts",
146 | "separator": "\\\\",
147 | "if": "ctx?.winlog?.event_data?.UserId != null"
148 | }
149 | },
150 | {
151 | "set": {
152 | "ignore_empty_value": true,
153 | "if": "ctx?._temp?.user_parts != null && ctx._temp.user_parts.size() == 2",
154 | "field": "user.domain",
155 | "value": "{{_temp.user_parts.0}}",
156 | "ignore_failure": true
157 | }
158 | },
159 | {
160 | "set": {
161 | "ignore_failure": true,
162 | "ignore_empty_value": true,
163 | "if": "ctx?._temp?.user_parts != null && ctx._temp.user_parts.size() == 2",
164 | "field": "user.name",
165 | "value": "{{_temp.user_parts.1}}"
166 | }
167 | },
168 | {
169 | "append": {
170 | "field": "related.user",
171 | "value": "{{user.name}}",
172 | "ignore_failure": true,
173 | "allow_duplicates": false,
174 | "if": "ctx?.user?.name != null"
175 | }
176 | },
177 | {
178 | "rename": {
179 | "ignore_failure": true,
180 | "ignore_missing": true,
181 | "if": "ctx?.winlog?.event_data?.NewEngineState != \"\"",
182 | "field": "winlog.event_data.NewEngineState",
183 | "target_field": "powershell.engine.new_state"
184 | }
185 | },
186 | {
187 | "rename": {
188 | "target_field": "powershell.engine.previous_state",
189 | "ignore_failure": true,
190 | "ignore_missing": true,
191 | "if": "ctx?.winlog?.event_data?.PreviousEngineState != \"\"",
192 | "field": "winlog.event_data.PreviousEngineState"
193 | }
194 | },
195 | {
196 | "rename": {
197 | "if": "ctx?.winlog?.event_data?.NewProviderState != \"\"",
198 | "field": "winlog.event_data.NewProviderState",
199 | "target_field": "powershell.provider.new_state",
200 | "ignore_failure": true,
201 | "ignore_missing": true
202 | }
203 | },
204 | {
205 | "rename": {
206 | "field": "winlog.event_data.ProviderName",
207 | "target_field": "powershell.provider.name",
208 | "ignore_failure": true,
209 | "ignore_missing": true,
210 | "if": "ctx?.winlog?.event_data?.ProviderName != \"\""
211 | }
212 | },
213 | {
214 | "convert": {
215 | "ignore_missing": true,
216 | "if": "ctx?.winlog?.event_data?.DetailTotal != \"\"",
217 | "field": "winlog.event_data.DetailTotal",
218 | "target_field": "powershell.total",
219 | "type": "long",
220 | "ignore_failure": true
221 | }
222 | },
223 | {
224 | "convert": {
225 | "field": "winlog.event_data.DetailSequence",
226 | "target_field": "powershell.sequence",
227 | "type": "long",
228 | "ignore_failure": true,
229 | "ignore_missing": true,
230 | "if": "ctx?.winlog?.event_data?.DetailSequence != \"\""
231 | }
232 | },
233 | {
234 | "rename": {
235 | "if": "ctx?.winlog?.event_data?.EngineVersion != \"\"",
236 | "field": "winlog.event_data.EngineVersion",
237 | "target_field": "powershell.engine.version",
238 | "ignore_missing": true,
239 | "ignore_failure": true
240 | }
241 | },
242 | {
243 | "rename": {
244 | "ignore_missing": true,
245 | "ignore_failure": true,
246 | "if": "ctx?.winlog?.event_data?.PipelineId != \"\"",
247 | "field": "winlog.event_data.PipelineId",
248 | "target_field": "powershell.pipeline_id"
249 | }
250 | },
251 | {
252 | "rename": {
253 | "field": "winlog.event_data.RunspaceId",
254 | "target_field": "powershell.runspace_id",
255 | "ignore_missing": true,
256 | "ignore_failure": true,
257 | "if": "ctx?.winlog?.event_data?.RunspaceId != \"\""
258 | }
259 | },
260 | {
261 | "rename": {
262 | "field": "winlog.event_data.HostVersion",
263 | "target_field": "powershell.process.executable_version",
264 | "ignore_missing": true,
265 | "ignore_failure": true,
266 | "if": "ctx?.winlog?.event_data?.HostVersion != \"\""
267 | }
268 | },
269 | {
270 | "rename": {
271 | "ignore_failure": true,
272 | "ignore_missing": true,
273 | "if": "ctx?.winlog?.event_data?.CommandLine != \"\"",
274 | "field": "winlog.event_data.CommandLine",
275 | "target_field": "powershell.command.value"
276 | }
277 | },
278 | {
279 | "rename": {
280 | "target_field": "powershell.command.path",
281 | "ignore_failure": true,
282 | "ignore_missing": true,
283 | "if": "ctx?.winlog?.event_data?.CommandPath != \"\"",
284 | "field": "winlog.event_data.CommandPath"
285 | }
286 | },
287 | {
288 | "rename": {
289 | "field": "winlog.event_data.CommandName",
290 | "target_field": "powershell.command.name",
291 | "ignore_failure": true,
292 | "ignore_missing": true,
293 | "if": "ctx?.winlog?.event_data?.CommandName != \"\""
294 | }
295 | },
296 | {
297 | "rename": {
298 | "ignore_missing": true,
299 | "if": "ctx?.winlog?.event_data?.CommandType != \"\"",
300 | "field": "winlog.event_data.CommandType",
301 | "target_field": "powershell.command.type",
302 | "ignore_failure": true
303 | }
304 | },
305 | {
306 | "split": {
307 | "description": "Split Event 800 command invocation details.",
308 | "field": "winlog.event_data.param3",
309 | "separator": "\n",
310 | "ignore_failure": true,
311 | "ignore_missing": true,
312 | "if": "ctx.event.code == \"800\""
313 | }
314 | },
315 | {
316 | "script": {
317 | "lang": "painless",
318 | "if": "ctx.event.code == \"800\"",
319 | "params": {
320 | "field": "param3"
321 | },
322 | "source": "def parseRawDetail(String raw) {\n Pattern detailRegex = /^([^:(]+)\\((.+)\\)\\:\\s*(.+)?$/;\n Pattern parameterBindingRegex = /name\\=(.+);\\s*value\\=(.+)$/;\n\n def matcher = detailRegex.matcher(raw);\n if (!matcher.matches()) {\n return [\"value\": raw];\n }\n def matches = new ArrayList();\n for (def i = 0; i <= matcher.groupCount(); i++) {\n matches.add(matcher.group(i));\n }\n \n if (matches.length != 4) {\n return [\"value\": raw];\n } \n \n if (matches[1] != \"ParameterBinding\") {\n return [\n \"type\": matches[1], \n \"related_command\": matches[2], \n \"value\": matches[3]\n ];\n }\n\n matcher = parameterBindingRegex.matcher(matches[3]);\n if (!matcher.matches()) {\n return [\"value\": matches[4]];\n }\n def nameValMatches = new ArrayList();\n for (def i = 0; i <= matcher.groupCount(); i++) {\n nameValMatches.add(matcher.group(i));\n }\n if (nameValMatches.length !== 3) {\n return [\"value\": matches[3]];\n }\n\n return [\n \"type\": matches[1],\n \"related_command\": matches[2],\n \"name\": nameValMatches[1],\n \"value\": nameValMatches[2]\n ];\n}\n\nif (ctx?._temp == null) {\n ctx._temp = new HashMap();\n}\n\nif (ctx._temp.details == null) {\n ctx._temp.details = new ArrayList();\n}\n\ndef values = ctx?.winlog?.event_data[params[\"field\"]];\nif (values != null && values.length > 0) {\n for (v in values) {\n ctx._temp.details.add(parseRawDetail(v));\n }\n}",
323 | "description": "Parses all command invocation detail raw lines, and converts them to an object, based on their type.\n - for unexpectedly formatted ones: {value: \"the raw line as it is\"}\n - for all:\n * related_command: describes to what command it is related to\n * value: the value for that detail line\n * type: the type of the detail line, i.e.: CommandInvocation, ParameterBinding, NonTerminatingError\n - additionally, ParameterBinding adds a `name` field with the parameter name being bound."
324 | }
325 | },
326 | {
327 | "rename": {
328 | "if": "ctx?._temp?.details != null && ctx?._temp?.details.length > 0",
329 | "field": "_temp.details",
330 | "target_field": "powershell.command.invocation_details"
331 | }
332 | },
333 | {
334 | "script": {
335 | "description": "Implements Windows-like SplitCommandLine",
336 | "lang": "painless",
337 | "if": "ctx?.process?.command_line != null && ctx.process.command_line != \"\"",
338 | "source": "// appendBSBytes appends n '\\\\' bytes to b and returns the resulting slice.\ndef appendBSBytes(StringBuilder b, int n) {\n for (; n > 0; n--) {\n b.append('\\\\');\n }\n return b;\n}\n\n// readNextArg splits command line string cmd into next\n// argument and command line remainder.\ndef readNextArg(String cmd) {\n def b = new StringBuilder();\n boolean inquote;\n int nslash;\n for (; cmd.length() > 0; cmd = cmd.substring(1)) {\n def c = cmd.charAt(0);\n if (c == (char)' ' || c == (char)0x09) {\n if (!inquote) {\n return [\n \"arg\": appendBSBytes(b, nslash).toString(),\n \"rest\": cmd.substring(1)\n ];\n }\n } else if (c == (char)'\"') {\n b = appendBSBytes(b, nslash/2);\n if (nslash%2 == 0) {\n // use \"Prior to 2008\" rule from\n // http://daviddeley.com/autohotkey/parameters/parameters.htm\n // section 5.2 to deal with double double quotes\n if (inquote && cmd.length() > 1 && cmd.charAt(1) == (char)'\"') {\n b.append(c);\n cmd = cmd.substring(1);\n }\n inquote = !inquote;\n } else {\n b.append(c);\n }\n nslash = 0;\n continue;\n } else if (c == (char)'\\\\') {\n nslash++;\n continue;\n }\n b = appendBSBytes(b, nslash);\n nslash = 0;\n b.append(c);\n }\n return [\n \"arg\": appendBSBytes(b, nslash).toString(), \n \"rest\": ''\n ];\n}\n\n// commandLineToArgv splits a command line into individual argument\n// strings, following the Windows conventions documented\n// at http://daviddeley.com/autohotkey/parameters/parameters.htm#WINARGV\n// Original implementation found at: https://github.com/golang/go/commit/39c8d2b7faed06b0e91a1ad7906231f53aab45d1\ndef commandLineToArgv(String cmd) {\n def args = new ArrayList();\n while (cmd.length() > 0) {\n if (cmd.charAt(0) == (char)' ' || cmd.charAt(0) == (char)0x09) {\n cmd = cmd.substring(1);\n continue;\n }\n def next = readNextArg(cmd);\n cmd = next.rest;\n args.add(next.arg);\n }\n return args;\n}\n\nctx.process.args = commandLineToArgv(ctx.process.command_line);\nctx.process.args_count = ctx.process.args.length;"
339 | }
340 | },
341 | {
342 | "script": {
343 | "lang": "painless",
344 | "if": "ctx?.winlog?.event_data?.ScriptName != null && ctx.winlog.event_data.ScriptName.length() > 1",
345 | "source": "def path = ctx.winlog.event_data.ScriptName;\ndef idx = path.lastIndexOf(\"\\\\\");\nif (idx > -1) {\n if (ctx?.file == null) {\n ctx.file = new HashMap();\n }\n ctx.file.name = path.substring(idx+1);\n ctx.file.directory = path.substring(0, idx);\n\n def extIdx = path.lastIndexOf(\".\");\n if (extIdx > -1) {\n ctx.file.extension = path.substring(extIdx+1);\n }\n}",
346 | "description": "Adds file information."
347 | }
348 | },
349 | {
350 | "rename": {
351 | "ignore_missing": true,
352 | "if": "ctx?.winlog?.event_data?.ScriptName != \"\"",
353 | "field": "winlog.event_data.ScriptName",
354 | "target_field": "file.path",
355 | "ignore_failure": true
356 | }
357 | },
358 | {
359 | "remove": {
360 | "ignore_failure": true,
361 | "field": [
362 | "_temp",
363 | "winlog.event_data.param1",
364 | "winlog.event_data.param2",
365 | "winlog.event_data.param3",
366 | "winlog.event_data.SequenceNumber",
367 | "winlog.event_data.DetailTotal",
368 | "winlog.event_data.DetailSequence",
369 | "winlog.event_data.UserId",
370 | "winlog.time_created",
371 | "winlog.level"
372 | ],
373 | "ignore_missing": true
374 | }
375 | },
376 | {
377 | "script": {
378 | "lang": "painless",
379 | "source": "ctx?.winlog?.event_data?.entrySet().removeIf(entry -> entry.getValue() == null || entry.getValue().equals(\"\"));",
380 | "description": "Remove all empty values from event_data."
381 | }
382 | },
383 | {
384 | "remove": {
385 | "ignore_missing": true,
386 | "ignore_failure": true,
387 | "if": "ctx?.winlog?.event_data != null && ctx.winlog.event_data.size() == 0",
388 | "description": "Remove empty event data.",
389 | "field": "winlog.event_data"
390 | }
391 | }
392 | ],
393 | "on_failure": [
394 | {
395 | "set": {
396 | "value": "{{ _ingest.on_failure_message }}",
397 | "field": "error.message"
398 | }
399 | }
400 | ]
401 | }
--------------------------------------------------------------------------------
/installer/stage/BeaKer/elasticsearch/templates/winlogbeat-8.7.0-powershell_operational.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "Pipeline for Windows Powershell/Operational events",
3 | "processors": [
4 | {
5 | "kv": {
6 | "value_split": "=",
7 | "if": "ctx?.winlog?.event_id == \"4103\"",
8 | "description": "Split Event 4103 event data fields.",
9 | "field": "winlog.event_data.ContextInfo",
10 | "target_field": "winlog.event_data",
11 | "field_split": "\n",
12 | "trim_key": " \n\t",
13 | "trim_value": " \n\t"
14 | }
15 | },
16 | {
17 | "script": {
18 | "if": "ctx?.winlog?.event_data != null",
19 | "source": "def newEventData = new HashMap();\nfor (entry in ctx.winlog.event_data.entrySet()) {\n def newKey = /\\s/.matcher(entry.getKey().toString()).replaceAll(\"\");\n newEventData.put(newKey, entry.getValue());\n}\nctx.winlog.event_data = newEventData;",
20 | "description": "Remove spaces from all event_data keys.",
21 | "lang": "painless"
22 | }
23 | },
24 | {
25 | "set": {
26 | "field": "ecs.version",
27 | "value": "1.12.0"
28 | }
29 | },
30 | {
31 | "set": {
32 | "ignore_failure": true,
33 | "if": "ctx?.winlog?.level != \"\"",
34 | "field": "log.level",
35 | "copy_from": "winlog.level",
36 | "ignore_empty_value": true
37 | }
38 | },
39 | {
40 | "date": {
41 | "ignore_failure": true,
42 | "if": "ctx?.winlog?.time_created != null",
43 | "field": "winlog.time_created",
44 | "formats": [
45 | "ISO8601"
46 | ]
47 | }
48 | },
49 | {
50 | "set": {
51 | "field": "event.module",
52 | "value": "powershell"
53 | }
54 | },
55 | {
56 | "set": {
57 | "value": "event",
58 | "field": "event.kind"
59 | }
60 | },
61 | {
62 | "set": {
63 | "value": "{{winlog.event_id}}",
64 | "field": "event.code"
65 | }
66 | },
67 | {
68 | "set": {
69 | "field": "event.category",
70 | "value": "process"
71 | }
72 | },
73 | {
74 | "set": {
75 | "field": "event.type",
76 | "value": "start",
77 | "if": "ctx?.event.code == \"4105\""
78 | }
79 | },
80 | {
81 | "set": {
82 | "if": "ctx?.event.code == \"4106\"",
83 | "field": "event.type",
84 | "value": "end"
85 | }
86 | },
87 | {
88 | "set": {
89 | "field": "event.type",
90 | "value": "info",
91 | "if": "ctx?.event?.type == null"
92 | }
93 | },
94 | {
95 | "convert": {
96 | "ignore_missing": true,
97 | "field": "winlog.event_data.SequenceNumber",
98 | "target_field": "event.sequence",
99 | "type": "long",
100 | "ignore_failure": true
101 | }
102 | },
103 | {
104 | "convert": {
105 | "field": "winlog.record_id",
106 | "type": "string",
107 | "ignore_failure": true,
108 | "ignore_missing": true
109 | }
110 | },
111 | {
112 | "rename": {
113 | "ignore_failure": true,
114 | "ignore_missing": true,
115 | "if": "ctx?.winlog?.event_data?.HostID != \"\"",
116 | "field": "winlog.event_data.HostID",
117 | "target_field": "process.entity_id"
118 | }
119 | },
120 | {
121 | "rename": {
122 | "target_field": "process.command_line",
123 | "ignore_failure": true,
124 | "ignore_missing": true,
125 | "if": "ctx?.winlog?.event_data?.HostApplication != \"\"",
126 | "field": "winlog.event_data.HostApplication"
127 | }
128 | },
129 | {
130 | "rename": {
131 | "field": "winlog.event_data.HostName",
132 | "target_field": "process.title",
133 | "ignore_failure": true,
134 | "ignore_missing": true,
135 | "if": "ctx?.winlog?.event_data?.HostName != \"\""
136 | }
137 | },
138 | {
139 | "set": {
140 | "copy_from": "winlog.user.identifier",
141 | "ignore_failure": true,
142 | "ignore_empty_value": true,
143 | "field": "user.id"
144 | }
145 | },
146 | {
147 | "split": {
148 | "target_field": "_temp.user_parts",
149 | "separator": "\\\\",
150 | "if": "ctx?.winlog?.event_data?.User != null",
151 | "field": "winlog.event_data.User"
152 | }
153 | },
154 | {
155 | "set": {
156 | "field": "user.domain",
157 | "value": "{{_temp.user_parts.0}}",
158 | "ignore_failure": true,
159 | "ignore_empty_value": true,
160 | "if": "ctx?._temp?.user_parts != null && ctx._temp.user_parts.size() == 2"
161 | }
162 | },
163 | {
164 | "set": {
165 | "field": "user.name",
166 | "value": "{{_temp.user_parts.1}}",
167 | "ignore_failure": true,
168 | "ignore_empty_value": true,
169 | "if": "ctx?._temp?.user_parts != null && ctx._temp.user_parts.size() == 2"
170 | }
171 | },
172 | {
173 | "append": {
174 | "value": "{{user.name}}",
175 | "ignore_failure": true,
176 | "allow_duplicates": false,
177 | "if": "ctx?.user?.name != null",
178 | "field": "related.user"
179 | }
180 | },
181 | {
182 | "split": {
183 | "target_field": "_temp.connected_user_parts",
184 | "separator": "\\\\",
185 | "if": "ctx?.winlog?.event_data?.ConnectedUser != null",
186 | "field": "winlog.event_data.ConnectedUser"
187 | }
188 | },
189 | {
190 | "set": {
191 | "field": "source.user.domain",
192 | "value": "{{_temp.connected_user_parts.0}}",
193 | "ignore_failure": true,
194 | "ignore_empty_value": true,
195 | "if": "ctx?._temp?.connected_user_parts != null && ctx._temp.connected_user_parts.size() == 2"
196 | }
197 | },
198 | {
199 | "set": {
200 | "if": "ctx?._temp?.connected_user_parts != null && ctx._temp.connected_user_parts.size() == 2",
201 | "field": "source.user.name",
202 | "value": "{{_temp.connected_user_parts.1}}",
203 | "ignore_failure": true,
204 | "ignore_empty_value": true
205 | }
206 | },
207 | {
208 | "append": {
209 | "value": "{{source.user.name}}",
210 | "ignore_failure": true,
211 | "allow_duplicates": false,
212 | "if": "ctx?.source?.user?.name != null",
213 | "field": "related.user"
214 | }
215 | },
216 | {
217 | "rename": {
218 | "field": "user.domain",
219 | "target_field": "destination.user.domain",
220 | "ignore_failure": true,
221 | "ignore_missing": true,
222 | "if": "ctx?.source?.user != null"
223 | }
224 | },
225 | {
226 | "rename": {
227 | "ignore_missing": true,
228 | "if": "ctx?.source?.user != null",
229 | "field": "user.name",
230 | "target_field": "destination.user.name",
231 | "ignore_failure": true
232 | }
233 | },
234 | {
235 | "set": {
236 | "field": "user.domain",
237 | "copy_from": "source.user.domain",
238 | "ignore_failure": true,
239 | "ignore_empty_value": true,
240 | "if": "ctx?.source?.user != null"
241 | }
242 | },
243 | {
244 | "set": {
245 | "ignore_empty_value": true,
246 | "if": "ctx?.source?.user != null",
247 | "field": "user.name",
248 | "copy_from": "source.user.name",
249 | "ignore_failure": true
250 | }
251 | },
252 | {
253 | "convert": {
254 | "field": "winlog.event_data.MessageNumber",
255 | "target_field": "powershell.sequence",
256 | "type": "long",
257 | "ignore_failure": true,
258 | "ignore_missing": true
259 | }
260 | },
261 | {
262 | "convert": {
263 | "type": "long",
264 | "ignore_failure": true,
265 | "ignore_missing": true,
266 | "field": "winlog.event_data.MessageTotal",
267 | "target_field": "powershell.total"
268 | }
269 | },
270 | {
271 | "rename": {
272 | "if": "ctx?.winlog?.event_data?.ShellID != \"\"",
273 | "field": "winlog.event_data.ShellID",
274 | "target_field": "powershell.id",
275 | "ignore_failure": true,
276 | "ignore_missing": true
277 | }
278 | },
279 | {
280 | "rename": {
281 | "if": "ctx?.winlog?.event_data?.EngineVersion != \"\"",
282 | "field": "winlog.event_data.EngineVersion",
283 | "target_field": "powershell.engine.version",
284 | "ignore_missing": true,
285 | "ignore_failure": true
286 | }
287 | },
288 | {
289 | "rename": {
290 | "field": "winlog.event_data.PipelineID",
291 | "target_field": "powershell.pipeline_id",
292 | "ignore_missing": true,
293 | "ignore_failure": true,
294 | "if": "ctx?.winlog?.event_data?.PipelineID != \"\""
295 | }
296 | },
297 | {
298 | "rename": {
299 | "ignore_failure": true,
300 | "if": "ctx?.winlog?.event_data?.RunspaceID != \"\"",
301 | "field": "winlog.event_data.RunspaceID",
302 | "target_field": "powershell.runspace_id",
303 | "ignore_missing": true
304 | }
305 | },
306 | {
307 | "rename": {
308 | "field": "winlog.event_data.RunspaceId",
309 | "target_field": "powershell.runspace_id",
310 | "ignore_missing": true,
311 | "ignore_failure": true,
312 | "if": "ctx?.winlog?.event_data?.RunspaceId != \"\""
313 | }
314 | },
315 | {
316 | "rename": {
317 | "field": "winlog.event_data.HostVersion",
318 | "target_field": "powershell.process.executable_version",
319 | "ignore_missing": true,
320 | "ignore_failure": true,
321 | "if": "ctx?.winlog?.event_data?.HostVersion != \"\""
322 | }
323 | },
324 | {
325 | "rename": {
326 | "field": "winlog.event_data.CommandLine",
327 | "target_field": "powershell.command.value",
328 | "ignore_failure": true,
329 | "ignore_missing": true,
330 | "if": "ctx?.winlog?.event_data?.CommandLine != \"\""
331 | }
332 | },
333 | {
334 | "rename": {
335 | "ignore_failure": true,
336 | "ignore_missing": true,
337 | "if": "ctx?.winlog?.event_data?.CommandPath != \"\"",
338 | "field": "winlog.event_data.CommandPath",
339 | "target_field": "powershell.command.path"
340 | }
341 | },
342 | {
343 | "rename": {
344 | "field": "winlog.event_data.CommandName",
345 | "target_field": "powershell.command.name",
346 | "ignore_failure": true,
347 | "ignore_missing": true,
348 | "if": "ctx?.winlog?.event_data?.CommandName != \"\""
349 | }
350 | },
351 | {
352 | "rename": {
353 | "ignore_missing": true,
354 | "if": "ctx?.winlog?.event_data?.CommandType != \"\"",
355 | "field": "winlog.event_data.CommandType",
356 | "target_field": "powershell.command.type",
357 | "ignore_failure": true
358 | }
359 | },
360 | {
361 | "rename": {
362 | "ignore_failure": true,
363 | "ignore_missing": true,
364 | "if": "ctx?.winlog?.event_data?.ScriptBlockId != \"\"",
365 | "field": "winlog.event_data.ScriptBlockId",
366 | "target_field": "powershell.file.script_block_id"
367 | }
368 | },
369 | {
370 | "rename": {
371 | "field": "winlog.event_data.ScriptBlockText",
372 | "target_field": "powershell.file.script_block_text",
373 | "ignore_failure": true,
374 | "ignore_missing": true,
375 | "if": "ctx?.winlog?.event_data?.ScriptBlockText != \"\""
376 | }
377 | },
378 | {
379 | "split": {
380 | "separator": "\n",
381 | "ignore_failure": true,
382 | "ignore_missing": true,
383 | "if": "ctx.event.code == \"4103\"",
384 | "description": "Split Event 800 command invocation details.",
385 | "field": "winlog.event_data.Payload"
386 | }
387 | },
388 | {
389 | "script": {
390 | "description": "Parses all command invocation detail raw lines, and converts them to an object, based on their type.\n - for unexpectedly formatted ones: {value: \"the raw line as it is\"}\n - for all:\n * related_command: describes to what command it is related to\n * value: the value for that detail line\n * type: the type of the detail line, i.e.: CommandInvocation, ParameterBinding, NonTerminatingError\n - additionally, ParameterBinding adds a `name` field with the parameter name being bound.",
391 | "lang": "painless",
392 | "if": "ctx.event.code == \"4103\"",
393 | "params": {
394 | "field": "Payload"
395 | },
396 | "source": "def parseRawDetail(String raw) {\n Pattern detailRegex = /^(.+)\\((.+)\\)\\:\\s*(.+)?$/;\n Pattern parameterBindingRegex = /name\\=(.+);\\s*value\\=(.+)$/;\n\n def matcher = detailRegex.matcher(raw);\n if (!matcher.matches()) {\n return [\"value\": raw];\n }\n def matches = new ArrayList();\n for (def i = 0; i <= matcher.groupCount(); i++) {\n matches.add(matcher.group(i));\n }\n \n if (matches.length != 4) {\n return [\"value\": raw];\n } \n \n if (matches[1] != \"ParameterBinding\") {\n return [\n \"type\": matches[1], \n \"related_command\": matches[2], \n \"value\": matches[3]\n ];\n }\n\n matcher = parameterBindingRegex.matcher(matches[3]);\n if (!matcher.matches()) {\n return [\"value\": matches[4]];\n }\n def nameValMatches = new ArrayList();\n for (def i = 0; i <= matcher.groupCount(); i++) {\n nameValMatches.add(matcher.group(i));\n }\n if (nameValMatches.length !== 3) {\n return [\"value\": matches[3]];\n }\n\n return [\n \"type\": matches[1],\n \"related_command\": matches[2],\n \"name\": nameValMatches[1],\n \"value\": nameValMatches[2]\n ];\n}\n\nif (ctx?._temp == null) {\n ctx._temp = new HashMap();\n}\n\nif (ctx._temp.details == null) {\n ctx._temp.details = new ArrayList();\n}\n\ndef values = ctx?.winlog?.event_data[params[\"field\"]];\nif (values != null && values.length > 0) {\n for (v in values) {\n ctx._temp.details.add(parseRawDetail(v));\n }\n}"
397 | }
398 | },
399 | {
400 | "rename": {
401 | "field": "_temp.details",
402 | "target_field": "powershell.command.invocation_details",
403 | "if": "ctx?._temp?.details != null && ctx?._temp?.details.length > 0"
404 | }
405 | },
406 | {
407 | "script": {
408 | "lang": "painless",
409 | "if": "ctx?.process?.command_line != null && ctx.process.command_line != \"\"",
410 | "source": "// appendBSBytes appends n '\\\\' bytes to b and returns the resulting slice.\ndef appendBSBytes(StringBuilder b, int n) {\n for (; n > 0; n--) {\n b.append('\\\\');\n }\n return b;\n}\n\n// readNextArg splits command line string cmd into next\n// argument and command line remainder.\ndef readNextArg(String cmd) {\n def b = new StringBuilder();\n boolean inquote;\n int nslash;\n for (; cmd.length() > 0; cmd = cmd.substring(1)) {\n def c = cmd.charAt(0);\n if (c == (char)' ' || c == (char)0x09) {\n if (!inquote) {\n return [\n \"arg\": appendBSBytes(b, nslash).toString(),\n \"rest\": cmd.substring(1)\n ];\n }\n } else if (c == (char)'\"') {\n b = appendBSBytes(b, nslash/2);\n if (nslash%2 == 0) {\n // use \"Prior to 2008\" rule from\n // http://daviddeley.com/autohotkey/parameters/parameters.htm\n // section 5.2 to deal with double double quotes\n if (inquote && cmd.length() > 1 && cmd.charAt(1) == (char)'\"') {\n b.append(c);\n cmd = cmd.substring(1);\n }\n inquote = !inquote;\n } else {\n b.append(c);\n }\n nslash = 0;\n continue;\n } else if (c == (char)'\\\\') {\n nslash++;\n continue;\n }\n b = appendBSBytes(b, nslash);\n nslash = 0;\n b.append(c);\n }\n return [\n \"arg\": appendBSBytes(b, nslash).toString(), \n \"rest\": ''\n ];\n}\n\n// commandLineToArgv splits a command line into individual argument\n// strings, following the Windows conventions documented\n// at http://daviddeley.com/autohotkey/parameters/parameters.htm#WINARGV\n// Original implementation found at: https://github.com/golang/go/commit/39c8d2b7faed06b0e91a1ad7906231f53aab45d1\ndef commandLineToArgv(String cmd) {\n def args = new ArrayList();\n while (cmd.length() > 0) {\n if (cmd.charAt(0) == (char)' ' || cmd.charAt(0) == (char)0x09) {\n cmd = cmd.substring(1);\n continue;\n }\n def next = readNextArg(cmd);\n cmd = next.rest;\n args.add(next.arg);\n }\n return args;\n}\n\nctx.process.args = commandLineToArgv(ctx.process.command_line);\nctx.process.args_count = ctx.process.args.length;",
411 | "description": "Implements Windows-like SplitCommandLine"
412 | }
413 | },
414 | {
415 | "rename": {
416 | "ignore_missing": true,
417 | "if": "ctx?.winlog?.event_data?.Path != \"\"",
418 | "field": "winlog.event_data.Path",
419 | "target_field": "winlog.event_data.ScriptName",
420 | "ignore_failure": true
421 | }
422 | },
423 | {
424 | "script": {
425 | "source": "def path = ctx.winlog.event_data.ScriptName;\ndef idx = path.lastIndexOf(\"\\\\\");\nif (idx > -1) {\n if (ctx?.file == null) {\n ctx.file = new HashMap();\n }\n ctx.file.name = path.substring(idx+1);\n ctx.file.directory = path.substring(0, idx);\n\n def extIdx = path.lastIndexOf(\".\");\n if (extIdx > -1) {\n ctx.file.extension = path.substring(extIdx+1);\n }\n}",
426 | "description": "Adds file information.",
427 | "lang": "painless",
428 | "if": "ctx?.winlog?.event_data?.ScriptName != null && ctx.winlog.event_data.ScriptName.length() > 1"
429 | }
430 | },
431 | {
432 | "rename": {
433 | "field": "winlog.event_data.ScriptName",
434 | "target_field": "file.path",
435 | "ignore_failure": true,
436 | "ignore_missing": true,
437 | "if": "ctx?.winlog?.event_data?.ScriptName != \"\""
438 | }
439 | },
440 | {
441 | "remove": {
442 | "field": [
443 | "_temp",
444 | "winlog.event_data.SequenceNumber",
445 | "winlog.event_data.User",
446 | "winlog.event_data.ConnectedUser",
447 | "winlog.event_data.ContextInfo",
448 | "winlog.event_data.Severity",
449 | "winlog.event_data.MessageTotal",
450 | "winlog.event_data.MessageNumber",
451 | "winlog.event_data.Payload",
452 | "winlog.time_created",
453 | "winlog.level"
454 | ],
455 | "ignore_missing": true,
456 | "ignore_failure": true
457 | }
458 | },
459 | {
460 | "script": {
461 | "lang": "painless",
462 | "source": "ctx?.winlog?.event_data?.entrySet().removeIf(entry -> entry.getValue() == null || entry.getValue().equals(\"\"));",
463 | "description": "Remove all empty values from event_data."
464 | }
465 | },
466 | {
467 | "remove": {
468 | "description": "Remove empty event data.",
469 | "field": "winlog.event_data",
470 | "ignore_missing": true,
471 | "ignore_failure": true,
472 | "if": "ctx?.winlog?.event_data != null && ctx.winlog.event_data.size() == 0"
473 | }
474 | }
475 | ],
476 | "on_failure": [
477 | {
478 | "set": {
479 | "value": "{{ _ingest.on_failure_message }}",
480 | "field": "error.message"
481 | }
482 | }
483 | ]
484 | }
--------------------------------------------------------------------------------
/installer/stage/BeaKer/elasticsearch/templates/winlogbeat-8.7.0-routing.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "Winlogbeat Routing Pipeline",
3 | "processors": [
4 | {
5 | "set": {
6 | "field": "event.ingested",
7 | "value": "{{_ingest.timestamp}}"
8 | }
9 | },
10 | {
11 | "pipeline": {
12 | "name": "winlogbeat-8.7.0-security",
13 | "if": "ctx?.winlog?.channel == 'Security' && ['Microsoft-Windows-Eventlog', 'Microsoft-Windows-Security-Auditing'].contains(ctx?.winlog?.provider_name)"
14 | }
15 | },
16 | {
17 | "pipeline": {
18 | "name": "winlogbeat-8.7.0-sysmon",
19 | "if": "ctx?.winlog?.channel == 'Microsoft-Windows-Sysmon/Operational'"
20 | }
21 | },
22 | {
23 | "pipeline": {
24 | "name": "winlogbeat-8.7.0-powershell",
25 | "if": "ctx?.winlog?.channel == 'Windows PowerShell'"
26 | }
27 | },
28 | {
29 | "pipeline": {
30 | "name": "winlogbeat-8.7.0-powershell_operational",
31 | "if": "ctx?.winlog?.channel == 'Microsoft-Windows-PowerShell/Operational'"
32 | }
33 | }
34 | ],
35 | "on_failure": [
36 | {
37 | "set": {
38 | "field": "error.message",
39 | "value": "Processor \"{{ _ingest.on_failure_processor_type }}\" with tag \"{{ _ingest.on_failure_processor_tag }}\" in pipeline \"{{ _ingest.on_failure_pipeline }}\" failed with message \"{{ _ingest.on_failure_message }}\""
40 | }
41 | }
42 | ]
43 | }
--------------------------------------------------------------------------------
/installer/stage/BeaKer/elasticsearch/templates/winlogbeat-8.7.0-sysmon.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "Pipeline for Windows Sysmon Event Logs",
3 | "processors": [
4 | {
5 | "set": {
6 | "field": "ecs.version",
7 | "value": "1.12.0"
8 | }
9 | },
10 | {
11 | "script": {
12 | "lang": "painless",
13 | "source": "ctx.winlog?.event_data?.entrySet().removeIf(entry -> [null, \"\", \"-\", \"{00000000-0000-0000-0000-000000000000}\"].contains(entry.getValue()))",
14 | "description": "Remove all empty values from event_data."
15 | }
16 | },
17 | {
18 | "rename": {
19 | "field": "winlog.level",
20 | "target_field": "log.level",
21 | "ignore_missing": true,
22 | "ignore_failure": true,
23 | "if": "ctx?.winlog?.level != \"\""
24 | }
25 | },
26 | {
27 | "date": {
28 | "target_field": "event.created",
29 | "formats": [
30 | "ISO8601"
31 | ],
32 | "ignore_failure": true,
33 | "if": "ctx?.winlog?.time_created != null",
34 | "field": "winlog.time_created"
35 | }
36 | },
37 | {
38 | "date": {
39 | "if": "ctx?.winlog?.event_data?.UtcTime != null",
40 | "field": "winlog.event_data.UtcTime",
41 | "formats": [
42 | "yyyy-MM-dd HH:mm:ss.SSS"
43 | ],
44 | "timezone": "UTC",
45 | "ignore_failure": true
46 | }
47 | },
48 | {
49 | "set": {
50 | "field": "event.module",
51 | "value": "sysmon"
52 | }
53 | },
54 | {
55 | "set": {
56 | "field": "event.kind",
57 | "value": "event"
58 | }
59 | },
60 | {
61 | "set": {
62 | "field": "event.code",
63 | "value": "{{winlog.event_id}}"
64 | }
65 | },
66 | {
67 | "script": {
68 | "source": "if (ctx?.event?.code == null || params.get(ctx.event.code) == null) {\n return;\n}\ndef hm = new HashMap(params[ctx.event.code]);\nhm.forEach((k, v) -> ctx.event[k] = v);",
69 | "description": "Set event category and type for all event types.",
70 | "lang": "painless",
71 | "params": {
72 | "1": {
73 | "category": [
74 | "process"
75 | ],
76 | "type": [
77 | "start"
78 | ]
79 | },
80 | "2": {
81 | "category": [
82 | "file"
83 | ],
84 | "type": [
85 | "change"
86 | ]
87 | },
88 | "3": {
89 | "category": [
90 | "network"
91 | ],
92 | "type": [
93 | "start",
94 | "connection",
95 | "protocol"
96 | ]
97 | },
98 | "4": {
99 | "category": [
100 | "process"
101 | ],
102 | "type": [
103 | "change"
104 | ]
105 | },
106 | "5": {
107 | "category": [
108 | "process"
109 | ],
110 | "type": [
111 | "end"
112 | ]
113 | },
114 | "6": {
115 | "category": [
116 | "driver"
117 | ],
118 | "type": [
119 | "start"
120 | ]
121 | },
122 | "7": {
123 | "type": [
124 | "change"
125 | ],
126 | "category": [
127 | "process"
128 | ]
129 | },
130 | "10": {
131 | "category": [
132 | "process"
133 | ],
134 | "type": [
135 | "access"
136 | ]
137 | },
138 | "11": {
139 | "category": [
140 | "file"
141 | ],
142 | "type": [
143 | "creation"
144 | ]
145 | },
146 | "12": {
147 | "type": [
148 | "change"
149 | ],
150 | "category": [
151 | "configuration",
152 | "registry"
153 | ]
154 | },
155 | "13": {
156 | "category": [
157 | "configuration",
158 | "registry"
159 | ],
160 | "type": [
161 | "change"
162 | ]
163 | },
164 | "14": {
165 | "category": [
166 | "configuration",
167 | "registry"
168 | ],
169 | "type": [
170 | "change"
171 | ]
172 | },
173 | "15": {
174 | "category": [
175 | "file"
176 | ],
177 | "type": [
178 | "access"
179 | ]
180 | },
181 | "16": {
182 | "category": [
183 | "configuration"
184 | ],
185 | "type": [
186 | "change"
187 | ]
188 | },
189 | "17": {
190 | "category": [
191 | "file"
192 | ],
193 | "type": [
194 | "creation"
195 | ]
196 | },
197 | "18": {
198 | "category": [
199 | "file"
200 | ],
201 | "type": [
202 | "access"
203 | ]
204 | },
205 | "22": {
206 | "category": [
207 | "network"
208 | ],
209 | "type": [
210 | "connection",
211 | "protocol",
212 | "info"
213 | ]
214 | },
215 | "23": {
216 | "category": [
217 | "file"
218 | ],
219 | "type": [
220 | "deletion"
221 | ]
222 | },
223 | "24": {
224 | "type": [
225 | "change"
226 | ]
227 | },
228 | "25": {
229 | "category": [
230 | "process"
231 | ],
232 | "type": [
233 | "change"
234 | ]
235 | },
236 | "26": {
237 | "category": [
238 | "file"
239 | ],
240 | "type": [
241 | "deletion"
242 | ]
243 | }
244 | },
245 | "tag": "Add ECS categorization fields"
246 | }
247 | },
248 | {
249 | "convert": {
250 | "field": "winlog.record_id",
251 | "type": "string",
252 | "ignore_failure": true,
253 | "ignore_missing": true
254 | }
255 | },
256 | {
257 | "rename": {
258 | "if": "ctx.event.code == \"255\"",
259 | "field": "winlog.event_data.ID",
260 | "target_field": "error.code",
261 | "ignore_failure": true,
262 | "ignore_missing": true
263 | }
264 | },
265 | {
266 | "rename": {
267 | "field": "winlog.event_data.RuleName",
268 | "target_field": "rule.name",
269 | "ignore_missing": true,
270 | "ignore_failure": true
271 | }
272 | },
273 | {
274 | "rename": {
275 | "field": "winlog.event_data.Type",
276 | "target_field": "message",
277 | "ignore_missing": true,
278 | "ignore_failure": true,
279 | "if": "ctx.event.code == \"25\""
280 | }
281 | },
282 | {
283 | "rename": {
284 | "field": "winlog.event_data.Hash",
285 | "target_field": "winlog.event_data.Hashes",
286 | "ignore_missing": true,
287 | "ignore_failure": true
288 | }
289 | },
290 | {
291 | "kv": {
292 | "value_split": "=",
293 | "ignore_failure": true,
294 | "if": "ctx?.winlog?.event_data?.Hashes != null",
295 | "field": "winlog.event_data.Hashes",
296 | "target_field": "_temp.hashes",
297 | "field_split": ","
298 | }
299 | },
300 | {
301 | "script": {
302 | "if": "ctx?._temp?.hashes != null",
303 | "source": "def hashIsEmpty(String hash) {\n if (hash == \"\") {\n return true;\n }\n \n Pattern emptyHashRegex = /^0*$/;\n def matcher = emptyHashRegex.matcher(hash);\n \n return matcher.matches(); \n}\n\ndef hashes = new HashMap();\ndef related = [\n \"hash\": new ArrayList()\n];\nfor (entry in ctx._temp.hashes.entrySet()) {\n def key = entry.getKey().toString().toLowerCase();\n def value = entry.getValue().toString().toLowerCase();\n\n if (hashIsEmpty(value)) {\n continue;\n }\n\n hashes[key] = value;\n related.hash.add(value);\n}\n\nctx._temp.hashes = hashes;\nif (related.hash.length > 0) {\n ctx.related = related;\n}",
304 | "lang": "painless"
305 | }
306 | },
307 | {
308 | "rename": {
309 | "if": "ctx?._temp?.hashes != null &&\n[\"1\", \"23\", \"24\", \"25\", \"26\"].contains(ctx.event.code)",
310 | "field": "_temp.hashes",
311 | "target_field": "process.hash"
312 | }
313 | },
314 | {
315 | "rename": {
316 | "ignore_failure": true,
317 | "ignore_missing": true,
318 | "field": "process.hash.imphash",
319 | "target_field": "process.pe.imphash"
320 | }
321 | },
322 | {
323 | "rename": {
324 | "ignore_failure": true,
325 | "field": "winlog.event_data.ProcessGuid",
326 | "target_field": "process.entity_id",
327 | "ignore_missing": true
328 | }
329 | },
330 | {
331 | "convert": {
332 | "field": "winlog.event_data.ProcessId",
333 | "target_field": "process.pid",
334 | "type": "long",
335 | "ignore_failure": true,
336 | "ignore_missing": true
337 | }
338 | },
339 | {
340 | "rename": {
341 | "target_field": "process.executable",
342 | "ignore_missing": true,
343 | "ignore_failure": true,
344 | "field": "winlog.event_data.Image"
345 | }
346 | },
347 | {
348 | "rename": {
349 | "target_field": "process.entity_id",
350 | "ignore_missing": true,
351 | "ignore_failure": true,
352 | "field": "winlog.event_data.SourceProcessGuid"
353 | }
354 | },
355 | {
356 | "rename": {
357 | "ignore_failure": true,
358 | "field": "winlog.event_data.SourceProcessGUID",
359 | "target_field": "process.entity_id",
360 | "ignore_missing": true
361 | }
362 | },
363 | {
364 | "convert": {
365 | "target_field": "process.pid",
366 | "type": "long",
367 | "ignore_failure": true,
368 | "ignore_missing": true,
369 | "field": "winlog.event_data.SourceProcessId"
370 | }
371 | },
372 | {
373 | "convert": {
374 | "target_field": "process.thread.id",
375 | "type": "long",
376 | "ignore_failure": true,
377 | "ignore_missing": true,
378 | "field": "winlog.event_data.SourceThreadId"
379 | }
380 | },
381 | {
382 | "rename": {
383 | "field": "winlog.event_data.SourceImage",
384 | "target_field": "process.executable",
385 | "ignore_missing": true,
386 | "ignore_failure": true
387 | }
388 | },
389 | {
390 | "rename": {
391 | "ignore_failure": true,
392 | "field": "winlog.event_data.Destination",
393 | "target_field": "process.executable",
394 | "ignore_missing": true
395 | }
396 | },
397 | {
398 | "rename": {
399 | "field": "winlog.event_data.CommandLine",
400 | "target_field": "process.command_line",
401 | "ignore_missing": true,
402 | "ignore_failure": true
403 | }
404 | },
405 | {
406 | "rename": {
407 | "field": "winlog.event_data.CurrentDirectory",
408 | "target_field": "process.working_directory",
409 | "ignore_missing": true,
410 | "ignore_failure": true
411 | }
412 | },
413 | {
414 | "rename": {
415 | "ignore_missing": true,
416 | "ignore_failure": true,
417 | "field": "winlog.event_data.ParentProcessGuid",
418 | "target_field": "process.parent.entity_id"
419 | }
420 | },
421 | {
422 | "convert": {
423 | "target_field": "process.parent.pid",
424 | "type": "long",
425 | "ignore_failure": true,
426 | "ignore_missing": true,
427 | "field": "winlog.event_data.ParentProcessId"
428 | }
429 | },
430 | {
431 | "rename": {
432 | "field": "winlog.event_data.ParentImage",
433 | "target_field": "process.parent.executable",
434 | "ignore_missing": true,
435 | "ignore_failure": true
436 | }
437 | },
438 | {
439 | "rename": {
440 | "target_field": "process.parent.command_line",
441 | "ignore_missing": true,
442 | "ignore_failure": true,
443 | "field": "winlog.event_data.ParentCommandLine"
444 | }
445 | },
446 | {
447 | "rename": {
448 | "field": "winlog.event_data.OriginalFileName",
449 | "target_field": "process.pe.original_file_name",
450 | "ignore_missing": true,
451 | "ignore_failure": true,
452 | "if": "ctx.event.code != \"7\""
453 | }
454 | },
455 | {
456 | "set": {
457 | "ignore_failure": true,
458 | "if": "ctx.event.code != \"7\"",
459 | "field": "process.pe.company",
460 | "copy_from": "winlog.event_data.Company",
461 | "ignore_empty_value": true
462 | }
463 | },
464 | {
465 | "set": {
466 | "ignore_failure": true,
467 | "if": "ctx.event.code != \"7\"",
468 | "field": "process.pe.description",
469 | "copy_from": "winlog.event_data.Description",
470 | "ignore_empty_value": true
471 | }
472 | },
473 | {
474 | "set": {
475 | "copy_from": "winlog.event_data.FileVersion",
476 | "ignore_empty_value": true,
477 | "ignore_failure": true,
478 | "if": "ctx.event.code != \"7\"",
479 | "field": "process.pe.file_version"
480 | }
481 | },
482 | {
483 | "set": {
484 | "copy_from": "winlog.event_data.Product",
485 | "ignore_empty_value": true,
486 | "ignore_failure": true,
487 | "if": "ctx.event.code != \"7\"",
488 | "field": "process.pe.product"
489 | }
490 | },
491 | {
492 | "script": {
493 | "lang": "painless",
494 | "if": "(ctx?.process?.command_line != null && ctx.process.command_line != \"\") || \n(ctx?.process?.parent?.command_line != null && ctx.process.parent.command_line != \"\")",
495 | "source": "// appendBSBytes appends n '\\\\' bytes to b and returns the resulting slice.\ndef appendBSBytes(StringBuilder b, int n) {\n for (; n > 0; n--) {\n b.append('\\\\');\n }\n return b;\n}\n\n// readNextArg splits command line string cmd into next\n// argument and command line remainder.\ndef readNextArg(String cmd) {\n def b = new StringBuilder();\n boolean inquote;\n int nslash;\n for (; cmd.length() > 0; cmd = cmd.substring(1)) {\n def c = cmd.charAt(0);\n if (c == (char)' ' || c == (char)0x09) {\n if (!inquote) {\n return [\n \"arg\": appendBSBytes(b, nslash).toString(),\n \"rest\": cmd.substring(1)\n ];\n }\n } else if (c == (char)'\"') {\n b = appendBSBytes(b, nslash/2);\n if (nslash%2 == 0) {\n // use \"Prior to 2008\" rule from\n // http://daviddeley.com/autohotkey/parameters/parameters.htm\n // section 5.2 to deal with double double quotes\n if (inquote && cmd.length() > 1 && cmd.charAt(1) == (char)'\"') {\n b.append(c);\n cmd = cmd.substring(1);\n }\n inquote = !inquote;\n } else {\n b.append(c);\n }\n nslash = 0;\n continue;\n } else if (c == (char)'\\\\') {\n nslash++;\n continue;\n }\n b = appendBSBytes(b, nslash);\n nslash = 0;\n b.append(c);\n }\n return [\n \"arg\": appendBSBytes(b, nslash).toString(), \n \"rest\": ''\n ];\n}\n\n// commandLineToArgv splits a command line into individual argument\n// strings, following the Windows conventions documented\n// at http://daviddeley.com/autohotkey/parameters/parameters.htm#WINARGV\n// Original implementation found at: https://github.com/golang/go/commit/39c8d2b7faed06b0e91a1ad7906231f53aab45d1\ndef commandLineToArgv(String cmd) {\n def args = new ArrayList();\n while (cmd.length() > 0) {\n if (cmd.charAt(0) == (char)' ' || cmd.charAt(0) == (char)0x09) {\n cmd = cmd.substring(1);\n continue;\n }\n def next = readNextArg(cmd);\n cmd = next.rest;\n args.add(next.arg);\n }\n return args;\n}\n\ndef cmd = ctx?.process?.command_line;\nif (cmd != null && cmd != \"\") {\n ctx.process.args = commandLineToArgv(cmd);\n ctx.process.args_count = ctx.process.args.length;\n}\n\ndef parentCmd = ctx?.process?.parent?.command_line;\nif (parentCmd != null && parentCmd != \"\") {\n ctx.process.parent.args = commandLineToArgv(parentCmd);\n ctx.process.parent.args_count = ctx.process.parent.args.length;\n}",
496 | "description": "Implements Windows-like SplitCommandLine"
497 | }
498 | },
499 | {
500 | "script": {
501 | "description": "Adds process name information.",
502 | "lang": "painless",
503 | "if": "(ctx?.process?.executable != null && ctx.process.executable.length() > 1) ||\n(ctx?.process?.parent?.executable != null && ctx.process.parent.executable.length() > 1)",
504 | "source": "def getProcessName(def path) {\n def idx = path.lastIndexOf(\"\\\\\");\n if (idx > -1) {\n return path.substring(idx+1);\n }\n return \"\";\n}\n\ndef cmd = ctx?.process?.executable;\nif (cmd != null && cmd != \"\" && ctx?.process?.name == null) {\n def name = getProcessName(cmd);\n if (name != \"\") {\n ctx.process.name = name;\n }\n}\n\ndef parentCmd = ctx?.process?.parent?.executable;\nif (parentCmd != null && parentCmd != \"\" && ctx?.process?.parent?.name == null) {\n def name = getProcessName(parentCmd);\n if (name != \"\") {\n ctx.process.parent.name = name;\n }\n}"
505 | }
506 | },
507 | {
508 | "rename": {
509 | "field": "_temp.hashes",
510 | "target_field": "file.hash",
511 | "if": "ctx?._temp?.hashes != null &&\n[\"6\", \"7\", \"15\"].contains(ctx.event.code)"
512 | }
513 | },
514 | {
515 | "rename": {
516 | "field": "file.hash.imphash",
517 | "target_field": "file.pe.imphash",
518 | "ignore_failure": true,
519 | "ignore_missing": true
520 | }
521 | },
522 | {
523 | "rename": {
524 | "field": "winlog.event_data.TargetFilename",
525 | "target_field": "file.path",
526 | "ignore_missing": true,
527 | "ignore_failure": true
528 | }
529 | },
530 | {
531 | "rename": {
532 | "target_field": "file.path",
533 | "ignore_missing": true,
534 | "ignore_failure": true,
535 | "field": "winlog.event_data.Device"
536 | }
537 | },
538 | {
539 | "rename": {
540 | "target_field": "file.name",
541 | "ignore_missing": true,
542 | "ignore_failure": true,
543 | "field": "winlog.event_data.PipeName"
544 | }
545 | },
546 | {
547 | "rename": {
548 | "field": "winlog.event_data.ImageLoaded",
549 | "target_field": "file.path",
550 | "ignore_missing": true,
551 | "ignore_failure": true
552 | }
553 | },
554 | {
555 | "set": {
556 | "ignore_empty_value": true,
557 | "field": "file.code_signature.subject_name",
558 | "copy_from": "winlog.event_data.Signature",
559 | "ignore_failure": true
560 | }
561 | },
562 | {
563 | "set": {
564 | "field": "file.code_signature.status",
565 | "copy_from": "winlog.event_data.SignatureStatus",
566 | "ignore_failure": true,
567 | "ignore_empty_value": true
568 | }
569 | },
570 | {
571 | "rename": {
572 | "field": "winlog.event_data.OriginalFileName",
573 | "target_field": "file.pe.original_file_name",
574 | "ignore_missing": true,
575 | "ignore_failure": true,
576 | "if": "ctx.event.code == \"7\""
577 | }
578 | },
579 | {
580 | "set": {
581 | "ignore_empty_value": true,
582 | "if": "ctx.event.code == \"7\"",
583 | "field": "file.pe.company",
584 | "copy_from": "winlog.event_data.Company",
585 | "ignore_failure": true
586 | }
587 | },
588 | {
589 | "set": {
590 | "ignore_empty_value": true,
591 | "if": "ctx.event.code == \"7\"",
592 | "field": "file.pe.description",
593 | "copy_from": "winlog.event_data.Description",
594 | "ignore_failure": true
595 | }
596 | },
597 | {
598 | "set": {
599 | "copy_from": "winlog.event_data.FileVersion",
600 | "ignore_failure": true,
601 | "ignore_empty_value": true,
602 | "if": "ctx.event.code == \"7\"",
603 | "field": "file.pe.file_version"
604 | }
605 | },
606 | {
607 | "set": {
608 | "if": "ctx.event.code == \"7\"",
609 | "field": "file.pe.product",
610 | "copy_from": "winlog.event_data.Product",
611 | "ignore_failure": true,
612 | "ignore_empty_value": true
613 | }
614 | },
615 | {
616 | "set": {
617 | "field": "file.code_signature.signed",
618 | "value": true,
619 | "if": "ctx?.winlog?.event_data?.Signed == true"
620 | }
621 | },
622 | {
623 | "set": {
624 | "field": "file.code_signature.valid",
625 | "value": true,
626 | "if": "ctx?.winlog?.event_data?.SignatureStatus == \"Valid\""
627 | }
628 | },
629 | {
630 | "script": {
631 | "lang": "painless",
632 | "if": "ctx?.file?.path != null && ctx.file.path.length() > 1",
633 | "source": "def path = ctx.file.path;\ndef idx = path.lastIndexOf(\"\\\\\");\nif (idx > -1) {\n if (ctx?.file == null) {\n ctx.file = new HashMap();\n }\n ctx.file.name = path.substring(idx+1);\n ctx.file.directory = path.substring(0, idx);\n\n def extIdx = path.lastIndexOf(\".\");\n if (extIdx > -1) {\n ctx.file.extension = path.substring(extIdx+1);\n }\n}",
634 | "description": "Adds file information."
635 | }
636 | },
637 | {
638 | "rename": {
639 | "ignore_failure": true,
640 | "field": "winlog.event_data.Protocol",
641 | "target_field": "network.transport",
642 | "ignore_missing": true
643 | }
644 | },
645 | {
646 | "rename": {
647 | "target_field": "network.protocol",
648 | "ignore_missing": true,
649 | "ignore_failure": true,
650 | "if": "ctx.event.code != \"22\"",
651 | "field": "winlog.event_data.DestinationPortName"
652 | }
653 | },
654 | {
655 | "rename": {
656 | "field": "winlog.event_data.SourcePortName",
657 | "target_field": "network.protocol",
658 | "ignore_missing": true,
659 | "ignore_failure": true,
660 | "if": "ctx.event.code != \"22\""
661 | }
662 | },
663 | {
664 | "set": {
665 | "field": "network.protocol",
666 | "value": "dns",
667 | "if": "ctx.event.code == \"22\""
668 | }
669 | },
670 | {
671 | "convert": {
672 | "ignore_missing": true,
673 | "field": "winlog.event_data.SourceIp",
674 | "target_field": "source.ip",
675 | "type": "ip",
676 | "ignore_failure": true
677 | }
678 | },
679 | {
680 | "rename": {
681 | "target_field": "source.domain",
682 | "ignore_missing": true,
683 | "ignore_failure": true,
684 | "field": "winlog.event_data.SourceHostname"
685 | }
686 | },
687 | {
688 | "convert": {
689 | "type": "long",
690 | "ignore_failure": true,
691 | "ignore_missing": true,
692 | "field": "winlog.event_data.SourcePort",
693 | "target_field": "source.port"
694 | }
695 | },
696 | {
697 | "convert": {
698 | "type": "ip",
699 | "ignore_failure": true,
700 | "ignore_missing": true,
701 | "field": "winlog.event_data.DestinationIp",
702 | "target_field": "destination.ip"
703 | }
704 | },
705 | {
706 | "rename": {
707 | "ignore_missing": true,
708 | "ignore_failure": true,
709 | "field": "winlog.event_data.DestinationHostname",
710 | "target_field": "destination.domain"
711 | }
712 | },
713 | {
714 | "convert": {
715 | "type": "long",
716 | "ignore_failure": true,
717 | "ignore_missing": true,
718 | "field": "winlog.event_data.DestinationPort",
719 | "target_field": "destination.port"
720 | }
721 | },
722 | {
723 | "rename": {
724 | "field": "winlog.event_data.QueryName",
725 | "target_field": "dns.question.name",
726 | "ignore_missing": true,
727 | "ignore_failure": true
728 | }
729 | },
730 | {
731 | "set": {
732 | "value": "egress",
733 | "if": "ctx?.winlog?.event_data?.Initiated == \"true\"",
734 | "field": "network.direction"
735 | }
736 | },
737 | {
738 | "set": {
739 | "if": "ctx?.winlog?.event_data?.Initiated == \"false\"",
740 | "field": "network.direction",
741 | "value": "ingress"
742 | }
743 | },
744 | {
745 | "set": {
746 | "field": "network.type",
747 | "value": "ipv4",
748 | "if": "ctx?.winlog?.event_data?.SourceIsIpv6 == \"false\""
749 | }
750 | },
751 | {
752 | "set": {
753 | "field": "network.type",
754 | "value": "ipv6",
755 | "if": "ctx?.winlog?.event_data?.SourceIsIpv6 == \"true\""
756 | }
757 | },
758 | {
759 | "script": {
760 | "description": "Splits the QueryResults field that contains the DNS responses.\nExample: \"type: 5 f2.taboola.map.fastly.net;::ffff:151.101.66.2;::ffff:151.101.130.2;::ffff:151.101.194.2;::ffff:151.101.2.2;\"\n",
761 | "lang": "painless",
762 | "if": "ctx?.winlog?.event_data?.QueryResults != null",
763 | "params": {
764 | "1": "A",
765 | "2": "NS",
766 | "3": "MD",
767 | "4": "MF",
768 | "5": "CNAME",
769 | "6": "SOA",
770 | "7": "MB",
771 | "8": "MG",
772 | "9": "MR",
773 | "10": "NULL",
774 | "11": "WKS",
775 | "12": "PTR",
776 | "13": "HINFO",
777 | "14": "MINFO",
778 | "15": "MX",
779 | "16": "TXT",
780 | "17": "RP",
781 | "18": "AFSDB",
782 | "19": "X25",
783 | "20": "ISDN",
784 | "21": "RT",
785 | "22": "NSAP",
786 | "23": "NSAPPTR",
787 | "24": "SIG",
788 | "25": "KEY",
789 | "26": "PX",
790 | "27": "GPOS",
791 | "28": "AAAA",
792 | "29": "LOC",
793 | "30": "NXT",
794 | "31": "EID",
795 | "32": "NIMLOC",
796 | "33": "SRV",
797 | "34": "ATMA",
798 | "35": "NAPTR",
799 | "36": "KX",
800 | "37": "CERT",
801 | "38": "A6",
802 | "39": "DNAME",
803 | "40": "SINK",
804 | "41": "OPT",
805 | "43": "DS",
806 | "46": "RRSIG",
807 | "47": "NSEC",
808 | "48": "DNSKEY",
809 | "49": "DHCID",
810 | "100": "UINFO",
811 | "101": "UID",
812 | "102": "GID",
813 | "103": "UNSPEC",
814 | "248": "ADDRS",
815 | "249": "TKEY",
816 | "250": "TSIG",
817 | "251": "IXFR",
818 | "252": "AXFR",
819 | "253": "MAILB",
820 | "254": "MAILA",
821 | "255": "ANY",
822 | "65281": "WINS",
823 | "65282": "WINSR"
824 | },
825 | "source": "def results = /;/.split(ctx.winlog.event_data.QueryResults);\ndef answers = new ArrayList();\ndef ips = new ArrayList();\ndef relatedHosts = new ArrayList();\nfor (def i = 0; i < results.length; i++) {\n def answer = results[i];\n if (answer == \"\") {\n continue;\n }\n\n if (answer.startsWith(\"type:\")) {\n def parts = /\\s+/.split(answer);\n if (parts.length != 3) {\n throw new Exception(\"unexpected QueryResult format\");\n }\n\n answers.add([\n \"type\": params[parts[1]],\n \"data\": parts[2]\n ]);\n relatedHosts.add(parts[2]);\n } else {\n answer = answer.replace(\"::ffff:\", \"\");\n ips.add(answer);\n }\n}\n\nif (answers.length > 0) {\n ctx.dns.answers = answers;\n}\nif (ips.length > 0) {\n ctx.dns.resolved_ip = ips;\n}\nif (relatedHosts.length > 0) {\n if (ctx?.related == null) {\n ctx.related = new HashMap();\n }\n ctx.related.hosts = relatedHosts;\n}"
826 | }
827 | },
828 | {
829 | "foreach": {
830 | "ignore_missing": true,
831 | "processor": {
832 | "convert": {
833 | "type": "ip",
834 | "on_failure": [
835 | {
836 | "remove": {
837 | "field": "_ingest._value"
838 | }
839 | }
840 | ],
841 | "field": "_ingest._value"
842 | }
843 | },
844 | "field": "dns.resolved_ip"
845 | }
846 | },
847 | {
848 | "script": {
849 | "description": "Convert V4MAPPED addresses.",
850 | "lang": "painless",
851 | "if": "ctx?.dns?.resolved_ip != null",
852 | "source": "if (ctx.dns.answers == null) {\n ctx.dns.answers = new ArrayList();\n}\nfor (def i = 0; i < ctx.dns.resolved_ip.length; i++) {\n def ip = ctx.dns.resolved_ip[i];\n if (ip == null) {\n ctx.dns.resolved_ip.remove(i);\n continue;\n }\n\n // Synthesize record type based on IP address type.\n def type = \"A\";\n if (ip.indexOf(\":\") != -1) {\n type = \"AAAA\";\n }\n ctx.dns.answers.add([\n \"type\": type,\n \"data\": ip\n ]);\n}"
853 | }
854 | },
855 | {
856 | "registered_domain": {
857 | "target_field": "dns.question",
858 | "ignore_failure": true,
859 | "ignore_missing": true,
860 | "field": "dns.question.name"
861 | }
862 | },
863 | {
864 | "append": {
865 | "if": "ctx?.dns?.question?.name != null && ctx?.dns?.question?.name != \"\"",
866 | "field": "related.hosts",
867 | "value": "{{dns.question.name}}",
868 | "allow_duplicates": false
869 | }
870 | },
871 | {
872 | "remove": {
873 | "ignore_missing": true,
874 | "ignore_failure": true,
875 | "description": "Remove dns.question.domain because it is not part of ECS and is redundant with dns.question.name.",
876 | "field": "dns.question.domain"
877 | }
878 | },
879 | {
880 | "foreach": {
881 | "field": "dns.resolved_ip",
882 | "ignore_missing": true,
883 | "processor": {
884 | "append": {
885 | "ignore_failure": true,
886 | "field": "related.ip",
887 | "value": "{{_ingest._value}}",
888 | "allow_duplicates": false
889 | }
890 | }
891 | }
892 | },
893 | {
894 | "community_id": {
895 | "ignore_failure": true,
896 | "ignore_missing": false
897 | }
898 | },
899 | {
900 | "set": {
901 | "field": "user.id",
902 | "copy_from": "winlog.user.identifier",
903 | "ignore_empty_value": true,
904 | "ignore_failure": true
905 | }
906 | },
907 | {
908 | "split": {
909 | "field": "winlog.event_data.User",
910 | "target_field": "_temp.user_parts",
911 | "separator": "\\\\",
912 | "if": "ctx?.winlog?.event_data?.User != null"
913 | }
914 | },
915 | {
916 | "set": {
917 | "ignore_failure": true,
918 | "ignore_empty_value": true,
919 | "if": "ctx?._temp?.user_parts != null && ctx._temp.user_parts.size() == 2",
920 | "field": "user.domain",
921 | "value": "{{_temp.user_parts.0}}"
922 | }
923 | },
924 | {
925 | "set": {
926 | "ignore_empty_value": true,
927 | "if": "ctx?._temp?.user_parts != null && ctx._temp.user_parts.size() == 2",
928 | "field": "user.name",
929 | "value": "{{_temp.user_parts.1}}",
930 | "ignore_failure": true
931 | }
932 | },
933 | {
934 | "rename": {
935 | "field": "winlog.event_data.QueryStatus",
936 | "target_field": "sysmon.dns.status",
937 | "ignore_missing": true,
938 | "ignore_failure": true
939 | }
940 | },
941 | {
942 | "script": {
943 | "source": "def status = params[ctx.sysmon.dns.status];\nif (status != null) {\n ctx.sysmon.dns.status = status;\n}",
944 | "description": "Translate DNS Query status.",
945 | "lang": "painless",
946 | "params": {
947 | "0": "SUCCESS",
948 | "5": "ERROR_ACCESS_DENIED",
949 | "8": "ERROR_NOT_ENOUGH_MEMORY",
950 | "13": "ERROR_INVALID_DATA",
951 | "14": "ERROR_OUTOFMEMORY",
952 | "123": "ERROR_INVALID_NAME",
953 | "1214": "ERROR_INVALID_NETNAME",
954 | "1223": "ERROR_CANCELLED",
955 | "1460": "ERROR_TIMEOUT",
956 | "4312": "ERROR_OBJECT_NOT_FOUND",
957 | "9001": "DNS_ERROR_RCODE_FORMAT_ERROR",
958 | "9002": "DNS_ERROR_RCODE_SERVER_FAILURE",
959 | "9003": "DNS_ERROR_RCODE_NAME_ERROR",
960 | "9004": "DNS_ERROR_RCODE_NOT_IMPLEMENTED",
961 | "9005": "DNS_ERROR_RCODE_REFUSED",
962 | "9006": "DNS_ERROR_RCODE_YXDOMAIN",
963 | "9007": "DNS_ERROR_RCODE_YXRRSET",
964 | "9008": "DNS_ERROR_RCODE_NXRRSET",
965 | "9009": "DNS_ERROR_RCODE_NOTAUTH",
966 | "9010": "DNS_ERROR_RCODE_NOTZONE",
967 | "9016": "DNS_ERROR_RCODE_BADSIG",
968 | "9017": "DNS_ERROR_RCODE_BADKEY",
969 | "9018": "DNS_ERROR_RCODE_BADTIME",
970 | "9101": "DNS_ERROR_KEYMASTER_REQUIRED",
971 | "9102": "DNS_ERROR_NOT_ALLOWED_ON_SIGNED_ZONE",
972 | "9103": "DNS_ERROR_NSEC3_INCOMPATIBLE_WITH_RSA_SHA1",
973 | "9104": "DNS_ERROR_NOT_ENOUGH_SIGNING_KEY_DESCRIPTORS",
974 | "9105": "DNS_ERROR_UNSUPPORTED_ALGORITHM",
975 | "9106": "DNS_ERROR_INVALID_KEY_SIZE",
976 | "9107": "DNS_ERROR_SIGNING_KEY_NOT_ACCESSIBLE",
977 | "9108": "DNS_ERROR_KSP_DOES_NOT_SUPPORT_PROTECTION",
978 | "9109": "DNS_ERROR_UNEXPECTED_DATA_PROTECTION_ERROR",
979 | "9110": "DNS_ERROR_UNEXPECTED_CNG_ERROR",
980 | "9111": "DNS_ERROR_UNKNOWN_SIGNING_PARAMETER_VERSION",
981 | "9112": "DNS_ERROR_KSP_NOT_ACCESSIBLE",
982 | "9113": "DNS_ERROR_TOO_MANY_SKDS",
983 | "9114": "DNS_ERROR_INVALID_ROLLOVER_PERIOD",
984 | "9115": "DNS_ERROR_INVALID_INITIAL_ROLLOVER_OFFSET",
985 | "9116": "DNS_ERROR_ROLLOVER_IN_PROGRESS",
986 | "9117": "DNS_ERROR_STANDBY_KEY_NOT_PRESENT",
987 | "9118": "DNS_ERROR_NOT_ALLOWED_ON_ZSK",
988 | "9119": "DNS_ERROR_NOT_ALLOWED_ON_ACTIVE_SKD",
989 | "9120": "DNS_ERROR_ROLLOVER_ALREADY_QUEUED",
990 | "9121": "DNS_ERROR_NOT_ALLOWED_ON_UNSIGNED_ZONE",
991 | "9122": "DNS_ERROR_BAD_KEYMASTER",
992 | "9123": "DNS_ERROR_INVALID_SIGNATURE_VALIDITY_PERIOD",
993 | "9124": "DNS_ERROR_INVALID_NSEC3_ITERATION_COUNT",
994 | "9125": "DNS_ERROR_DNSSEC_IS_DISABLED",
995 | "9126": "DNS_ERROR_INVALID_XML",
996 | "9127": "DNS_ERROR_NO_VALID_TRUST_ANCHORS",
997 | "9128": "DNS_ERROR_ROLLOVER_NOT_POKEABLE",
998 | "9129": "DNS_ERROR_NSEC3_NAME_COLLISION",
999 | "9130": "DNS_ERROR_NSEC_INCOMPATIBLE_WITH_NSEC3_RSA_SHA1",
1000 | "9501": "DNS_INFO_NO_RECORDS",
1001 | "9502": "DNS_ERROR_BAD_PACKET",
1002 | "9503": "DNS_ERROR_NO_PACKET",
1003 | "9504": "DNS_ERROR_RCODE",
1004 | "9505": "DNS_ERROR_UNSECURE_PACKET",
1005 | "9506": "DNS_REQUEST_PENDING",
1006 | "9551": "DNS_ERROR_INVALID_TYPE",
1007 | "9552": "DNS_ERROR_INVALID_IP_ADDRESS",
1008 | "9553": "DNS_ERROR_INVALID_PROPERTY",
1009 | "9554": "DNS_ERROR_TRY_AGAIN_LATER",
1010 | "9555": "DNS_ERROR_NOT_UNIQUE",
1011 | "9556": "DNS_ERROR_NON_RFC_NAME",
1012 | "9557": "DNS_STATUS_FQDN",
1013 | "9558": "DNS_STATUS_DOTTED_NAME",
1014 | "9559": "DNS_STATUS_SINGLE_PART_NAME",
1015 | "9560": "DNS_ERROR_INVALID_NAME_CHAR",
1016 | "9561": "DNS_ERROR_NUMERIC_NAME",
1017 | "9562": "DNS_ERROR_NOT_ALLOWED_ON_ROOT_SERVER",
1018 | "9563": "DNS_ERROR_NOT_ALLOWED_UNDER_DELEGATION",
1019 | "9564": "DNS_ERROR_CANNOT_FIND_ROOT_HINTS",
1020 | "9565": "DNS_ERROR_INCONSISTENT_ROOT_HINTS",
1021 | "9566": "DNS_ERROR_DWORD_VALUE_TOO_SMALL",
1022 | "9567": "DNS_ERROR_DWORD_VALUE_TOO_LARGE",
1023 | "9568": "DNS_ERROR_BACKGROUND_LOADING",
1024 | "9569": "DNS_ERROR_NOT_ALLOWED_ON_RODC",
1025 | "9570": "DNS_ERROR_NOT_ALLOWED_UNDER_DNAME",
1026 | "9571": "DNS_ERROR_DELEGATION_REQUIRED",
1027 | "9572": "DNS_ERROR_INVALID_POLICY_TABLE",
1028 | "9573": "DNS_ERROR_ADDRESS_REQUIRED",
1029 | "9601": "DNS_ERROR_ZONE_DOES_NOT_EXIST",
1030 | "9602": "DNS_ERROR_NO_ZONE_INFO",
1031 | "9603": "DNS_ERROR_INVALID_ZONE_OPERATION",
1032 | "9604": "DNS_ERROR_ZONE_CONFIGURATION_ERROR",
1033 | "9605": "DNS_ERROR_ZONE_HAS_NO_SOA_RECORD",
1034 | "9606": "DNS_ERROR_ZONE_HAS_NO_NS_RECORDS",
1035 | "9607": "DNS_ERROR_ZONE_LOCKED",
1036 | "9608": "DNS_ERROR_ZONE_CREATION_FAILED",
1037 | "9609": "DNS_ERROR_ZONE_ALREADY_EXISTS",
1038 | "9610": "DNS_ERROR_AUTOZONE_ALREADY_EXISTS",
1039 | "9611": "DNS_ERROR_INVALID_ZONE_TYPE",
1040 | "9612": "DNS_ERROR_SECONDARY_REQUIRES_MASTER_IP",
1041 | "9613": "DNS_ERROR_ZONE_NOT_SECONDARY",
1042 | "9614": "DNS_ERROR_NEED_SECONDARY_ADDRESSES",
1043 | "9615": "DNS_ERROR_WINS_INIT_FAILED",
1044 | "9616": "DNS_ERROR_NEED_WINS_SERVERS",
1045 | "9617": "DNS_ERROR_NBSTAT_INIT_FAILED",
1046 | "9618": "DNS_ERROR_SOA_DELETE_INVALID",
1047 | "9619": "DNS_ERROR_FORWARDER_ALREADY_EXISTS",
1048 | "9620": "DNS_ERROR_ZONE_REQUIRES_MASTER_IP",
1049 | "9621": "DNS_ERROR_ZONE_IS_SHUTDOWN",
1050 | "9622": "DNS_ERROR_ZONE_LOCKED_FOR_SIGNING",
1051 | "9651": "DNS_ERROR_PRIMARY_REQUIRES_DATAFILE",
1052 | "9652": "DNS_ERROR_INVALID_DATAFILE_NAME",
1053 | "9653": "DNS_ERROR_DATAFILE_OPEN_FAILURE",
1054 | "9654": "DNS_ERROR_FILE_WRITEBACK_FAILED",
1055 | "9655": "DNS_ERROR_DATAFILE_PARSING",
1056 | "9701": "DNS_ERROR_RECORD_DOES_NOT_EXIST",
1057 | "9702": "DNS_ERROR_RECORD_FORMAT",
1058 | "9703": "DNS_ERROR_NODE_CREATION_FAILED",
1059 | "9704": "DNS_ERROR_UNKNOWN_RECORD_TYPE",
1060 | "9705": "DNS_ERROR_RECORD_TIMED_OUT",
1061 | "9706": "DNS_ERROR_NAME_NOT_IN_ZONE",
1062 | "9707": "DNS_ERROR_CNAME_LOOP",
1063 | "9708": "DNS_ERROR_NODE_IS_CNAME",
1064 | "9709": "DNS_ERROR_CNAME_COLLISION",
1065 | "9710": "DNS_ERROR_RECORD_ONLY_AT_ZONE_ROOT",
1066 | "9711": "DNS_ERROR_RECORD_ALREADY_EXISTS",
1067 | "9712": "DNS_ERROR_SECONDARY_DATA",
1068 | "9713": "DNS_ERROR_NO_CREATE_CACHE_DATA",
1069 | "9714": "DNS_ERROR_NAME_DOES_NOT_EXIST",
1070 | "9715": "DNS_WARNING_PTR_CREATE_FAILED",
1071 | "9716": "DNS_WARNING_DOMAIN_UNDELETED",
1072 | "9717": "DNS_ERROR_DS_UNAVAILABLE",
1073 | "9718": "DNS_ERROR_DS_ZONE_ALREADY_EXISTS",
1074 | "9719": "DNS_ERROR_NO_BOOTFILE_IF_DS_ZONE",
1075 | "9720": "DNS_ERROR_NODE_IS_DNAME",
1076 | "9721": "DNS_ERROR_DNAME_COLLISION",
1077 | "9722": "DNS_ERROR_ALIAS_LOOP",
1078 | "9751": "DNS_INFO_AXFR_COMPLETE",
1079 | "9752": "DNS_ERROR_AXFR",
1080 | "9753": "DNS_INFO_ADDED_LOCAL_WINS",
1081 | "9801": "DNS_STATUS_CONTINUE_NEEDED",
1082 | "9851": "DNS_ERROR_NO_TCPIP",
1083 | "9852": "DNS_ERROR_NO_DNS_SERVERS",
1084 | "9901": "DNS_ERROR_DP_DOES_NOT_EXIST",
1085 | "9902": "DNS_ERROR_DP_ALREADY_EXISTS",
1086 | "9903": "DNS_ERROR_DP_NOT_ENLISTED",
1087 | "9904": "DNS_ERROR_DP_ALREADY_ENLISTED",
1088 | "9905": "DNS_ERROR_DP_NOT_AVAILABLE",
1089 | "9906": "DNS_ERROR_DP_FSMO_ERROR",
1090 | "9911": "DNS_ERROR_RRL_NOT_ENABLED",
1091 | "9912": "DNS_ERROR_RRL_INVALID_WINDOW_SIZE",
1092 | "9913": "DNS_ERROR_RRL_INVALID_IPV4_PREFIX",
1093 | "9914": "DNS_ERROR_RRL_INVALID_IPV6_PREFIX",
1094 | "9915": "DNS_ERROR_RRL_INVALID_TC_RATE",
1095 | "9916": "DNS_ERROR_RRL_INVALID_LEAK_RATE",
1096 | "9917": "DNS_ERROR_RRL_LEAK_RATE_LESSTHAN_TC_RATE",
1097 | "9921": "DNS_ERROR_VIRTUALIZATION_INSTANCE_ALREADY_EXISTS",
1098 | "9922": "DNS_ERROR_VIRTUALIZATION_INSTANCE_DOES_NOT_EXIST",
1099 | "9923": "DNS_ERROR_VIRTUALIZATION_TREE_LOCKED",
1100 | "9924": "DNS_ERROR_INVAILD_VIRTUALIZATION_INSTANCE_NAME",
1101 | "9925": "DNS_ERROR_DEFAULT_VIRTUALIZATION_INSTANCE",
1102 | "9951": "DNS_ERROR_ZONESCOPE_ALREADY_EXISTS",
1103 | "9952": "DNS_ERROR_ZONESCOPE_DOES_NOT_EXIST",
1104 | "9953": "DNS_ERROR_DEFAULT_ZONESCOPE",
1105 | "9954": "DNS_ERROR_INVALID_ZONESCOPE_NAME",
1106 | "9955": "DNS_ERROR_NOT_ALLOWED_WITH_ZONESCOPES",
1107 | "9956": "DNS_ERROR_LOAD_ZONESCOPE_FAILED",
1108 | "9957": "DNS_ERROR_ZONESCOPE_FILE_WRITEBACK_FAILED",
1109 | "9958": "DNS_ERROR_INVALID_SCOPE_NAME",
1110 | "9959": "DNS_ERROR_SCOPE_DOES_NOT_EXIST",
1111 | "9960": "DNS_ERROR_DEFAULT_SCOPE",
1112 | "9961": "DNS_ERROR_INVALID_SCOPE_OPERATION",
1113 | "9962": "DNS_ERROR_SCOPE_LOCKED",
1114 | "9963": "DNS_ERROR_SCOPE_ALREADY_EXISTS",
1115 | "9971": "DNS_ERROR_POLICY_ALREADY_EXISTS",
1116 | "9972": "DNS_ERROR_POLICY_DOES_NOT_EXIST",
1117 | "9973": "DNS_ERROR_POLICY_INVALID_CRITERIA",
1118 | "9974": "DNS_ERROR_POLICY_INVALID_SETTINGS",
1119 | "9975": "DNS_ERROR_CLIENT_SUBNET_IS_ACCESSED",
1120 | "9976": "DNS_ERROR_CLIENT_SUBNET_DOES_NOT_EXIST",
1121 | "9977": "DNS_ERROR_CLIENT_SUBNET_ALREADY_EXISTS",
1122 | "9978": "DNS_ERROR_SUBNET_DOES_NOT_EXIST",
1123 | "9979": "DNS_ERROR_SUBNET_ALREADY_EXISTS",
1124 | "9980": "DNS_ERROR_POLICY_LOCKED",
1125 | "9981": "DNS_ERROR_POLICY_INVALID_WEIGHT",
1126 | "9982": "DNS_ERROR_POLICY_INVALID_NAME",
1127 | "9983": "DNS_ERROR_POLICY_MISSING_CRITERIA",
1128 | "9984": "DNS_ERROR_INVALID_CLIENT_SUBNET_NAME",
1129 | "9985": "DNS_ERROR_POLICY_PROCESSING_ORDER_INVALID",
1130 | "9986": "DNS_ERROR_POLICY_SCOPE_MISSING",
1131 | "9987": "DNS_ERROR_POLICY_SCOPE_NOT_ALLOWED",
1132 | "9988": "DNS_ERROR_SERVERSCOPE_IS_REFERENCED",
1133 | "9989": "DNS_ERROR_ZONESCOPE_IS_REFERENCED",
1134 | "9990": "DNS_ERROR_POLICY_INVALID_CRITERIA_CLIENT_SUBNET",
1135 | "9991": "DNS_ERROR_POLICY_INVALID_CRITERIA_TRANSPORT_PROTOCOL",
1136 | "9992": "DNS_ERROR_POLICY_INVALID_CRITERIA_NETWORK_PROTOCOL",
1137 | "9993": "DNS_ERROR_POLICY_INVALID_CRITERIA_INTERFACE",
1138 | "9994": "DNS_ERROR_POLICY_INVALID_CRITERIA_FQDN",
1139 | "9995": "DNS_ERROR_POLICY_INVALID_CRITERIA_QUERY_TYPE",
1140 | "9996": "DNS_ERROR_POLICY_INVALID_CRITERIA_TIME_OF_DAY",
1141 | "10054": "WSAECONNRESET",
1142 | "10055": "WSAENOBUFS",
1143 | "10060": "WSAETIMEDOUT"
1144 | },
1145 | "if": "ctx?.sysmon?.dns?.status != null && ctx?.sysmon?.dns?.status != \"\""
1146 | }
1147 | },
1148 | {
1149 | "convert": {
1150 | "ignore_failure": true,
1151 | "field": "winlog.event_data.Archived",
1152 | "target_field": "sysmon.file.archived",
1153 | "type": "boolean",
1154 | "ignore_missing": true
1155 | }
1156 | },
1157 | {
1158 | "convert": {
1159 | "field": "winlog.event_data.IsExecutable",
1160 | "target_field": "sysmon.file.is_executable",
1161 | "type": "boolean",
1162 | "ignore_missing": true,
1163 | "ignore_failure": true
1164 | }
1165 | },
1166 | {
1167 | "append": {
1168 | "field": "related.user",
1169 | "value": "{{user.name}}",
1170 | "ignore_failure": true,
1171 | "allow_duplicates": false,
1172 | "if": "ctx?.user?.name != null && ctx.user.name != \"\""
1173 | }
1174 | },
1175 | {
1176 | "append": {
1177 | "field": "related.ip",
1178 | "value": "{{source.ip}}",
1179 | "ignore_failure": true,
1180 | "allow_duplicates": false,
1181 | "if": "ctx?.source?.ip != null && ctx.source.ip != \"\""
1182 | }
1183 | },
1184 | {
1185 | "append": {
1186 | "ignore_failure": true,
1187 | "allow_duplicates": false,
1188 | "if": "ctx?.destination?.ip != null && ctx.destination.ip != \"\"",
1189 | "field": "related.ip",
1190 | "value": "{{destination.ip}}"
1191 | }
1192 | },
1193 | {
1194 | "script": {
1195 | "params": {
1196 | "HKPD": "HKPD",
1197 | "HKCC": "HKCC",
1198 | "HKEY_DYN_DATA": "HKDD",
1199 | "HKCU": "HKCU",
1200 | "HKCR": "HKCR",
1201 | "HKEY_CURRENT_CONFIG": "HKCC",
1202 | "HKLM": "HKLM",
1203 | "HKEY_USERS": "HKU",
1204 | "HKEY_LOCAL_MACHINE": "HKLM",
1205 | "HKEY_CLASSES_ROOT": "HKCR",
1206 | "HKU": "HKU",
1207 | "HKDD": "HKDD",
1208 | "HKEY_PERFORMANCE_DATA": "HKPD",
1209 | "HKEY_CURRENT_USER": "HKCU"
1210 | },
1211 | "source": "ctx.registry = new HashMap();\nPattern qwordRegex = /(?i)QWORD \\(((0x[0-9A-F]{8})-(0x[0-9A-F]{8}))\\)/;\nPattern dwordRegex = /(?i)DWORD \\((0x[0-9A-F]{8})\\)/;\nPattern binDataRegex = /Binary Data/;\n\ndef path = ctx.winlog.event_data.TargetObject;\nctx.registry.path = path;\n\ndef pathTokens = Arrays.asList(/\\\\/.split(path));\ndef hive = params[pathTokens[0]];\nif (hive != null) {\n ctx.registry.hive = hive;\n if (pathTokens.length > 1) {\n ctx.registry.key = pathTokens.subList(1, pathTokens.length).join(\"\\\\\");\n }\n}\n\ndef value = pathTokens[pathTokens.length - 1];\nctx.registry.value = value;\n\ndef data = ctx?.winlog?.event_data?.Details;\nif (data != null && data != \"\") {\n def prefixLen = 2; // to remove 0x prefix\n def dataValue = \"\";\n def dataType = \"\";\n def matcher = qwordRegex.matcher(data);\n if (matcher.matches()) {\n def parsedHighByte = Long.parseLong(matcher.group(2).substring(prefixLen), 16);\n def parsedLowByte = Long.parseLong(matcher.group(3).substring(prefixLen), 16);\n if (!Double.isNaN(parsedHighByte) && !Double.isNaN(parsedLowByte)) {\n dataType = \"SZ_QWORD\";\n dataValue = Long.toString(((parsedHighByte << 8) + parsedLowByte));\n ctx.registry.data = [\n \"strings\": [dataValue],\n \"type\": dataType\n ];\n }\n return;\n }\n\n matcher = dwordRegex.matcher(data);\n if (matcher.matches()) {\n def parsedValue = Long.parseLong(matcher.group(1).substring(prefixLen), 16);\n if (!Double.isNaN(parsedValue)) {\n dataType = \"SZ_DWORD\";\n dataValue = Long.toString(parsedValue);\n ctx.registry.data = [\n \"strings\": [dataValue],\n \"type\": dataType\n ];\n }\n return;\n }\n\n matcher = binDataRegex.matcher(data);\n if (matcher.matches()) {\n // Data type could be REG_BINARY or REG_MULTI_SZ\n ctx.registry.data = [\n \"strings\": [data],\n \"type\": \"REG_BINARY\"\n ];\n return;\n }\n\n // REG_SZ or REG_EXPAND_SZ\n ctx.registry.data = [\n \"strings\": [data],\n \"type\": \"REG_SZ\"\n ];\n}",
1212 | "description": "Set registry fields.",
1213 | "lang": "painless",
1214 | "if": "ctx?.winlog?.event_data?.TargetObject != null && [\"12\", \"13\", \"14\"].contains(ctx.event.code)"
1215 | }
1216 | },
1217 | {
1218 | "remove": {
1219 | "ignore_failure": true,
1220 | "ignore_missing": true,
1221 | "field": [
1222 | "_temp",
1223 | "winlog.event_data.ProcessId",
1224 | "winlog.event_data.ParentProcessId",
1225 | "winlog.event_data.SourceProcessId",
1226 | "winlog.event_data.SourceThreadId",
1227 | "winlog.event_data.SourceIp",
1228 | "winlog.event_data.SourcePort",
1229 | "winlog.event_data.SourcePortName",
1230 | "winlog.event_data.DestinationIp",
1231 | "winlog.event_data.DestinationPort",
1232 | "winlog.event_data.DestinationPortName",
1233 | "winlog.event_data.RuleName",
1234 | "winlog.event_data.User",
1235 | "winlog.event_data.Initiated",
1236 | "winlog.event_data.SourceIsIpv6",
1237 | "winlog.event_data.DestinationIsIpv6",
1238 | "winlog.event_data.QueryStatus",
1239 | "winlog.event_data.Archived",
1240 | "winlog.event_data.IsExecutable",
1241 | "winlog.event_data.QueryResults",
1242 | "winlog.event_data.UtcTime",
1243 | "winlog.event_data.Hash",
1244 | "winlog.event_data.Hashes",
1245 | "winlog.event_data.TargetObject",
1246 | "winlog.event_data.Details",
1247 | "winlog.time_created",
1248 | "winlog.level"
1249 | ]
1250 | }
1251 | },
1252 | {
1253 | "remove": {
1254 | "description": "Remove empty event data.",
1255 | "field": "winlog.event_data",
1256 | "ignore_missing": true,
1257 | "ignore_failure": true,
1258 | "if": "ctx?.winlog?.event_data != null && ctx.winlog.event_data.size() == 0"
1259 | }
1260 | }
1261 | ],
1262 | "on_failure": [
1263 | {
1264 | "set": {
1265 | "field": "error.message",
1266 | "value": "Processor \"{{ _ingest.on_failure_processor_type }}\" with tag \"{{ _ingest.on_failure_processor_tag }}\" in pipeline \"{{ _ingest.on_failure_pipeline }}\" failed with message \"{{ _ingest.on_failure_message }}\""
1267 | }
1268 | }
1269 | ]
1270 | }
--------------------------------------------------------------------------------
/installer/stage/BeaKer/elasticsearch/templates/winlogbeat-ilm-policy.json:
--------------------------------------------------------------------------------
1 | {
2 | "policy": {
3 | "phases": {
4 | "hot": {
5 | "min_age": "0ms",
6 | "actions": {
7 | "rollover": {
8 | "max_age": "30d",
9 | "max_primary_shard_size": "50gb"
10 | }
11 | }
12 | }
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/installer/stage/BeaKer/install_beaker.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | #Performs installation of BeaKer software
3 | #version = 1.0.1
4 |
5 | #### Environment Set Up
6 |
7 | # Set the working directory to the script directory
8 | pushd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null
9 |
10 | # Set exit on error
11 | set -o errexit
12 | set -o errtrace
13 | set -o pipefail
14 |
15 | # ERROR HANDLING
16 | __err() {
17 | echo2 ""
18 | echo2 "Installation failed on line $1:$2."
19 | echo2 ""
20 | exit 1
21 | }
22 |
23 | __int() {
24 | echo2 ""
25 | echo2 "Installation cancelled."
26 | echo2 ""
27 | exit 1
28 | }
29 |
30 | trap '__err ${BASH_SOURCE##*/} $LINENO' ERR
31 | trap '__int' INT
32 |
33 | # Constants for output color formatting
34 | GREEN='\033[1;32m'
35 | YELLOW='\033[1;33m'
36 | NC='\033[0m' # No Color
37 |
38 |
39 | # Load the function library
40 | . ./shell-lib/acmlib.sh
41 | normalize_environment
42 |
43 | BEAKER_CONFIG_DIR="${BEAKER_CONFIG_DIR:-/etc/BeaKer/}"
44 | UPGRADE_INSTALL=false
45 | CURRENT_ELASTIC_VERSION=""
46 | INSTALL_ELASTIC_VERSION=""
47 |
48 | test_system () {
49 | status "Checking minimum requirements"
50 | require_supported_os
51 | require_free_space_MB "$HOME" "/var/lib" "/etc" "/usr" 5120
52 | }
53 |
54 | install_docker () {
55 | status "Installing Docker"
56 | shell-lib/docker/install_docker.sh
57 | echo2 ''
58 | if $SUDO docker ps &>/dev/null ; then
59 | echo2 'Docker appears to be working, continuing.'
60 | else
61 | fail 'Docker does not appear to be working. Does the current user have sudo or docker privileges?'
62 | fi
63 | }
64 |
65 |
66 | ensure_env_file_exists () {
67 | $SUDO mkdir -p "$BEAKER_CONFIG_DIR"
68 |
69 | # Determine if the current user has permission to run docker
70 | local docker_sudo=""
71 | if [ ! -w "/var/run/docker.sock" ]; then
72 | docker_sudo="sudo"
73 | fi
74 |
75 | CURRENT_ELASTIC_VERSION=$({ "$docker_sudo" grep "^ELK_STACK_VERSION" "$BEAKER_CONFIG_DIR/env" || true; })
76 | CURRENT_ELASTIC_VERSION=${CURRENT_ELASTIC_VERSION##*=}
77 |
78 | local savedObjectsEncryptionKey=$(openssl rand -hex 16)
79 | local reportingEncryptionKey=$(openssl rand -hex 16)
80 | local securityEncryptionKey=$(openssl rand -hex 16)
81 |
82 | if [ "$acm_no_interactive" = 'yes' ] && [ ! -f "$BEAKER_CONFIG_DIR/env" ]; then
83 | echo2 "We are in non-interactive mode but there is no $BEAKER_CONFIG_DIR/env file, exiting."
84 | exit 1
85 | elif [ ! -f "$BEAKER_CONFIG_DIR/env" ]; then
86 | status "Generating BeaKer configuration"
87 | echo "Please enter a password for the admin Elasticsearch user account."
88 | echo "Username: elastic"
89 | local elastic_password=""
90 | local pw_confirmation="foobar"
91 | while [ "$elastic_password" != "$pw_confirmation" ]; do
92 | read -es -p "Password: " elastic_password
93 | echo ""
94 | read -es -p "Password (Confirmation): " pw_confirmation
95 | echo ""
96 | done
97 | # This is a fresh install, so set the version to the newest version available
98 | elastic_version=$( tail -n 1 ELK_VERSIONS )
99 | cat << EOF | $SUDO tee "$BEAKER_CONFIG_DIR/env" > /dev/null
100 | ###############################################################################
101 | # By putting variables in this file, they will be made available to use in
102 | # your Docker Compose files, including to pass to containers. This file must
103 | # be named ".env" in order for Docker Compose to automatically load these
104 | # variables into its working environment.
105 | #
106 | # https://docs.docker.com/compose/environment-variables/#the-env-file
107 | ###############################################################################
108 |
109 | ###############################################################################
110 | # Changing the elastic password in the Kibana UI requires also changing it
111 | # in this file.
112 | #
113 | # Once the password has been changed in both places, run "beaker down" followed
114 | # by "beaker up -d" to restart the containers with the updated password.
115 | ###############################################################################
116 |
117 | ###############################################################################
118 | # Elastic Search Settings
119 | #
120 | ELASTIC_PASSWORD=${elastic_password}
121 | BEAKER_CONFIG_DIR=${BEAKER_CONFIG_DIR}
122 | ###############################################################################
123 |
124 | ###############################################################################
125 | # Kibana Settings
126 | #
127 | KIBANA_SERVICE_TOKEN=KIBANA_TOKEN_PLACEHOLDER
128 | SAVED_OBJECTS_ENCRYPTION_KEY=${savedObjectsEncryptionKey}
129 | REPORTING_ENCRYPTION_KEY=${reportingEncryptionKey}
130 | SECURITY_ENCRYPTION_KEY=${securityEncryptionKey}
131 | ###############################################################################
132 |
133 | ###############################################################################
134 | # ELK Stack Settings
135 | ELK_STACK_VERSION=${elastic_version}
136 | ###############################################################################
137 |
138 | EOF
139 | else
140 | # If the env file exists, then this is an upgrade install
141 | UPGRADE_INSTALL=true
142 |
143 | # The KIBANA_SERVICE_TOKEN entry was introduced for v7.17+
144 | # If the KIBANA_SERVICE_TOKEN entry doesn't exist, then the installed version
145 | # must be less than 7.17, so set it as 7.0.0
146 | if ! $("$docker_sudo" grep -q "^KIBANA_SERVICE_TOKEN" "$BEAKER_CONFIG_DIR/env" ); then
147 | cat << EOF | $SUDO tee -a "$BEAKER_CONFIG_DIR/env" > /dev/null
148 |
149 |
150 | ###############################################################################
151 | # Kibana Settings
152 | #
153 | KIBANA_SERVICE_TOKEN=KIBANA_TOKEN_PLACEHOLDER
154 | SAVED_OBJECTS_ENCRYPTION_KEY=${savedObjectsEncryptionKey}
155 | REPORTING_ENCRYPTION_KEY=${reportingEncryptionKey}
156 | SECURITY_ENCRYPTION_KEY=${securityEncryptionKey}
157 | ###############################################################################
158 |
159 | ###############################################################################
160 | # ELK Stack Settings
161 | ELK_STACK_VERSION=7.0.0
162 | ###############################################################################
163 | EOF
164 | fi
165 | fi
166 |
167 |
168 | $SUDO chown root:docker "$BEAKER_CONFIG_DIR/env"
169 | $SUDO chmod 640 "$BEAKER_CONFIG_DIR/env"
170 |
171 | if ! can_write_or_create ".env"; then
172 | sudo ln -sf "$BEAKER_CONFIG_DIR/env" .env
173 | else
174 | ln -sf "$BEAKER_CONFIG_DIR/env" .env
175 | fi
176 | }
177 |
178 | ensure_snapshot_repo_exists() {
179 | # Create snapshot folder if it doesn't exist
180 | if [ ! -d "/var/BeaKer/snapshots" ]; then
181 | $SUDO mkdir -p "/var/BeaKer/snapshots"
182 | fi
183 | $SUDO chmod 777 /var/BeaKer/snapshots
184 | }
185 |
186 | require_aih_web_server_listening () {
187 | if nc -z -w 15 127.0.0.1 5601 >/dev/null 2>&1 ; then
188 | echo2 "Able to reach Kibana web server, good."
189 | else
190 | fail "Unable to reach Kibana web server"
191 | fi
192 | }
193 |
194 | ensure_certificates_exist () {
195 |
196 | local cert_files=(
197 | ca/ca.crt ca/ca.key
198 | Elasticsearch/Elasticsearch.crt Elasticsearch/Elasticsearch.key
199 | Kibana/Kibana.crt Kibana/Kibana.key
200 | )
201 |
202 | local certs_exist=true
203 |
204 | for cert_file in ${cert_files[@]}; do
205 | if [ ! -f "$BEAKER_CONFIG_DIR/certificates/$cert_file" ]; then
206 | certs_exist=false
207 | break
208 | fi
209 | done
210 |
211 | if [ "$certs_exist" != "true" ]; then
212 | $SUDO rm -rf "$BEAKER_CONFIG_DIR/certificates"
213 | $SUDO mkdir "$BEAKER_CONFIG_DIR/certificates"
214 |
215 | # The following beaker commands must be run using the root user since the elasticsearch container
216 | # runs with the elasticsearch user by default, and the certificates directory is owned by root
217 |
218 | # Create CA
219 | ./beaker run --rm --user root elasticsearch /usr/share/elasticsearch/bin/elasticsearch-certutil ca --pem \
220 | --days 10950 --out /usr/share/elasticsearch/config/certificates/ca.zip > /dev/null
221 | (cd /etc/BeaKer/certificates && $SUDO unzip ca.zip > /dev/null)
222 | $SUDO rm "$BEAKER_CONFIG_DIR/certificates/ca.zip"
223 |
224 | # Create Elasticsearch certificate using CA
225 | ./beaker run --rm --user root elasticsearch /usr/share/elasticsearch/bin/elasticsearch-certutil cert \
226 | --ca-cert /usr/share/elasticsearch/config/certificates/ca/ca.crt \
227 | --ca-key /usr/share/elasticsearch/config/certificates/ca/ca.key \
228 | --name Elasticsearch --pem --days 10950 --out /usr/share/elasticsearch/config/certificates/certs.zip > /dev/null
229 | (cd /etc/BeaKer/certificates && $SUDO unzip certs.zip > /dev/null)
230 | $SUDO rm "$BEAKER_CONFIG_DIR/certificates/certs.zip"
231 |
232 | # Create Kibana certicate, reusing the CA
233 | ./beaker run --rm --user root elasticsearch /usr/share/elasticsearch/bin/elasticsearch-certutil cert \
234 | --ca-cert /usr/share/elasticsearch/config/certificates/ca/ca.crt \
235 | --ca-key /usr/share/elasticsearch/config/certificates/ca/ca.key \
236 | --name Kibana --pem --days 10950 --out /usr/share/elasticsearch/config/certificates/certs.zip > /dev/null
237 | (cd "$BEAKER_CONFIG_DIR/certificates" && $SUDO unzip certs.zip > /dev/null)
238 | $SUDO rm "$BEAKER_CONFIG_DIR/certificates/certs.zip"
239 |
240 | $SUDO chmod 755 /etc/BeaKer/ /etc/BeaKer/certificates/ /etc/BeaKer/certificates/ca/ \
241 | /etc/BeaKer/certificates/Elasticsearch/ /etc/BeaKer/certificates/Kibana/
242 | $SUDO chmod 644 /etc/BeaKer/certificates/Kibana/Kibana.* /etc/BeaKer/certificates/Elasticsearch/Elasticsearch.* \
243 | /etc/BeaKer/certificates/ca/ca.*
244 | fi
245 |
246 | }
247 |
248 | require_elasticsearch_api_up() {
249 | local es_pass="$1"
250 |
251 | local connection_attempts=0
252 | local elastic_api_up="false"
253 | while [ $connection_attempts -lt 8 -a "$elastic_api_up" != "true" ]; do
254 | if printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -s -XGET -k -K- "https://localhost:9200" > /dev/null ; then
255 | echo2 "The Elasticsearch API is up and running."
256 | elastic_api_up="true"
257 | break
258 | fi
259 | echo2 "Waiting for Elasticsearch API to start..."
260 | sleep 15
261 | connection_attempts=$((connection_attempts + 1))
262 | done
263 | if [ "$elastic_api_up" != "true" ]; then
264 | fail "The installer failed to authenticate to the Elasticsearch API"
265 | fi
266 | }
267 |
268 | require_kibana_available() {
269 | local es_pass="$1"
270 |
271 | local minutes_to_wait=15
272 | local attempts=$(( ( $minutes_to_wait * 60 ) / 15 ))
273 |
274 | local connection_attempts=0
275 | local kibana_available="false"
276 | while [ $connection_attempts -lt $attempts -a "$kibana_available" != "true" ]; do
277 | if printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -s -XGET -k -K- "https://localhost:5601/api/status" | ./beaker run --rm -T check_kibana ; then
278 | echo2 "Kibana is up and running."
279 | kibana_available="true"
280 | break
281 | fi
282 | echo2 "Waiting for Kibana to finish migrations and become available..."
283 | sleep 15
284 | connection_attempts=$((connection_attempts + 1))
285 | done
286 | if [ "$kibana_available" != "true" ]; then
287 | fail "Kibana failed to upgrade/start within $minutes_to_wait minutes"
288 | fi
289 | }
290 |
291 | create_snapshot() {
292 | local es_pass="$1"
293 |
294 | # Make sure the existing BeaKer install is running before attempting to create a snapshot
295 | if [ `$SUDO docker ps | grep 'beaker-elasticsearch' | wc -l` -eq 0 ]; then
296 | echo "BeaKer doesn't appear to be running, starting..."
297 | ./beaker up -d
298 | fi
299 | require_elasticsearch_api_up "$es_pass"
300 | local repository_ok=true
301 |
302 | # Check if snapshot repository already exists
303 | if ! printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -s -k -K- "https://localhost:9200/_snapshot/beaker" > /dev/null ; then
304 | # Create snapshot repository if it doesn't exist
305 | if ! printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -s -X PUT -k -K- "https://localhost:9200/_snapshot/beaker" -H 'Content-Type: application/json' -d'{
306 | "type": "fs",
307 | "settings": {
308 | "location": "/usr/share/elasticsearch/snapshots"
309 | }
310 | }
311 | ' > /dev/null ; then
312 | fail "Failed to create snapshot repository"
313 | repository_ok=false
314 | fi
315 | fi
316 |
317 | if "$repository_ok" ; then
318 | local output=$(printf -- '-u "%s"' "elastic:$es_pass" | curl -s -XGET -k -K- "https://localhost:9200/_snapshot/beaker/beaker_snapshot*")
319 | snapshot_iteration=1
320 | existing_snapshot=$(echo "$output" | { grep -o '"snapshot":"beaker_snapshot-[[:digit:]]*.[[:digit:]]*.[[:digit:]]*-[[:digit:]]*' || true; })
321 | if [ -n "$existing_snapshot" ]; then
322 | iteration=${existing_snapshot##*-}
323 | snapshot_iteration=$(( $iteration + 1 ))
324 | fi
325 | if ! printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -s -X PUT -k -K- "https://localhost:9200/_snapshot/beaker/%3Cbeaker_snapshot-%7Bnow%2Fd%7D-$snapshot_iteration%3E?wait_for_completion=true" > /dev/null ; then
326 | printf "${YELLOW}[!!!] Couldn't create snapshot... If you continue the installation without a snapshot and are unable to recover your data, you will NOT be able to downgrade.${NC}\n"
327 | echo "Would you like to stop the installation and manually create a snapshot? (Y/N, recommended: Y)"
328 | if askYN ; then
329 | echo "The instructions for manually creating a snapshot are listed here: https://www.elastic.co/guide/en/elasticsearch/reference/current/snapshots-take-snapshot.html#manually-create-snapshot"
330 | echo "The snapshot repository for BeaKer is a 'Shared file system' repository named 'beaker', located at /usr/share/elasticsearch/snapshots within the Elasticsearch container."
331 | echo "Stopping installation due to failure to create snapshot"
332 | exit
333 | else
334 | printf "${YELLOW}[!!!] Continuing the installation WITHOUT a snapshot. PROCEED AT YOUR OWN RISK [!!!]${NC}\n"
335 | fi
336 | else
337 | printf "${GREEN}\u2714${NC} Successfully created snapshot\n"
338 | fi
339 | fi
340 | }
341 |
342 | create_service_account_token() {
343 | local es_pass="$1"
344 | require_elasticsearch_api_up "$es_pass"
345 |
346 | # Determine if the current user has permission to run docker
347 | local docker_sudo=""
348 | if [ ! -w "/var/run/docker.sock" ]; then
349 | docker_sudo="sudo -E"
350 | fi
351 |
352 | # Use docker_sudo since the env file ownership is root:docker.
353 | local service_token=`$docker_sudo grep '^KIBANA_SERVICE_TOKEN' "$BEAKER_CONFIG_DIR/env" | sed -e 's/^[^=][^=]*=//'`
354 | local token_already_valid=false
355 | if [ -n "$service_token" -a "$service_token" != "KIBANA_TOKEN_PLACEHOLDER" ]; then
356 | # Token was already generated, could be upgrade install or overwrite install
357 | # Check to see if token is valid
358 | if printf -- '-H "%s"' "Authorization: Bearer $service_token" | curl --fail -s -k -K- "https://localhost:9200/_security/_authenticate" > /dev/null ; then
359 | # Token is valid, don't modify anything
360 | token_already_valid=true
361 | echo "Kibana service account token already exists and is valid, skipping creation"
362 | fi
363 | fi
364 |
365 | if ! "$token_already_valid"; then
366 | # Verify that the token does exist for the elastic/kibana service account
367 | if ! printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -s -X GET -k -K- "https://localhost:9200/_security/service/elastic/kibana/credential" | grep -q "\"kibana-beaker\""; then
368 | echo "Token does not already exist, creating..."
369 | else
370 | echo "Token already exists, recreating..."
371 | if ! printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -s -X DELETE -k -K- "https://localhost:9200/_security/service/elastic/kibana/credential/token/kibana-beaker" > /dev/null; then
372 | fail "Failed to remove service account token"
373 | fi
374 | fi
375 |
376 | local output=$(printf -- '-u "%s"' "elastic:$es_pass" | curl -s -X PUT -k -K- "https://localhost:9200/_security/service/elastic/kibana/credential/token/kibana-beaker")
377 | has_token=$(echo "$output" | { grep -o "\"value\":\".*\"" || true; })
378 | if [ -n "$has_token" ]; then
379 | local new_token=${has_token##*\":} # grab the portion of the string that comes after "value":
380 | new_token=${new_token//\"/} # remove all double quotes
381 | if [ -n "$new_token" ]; then
382 | if [ -n "$service_token" ]; then
383 | $docker_sudo sed -i "s/KIBANA_SERVICE_TOKEN=.*/KIBANA_SERVICE_TOKEN=$new_token/g" "$BEAKER_CONFIG_DIR/env"
384 | else
385 | echo "KIBANA_SERVICE_TOKEN=$new_token" | $docker_sudo tee -a "$BEAKER_CONFIG_DIR/env" > /dev/null
386 | fi
387 | printf "${GREEN}\u2714${NC} Successfully created Kibana service account token\n"
388 | echo "Restarting BeaKer..."
389 | ./beaker down && ./beaker up -d --force-recreate >&2
390 | status "Waiting for initialization"
391 | sleep 15
392 | else
393 | fail "Failed to create Kibana service account token, token parsing failed"
394 | fi
395 | else
396 | fail "Failed to create Kibana service account token"
397 | fi
398 | fi
399 |
400 | }
401 |
402 | create_index_lifecycle_policy() {
403 | # Loads index lifecycle policy if it doesn't already exist
404 | local es_pass="$1"
405 |
406 | require_elasticsearch_api_up "$es_pass"
407 |
408 | INDEX_LIFECYCLE_POLICY="elasticsearch/templates/winlogbeat-ilm-policy.json"
409 |
410 | if [ ! -r "$INDEX_LIFECYCLE_POLICY" ]; then
411 | fail "Couldn't find required index lifecycle policy file: $INDEX_LIFECYCLE_POLICY"
412 | fi
413 |
414 | # Check if policy exists
415 | if ! printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -s -XGET -k -K- "https://localhost:9200/_ilm/policy/beaker" > /dev/null; then
416 | # Load policy if it doesn't exist
417 | if ! printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -X PUT -k -K- "https://localhost:9200/_ilm/policy/beaker" -H 'Content-Type: application/json' --data-binary "@$INDEX_LIFECYCLE_POLICY" > /dev/null; then
418 | fail "Couldn't load index lifecycle policy"
419 | fi
420 | printf " ${GREEN}\u2714${NC} Loaded winlogbeat index lifecycle policy\n"
421 | else
422 | echo "Index lifecycle policy already exists, skipping..."
423 | fi
424 |
425 | }
426 |
427 | create_data_stream() {
428 | # Loads index template
429 | # Creates data stream using new index template
430 | local es_pass="$1"
431 | local version="$2"
432 |
433 | require_elasticsearch_api_up "$es_pass"
434 |
435 | INDEX_TEMPLATE="elasticsearch/templates/winlogbeat-$version.template.json"
436 | if [ ! -r "$INDEX_TEMPLATE" ]; then
437 | fail "Couldn't find required index template file: $INDEX_TEMPLATE"
438 | fi
439 |
440 | # Load index template
441 | if ! printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -X PUT -k -K- "https://localhost:9200/_index_template/winlogbeat-$version" -H 'Content-Type: application/json' --data-binary "@$INDEX_TEMPLATE" > /dev/null; then
442 | fail "Couldn't load winlogbeat-$version index template"
443 | else
444 | printf " ${GREEN}\u2714${NC} Loaded winlogbeat-$version index template\n"
445 | # Check if data stream exists, as this route doesn't accept overwriting with PUT
446 | if printf -- '-u "%s"' "elastic:$es_pass" | curl -s -XGET -k -K- "https://localhost:9200/_data_stream/winlogbeat-$version" | grep -q "index_not_found_exception"; then
447 | # Load data stream since it doesn't already exist
448 | echo "Data stream doesn't exist, creating..."
449 | if ! printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -s -X PUT -k -K- "https://localhost:9200/_data_stream/winlogbeat-$version" > /dev/null; then
450 | fail "Couldn't load winlogbeat-$version data stream"
451 | fi
452 | printf " ${GREEN}\u2714${NC} Loaded winlogbeat-$version data stream\n"
453 | fi
454 | fi
455 |
456 | }
457 |
458 | create_ingest_pipelines() {
459 | # Creates winlogbeat ingest pipelines by loading the default templates
460 | # In order for data to properly be ingested into Kibana, the following must exist:
461 | # Index template with matching winlogbeat version
462 | # Data stream with matching index name
463 | # Winlogbeat ingest pipelines
464 |
465 | local es_pass="$1"
466 | local version="$2"
467 |
468 | POWERSHELL_PIPELINE="elasticsearch/templates/winlogbeat-$version-powershell.json"
469 | POWERSHELL_OPERATIONAL_PIPELINE="elasticsearch/templates/winlogbeat-$version-powershell_operational.json"
470 | ROUTING_PIPELINE="elasticsearch/templates/winlogbeat-$version-routing.json"
471 | SECURITY_PIPELINE="elasticsearch/templates/winlogbeat-$version-security.json"
472 | SYSMON_PIPELINE="elasticsearch/templates/winlogbeat-$version-sysmon.json"
473 |
474 | if [[ ! -r "$ROUTING_PIPELINE" || ! -r "$SYSMON_PIPELINE" || ! -r "$POWERSHELL_PIPELINE" || ! -r "$POWERSHELL_OPERATIONAL_PIPELINE" || ! -r "$SECURITY_PIPELINE" ]]; then
475 | fail "Couldn't find required ingest pipeline template files: $ROUTING_PIPELINE, $SYSMON_PIPELINE, $POWERSHELL_PIPELINE, $POWERSHELL_OPERATIONAL_PIPELINE, $SECURITY_PIPELINE"
476 | fi
477 |
478 | # Load index template and data stream
479 | create_data_stream "$es_pass" "$version"
480 |
481 | require_elasticsearch_api_up "$es_pass"
482 |
483 | # Load winlogbeat-x.x.x-routing ingest pipeline
484 | if ! printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -X PUT -k -K- "https://localhost:9200/_ingest/pipeline/winlogbeat-$version-routing" -H 'Content-Type: application/json' --data-binary "@$ROUTING_PIPELINE" > /dev/null; then
485 | fail "Couldn't load winlogbeat-$version routing ingest pipeline"
486 | else
487 | # Load winlogbeat-x.x.x-sysmon ingest pipeline
488 | printf " ${GREEN}\u2714${NC} Loaded winlogbeat-$version routing ingest pipeline\n"
489 | if ! printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -X PUT -k -K- "https://localhost:9200/_ingest/pipeline/winlogbeat-$version-sysmon" -H 'Content-Type: application/json' --data-binary "@$SYSMON_PIPELINE" > /dev/null; then
490 | fail "Couldn't load winlogbeat-$version sysmon ingest pipeline"
491 | else
492 | # Load winlogbeat-x.x.x-security ingest pipeline
493 | printf " ${GREEN}\u2714${NC} Loaded winlogbeat-$version sysmon ingest pipeline\n"
494 | if ! printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -X PUT -k -K- "https://localhost:9200/_ingest/pipeline/winlogbeat-$version-security" -H 'Content-Type: application/json' --data-binary "@$SECURITY_PIPELINE" > /dev/null; then
495 | fail "Couldn't load winlogbeat-$version security ingest pipeline"
496 | else
497 | # Load winlogbeat-x.x.x-powershell ingest pipeline
498 | printf " ${GREEN}\u2714${NC} Loaded winlogbeat-$version security ingest pipeline\n"
499 | if ! printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -X PUT -k -K- "https://localhost:9200/_ingest/pipeline/winlogbeat-$version-powershell" -H 'Content-Type: application/json' --data-binary "@$POWERSHELL_PIPELINE" > /dev/null; then
500 | fail "Couldn't load winlogbeat-$version powershell ingest pipeline"
501 | else
502 | # Load winlogbeat-x.x.x-powershell_operational ingest pipeline
503 | printf " ${GREEN}\u2714${NC} Loaded winlogbeat-$version powershell ingest pipeline\n"
504 | if ! printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -X PUT -k -K- "https://localhost:9200/_ingest/pipeline/winlogbeat-$version-powershell_operational" -H 'Content-Type: application/json' --data-binary "@$POWERSHELL_OPERATIONAL_PIPELINE" > /dev/null; then
505 | fail "Couldn't load winlogbeat-$version powershell_operational ingest pipeline"
506 | else
507 | printf " ${GREEN}\u2714${NC} Loaded winlogbeat-$version powershell_operational ingest pipeline\n"
508 | fi
509 | fi
510 | fi
511 | fi
512 | fi
513 | }
514 |
515 | upgrade_beaker() {
516 | local es_pass="$1"
517 | local docker_sudo="$2"
518 | local install_elastic_version="$INSTALL_ELASTIC_VERSION"
519 | mandatory_upgrade_version="7.17.9"
520 | if "$UPGRADE_INSTALL" ; then
521 | # default to v7.0.0 if current version doesn't exist in env file
522 | if [ -z "$CURRENT_ELASTIC_VERSION" ]; then
523 | CURRENT_ELASTIC_VERSION="7.0.0"
524 | fi
525 | major_version=$(echo "$CURRENT_ELASTIC_VERSION" | cut -d "." -f 1)
526 | minor_version=$(echo "$CURRENT_ELASTIC_VERSION" | cut -d "." -f 2)
527 |
528 | # If ELK version less than 8.0.0
529 | if [ $major_version -lt 8 ]; then
530 | if [ $minor_version -lt 17 ]; then
531 | # If ELK version less than 7.17, force upgrade to 7.17.x
532 | install_elastic_version="$mandatory_upgrade_version"
533 | elif [ $minor_version -eq 17 ]; then
534 | if [ "$acm_no_interactive" != 'yes' ]; then
535 | echo "The currently installed Elastic stack version is v$CURRENT_ELASTIC_VERSION"
536 | echo "Would you like to upgrade to Elastic stack v$install_elastic_version or reinstall v$CURRENT_ELASTIC_VERSION?"
537 | echo "[Y] Upgrade to v$install_elastic_version [N] Reinstall $CURRENT_ELASTIC_VERSION"
538 | if askYN; then
539 | printf "${YELLOW}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!${NC}\n"
540 | printf "${YELLOW}Elastic v$install_elastic_version is a major release version upgrade!${NC}\n"
541 | echo "While BeaKer attempts to prepare your system as best as possible for the upgrade, your particular deployment and usage of the Elastic stack may require additional preparation."
542 | echo "If your BeaKer installation is meant to run in a production environment, please take the following precautionary steps:"
543 | echo " [1] Use the Kibana Upgrade assistant to resolve any critical issues before upgrading. It can be found in the Kibana UI under Stack Management > Upgrade Assistant."
544 | echo " [2] Upgrade your Windows agents to Winlogbeat v$mandatory_upgrade_version using install-sysmon-beats.ps1 if you have not already."
545 | echo ""
546 | echo "The Elastic stack $(tput bold)cannot$(tput sgr0) be downgraded to a previous version."
547 | echo "In the event of upgrade failure, BeaKer must be reinstalled with the previously installed version."
548 | echo "The BeaKer installer will prompt you to create a snapshot that can be used to restore your data in the event of upgrade failure."
549 | printf "${YELLOW}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!${NC}\n"
550 | echo ""
551 | echo "Would you like to continue upgrading to Elastic v$install_elastic_version? (Y/N)"
552 | if ! askYN; then
553 | echo "Upgrade installation was cancelled by the user."
554 | exit
555 | fi
556 | echo "Would you like to create a snapshot?"
557 | if askYN; then
558 | status "Creating snapshot"
559 | create_snapshot "$es_pass"
560 | else
561 | echo "Upgrading without creating snapshot..."
562 | fi
563 | else
564 | install_elastic_version="$mandatory_upgrade_version"
565 | fi
566 | fi
567 | fi
568 | else
569 | # ELK stack version is at least 8.0.0
570 | patch_version=$(echo "$CURRENT_ELASTIC_VERSION" | cut -d "." -f 3)
571 | install_major_version=$(echo "$install_elastic_version" | cut -d "." -f 1)
572 | install_minor_version=$(echo "$install_elastic_version" | cut -d "." -f 2)
573 | install_patch_version=$(echo "$install_elastic_version" | cut -d "." -f 3)
574 | # If the upgrade is not to a higher major version
575 | if [ $major_version -eq $install_major_version ]; then
576 | # If the upgrade is to a higher minor version or higher patch version, ask to upgrade or reinstall current version
577 | if [ $install_minor_version -gt $minor_version ] || [ $install_minor_version -eq $minor_version -a $install_patch_version -gt $patch_version ]; then
578 | echo "The currently installed Elastic stack version is v$CURRENT_ELASTIC_VERSION"
579 | echo "Would you like to upgrade to Elastic stack v$install_elastic_version or reinstall v$CURRENT_ELASTIC_VERSION?"
580 | echo "[Y] Upgrade to v$install_elastic_version [N] Reinstall $CURRENT_ELASTIC_VERSION"
581 |
582 | if ! askYN; then
583 | install_elastic_version="$CURRENT_ELASTIC_VERSION"
584 | fi
585 | else
586 | install_elastic_version="$CURRENT_ELASTIC_VERSION"
587 | fi
588 | fi
589 | fi
590 | INSTALL_ELASTIC_VERSION=$install_elastic_version
591 | status "Upgrading to Elastic v$INSTALL_ELASTIC_VERSION..."
592 | $docker_sudo sed -i "s/activecm-beaker\/elasticsearch:.*/activecm-beaker\/elasticsearch:$INSTALL_ELASTIC_VERSION/g" /opt/BeaKer/docker-compose.yml
593 | $docker_sudo sed -i "s/activecm-beaker\/kibana:.*/activecm-beaker\/kibana:$INSTALL_ELASTIC_VERSION/g" /opt/BeaKer/docker-compose.yml
594 | else
595 | INSTALL_ELASTIC_VERSION=$install_elastic_version
596 | status "Installing Elastic v$INSTALL_ELASTIC_VERSION..."
597 | fi
598 | }
599 |
600 | install_beaker () {
601 | status "Installing Elasticsearch and Kibana"
602 |
603 | # Determine if the current user has permission to run docker
604 | local docker_sudo=""
605 | if [ ! -w "/var/run/docker.sock" ]; then
606 | docker_sudo="sudo -E"
607 | fi
608 |
609 | # Load password
610 | # Use docker_sudo since the env file ownership is root:docker.
611 | local es_pass=`$docker_sudo grep '^ELASTIC_PASSWORD' "$BEAKER_CONFIG_DIR/env" | sed -e 's/^[^=][^=]*=//'`
612 |
613 | INSTALL_ELASTIC_VERSION=$( tail -n 1 ELK_VERSIONS )
614 |
615 | upgrade_beaker "$es_pass" "$docker_sudo"
616 |
617 | # Load the docker images
618 | gzip -d -c images-latest.tar.gz | $docker_sudo docker load >&2
619 |
620 | ensure_certificates_exist
621 |
622 | # Start Elasticsearch and Kibana with the new images
623 | ./beaker up -d --force-recreate >&2
624 |
625 | status "Waiting for initialization"
626 | sleep 15
627 |
628 | install_major_version=$(echo "$INSTALL_ELASTIC_VERSION" | cut -d "." -f 1)
629 |
630 | status "Creating service account token"
631 | create_service_account_token "$es_pass"
632 |
633 | status "Loading index lifecycle policy"
634 | create_index_lifecycle_policy "$es_pass"
635 |
636 | dashboard_filename="kibana_dashboards-8.0.0.ndjson"
637 |
638 | if [ $install_major_version -eq 8 ]; then
639 | status "Loading Ingest Pipelines"
640 | create_ingest_pipelines "$es_pass" "$INSTALL_ELASTIC_VERSION"
641 | elif [ $install_major_version -lt 8 ]; then
642 | status "Loading Index Template & Data Stream"
643 | create_data_stream "$es_pass" "$INSTALL_ELASTIC_VERSION"
644 | dashboard_filename="kibana_dashboards-7.17.0.ndjson"
645 | fi
646 |
647 | require_elasticsearch_api_up "$es_pass"
648 | status "Waiting for Kibana to come online"
649 | echo "This might take a while..."
650 | require_kibana_available "$es_pass"
651 |
652 | status "Loading Kibana dashboards"
653 |
654 | echo "Uploading $dashboard_filename"
655 | local connection_attempts=0
656 | local data_uploaded="false"
657 | while [ $connection_attempts -lt 8 -a "$data_uploaded" != "true" ]; do
658 | if echo "$es_pass" | kibana/import_dashboards.sh "kibana/$dashboard_filename" >&2 ; then
659 | printf "${GREEN}\u2714${NC} The installer successfully uploaded dashboards to Kibana.\n"
660 | data_uploaded="true"
661 | break
662 | fi
663 | echo2 "The installer encountered an error while uploading dashboards to Kibana."
664 | echo2 "Retrying..."
665 | sleep 15
666 | connection_attempts=$((connection_attempts + 1))
667 | done
668 | if [ "$data_uploaded" != "true" ]; then
669 | fail "The installer failed to load the Kibana dashboards"
670 | fi
671 |
672 | # Update installed version tag in config
673 | $docker_sudo sed -i "s/ELK_STACK_VERSION=.*/ELK_STACK_VERSION=$INSTALL_ELASTIC_VERSION/g" "$BEAKER_CONFIG_DIR/env"
674 | }
675 |
676 |
677 | configure_ingest_account () {
678 | # Determine if the current user has permission to run docker/ read the env file
679 | local docker_sudo=""
680 | if [ ! -w "/var/run/docker.sock" ]; then
681 | docker_sudo="sudo"
682 | fi
683 | local es_pass=`$docker_sudo grep ELASTIC_PASSWORD "$BEAKER_CONFIG_DIR/env" | cut -d= -f2`
684 |
685 | require_elasticsearch_api_up "$es_pass"
686 |
687 | ingest_account_exists=false
688 |
689 | # Don't configure the ingest account if it already exists
690 | if printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -s -X GET -k -K- "https://localhost:9200/_security/user/sysmon-ingest" | grep -q "\"username\":\"sysmon-ingest\""; then
691 | ingest_account_exists=true
692 | fi
693 |
694 | if [ "$acm_no_interactive" = 'yes' ]; then
695 | echo2 "We are in non-interactive mode but the ingest account is not configured, exiting."
696 | exit 1
697 | fi
698 |
699 | if ! $ingest_account_exists ; then
700 | status "Configuring Elasticsearch ingest account"
701 |
702 | echo "Please enter a password for the Elasticsearch Sysmon-ingest user account."
703 | echo "Use this account when connecting the BeaKer agent."
704 | echo "Username: sysmon-ingest"
705 | local ingest_password=""
706 | local pw_confirmation="foobar"
707 | while [ "$ingest_password" != "$pw_confirmation" ]; do
708 | read -es -p "Password: " ingest_password
709 | echo ""
710 | read -es -p "Password (Confirmation): " pw_confirmation
711 | echo ""
712 | done
713 | fi
714 |
715 | if ! printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -s -X POST -k -K- "https://localhost:9200/_security/role/sysmon-ingest" -H 'Content-Type: application/json' -d'
716 | {
717 | "run_as": [],
718 | "cluster": [ "monitor", "read_ilm", "read_pipeline" ],
719 | "indices": [
720 | {
721 | "names": [ "sysmon-*" ],
722 | "privileges": [ "create_doc", "create_index" ]
723 | },
724 | {
725 | "names": [ "winlogbeat-*" ],
726 | "privileges": [ "create_doc", "create_index", "auto_configure" ]
727 | }
728 | ]
729 | }
730 | ' > /dev/null ; then
731 | fail "Unable to create Elasticsearch ingest role."
732 | fi
733 |
734 | if ! $ingest_account_exists ; then
735 | if ! printf -- '-u "%s"' "elastic:$es_pass" | curl --fail -s -X POST -k -K- "https://localhost:9200/_security/user/sysmon-ingest" -H 'Content-Type: application/json' -d"
736 | {
737 | \"password\" : \"$ingest_password\",
738 | \"roles\" : [ \"sysmon-ingest\" ]
739 | }
740 | " > /dev/null ; then
741 | fail "Unable to create Elasticsearch ingest user."
742 | fi
743 | fi
744 | }
745 |
746 | move_files () {
747 | local installation_dir="/opt/$(basename "$(pwd)")"
748 | if [[ `pwd` -ef "$installation_dir" ]]; then
749 | return 0
750 | fi
751 |
752 | status "Moving files to $installation_dir"
753 | $SUDO rm -rf "$installation_dir"
754 | move_working_directory `dirname "$installation_dir"`
755 | }
756 |
757 | link_executables () {
758 | local executables=(
759 | "./beaker"
760 | )
761 |
762 | for executable in "${executables[@]}"; do
763 | local executable_name=`basename "$executable"`
764 | local link_name="/usr/local/bin/$executable_name"
765 | $SUDO rm -f "$link_name"
766 | $SUDO ln -sf `realpath "$executable"` "$link_name"
767 | done
768 | }
769 |
770 | main () {
771 | status "Checking for administrator priviledges"
772 | require_sudo
773 | export acm_no_interactive
774 |
775 | test_system
776 |
777 | move_files
778 | link_executables
779 |
780 | status "Installing supporting software"
781 | ensure_common_tools_installed
782 |
783 | install_docker
784 |
785 | ensure_snapshot_repo_exists
786 | ensure_env_file_exists
787 |
788 | install_beaker
789 | configure_ingest_account
790 |
791 | status "Congratulations, BeaKer is installed"
792 |
793 | if [[ "$INSTALL_ELASTIC_VERSION" == "7.17.9" ]]; then
794 | echo ""
795 | printf "${GREEN}----- BeaKer Post-Upgrade Tasks -----${NC}\n"
796 | echo "This upgrade to Elastic v7.17.9 is intended to be an intermediary upgrade before upgrading to Elastic v8.7.0."
797 | echo "Upgrading to Elastic v8.7.0 is optional."
798 | echo "The following tasks should be completed before upgrading to Elastic v8.7.0:"
799 | echo "1. Upgrade all Windows agents to Winlogbeat v7.17.9 by running $(tput bold)install-sysmon-beats.ps1$(tput sgr0) on each machine."
800 | echo " > After upgrading Elastic to v8.7.0, any Windows agents running Winlogbeat versions lower than 7.17.0 will not be able to send data to BeaKer."
801 | echo ""
802 | echo "To upgrade to Elastic v8.7.0, run $(tput bold)/opt/BeaKer/install_beaker.sh$(tput sgr0)"
803 | else
804 | echo ""
805 | printf "${GREEN}----- BeaKer Post-Upgrade Tasks -----${NC}\n"
806 | echo "Ensure that all Windows agents are running a compatible version of Winlogbeat. Not every Elasticsearch upgrade requires upgrading Winlogbeat on Windows agents."
807 | echo "Generally, lower versions of Winlogbeat are compatible with the currently installed Elastic version so as long as they share the same major version."
808 | echo "To verify whether or not an upgrade of Winlogbeat is required, check compatibility at https://www.elastic.co/support/matrix#matrix_compatibility"
809 | echo "To upgrade Winlogbeat, run $(tput bold)install-sysmon-beats.ps1$(tput sgr0) on each Windows agent."
810 | fi
811 |
812 | }
813 |
814 | main "$@"
815 |
816 | #### Clean Up
817 | # Change back to the initial working directory
818 | # If the script was launched from the script directory, popd will fail since it moved
819 | popd &> /dev/null || true
820 |
--------------------------------------------------------------------------------
/installer/stage/BeaKer/kibana/import_dashboards.sh:
--------------------------------------------------------------------------------
1 | ../../../../kibana/import_dashboards.sh
--------------------------------------------------------------------------------
/installer/stage/BeaKer/kibana/kibana_dashboards-7.17.0.ndjson:
--------------------------------------------------------------------------------
1 | ../../../../kibana/kibana_dashboards-7.17.0.ndjson
--------------------------------------------------------------------------------
/installer/stage/BeaKer/kibana/kibana_dashboards-8.0.0.ndjson:
--------------------------------------------------------------------------------
1 | ../../../../kibana/kibana_dashboards-8.0.0.ndjson
--------------------------------------------------------------------------------
/installer/stage/BeaKer/shell-lib:
--------------------------------------------------------------------------------
1 | ../../../shell-lib/
--------------------------------------------------------------------------------
/kibana/Dockerfile:
--------------------------------------------------------------------------------
1 | ARG ELK_STACK_VERSION
2 |
3 | FROM kibana:${ELK_STACK_VERSION}
4 | ADD ./kibana.yml /usr/share/kibana/config/kibana.yml
--------------------------------------------------------------------------------
/kibana/export_dashboards.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | curl -u "elastic:$ELASTIC_PASSWORD" -X POST -k "https://localhost:5601/api/saved_objects/_export" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d'
4 | {
5 | "type": ["index-pattern", "config", "visualization", "dashboard", "map", "canvas-workpad", "canvas-element", "query", "search", "url"],
6 | "includeReferencesDeep": true
7 | }
8 | '
--------------------------------------------------------------------------------
/kibana/import_dashboards.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Reads the elasticsearch password from stdin and uploads
4 | # the file given to localhost:5601.
5 |
6 | set -e
7 |
8 | DASHBOARD_FILE="$1"
9 |
10 | read_password() {
11 | local reply=""
12 | if [ -t 0 ]; then
13 | IFS="" read -es -p "Elasticsearch Password: " reply
14 | echo "" >&2
15 | else
16 | IFS="" read reply <&0;
17 | fi
18 | echo "$reply"
19 | }
20 |
21 | main () {
22 | local es_pass="$(read_password)"
23 | local resp # local resp has to be separate from the next line to generate a valid $? for the curl command
24 | resp=`curl --fail -u "elastic:$es_pass" -X POST -k "https://localhost:5601/api/saved_objects/_import?overwrite=true" -H "kbn-xsrf: true" -F file=@$DASHBOARD_FILE`
25 | if [ $? -ne 0 -o "$resp" == "Kibana server is not ready yet" ]; then
26 | exit 2
27 | fi
28 | }
29 |
30 | main "$@"
--------------------------------------------------------------------------------
/kibana/kibana.yml:
--------------------------------------------------------------------------------
1 | ---
2 | server.name: "AI-Hunter: Kibana"
3 | server.host: "0.0.0.0"
4 | server.ssl.enabled: true
5 | server.ssl.certificate: /usr/share/kibana/config/certificates/Kibana/Kibana.crt
6 | server.ssl.key: /usr/share/kibana/config/certificates/Kibana/Kibana.key
7 |
8 | elasticsearch.hosts: [ "https://elasticsearch:9200" ]
9 | elasticsearch.ssl.verificationMode: certificate
10 | elasticsearch.ssl.certificateAuthorities: [ "/usr/share/kibana/config/certificates/ca/ca.crt" ]
11 | elasticsearch.serviceAccountToken: "${KIBANA_SERVICE_TOKEN}"
12 |
13 | xpack.encryptedSavedObjects.encryptionKey: "${SAVED_OBJECTS_ENCRYPTION_KEY}"
14 | xpack.reporting.encryptionKey: "${REPORTING_ENCRYPTION_KEY}"
15 | xpack.security.encryptionKey: "${SECURITY_ENCRYPTION_KEY}"
--------------------------------------------------------------------------------