Skip to content

Commit b72746c

Browse files
author
marcobizzarr1
committed
bug fix; updated examples
1 parent b21a4c8 commit b72746c

File tree

6 files changed

+52
-45
lines changed

6 files changed

+52
-45
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Saferbytes s.r.l.s.
3+
Copyright (c) 2016 Saferbytes s.r.l.s.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,45 @@ To upload a sample:
2020
```python
2121
from deepviz import sandbox
2222
sbx = sandbox.Sandbox()
23-
sbx.upload_sample(path="path\\to\\file.exe", api_key="my-api-key")
23+
result = sbx.upload_sample(path="path\\to\\file.exe", api_key="my-api-key")
24+
print result
2425
```
2526

2627
To upload a folder:
2728

2829
```python
2930
from deepviz import sandbox
3031
sbx = sandbox.Sandbox()
31-
sbx.upload_folder(path="path\\to\\files", api_key="my-api-key")
32+
result = sbx.upload_folder(path="path\\to\\files", api_key="my-api-key")
33+
print result
3234
```
3335

3436
To download a sample:
3537

3638
```python
3739
from deepviz import sandbox
3840
sbx = sandbox.Sandbox()
39-
sbx.download_sample(md5="MD5-hash", api_key="my-api-key", path="output\\directory\\")
41+
result = sbx.download_sample(md5="MD5-hash", api_key="my-api-key", path="output\\directory\\")
42+
print result
4043
```
4144

42-
To send a bulk download request:
45+
To send a bulk download request and download the related archive:
4346

4447
```python
48+
from deepviz.sandbox import Sandbox
49+
from deepviz.result import *
50+
51+
sbx = Sandbox()
4552
md5_list = [
4653
"a6ca3b8c79e1b7e2a6ef046b0702aeb2",
4754
"34781d4f8654f9547cc205061221aea5",
4855
"a8c5c0d39753c97e1ffdfc6b17423dd6"
4956
]
5057

51-
print sbx.bulk_download_request(md5_list=md5_list, api_key="my-api-key")
52-
```
53-
54-
To download the archive af a bulk download request:
55-
56-
```python
57-
from deepviz import sandbox
58-
sbx = sandbox.Sandbox()
59-
sbx.bulk_download_retrieve(id_request="id-request", api_key="my-api-key", path="output\\directory\\")
58+
result = sbx.bulk_download_request(md5_list=md5_list, api_key="my-api-key")
59+
print result
60+
if result.status == SUCCESS:
61+
print sbx.bulk_download_retrieve(id_request=result.msg['id_request'], api_key="my-api-key", path="output\\directory\\")
6062
```
6163

6264
To retrieve scan result of a specific MD5
@@ -178,7 +180,7 @@ behavioral rules
178180

179181
```python
180182
from deepviz import intel, sandbox
181-
API_KEY="0000000000"
183+
API_KEY = "0000000000000000000000000000000000000000000000000000000000000000"
182184
ThreatIntel = intel.Intel()
183185
ThreatSbx = sandbox.Sandbox()
184186
result_domains = ThreatIntel.domain_info(api_key=API_KEY, time_delta="7d")

deepviz/intel.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import inspect
22
import requests
33
import simplejson
4+
45
from deepviz.result import *
56

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

6869

6970
def domain_info(self, api_key=None, domain=None, time_delta=None, history=False, filters=None):
@@ -138,9 +139,9 @@ def domain_info(self, api_key=None, domain=None, time_delta=None, history=False,
138139
return Result(status=SUCCESS, msg=data['data'])
139140
else:
140141
if r.status_code >= 500:
141-
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
142+
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
142143
else:
143-
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
144+
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
144145

145146

146147
def search(self, api_key=None, search_string=None, start_offset=None, elements=None):
@@ -178,9 +179,9 @@ def search(self, api_key=None, search_string=None, start_offset=None, elements=N
178179
return Result(status=SUCCESS, msg=data['data'])
179180
else:
180181
if r.status_code >= 500:
181-
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
182+
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
182183
else:
183-
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
184+
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
184185

185186

186187
def advanced_search(self, api_key=None, sim_hash=None, created_files=None, imp_hash=None, url=None, strings=None,
@@ -226,6 +227,6 @@ def advanced_search(self, api_key=None, sim_hash=None, created_files=None, imp_h
226227
return Result(status=SUCCESS, msg=msg)
227228
else:
228229
if r.status_code >= 500:
229-
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
230+
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
230231
else:
231-
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
232+
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))

deepviz/sandbox.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def upload_sample(self, path=None, api_key=None):
5858
else:
5959
data = simplejson.loads(r.content)
6060
if r.status_code >= 500:
61-
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
61+
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
6262
else:
63-
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
63+
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
6464

6565

6666
def upload_folder(self, path=None, api_key=None):
@@ -82,11 +82,9 @@ def upload_folder(self, path=None, api_key=None):
8282
for item in buf:
8383
_file = os.path.join(path, item)
8484
result = self.upload_sample(_file, api_key)
85-
if result.status == 'error':
85+
if result.status != SUCCESS:
8686
result.msg = "Error uploading file '{file}': {msg}".format(file=_file, msg=result.msg)
8787
return result
88-
89-
break
9088
else:
9189
return Result(status=SUCCESS, msg="Every file in folder has been uploaded")
9290
else:
@@ -133,9 +131,9 @@ def download_sample(self, md5=None, path=None, api_key=None):
133131
else:
134132
data = simplejson.loads(r.content)
135133
if r.status_code >= 500:
136-
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
134+
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
137135
else:
138-
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
136+
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
139137

140138

141139
def sample_result(self, md5=None, api_key=None):
@@ -163,9 +161,9 @@ def sample_result(self, md5=None, api_key=None):
163161
return Result(status=SUCCESS, msg=data['data'])
164162
else:
165163
if r.status_code >= 500:
166-
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
164+
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
167165
else:
168-
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
166+
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
169167

170168

171169
def sample_report(self, md5=None, api_key=None, filters=None):
@@ -202,9 +200,9 @@ def sample_report(self, md5=None, api_key=None, filters=None):
202200
return Result(status=SUCCESS, msg=data['data'])
203201
else:
204202
if r.status_code >= 500:
205-
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
203+
return Result(status=SERVER_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
206204
else:
207-
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {ex}".format(status_code=r.status_code, errmsg=data['errmsg']))
205+
return Result(status=CLIENT_ERROR, msg="{status_code} - Error while connecting to Deepviz: {errmsg}".format(status_code=r.status_code, errmsg=data['errmsg']))
208206

209207

210208
def bulk_download_request(self, md5_list=None, api_key=None):

examples/sandbox_test.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import time
22
import hashlib
3-
from deepviz import intel
4-
from deepviz import sandbox
3+
import sys
4+
sys.path.insert(0, r'../')
5+
from deepviz.intel import Intel
6+
from deepviz.sandbox import Sandbox
7+
from deepviz.result import *
58

69
API_KEY = "0000000000000000000000000000000000000000000000000000000000000000"
710

8-
sbx = sandbox.Sandbox()
11+
sbx = Sandbox()
912

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

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

32-
while result.status != "success":
35+
while result.status != SUCCESS:
3336
time.sleep(30)
3437
result = sbx.sample_result(md5=_hash, api_key=API_KEY)
3538

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

38-
# Send a bulk download request
41+
# Upload a folder
42+
result = sbx.upload_folder(path="uploadfolder", api_key=API_KEY)
43+
print result
44+
45+
# Send a bulk download request and download the related archive
3946
md5_list = [
4047
"a6ca3b8c79e1b7e2a6ef046b0702aeb2",
4148
"34781d4f8654f9547cc205061221aea5",
@@ -44,13 +51,12 @@
4451

4552
result = sbx.bulk_download_request(md5_list=md5_list, api_key=API_KEY)
4653
print result
47-
48-
# Download bulk request archive
49-
print sbx.bulk_download_retrieve(id_request=1, api_key=API_KEY, path=".")
54+
if result.status == SUCCESS:
55+
print sbx.bulk_download_retrieve(id_request=result.msg['id_request'], api_key=API_KEY, path=".")
5056

5157
########################################################################################################################
5258

53-
ThreatIntel = intel.Intel()
59+
ThreatIntel = Intel()
5460

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

86-
ThreatSbx = sandbox.Sandbox()
92+
ThreatSbx = Sandbox()
8793
result_domains = ThreatIntel.domain_info(api_key=API_KEY, time_delta="7d")
8894
domains = result_domains.msg
8995
for domain in domains.keys():

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setuptools.setup(
44
name='python-deepviz',
5-
version='1.0.2',
5+
version='1.1.0',
66
author='Saferbytes',
77
author_email='info@saferbytes.it',
88
url="https://github.com/saferbytes/python-deepviz",

0 commit comments

Comments
 (0)