Skip to content

Commit

Permalink
bug fix; updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
marcobizzarr1 committed Feb 9, 2016
1 parent b21a4c8 commit b72746c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 45 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Saferbytes s.r.l.s.
Copyright (c) 2016 Saferbytes s.r.l.s.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,45 @@ To upload a sample:
```python
from deepviz import sandbox
sbx = sandbox.Sandbox()
sbx.upload_sample(path="path\\to\\file.exe", api_key="my-api-key")
result = sbx.upload_sample(path="path\\to\\file.exe", api_key="my-api-key")
print result
```

To upload a folder:

```python
from deepviz import sandbox
sbx = sandbox.Sandbox()
sbx.upload_folder(path="path\\to\\files", api_key="my-api-key")
result = sbx.upload_folder(path="path\\to\\files", api_key="my-api-key")
print result
```

To download a sample:

```python
from deepviz import sandbox
sbx = sandbox.Sandbox()
sbx.download_sample(md5="MD5-hash", api_key="my-api-key", path="output\\directory\\")
result = sbx.download_sample(md5="MD5-hash", api_key="my-api-key", path="output\\directory\\")
print result
```

To send a bulk download request:
To send a bulk download request and download the related archive:

```python
from deepviz.sandbox import Sandbox
from deepviz.result import *

sbx = Sandbox()
md5_list = [
"a6ca3b8c79e1b7e2a6ef046b0702aeb2",
"34781d4f8654f9547cc205061221aea5",
"a8c5c0d39753c97e1ffdfc6b17423dd6"
]

print sbx.bulk_download_request(md5_list=md5_list, api_key="my-api-key")
```

To download the archive af a bulk download request:

```python
from deepviz import sandbox
sbx = sandbox.Sandbox()
sbx.bulk_download_retrieve(id_request="id-request", api_key="my-api-key", path="output\\directory\\")
result = sbx.bulk_download_request(md5_list=md5_list, api_key="my-api-key")
print result
if result.status == SUCCESS:
print sbx.bulk_download_retrieve(id_request=result.msg['id_request'], api_key="my-api-key", path="output\\directory\\")
```

To retrieve scan result of a specific MD5
Expand Down Expand Up @@ -178,7 +180,7 @@ behavioral rules

```python
from deepviz import intel, sandbox
API_KEY="0000000000"
API_KEY = "0000000000000000000000000000000000000000000000000000000000000000"
ThreatIntel = intel.Intel()
ThreatSbx = sandbox.Sandbox()
result_domains = ThreatIntel.domain_info(api_key=API_KEY, time_delta="7d")
Expand Down
17 changes: 9 additions & 8 deletions deepviz/intel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import inspect
import requests
import simplejson

from deepviz.result import *

URL_INTEL_SEARCH = "https://api.deepviz.com/intel/search"
Expand Down Expand Up @@ -61,9 +62,9 @@ def ip_info(self, api_key=None, ip=None, time_delta=None, history=False):
else:
data = simplejson.loads(r.content)
if r.status_code >= 500:
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
else:
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))


def domain_info(self, api_key=None, domain=None, time_delta=None, history=False, filters=None):
Expand Down Expand Up @@ -138,9 +139,9 @@ def domain_info(self, api_key=None, domain=None, time_delta=None, history=False,
return Result(status=SUCCESS, msg=data['data'])
else:
if r.status_code >= 500:
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
else:
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))


def search(self, api_key=None, search_string=None, start_offset=None, elements=None):
Expand Down Expand Up @@ -178,9 +179,9 @@ def search(self, api_key=None, search_string=None, start_offset=None, elements=N
return Result(status=SUCCESS, msg=data['data'])
else:
if r.status_code >= 500:
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
else:
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))


def advanced_search(self, api_key=None, sim_hash=None, created_files=None, imp_hash=None, url=None, strings=None,
Expand Down Expand Up @@ -226,6 +227,6 @@ def advanced_search(self, api_key=None, sim_hash=None, created_files=None, imp_h
return Result(status=SUCCESS, msg=msg)
else:
if r.status_code >= 500:
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
else:
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
20 changes: 9 additions & 11 deletions deepviz/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def upload_sample(self, path=None, api_key=None):
else:
data = simplejson.loads(r.content)
if r.status_code >= 500:
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
else:
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))


def upload_folder(self, path=None, api_key=None):
Expand All @@ -82,11 +82,9 @@ def upload_folder(self, path=None, api_key=None):
for item in buf:
_file = os.path.join(path, item)
result = self.upload_sample(_file, api_key)
if result.status == 'error':
if result.status != SUCCESS:
result.msg = "Error uploading file '{file}': {msg}".format(file=_file, msg=result.msg)
return result

break
else:
return Result(status=SUCCESS, msg="Every file in folder has been uploaded")
else:
Expand Down Expand Up @@ -133,9 +131,9 @@ def download_sample(self, md5=None, path=None, api_key=None):
else:
data = simplejson.loads(r.content)
if r.status_code >= 500:
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
else:
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))


def sample_result(self, md5=None, api_key=None):
Expand Down Expand Up @@ -163,9 +161,9 @@ def sample_result(self, md5=None, api_key=None):
return Result(status=SUCCESS, msg=data['data'])
else:
if r.status_code >= 500:
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
else:
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))


def sample_report(self, md5=None, api_key=None, filters=None):
Expand Down Expand Up @@ -202,9 +200,9 @@ def sample_report(self, md5=None, api_key=None, filters=None):
return Result(status=SUCCESS, msg=data['data'])
else:
if r.status_code >= 500:
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
else:
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))


def bulk_download_request(self, md5_list=None, api_key=None):
Expand Down
26 changes: 16 additions & 10 deletions examples/sandbox_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import time
import hashlib
from deepviz import intel
from deepviz import sandbox
import sys
sys.path.insert(0, r'../')
from deepviz.intel import Intel
from deepviz.sandbox import Sandbox
from deepviz.result import *

API_KEY = "0000000000000000000000000000000000000000000000000000000000000000"

sbx = sandbox.Sandbox()
sbx = Sandbox()

# Retrieve sample scan result
result = sbx.sample_result(md5="a6ca3b8c79e1b7e2a6ef046b0702aeb2", api_key=API_KEY)
Expand All @@ -29,13 +32,17 @@

result = sbx.sample_result(md5=_hash, api_key=API_KEY)

while result.status != "success":
while result.status != SUCCESS:
time.sleep(30)
result = sbx.sample_result(md5=_hash, api_key=API_KEY)

print result.msg['classification']['result']

# Send a bulk download request
# Upload a folder
result = sbx.upload_folder(path="uploadfolder", api_key=API_KEY)
print result

# Send a bulk download request and download the related archive
md5_list = [
"a6ca3b8c79e1b7e2a6ef046b0702aeb2",
"34781d4f8654f9547cc205061221aea5",
Expand All @@ -44,13 +51,12 @@

result = sbx.bulk_download_request(md5_list=md5_list, api_key=API_KEY)
print result

# Download bulk request archive
print sbx.bulk_download_retrieve(id_request=1, api_key=API_KEY, path=".")
if result.status == SUCCESS:
print sbx.bulk_download_retrieve(id_request=result.msg['id_request'], api_key=API_KEY, path=".")

########################################################################################################################

ThreatIntel = intel.Intel()
ThreatIntel = Intel()

# To retrieve intel data about IPs in the last 7 days:
result = ThreatIntel.ip_info(api_key=API_KEY, time_delta="7d")
Expand Down Expand Up @@ -83,7 +89,7 @@
# list all MD5 samples connecting to them. Then for each one of the samples retrieve the matched
# behavioral rules

ThreatSbx = sandbox.Sandbox()
ThreatSbx = Sandbox()
result_domains = ThreatIntel.domain_info(api_key=API_KEY, time_delta="7d")
domains = result_domains.msg
for domain in domains.keys():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name='python-deepviz',
version='1.0.2',
version='1.1.0',
author='Saferbytes',
author_email='[email protected]',
url="https://github.com/saferbytes/python-deepviz",
Expand Down

0 comments on commit b72746c

Please sign in to comment.