You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/adding-yara-rules.rst
+6-11Lines changed: 6 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -79,15 +79,15 @@ In summary, BinaryAlert will copy a file from a remote repository if and only if
79
79
80
80
Write Your Own Rules
81
81
--------------------
82
-
You can add your own ``.yar`` or ``.yara`` files anywhere in the ``rules/`` directory tree. Refer to the `writing YARA rules <http://yara.readthedocs.io/en/latest/writingrules.html>`_ documentation for guidance and examples. Note that when BinaryAlert finds a file which matches a YARA rule, the rule name, `metadata <http://yara.readthedocs.io/en/latest/writingrules.html#metadata>`_, `tags <http://yara.readthedocs.io/en/latest/writingrules.html#rule-tags>`_, and matched `string <http://yara.readthedocs.io/en/latest/writingrules.html#strings>`_ names will be included in the alert for your convenience.
82
+
You can add your own ``.yar`` or ``.yara`` files anywhere in the ``rules/`` directory tree. Refer to the `writing YARA rules <http://yara.readthedocs.io/en/latest/writingrules.html>`_ documentation for guidance and examples. Note that when BinaryAlert finds a file which matches a YARA rule, the rule name, `metadata <http://yara.readthedocs.io/en/latest/writingrules.html#metadata>`_, `tags <http://yara.readthedocs.io/en/latest/writingrules.html#rule-tags>`_, and matched `string <http://yara.readthedocs.io/en/latest/writingrules.html#strings>`_ names and string data will be included in the alert for your convenience.
83
83
84
84
.. note:: Because the folders for each remote source will be overwritten during rule cloning, we recommend keeping your own YARA rules in ``rules/private`` or similar.
85
85
86
86
.. _external-variables:
87
87
88
88
External Variables
89
89
------------------
90
-
In order to support the rule repositories listed above, BinaryAlert provides the following `external variables <http://yara.readthedocs.io/en/latest/writingrules.html#external-variables>`_:
90
+
In order to support the rule repositories listed above, BinaryAlert provides the following `external variables <http://yara.readthedocs.io/en/latest/writingrules.html#external-variables>`_ to YARA:
There may be times you want to disable certain YARA rules, but not delete them (e.g. rules with high false-positive rates). Since only ``.yar`` and ``.yara`` files in the ``rules/`` directory tree are bundled in a BinaryAlert deploy, you can simply rename ``rules.yar`` to any other extension, e.g. ``rules.yar.DISABLED``, to skip it during rules compilation.
122
122
123
-
If you want to disable an individual rule (not the entire file), you can either comment it out or prefix the rule with the ``private`` modifier to elide it from reported YARA match results. Unfortunately, there is no easy way to automatically *remove* individual rules from a file.
123
+
If you want to disable an individual rule (not the entire file), you can either comment it out or prefix the rule with the ``private`` modifier to elide it from reported YARA match results.
124
124
125
125
126
126
.. _testing_yara_rules:
@@ -141,13 +141,8 @@ To test *all* of your YARA rules, you first need to compile them into a single b
Files uploaded to the BinaryAlert S3 bucket will be automatically queued for analysis. You can also
4
-
use the analyzer to scan files from other buckets directly or in response to event notifications.
4
+
invoke the analyzer directly, scan files in other buckets, or download files from CarbonBlack.
5
5
6
6
Uploading Files
7
7
---------------
8
8
9
-
To upload files for analysis, you need only upload them to the BinaryAlert S3 bucket. The S3 bucket name is of the form
9
+
All files uploaded to the BinaryAlert S3 bucket will be immediately queued for analysis. The S3 bucket name is of the form
10
10
11
11
.. code-block:: none
12
12
13
13
YOUR.NAME.PREFIX.binaryalert-binaries.REGION
14
14
15
15
When uploading to S3, any object metadata you set will be included in all match alerts. In addition, if there is a ``filepath`` metadata key, BinaryAlert will make the filepath :ref:`external variables <external-variables>` available to the YARA rules.
16
16
17
-
Uploaded files are persisted indefinitely so that BinaryAlert can retroactively analyze all files with every rule update. The S3 bucket has both `access logging <http://docs.aws.amazon.com/AmazonS3/latest/dev/ServerLogs.html>`_ and `object versioning <http://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectVersioning.html>`_ enabled.
17
+
Uploaded files are persisted indefinitely so that BinaryAlert can retroactively analyze all files.
18
+
The S3 bucket has `access logging <http://docs.aws.amazon.com/AmazonS3/latest/dev/ServerLogs.html>`_, `object versioning <http://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectVersioning.html>`_, `inventory <https://docs.aws.amazon.com/AmazonS3/latest/dev/storage-inventory.html>`_, and `server-side encryption <https://docs.aws.amazon.com/AmazonS3/latest/dev/serv-side-encryption.html>`_ enabled.
19
+
20
+
21
+
Analyzing Existing Buckets
22
+
--------------------------
23
+
To scan files in other S3 buckets, you first need to grant BinaryAlert permission to access them. Modify the S3 section of your `terraform.tfvars <https://github.com/airbnb/binaryalert/blob/master/terraform/terraform.tfvars>`_ file and `deploy <deploying.html>`_ the changes:
24
+
25
+
.. code-block:: terraform
26
+
27
+
# ##### S3 #####
28
+
29
+
# If using BinaryAlert to scan existing S3 buckets, add the S3 and KMS resource ARNs here
You can configure other buckets to send S3 event notifications to the BinaryAlert SQS queue.
94
+
To do so, create an `event notification <http://docs.aws.amazon.com/AmazonS3/latest/user-guide/enable-event-notifications.html>`_ on your existing bucket
95
+
and then modify the `BinaryAlert SQS permissions <https://github.com/airbnb/binaryalert/blob/ea5c31ee55a483e5216296e3e0598e3318b7eb24/terraform/sqs.tf#L28-L33>`_ accordingly.
96
+
Once configured, BinaryAlert will be automatically analyzing new objects in your existing buckets in addition to its own.
97
+
98
+
99
+
.. _retro_scan:
100
+
101
+
Retroactive Analysis
102
+
--------------------
103
+
When adding new YARA rules to your collection, you can easily re-scan all of your files in the BinaryAlert bucket to see if any of them match the new rules:
104
+
105
+
.. code-block:: bash
106
+
107
+
$ ./manage.py retro_fast
108
+
109
+
This will enumerate the most recent `S3 inventory manifest <https://docs.aws.amazon.com/AmazonS3/latest/dev/storage-inventory.html>`_, adding all object keys to the analysis SQS queue.
110
+
However, if your bucket is less than 48 hours old, it may not yet have an inventory manifest. In that case, you can list the objects yourself:
111
+
112
+
.. code-block:: bash
113
+
114
+
$ ./manage.py retro_slow
115
+
116
+
As its name suggests, enumerating the bucket directly will generally be much slower than reading the inventory, particularly for buckets with thousands of objects or more.
117
+
118
+
.. note:: Because the inventory may be up to 24 hours old, a ``retro_fast`` scan may miss the newest objects in the bucket. If you need to scan *all* files immediately, use ``retro_slow``.
119
+
120
+
In either case, once all of the objects are in the analyzer SQS queue, it will take some time for BinaryAlert to finish scanning all of them (depending on how many objects you have).
121
+
`YARA matches <yara-matches.html>`_ found during a retroactive scan are treated like any other - the matches are saved to Dynamo and reported via SNS.
122
+
123
+
Stopping a Retro Scan
124
+
.....................
125
+
Sometimes, a new YARA rule you thought would be great turns out to be super noisy, flooding you with false positive alerts.
126
+
Unfortunately, if you have millions of objects in your BinaryAlert bucket, a retro scan can take hours to finish.
127
+
To stop a retro scan dead in its tracks, you can drop all messages from the analysis queue:
128
+
129
+
.. code-block:: bash
130
+
131
+
$ ./manage.py purge_queue
132
+
133
+
.. warning:: This will also drop any event notifications from newly added objects that arrived after the retro scan started. These objects won't be scanned again until either (a) the next ``retro_slow`` scan or (b) the next ``retro_fast`` after 24 hours when the new object is in the inventory.
18
134
19
135
20
136
.. _cb_downloader:
21
137
22
138
CarbonBlack Downloader
23
139
----------------------
24
-
If you use CarbonBlack Enterprise Response, you can enable BinaryAlert's optional downloader Lambda function. The downloader copies files (and some metadata) from CarbonBlack into BinaryAlert's S3 bucket. To enable it:
140
+
If you use CarbonBlack Enterprise Response, you can enable BinaryAlert's optional downloader SQS queue and Lambda function.
141
+
The downloader copies files (and some metadata) from CarbonBlack into BinaryAlert's S3 bucket. To enable it:
25
142
26
143
.. code-block:: none
27
144
@@ -32,6 +149,8 @@ If you use CarbonBlack Enterprise Response, you can enable BinaryAlert's optiona
32
149
CarbonBlack URL: https://your.carbonblack.url
33
150
CarbonBlack API token (only needs binary read access):
34
151
152
+
$ ./manage.py deploy
153
+
35
154
.. warning:: The API token only needs access to read binaries. Do not use a token with admin privileges, do not allow other users to share the same token, and be sure to regularly rotate the token.
36
155
37
156
.. note:: The API token will not be shown on screen and BinaryAlert will create a new KMS key to encrypt the credentials before saving them to the ``terraform.tfvars`` configuration file. The downloader (and no other component) is authorized to decrypt the credentials with the generated key.
@@ -51,8 +170,6 @@ Binaries downloaded from CarbonBlack are saved to the BinaryAlert S3 bucket with
51
170
'filepath'# from the "observed_filenames" CarbonBlack metadata
52
171
]
53
172
54
-
Once the downloader is enabled, you can either copy everything from CarbonBlack in one go, or you can `deploy <deploying.html>`_ the downloader components and setup real-time invocations for every new binary.
55
-
56
173
57
174
Copy All Files
58
175
..............
@@ -62,113 +179,20 @@ If you want to run a one-time job to copy every file from CarbonBlack into Binar
62
179
63
180
$ ./manage.py cb_copy_all
64
181
65
-
This runs *locally*, using multiple threads to enumerate the files in CarbonBlack and copy them over to BinaryAlert. The downloader *code* is used, but there are no Lambda invocations. This means you can copy all of the files from CarbonBlack without actually deploying the downloader components.
182
+
This runs locally, using multiple threads to enumerate the files in CarbonBlack into the BinaryAlertdownloader SQS queue.
66
183
67
184
68
185
Real-Time Invocations
69
186
.....................
70
-
To ensure real-time file analysis, we recommend invoking the downloader every time CarbonBlack logs a ``binarystore.file.added`` event. If you use `StreamAlert <https://streamalert.io/>`_ to process CarbonBlack logs, the following `rule <https://streamalert.io/rules.html>`_ will invoke the BinaryAlert downloader for every new binary (assuming BinaryAlert is a properly configured Lambda `output <https://streamalert.io/outputs.html>`_):
187
+
For real-time file analysis, we recommend publishing to the downloader SQS queue every time CarbonBlack logs a ``binarystore.file.added`` event. If you use `StreamAlert <https://streamalert.io/>`_ to process CarbonBlack logs, the following `rule <https://streamalert.io/rules.html>`_ will publish a message for every new binary (assuming the SQS queue is a properly configured StreamAlert `output <https://streamalert.io/outputs.html>`_):
.. note:: The analyzer will always save YARA matches to Dynamo and send alerts to the SNS topic, even when invoked directly or when analyzing other buckets.
167
-
168
-
Configuring Event Notifications
169
-
...............................
170
-
You can configure other buckets to send S3 event notifications to the BinaryAlert SQS queue
171
-
(recommended) or to the analyzer directly. In either case, once configured, BinaryAlert will be
172
-
automatically analyzing your existing buckets in addition to its own.
173
-
See `AWS: Enable Event Notifications <http://docs.aws.amazon.com/AmazonS3/latest/user-guide/enable-event-notifications.html>`_
174
-
and a `terraform example <https://www.terraform.io/docs/providers/aws/r/s3_bucket_notification.html#add-notification-configuration-to-sqs-queue>`_ to get started.
198
+
You can also directly publish messages to the downloader SQS queue. Messages are expected to be in the very simple format ``{'md5': 'ABCDE....'}``
Copy file name to clipboardExpand all lines: docs/source/architecture.rst
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ BinaryAlert utilizes a `serverless <https://aws.amazon.com/serverless/>`_ archit
4
4
5
5
.. image:: ../images/architecture.png
6
6
:align:center
7
-
:scale:30%
7
+
:scale:80%
8
8
:alt:BinaryAlert Architecture
9
9
10
10
@@ -16,5 +16,5 @@ Analysis Lifecycle
16
16
3. The SQS queue automatically batches files and invokes many analyzers in parallel.
17
17
4. Each analyzer scans its files using a list of pre-compiled `YARA rules <adding-yara-rules.html>`_.
18
18
5. `YARA matches <yara-matches.html>`_ are saved to DynamoDB and an alert is sent to an SNS topic. You can subscribe to these alerts via `StreamAlert <https://streamalert.io>`_, email, or any other supported `SNS subscription <http://docs.aws.amazon.com/sns/latest/api/API_Subscribe.html>`_.
19
-
6. For retroactive analysis, a batching Lambda function enqueues the entire S3 bucket to be re-analyzed.
19
+
6. For :ref:`retroactive analysis<retro_scan>`, the CLI will enqueue the entire S3 bucket to be re-analyzed.
20
20
7. Configurable :ref:`CloudWatch alarms <metric_alarms>` will trigger if any BinaryAlert component is behaving abnormally. This will notify a different SNS topic than the one used for YARA match alerts.
0 commit comments