GithubHelp home page GithubHelp logo

dropbox / securitybot Goto Github PK

View Code? Open in Web Editor NEW
990.0 58.0 127.0 83 KB

Distributed alerting for the masses!

License: Apache License 2.0

Python 85.00% CSS 0.24% JavaScript 5.15% HTML 9.49% Shell 0.11%
bot duo slack security-automation

securitybot's Introduction

Securitybot

Distributed alerting for the masses!

Securitybot is an open-source implementation of a distributed alerting chat bot, as described in Ryan Huber's blog post. Distributed alerting improves the monitoring efficiency of your security team and can help you catch security incidents faster and more efficiently. We've tried to remove all Dropbox-isms from this code so that setting up your own instance should be fairly painless. It should be relatively easy to install the listed requirements in a virtualenv/Docker container and simply have the bot do its thing. We also provide a simple front end to dive through the database, receive API calls, and create custom alerts for the bot to reach out to people as desired.

Deploying

This guide runs through setting up a Securitybot instance as quickly as possible with no frills. We'll be connecting it to Slack, SQL, and Duo. Once we're done, we'll have a file that looks something like main.py.

SQL

You'll need a database called securitybot on some MySQL server somewhere. We've provided a function called init_sql located in securitybot/sql.py that will initialize SQL. Currently it's set up to use the host localhost with user root and no password. You'll need to change this because of course that's not how your database is set up.

Slack

You'll need a token to be able to integrate with Slack. The best thing to do would be to create a bot user and use that token for Securitybot. You'll also want to set up a channel to which the bot will report when users specify that they haven't performed an action. Find the unique ID for that channel (it'll look similar to C123456) and be sure to invite the bot user into that channel, otherwise it won't be able to send messages.

Duo

For Duo, you'll want to create an Auth API instances, name it something clever, and keep track of the integration key, secret key, and auth API endpoint URI.

Running the bot

Take a look at the provided main.py in the root directory for an example on how to use all of these. Replace all of the global variables with whatever you found above. If the following were all generated successfully, Securitybot should be up and running. To test it, message the bot user it's assigned to and say hi. To test the process of dealing with an alert, message test to test the bot.

Architecture

Securitybot was designed to be as modular as possible. This means that it's possible to easily swap out chat systems, 2FA providers, and alerting data sources. The only system that is tightly integrated with the bot is SQL, but adding support for other databases shouldn't be difficult. Having a database allows alerts to be persistent and means that the bot doesn't lose (too much) state if there's some transient failure.

Securitybot proper

The bot itself performs a small set of functions:

  1. Reads messages, interpreting them as commands.
  2. Polls each user object to update their state of applicable.
  3. Grabs new alerts from the database and assigns them to users or escalates on an unknown user.

Messaging, 2FA, and alert management are provided by configurable modules, and added to the bot upon initialization.

Commands

The bot handles incoming messages as commands. Command parsing and handling is done in the Securitybot class and the commands themselves are provided in two places. The functions for the commands are defined in commands.py and their structure is defined in commands.yaml under the config/ directory.

Messaging

Securitybot is designed to be compatible with a wide variety of messaging systems. We currently provide bindings for Slack, but feel free to contribute any other plugins, like for Gitter or Zulip, upstream. Messaging is made possible by securitybot/chat/chat.py which provides a small number of functions for querying users in a messaging group, messaging those users, and sending messages to a specific channel/room. To add bindings for a new messaging system, subclass Chat.

2FA

2FA support is provided by auth/auth.py, which wraps async 2FA in a few functions that enable checking for 2FA capability, starting a 2FA session, and polling the state of the 2FA session. We provide support for Duo Push via the Duo Auth API, but adding support for a different product or some in-house 2FA solution is as easy as creating a subclass of Auth.

Task management

Task management is provided by tasker/tasker.py and the Tasker class. Since alerts are logged in an SQL database, the provided Tasker is SQLTasker. This provides support for grabbing new tasks and updating them via individual Task objects.

Blacklists

Blacklists are handled by the SQL database, provided in blacklist/blacklist.py and the subclass blacklist/sql_blacklist.py.

Users

The User object provides support for handling user state. We keep track of whatever information a messaging system gives to us, but really only ever use a user's unique ID and username in order to contact them.

Alerts

Alerts are uniquely identified by a SHA-256 hash which comes from some hash of the event that generated them. We assume that a SHA-256 hash is sufficiently random for there to be no collisions. If you encounter a SHA-256 collision, please contact someone at your nearest University and enjoy the fame and fortune it brings upon you.

FAQ

Please ask us things

Contributing

Contributors must abide by the Dropbox Contributor License Agreement.

License

Copyright 2016 Dropbox, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

securitybot's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

securitybot's Issues

Exposed metrics?

First of all thanks for publishing this, it looks useful and I'd like to give it a try soon.

Is there currently any way of external monitoring, e.g. using Prometheus? It'd be useful for making sure that securitybot runs fine from an ops perspective, but also potentially for further processing of alerts, and metrics derived from alerts.

Slack User lookup from email?

Have alerts with actions assigned as email addresses currently, any way to do a lookup on the tool side to map email to slack users?

Could do a lookup in splunk but rather not have to maintain a CSV :)

Cheers,
AB

SQLEngine: Too many connections

I've followed the setup instructions in a fresh virtualenv and tried to run main.py
It connects to the Slack API successfully, creates securitybot, loads configuration, and starts the RTM session.
Then it issues a couple hundred warnings "Recovering from lost MySQL connection" and crashes. Here is a truncated traceback:

Traceback (most recent call last):
  File "main.py", line 45, in <module>
    main()
  File "main.py", line 41, in main
    sb = SecurityBot(chat, tasker, duo_builder, REPORTING_CHANNEL, 'config/bot.yaml')
  File "/securitybot/securitybot/bot.py", line 95, in __init__
    self.blacklist = SQLBlacklist()
  File "/securitybot/securitybot/blacklist/sql_blacklist.py", line 17, in __init__
    names = SQLEngine.execute('SELECT * FROM blacklist')
  File "/securitybot/securitybot/sql.py", line 79, in execute
    return SQLEngine.execute(query, params)

Those last two lines repeat a couple hundred times and then

  File "/securitybot/securitybot/sql.py", line 78, in execute
    SQLEngine._db)
  File "/securitybot/securitybot/sql.py", line 51, in _create_engine
    db=db)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 193, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1040, 'Too many connections')

While the user defined on line 93 of sql.py (why is this setting buried?) has full rights to the database, no tables are created.

Failing to run main because of SQLEngine

I would like to get some assistance with a small issue I am facing (not strong in python). I have tried using pip install SQLEngine and even went on to install SQLAlchemy but I can't seem to go past this stage when I run python main.py

Can you please help

โ””> python2.7 main.py Traceback (most recent call last): File "main.py", line 4, in <module> from securitybot.bot import SecurityBot File "/Users/pathXXXX/securitybot/securitybot/bot.py", line 9, in <module> from securitybot.user import User File "/Users/pathXXXX/securitybot/securitybot/user.py", line 11, in <module> import securitybot.ignored_alerts as ignored_alerts File "/Users/pathXXXX/securitybot/securitybot/ignored_alerts.py", line 6, in <module> from securitybot.sql import SQLEngine File "/Users/pathXXXX/securitybot/securitybot/sql.py", line 7, in <module> from typing import Any, Sequence ImportError: No module named typing

pypi securitybot

Super great project, thanks so much for releasing it open source. I was going to spin up one of my own but it's clear this project is WAY better than mine would have ever been. So related to that, I'm happy to give you the pypi 'securitybot' project (https://pypi.python.org/pypi/securitybot). Just email me at [email protected] and we'll setup the 'switch'. :)

Postgres Support

Would be nice for those more Postgres-friendly shops (like where I work). Definitely a nice-to-have.

Disable auth component

Just started using the tool as a POC but getting crashes of main.py due to no duo keys (do not have this service)

How and Can I turn off this component for now?

Crashed main.py by 'ignore' sent for non-existent user alerts

Hi, Have been able to crash the bot via "ignore last 1h1m" when no alert assigned for myself (user).

Traceback (most recent call last):
  File "main.py", line 45, in <module>
    main()
  File "main.py", line 42, in main
    sb.run()
  File "/home/ec2-user/securitybot/securitybot/bot.py", line 180, in run
    self.handle_messages()
  File "/home/ec2-user/securitybot/securitybot/bot.py", line 199, in handle_messages
    self.handle_command(user, text)
  File "/home/ec2-user/securitybot/securitybot/bot.py", line 211, in handle_command
    if cmd['fn'](self, user, args):
  File "/home/ec2-user/securitybot/securitybot/commands.py", line 69, in ignore
    if which == 'last' and user.old_tasks:
AttributeError: 'User' object has no attribute 'old_tasks'

getting pytz error

hello! i am a newbie. i was trying to implement security bot as my class assignment. I am getting the following error when i run main.py by following your guidelines

Traceback (most recent call last):
File "main.py", line 4, in
from securitybot.bot import SecurityBot
File "C:\securitybot-master\securitybot\bot.py", line 9, in
from securitybot.user import User
File "C:\securitybot-master\securitybot\user.py", line 9, in
import pytz
ModuleNotFoundError: No module named 'pytz'

can u please help me?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.