Git Product home page Git Product logo

anteater's Introduction

Anteater - CI/CD Gate Check Framework

anteater

Build Status Documentation Status

Description

Anteater is an open framework to prevent the unwanted merging of nominated strings, filenames, binaries, depreciated functions, staging enviroment code / credentials etc. Anything that can be specified with regular expression syntax, can be sniffed out by anteater.

You tell anteater exactly what you don't want to get merged, and anteater looks after the rest.

If anteater finds something, it exits with a non-zero code which in turn fails the build of your CI tool, with the idea that it would prevent a pull request merging. Any false positives are easily negated by using the same RegExp framework to cancel out the false match.

Entire projects may also be scanned also, using a recursive directory walk.

With a few simple steps it can be easily implemented into a CI / CD workflow with tooling such as Travis CI, CircleCI, Gitlab CI/CD and Jenkins.

It is currently used in the Linux Foundations project 'OPNFV' as means to provide automated security checks at gate, but as shown in the examples below, it can be used for other scenarios.

Anteater also provides integrates with the Virus Total API, so any binaries, public IP addresses or URL's found by anteater, will be sent to the Virus Total API and a report will be returned. If any object is reported as malicous, it will fail the CI build job.

Example content is provided for those unsure of what to start with and its encouraged and welcomed to share any Anteater filter strings you find useful.

Why would I want to use this?

Anteater has many uses, and can easily be bent to cover your own specific needs.

First, as mentioned, it can be set up to block strings and files with a potential security impact or risk. This could include private keys, a shell history, aws credentials etc.

It is especially useful at ensuring that elements used in a staging / development enviroment don't find there way into a production enviroment.

Let's take a look at some examples:

apprun:
  regex: app\.run\s*\(.*debug.*=.*True.*\)
  desc: "Running flask in debug mode could potentially leak sensitive data"

The above will match code where a flask server is set to running in debug mode app.run(host='0.0.0.0' port=80 debug=true), which can be typical to a developers enviroment and mistakenly staged into production.

For a rails app, this could be:

regex: \<%=.*debug.*%>

Even more simple, look for the following in most logging frameworks:

regex: log\.debug

Need to stop developers mistakenly adding a private key?

  private_key:
    regex: -----BEGIN\sRSA\sPRIVATE\sKEY----
    desc: "This looks like it could be a private key"

How about credential files that would cause a job loss if ever leaked into production? Anteater works with file names too.

For Example:

jenkins\.plugins\.publish_over_ssh\.BapSshPublisherPlugin\.xml

Or even..

- \.pypirc
- \.gem\/credentials
- aws_access_key_id
- aws_secret_access_key
- LocalSettings\.php

If your app has its own custom secrets / config file, then its very easy to add your own regular expressions. Everything is set using YAML formatting, so no need to change anteaters code.

Depreciated functions, classes etc

Another use is for when a project depreciates an old function, yet developers might still make pull requests using the old function naming:

depreciated_function:``
  regex: depreciated_function\(.*\)
  desc: This function was depreciated in release X, use Y function.

Or perhaps stopping people from using 1.x versions of a framework:

<script.src.*="https:\/\/ajax\.googleapis\.com\/ajax\/libs\/angularjs\/1.*<\/script>

What if I get false postives?

Easy, you set a RegExp to stop the match , kind of like RegExp'ception.

Let's say we want to stop use of MD5:

md245:
  regex: md[245]
  desc: "Insecure hashing algorithm"

This then incorrectly gets matched to the following:

mystring = int(amd500) * 4

We set a specific ignore RegEx, so it matches and then is unmatched by the ignore entry.

mystring.=.int\(amd500\).*

Yet other instance of MD5 continue to get flagged.

Binaries

With anteater, if you pass the argument --binaries, any binary found causes a build failure on the originating pull request. It is not until a sha256 checksum is set within anteater's YAML ignore files, that the build is allowed to pass.

This means you can block people from checking in compiled objects, images, PDFs etc that may have an unknown origin or tampering with the existing binary files.

An example:

$ anteater --binaries --project myproj --patchset /tmp/patch
Non Whitelisted Binary file: /folder/to/repo/images/pal.png
Please submit patch with this hash: 3aeae9c71e82942e2f34341e9185b14b7cca9142d53f8724bb8e9531a73de8b2

Let's enter the hash::

binaries:
  images/pal.png:
    - 3aeae9c71e82942e2f34341e9185b14b7cca9142d53f8724bb8e9531a73de8b2

Run the job again::

$ anteater --binaries --project myproj --patchset /tmp/patch
Found matching file hash for: /folder/to/repo/images/pal.png

This way we can sure binaries are not tampered with by means of a failed cryptographic signature / checksum.

Any binaries not having a sha256 checksum will also be sent to the Virus Total API for scanning.

Virus Total API

If the following flags (combined or individually) --ips, -urls, --binaries are used, anteater will perform a lookup to the Virus Total API.

IP addresses, will be have their DNS history checked for any previous or present connection with known black listed domains marked as malicious or containing malware.

URLs, will be checked for any previous or present connection with known black listed domains marked as malicious or containing malware.

As mentioned, Binaries will be sent to Virus Total and verified as clean / infected.

For more details and indepth documentation, please visit readthedocs

Last of all, if you do use anteater, I would love to know (twitter: @decodebytes) and pull requests / issues are welcome!

Contribute

Contributions are welcome.

Please make a pull request in a new branch, and not master.

git checkout -b mypatch
git push origin mypatch

Unit tests and PEP8 checks are in tox, so simply run the tox command before pushing your code.

If your patch fixes and issue, please paste the issue url into the commit message.

anteater's People

Contributors

dependabot[bot] avatar dskrvk avatar lukehinds avatar programatt avatar

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

anteater's Issues

Set up ignore folder for CI projects

Problem: Anteater will pick up failures from it's own files such as 'fail_list', 'ignore_list'

Solution: Have a directory that can be set in anteater.conf to ignore. In the below case this can be anteater_store.

[config]
anteater_store = ./.anteater
reports_dir = ./%(anteater_store)/.reports/
anteater_log = ./%(anteater_store)/.reports/anteater.log
flag_list = ./%(anteater_store)/flag_list.yaml
ignore_list = ./%(anteater_store)/ignore_list.yaml

Add base64 scan feature

base64 is often used to obfuscate malicious code.

anteater should report on any base64 encoding and also provide a whitelist function.

Pass full url

Source an entire URL:

aneater clone --url https://github.com/lukehinds/testproject

Add a URL report field

users should be able to provide a URL for actions to take upon a failure. Make this a configurable field.

Allow finer scanner control

Allow user to config finer arguments for each scanner, exposed in yaml. For example, change attributes such as verbose level.

It gives different sha hash values for the same binary file.

I received the security notification email from the weekly Jenkins task of OPNFV. There are lots of binary file issues. I got no change when I add these hash values in the exception file. When I troubleshoot for this issue, I find that it gives different sha-hash values in different runs.

  1. This is the value from email:
    2018-08-20 13:27:36,963 - anteater.src.project_scan - ERROR - Non Whitelisted Binary file: /home/opnfv/anteater/pharos/docs/release/images/bridge2.png 2018-08-20 13:27:36,963 - anteater.src.project_scan - ERROR - Please submit patch with this hash: 32960ab1b353d58d6481e57f9df85433b44244b746ec5b03a952111fc57b7025

  2. This is the value in my local run:
    2018-08-21 09:29:53,206 - anteater.src.project_scan - ERROR - Non Whitelisted Binary file: /home/opnfv/anteater/pharos/docs/release/images/bridge2.png
    2018-08-21 09:29:53,209 - anteater.src.project_scan - ERROR - Please submit patch with this hash: ecf97aa0e7575b92a526983546166bb3481034274688ad502cd1eea1be5743dc

  3. This is the value using sha256sum in cli in the releng-anteater container:
    5539345a7a18d3cad65c240681a8ed82d8c01a3e0ebc7cd5fe9b077862c0190f /home/opnfv/anteater/pharos/docs/release/images/bridge2.png

  4. This is the value using gsha256sum in my laptop:
    5539345a7a18d3cad65c240681a8ed82d8c01a3e0ebc7cd5fe9b077862c0190f /Users/julien/Documents/git/opnfv/pharos/docs/release/images/bridge2.png

3 and 4 are the same. They are different from 1 and 2.

Includes List

Perhaps some functionality to check that a strings are present.

anteater pull <project> failing

For some reason docopts does not work with pull


(env) luke@casper  ~/repos/anteater   master ●  anteater pull insecure-python
Usage:
  anteater scan all
  anteater scan all --scanner <scanner>
  anteater scan <project>
  anteater scan <project> --scanner <scanner>
  anteater audit all
  anteater audit <project>
  anteater clone all
  anteater clone <project>
  anteater clone --url <url>
  anteater pull all
  anteater pull <project>
  anteater(-h | --help)
  anteater --version

Not using defaults when project is not listed in secretlist or binaries

2017-03-15 21:51:10,056 - anteater.src.scan_tasks - ERROR - Cannot find entry for daisy in ignorelist.yaml

2017-03-15 21:55:47,293 - anteater.src.scan_tasks - INFO - Checking for Binary files in project: daisy
I got a KeyError - reason "{0}"
Traceback (most recent call last):
  File "/home/vagrant/anteater/env/bin/anteater", line 11, in <module>
    load_entry_point('anteater==0.1.0', 'console_scripts', 'anteater')()
  File "/home/vagrant/anteater/env/lib/python2.7/site-packages/anteater-0.1.0-py2.7.egg/anteater/anteater.py", line 94, in main
    scan_all(reports_dir, repos_dir)
  File "/home/vagrant/anteater/env/lib/python2.7/site-packages/anteater-0.1.0-py2.7.egg/anteater/src/scan_tasks.py", line 22, in scan_all
    scan_project(reports_dir, project, scanner, repos_dir)
  File "/home/vagrant/anteater/env/lib/python2.7/site-packages/anteater-0.1.0-py2.7.egg/anteater/src/scan_tasks.py", line 66, in scan_project
    run_secretsearch(project, projdir)
  File "/home/vagrant/anteater/env/lib/python2.7/site-packages/anteater-0.1.0-py2.7.egg/anteater/src/scan_tasks.py", line 161, in run_secretsearch
    print ('I got a KeyError - reason "{0}"').format(str(e))
AttributeError: 'NoneType' object has no attribute 'format'

pep8 fixes

A fair amount of pep8 fixes are required:

pycodestyle --ignore E501,E722 --exclude ./buildroot,tests,.git,build,.tox,.eggs .   

Add CI functional test to anteater

Need an actual functional test for anteater for both --project and --patchet using the testproject and performing a setup.py install instead of pip install

Also include pep8, and py2 ad py3 checks

Post run summary

At the end of a run, a summary should be shown:

Amount of files scanned
Tool used
Report location

Implement Logging

All print statements and try / excepts to be converted to std logging module

Incorrect no. of arguments

Traceback (most recent call last):
File "/home/luke/repos/anteater/env/bin/anteater", line 6, in
from anteater.anteater import main
File "/home/luke/repos/anteater/env/lib/python2.7/site-packages/anteater/anteater.py", line 26, in
from src.scan_tasks import scan_all, scan_project
File "/home/luke/repos/anteater/env/lib/python2.7/site-packages/anteater/src/scan_tasks.py", line 25
def scan_project(reports_dir, reports_dir, project):
SyntaxError: duplicate argument 'reports_dir' in function definition

Validate project name

If the wrong project name is used, this is all we have to go on:

if project_list:
    UnboundLocalError: local variable 'project_list' referenced before assignment

LF Badge Checks

Key lengths:

symmetric key 112,
factoring modulus 2048,
discrete logarithm key 224,
discrete logarithmic group 2048,
elliptic curve 224,
hash 224 (password hashing is not covered by this bitlength)

Broken Cryptos

The default project security mechanisms MUST NOT depend on cryptographic algorithms that are broken (e.g., MD4, MD5, single DES, RC4, or Dual_EC_DRBG)

Passwords

If passwords are stored for authentication of external users, the project MUST store them as iterated hashes with a per-user salt by using a key stretching (iterated) algorithm (e.g., PBKDF2, Bcrypt or Scrypt)

RNG:

The project MUST generate all cryptographic keys and nonces using a cryptographically secure random number generator

Leak private details

The public repositories MUST NOT leak a valid private credential

TLS

The project SHOULD, if it supports TLS, support at least TLS version 1.2

Cert verification

The project MUST, if it supports TLS, perform TLS certificate verification by default when using TLS, including on subresources

Multi line matching

A series of regex can be harnessed for multiple line matching using a chaining approach.

For example:

line one
line two
line three

We may wish to have an expression where if we match line one toggle a token to a match to then see if another line if the same file contains a match for line three.

virustotal scanning

new changes using virus total API:

If file is a binary:

If IP address found (might need some code to find them): https://www.virustotal.com/en/documentation/public-api/#getting-ip-reports

If domain found: https://www.virustotal.com/en/documentation/public-api/#getting-domain-reports

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.