Skip to content

Commit b8aaf0b

Browse files
authored
Add documentation for architecture, deploying, and uploading files (#64)
1 parent 3c07f1b commit b8aaf0b

File tree

6 files changed

+167
-7
lines changed

6 files changed

+167
-7
lines changed

docs/source/adding-yara-rules.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,19 @@ Write Your Own Rules
2828
--------------------
2929
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.
3030

31+
32+
.. _external-variables:
33+
34+
External Variables
35+
------------------
3136
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>`_:
3237

3338
* ``extension`` - File extension (".docx", ".exe", ".pdf", etc)
3439
* ``filename`` - File basename ("file.exe")
3540
* ``filepath`` - Full file path ("/path/to/file.exe")
3641
* ``filetype`` - Uppercase ``extension`` without leading period ("DOCX", "EXE", "PDF"), etc
3742

38-
You can use these variables in your own rules to match or exclude certain filepaths. For example, this is a YARA rule which matches only files containing the string "evil" in the ``/home/`` directory:
43+
You can use these variables in your own rules to match or exclude certain filepaths. (Note that the variables will default to empty strings if they are not available.) For example, this is a YARA rule which matches only files containing the string "evil" in the ``/home/`` directory:
3944

4045
.. code-block:: none
4146

docs/source/architecture.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Architecture
2+
============
3+
BinaryAlert utilizes a `serverless <https://aws.amazon.com/serverless/>`_ architecture which is low-cost and easy to scale and maintain. While it's helpful to understand how BinaryAlert works, keep in mind that Terraform manages all of these components so you don't have to!
4+
5+
.. image:: ../images/architecture.png
6+
:align: center
7+
:scale: 80%
8+
:alt: BinaryAlert Architecture
9+
10+
11+
Analysis Lifecycle
12+
------------------
13+
14+
1. The organization collects files and `delivers them <uploading-files.html>`_ to their BinaryAlert S3 bucket. Files of interest could include executable binaries, email attachments, documents, etc.
15+
2. Every file uploaded to the S3 bucket is immediately queued for analysis (using `S3 event notifications <http://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html>`_).
16+
3. A dispatching Lambda function runs every minute, grouping files into batches and invoking up to dozens of analyzers in parallel.
17+
4. Each analyzer scans its files using a list of pre-compiled `YARA rules <adding-yara-rules.html>`_.
18+
5. YARA matches 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.
20+
7. Configurable CloudWatch 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.

docs/source/deploying.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Deploying
2+
=========
3+
After you've `setup your environment <getting-started.html>`_, deploying BinaryAlert is as easy as:
4+
5+
.. code-block:: bash
6+
7+
$ ./manage.py deploy
8+
9+
A ``deploy`` is equivalent to the following 4 operations executed in sequence:
10+
11+
.. code-block:: bash
12+
13+
$ ./manage.py unit_test # Unit tests ensure YARA rules compile correctly
14+
$ ./manage.py build # Build the Lambda ".zip" deployment packages
15+
$ ./manage.py apply # Runs "terraform apply" to update the infrastructure
16+
$ ./manage.py analyze_all # Starts a batch analysis of the entire S3 bucket
17+
18+
.. warning:: To ensure new YARA rules are applied ASAP, **every** ``deploy`` starts a batch analysis. If a batch analysis is already running or if you are not updating any YARA rules, you can just ``build`` and ``apply`` your changes.
19+
20+
21+
Terraform State
22+
---------------
23+
By default, Terraform will save the state of the infrastructure locally in ``terraform/terraform.tfstate``. If you are deploying BinaryAlert in an enterprise environment, we recommend configuring `Terraform remote state <https://www.terraform.io/docs/state/remote.html>`_. For example, you can store the Terraform state in a versioned `S3 bucket <https://www.terraform.io/docs/backends/types/s3.html>`_.
24+
25+
26+
Terraform Commands
27+
------------------
28+
We recommend using the ``manage.py`` wrapper script for most BinaryAlert management because it provides additional validation. However, you can run ``terraform`` commands directly from the ``terraform/`` directory. Examples:
29+
30+
.. code-block:: bash
31+
32+
$ cd terraform/
33+
$ terraform plan # Show pending changes
34+
$ terraform show # Print the current state of the infrastructure
35+
36+
37+
Terraform Destroy
38+
.................
39+
To teardown all of the BinaryAlert infrastructure:
40+
41+
.. code-block:: bash
42+
43+
$ cd terraform/
44+
$ terraform destroy
45+
46+
.. note:: By default, S3 objects will not be deleted by ``terraform destroy``. To do so, you have to enable the ``force_destroy`` option in the ``terraform/terraform.tfvars`` configuration file.

docs/source/index.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ BinaryAlert
33

44
.. image:: ../images/logo.png
55
:align: center
6-
:alt: BinaryAlert
6+
:scale: 75%
7+
:alt: BinaryAlert Logo
78

89

910
BinaryAlert is a serverless, real-time framework for detecting malicious files. BinaryAlert can efficiently analyze millions of files a day with a configurable set of `YARA <http://virustotal.github.io/yara/>`_ rules and will trigger an alert as soon as anything malicious is discovered! Organizations can deploy BinaryAlert to their private AWS account in a matter of minutes, allowing them to analyze internal files and documents within the confines of their own environment.
@@ -27,14 +28,17 @@ Resources
2728

2829
* `GitHub Repo <https://github.com/airbnb/binaryalert>`_
2930
* `Blog Post <https://medium.com/airbnb-engineering/binaryalert-real-time-serverless-malware-detection-ca44370c1b90>`_
30-
* `Slack <https://binaryalert.herokuapp.com/>`_
31+
* `Slack <https://binaryalert.herokuapp.com/>`_ (unofficial)
3132
* `Twitter <https://twitter.com/binaryalert_io>`_ (unofficial)
3233

3334

3435
Table of Contents
3536
=================
3637
.. toctree::
37-
:maxdepth: 2
38+
:maxdepth: 3
3839

3940
getting-started
41+
architecture
4042
adding-yara-rules
43+
deploying
44+
uploading-files

docs/source/uploading-files.rst

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
Uploading Files
2+
===============
3+
To upload files for analysis, you need only upload them to the BinaryAlert S3 bucket. The S3 bucket name is of the form
4+
5+
.. code-block:: none
6+
7+
YOUR.NAME.PREFIX.binaryalert-binaries.REGION
8+
9+
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` available to the YARA rules.
10+
11+
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.
12+
13+
14+
CarbonBlack Downloader
15+
----------------------
16+
If you use CarbonBlack Enterprise Response, you can enable BinaryAlert's optional downloader Lambda function. The downloader copies files from CarbonBlack into BinaryAlert's S3 bucket (including the appropriate metadata). To enable it:
17+
18+
.. code-block:: none
19+
20+
$ ./manage.py configure
21+
AWS Region (us-east-1):
22+
Unique name prefix, e.g. "company_team": your_unique_prefix
23+
Enable the CarbonBlack downloader? (no): yes
24+
CarbonBlack URL: https://your.carbonblack.url
25+
CarbonBlack API token (only needs binary read access):
26+
27+
.. 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.
28+
29+
.. 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.
30+
31+
Binaries downloaded from CarbonBlack are saved to the BinaryAlert S3 bucket with the key ``carbonblack/MD5`` and with the following metadata:
32+
33+
.. code-block:: python
34+
35+
[
36+
'carbon_black_group',
37+
'carbon_black_host_count',
38+
'carbon_black_last_seen',
39+
'carbon_black_md5',
40+
'carbon_black_os_type',
41+
'carbon_black_virustotal_score',
42+
'carbon_black_webui_link',
43+
'filepath' # from the "observed_filenames" CarbonBlack metadata
44+
]
45+
46+
Once the downloader is enabled, you can either copy everything from CarbonBlack in one go, or you can `deploy <deploying.rst>`_ the downloader components and setup real-time invocations for every new binary.
47+
48+
49+
Copy All Files
50+
..............
51+
If you want to run a one-time job to copy every file from CarbonBlack into BinaryAlert:
52+
53+
.. code-block:: bash
54+
55+
$ ./manage.py cb_copy_all
56+
57+
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.
58+
59+
60+
Real-Time Invocations
61+
.....................
62+
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>`_):
63+
64+
.. code-block:: python
65+
66+
@rule(logs=['carbonblack:binarystore.file.added'],
67+
matchers=[],
68+
outputs=['aws-lambda:binaryalert'])
69+
def cb_binarystore_file_added(rec):
70+
"""
71+
description: CarbonBlack found a new binary: forward to BinaryAlert for YARA analysis.
72+
"""
73+
return True
74+
75+
If you don't use StreamAlert, you can invoke the downloader yourself:
76+
77+
.. code-block:: python
78+
79+
import boto3, json
80+
boto3.client('lambda').invoke(
81+
FunctionName='your_prefix_binaryalert_downloader',
82+
InvocationType='Event', # Asynchronous invocation
83+
Qualifier='Production', # Invoke production alias
84+
Payload=json.dumps({'md5': 'FILE_MD5'}).encode('utf-8')
85+
)

terraform/cloudwatch_dashboard.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ EOF
9595
"annotations": {
9696
"horizontal": [
9797
{
98-
"label": "Maximum Age",
98+
"label": "Max",
9999
"value": ${aws_sqs_queue.s3_object_queue.message_retention_seconds}
100100
},
101101
{
102-
"label": "High Age Alarm",
102+
"label": "Alarm",
103103
"value": ${aws_cloudwatch_metric_alarm.sqs_age.threshold}
104104
}
105105
]
@@ -163,7 +163,7 @@ EOF
163163
"annotations": {
164164
"horizontal": [
165165
{
166-
"label": "Maximum",
166+
"label": "Max",
167167
"value": 300000
168168
}
169169
]

0 commit comments

Comments
 (0)