Giter VIP home page Giter VIP logo

sandboxapi's Introduction

sandboxapi

Developed by InQuest Build Status (GitHub Workflow) Documentation Status PyPi Version

A minimal, consistent API for building integrations with malware sandboxes.

This library currently supports the following sandbox systems:

It provides at least the following methods for each sandbox:

  • is_available(): Check if the sandbox is operable and reachable; returns a boolean
  • analyze(handle, filename): Submit a file for analysis; returns an item_id
  • check(item_id): Check if analysis has completed for a file; returns a boolean
  • report(item_id, report_format='json'): Retrieve the report for a submitted file
  • score(report): Parse out and return an integer score from the report object

Some sandbox classes may have additional methods implemented. See inline documentation for more details.

Note that the value returned from the score method may be on the range 0-10, or 0-100, depending on the sandbox in question, so you should refer to the specific sandbox's documentation when interpreting this value.

Installation

Install through pip:

pip install sandboxapi

Supports Python 2.7+.

Usage

Basic usage is as follows:

import sys
import time
import pprint

from sandboxapi import cuckoo

# connect to the sandbox
sandbox = cuckoo.CuckooAPI('http://192.168.0.20:8090/')

# verify connectivity
if not sandbox.is_available():
    print("sandbox is down, exiting")
    sys.exit(1)

# submit a file
with open('myfile.exe', "rb") as handle:
    file_id = sandbox.analyze(handle, 'myfile.exe')
    print("file {f} submitted for analysis, id {i}".format(f=filename, i=file_id))

# wait for the analysis to complete
while not sandbox.check(file_id):
    print("not done yet, sleeping 10 seconds...")
    time.sleep(10)

# print the report
print("analysis complete. fetching report...")
report = sandbox.report(file_id)
pprint.pprint(report)
print("Score: {score}".format(score=sandbox.score(report)))

Since the library provides a consistent API, you can treat all sandoxes the same way:

import sys
import time
import pprint

from sandboxapi import cuckoo, fireeye, joe

# connect to the sandbox
sandboxes = [
    cuckoo.CuckooAPI('http://192.168.0.20:8090/'),
    fireeye.FireEyeAPI('myusername', 'mypassword', 'https://192.168.0.21', 'winxp-sp3'),
    joe.JoeAPI('mykey', 'https://jbxcloud.joesecurity.org/api', True)
]

for sandbox in sandboxes:
    # verify connectivity
    if not sandbox.is_available():
        print("sandbox is down, exiting")
        sys.exit(1)

    # submit a file
    with open('myfile.exe', "rb") as handle:
        file_id = sandbox.analyze(handle, 'myfile.exe')
        print("file {f} submitted for analysis, id {i}".format(f=filename, i=file_id))

    # wait for the analysis to complete
    while not sandbox.check(file_id):
        print("not done yet, sleeping 10 seconds...")
        time.sleep(10)

    # print the report
    print("analysis complete. fetching report...")
    report = sandbox.report(file_id)
    pprint.pprint(report)
    print("Score: {score}".format(score=sandbox.score(report)))

Cuckoo Sandbox

Constructor signature:

CuckooAPI(url, verify_ssl=False)

Example:

CuckooAPI('http://192.168.0.20:8090/')

This library attempts to support any Cuckoo-like API, including older 1.x installations (though those without a score won't be able to use the .score method), compatible forks like spender-sandbox and CAPE, and the latest 2.x Cuckoo releases. If you find a version that doesn't work, let us know.

There is an unofficial Cuckoo library written by @keithjjones with much more functionality. For more information on the Cuckoo API, see the Cuckoo API documentation.

FireEye AX

Constructor signature:

FireEyeAPI(username, password, url, profile, legacy_api=False, verify_ssl=True)

Example:

FireEyeAPI('myusername', 'mypassword', 'https://192.168.0.20', 'winxp-sp3')

By default, the FireEyeAPI class uses v1.2.0 of the FireEye API, which is available on v8.x FireEye AX series appliances. The v1.1.0 API, which is available on v7.x appliances, is also supported - just set legacy_api=True to use the older version.

There is some limited FireEye API documentation on their blog. For more information on FireEye's sandbox systems, see the AX Series product page. FireEye customers have access to more API documentation.

Joe Sandbox

Constructor signature:

JoeAPI(apikey, apiurl, accept_tac, timeout=None, verify_ssl=True, retries=3)

Example:

JoeAPI('mykey', 'https://jbxcloud.joesecurity.org/api', True)

There is an official Joe Sandbox library with much more functionality. This library is installed as a dependency of sandboxapi, and wrapped by the sandboxapi.joe.JoeSandbox class.

VMRay Analyzer

Constructor signature:

VMRayAPI(api_key, url='https://cloud.vmray.com', verify_ssl=True)

Example:

VMRayAPI('mykey')

VMRay customers have access to a Python library with much more functionality. Check your VMRay documentation for more details.

Falcon Sandbox

Constructor signature:

FalconAPI(key, url='https://www.reverse.it/api/v2', env=100)

Example:

FalconAPI('mykey')

This class only supports version 2.0+ of the Falcon API, which is available in version 8.0.0+ of the Falcon Sandbox.

There is an official Falcon library with much more functionality, that supports the current and older versions of the Falcon API. Note that the official library only supports Python 3.4+.

WildFire Sandbox

Constructor signature:

WildFireAPI(api_key, url='https://wildfire.paloaltonetworks.com/publicapi')

Example:

WildFireAPI('mykey')

Currently, only the WildFire cloud sandbox is supported and not the WildFire appliance.

MetaDefender Sandbox

Constructor signature:

MetaDefenderSandboxAPI(api_key, url=None, verify_ssl=True)

Example:

MetaDefenderSandboxAPI('mykey')

MetaDefender Sandbox (previously known as OPSWAT Filescan Sandbox). You can use the Activation Key that you received from your OPSWAT Sales Representative, and follow the instructions on the OPSWAT Licence Activation page or you can create an API key on the MetaDefender Sandbox Community Site under API Key tab.

More details in the MetaDefender Sandbox API documentation.

Hatching Triage

Constructor signature:

TriageAPI(api_key, url='https://api.tria.ge', api_path='/v0')

Example:

TriageAPI("ApiKeyHere")

You're able to use this class with both the Triage public cloud and the private Triage instances. Look up the documentation for the right host and api path for your specific instance.

For more information on what is returned from the API you can look up the official Triage API documentation.

Notes

You may also be interested in malsub, a similar project with support for a number of online analysis services.

sandboxapi's People

Contributors

anikobartos avatar azazelm3dj3d avatar cmmorrow avatar keathmilligan avatar nbareil avatar nielsvangijzen avatar pedramamini avatar proc-freq avatar rshipp 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sandboxapi's Issues

Falcon unavailable issue

It looks like there is a need to tweak the is_available() for Falcon a bit for the off prem.

b = requests.get('https://example.falcon-sandbox.com/api/v2/system/heartbeat', proxies=proxies, headers=headers)
print b
<Response [403]>
print(b.content)
{"message":"This endpoint is available on in on-premise version"}

changing the endpoint to "/system/version" should work around this issue.

FireEye AX isn't closing sessions

Greetings!

We identified an issue where users were getting errors when trying to logon to the AX along the lines of Login failed: Too many web logins, 200 allowed.

I've referred to the AX documentation and found that it states: After you have completed your requests, you should log out using the logout command ... The Web Services API has a default limit of 100 concurrent open sessions.

I've added some code and we'll wait and see if this resolves the issue. I'll send a PR shortly.

cuckoo score TypeError handling

I'm sometimes running into...

File "/usr/local/lib/python3.5/dist-packages/sandboxapi/cuckoo.py", line 197, in score
    score = report['malscore']
TypeError: byte indices must be integers or slices, not str

when an analysis is being scored and my python script is running. I'm assuming just adding

        except TypeError as e:
            raise sandboxapi.SandboxError(e)

to the score function would resolve the issue.

I've modified my local copy of cuckoo.py and am attempting to test my local change. If I can validate this resolves the issue I'll submit a PR.

Triage report doesn't show completely correct

Hi, I made a dedicated uploader for triage, which works:
https://ghostbin.co/paste/45zt4

But the parsing of the return data fails in the end, any idea what goes wrong?

file ../malware/september-16-919948-2020.doc submitted for analysis, id 200916-2tvp3z18mn
not done yet, sleeping 10 seconds...
...etc
not done yet, sleeping 10 seconds...
analysis complete. fetching report...
{'completed': '2020-09-16T18:19:16Z',
 'created': '2020-09-16T18:16:41Z',
 'custom': 'frontend:269e478c-8ea9-49af-bfad-ce25b55713b9',
 'owner': 'shark2.ams5.hatching.io',
 'sample': '200916-2tvp3z18mn',
 'score': 10,
 'sha256': '44d6c7f1c3536454a19ef188240a6f58c415fb2da863308610e7e27a66e562cb',
 'status': 'reported',
 'target': '../malware/september-16-919948-2020.doc',
 'tasks': {'200916-2tvp3z18mn-behavioral1': {'backend': 'horse2',
                                             'kind': 'behavioral',
                                             'platform': 'windows7_x64',
                                             'queue_id': 1910667,
                                             'resource': 'win7v200722',
                                             'score': 10,
                                             'status': 'reported',
                                             'tags': ['trojan',
                                                      'banker',
                                                      'family:emotet'],
                                             'target': '../malware/september-16-919948-2020.doc'},
           '200916-2tvp3z18mn-behavioral2': {'backend': 'fu1m1',
                                             'kind': 'behavioral',
                                             'platform': 'windows10_x64',
                                             'queue_id': 1910668,
                                             'resource': 'win10',
                                             'score': 10,
                                             'status': 'reported',
                                             'tags': ['trojan',
                                                      'banker',
                                                      'family:emotet'],
                                             'target': '../malware/september-16-919948-2020.doc'},
           '200916-2tvp3z18mn-static1': {'kind': 'static',
                                         'score': 8,
                                         'status': 'reported',
                                         'tags': ['macro']}}}
Traceback (most recent call last):
  File "triage.py", line 31, in <module>
    print("Score: {score}".format(score=sandbox.score(report)))
  File "/home/remnux/.local/lib/python3.6/site-packages/sandboxapi/triage.py", line 148, in score
    report = self.report(item_id)
  File "/home/remnux/.local/lib/python3.6/site-packages/sandboxapi/triage.py", line 136, in report
    data = self.request("/samples/{:s}/summary".format(item_id))
TypeError: unsupported format string passed to dict.__format__

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.