Skip to content

Commit 1e40aa5

Browse files
authored
Merge pull request #7 from fireeye/feature/dod-1.2.0
Reverted submit_file() function to 0.1.0 syntax and added get_artifac…
2 parents dbc28c8 + b00481f commit 1e40aa5

File tree

4 files changed

+75
-23
lines changed

4 files changed

+75
-23
lines changed

CHANGE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### Version 1.1.0
2+
- Reverted the file_submit function back to 0.1.0 since the body parameter is used for additional options and specifying file size cutoffs is not the preferred way to handle large files.
3+
- Added the get_artifact() function.
14
### Version 1.0.0
25
- Changed parameters for submit_file function. Eliminated the "body" parameter since it isn't needed, added "file_name" parameter to name the file, and added parameter "contents" to put the binary contents of the file.
36
- Added an option to the submit_file function to specify how many bytes from the beginning of a file to send to the detection service. Default is the first 32 MB, but is configurable to any positive integer.

README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,27 @@ To obtain a free trial API key, subscribe on the [AWS Marketplace](https://aws.a
4040

4141
### Upload A File
4242
```python
43-
response = detection.submit_file(file_name="myfile.txt", contents=open("path/to/myfile.txt", "rb"))
44-
```
45-
By default, submit_file() will only send the first 32 MB (32,000,000 bytes) of a file, which is the API limit, but this can be configured by setting the "file_size_limit" option to any positive integer, where the unit is bytes. While you can send more than 32 MB, the API will only use the first 32 MB itself, so this option will save network bandwidth.
43+
import fireeyepy
44+
45+
detection = fireeyepy.Detection(key="yourapikeyhere")
46+
47+
result = detection.submit_file(
48+
files={
49+
"file": ('filename', open('./path/to/filename', 'rb'))
50+
}
51+
)
4652
```
47-
# Send the first 10 MB of the file
48-
result = detection.submit_file(file_name="myfile.txt", contents=open("path/to/myfile.txt", "rb"), file_size_limit=10000000)
53+
With configuration options:
54+
```python
55+
result = detection.submit_file(
56+
body={
57+
"file_name": "different_name.txt",
58+
"screenshot": true
59+
},
60+
files={
61+
"file": ('filename', open('./path/to/filename', 'rb'))
62+
}
63+
)
4964
```
5065

5166
### Retrieve File Report
@@ -66,3 +81,8 @@ result = detection.get_presigned_url(report_id)
6681
```python
6782
response = detection.get_hash(hash)
6883
```
84+
85+
### Get a report artifact
86+
```python
87+
artifact = detection.get_artifact(report_id="8d0aa90b-8bf3-4483-ae3b-0ded00d157ab", artifact_type="screenshot")
88+
```

fireeyepy/__init__.py

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import requests
66
import logging
77

8-
__version__ = "1.0.2"
8+
__version__ = "1.1.0"
99
logger = logging.getLogger("fireeye")
1010

1111
class Detection:
@@ -26,13 +26,24 @@ class Detection:
2626
2727
detection = fireeyepy.Detection(key="yourapikeyhere")
2828
29-
result = detection.submit_file(file_name="myfile.txt", contents=open("path/to/myfile.txt", "rb"))
29+
result = detection.submit_file(
30+
files={
31+
"file": ('filename', open('./path/to/filename', 'rb'))
32+
}
33+
)
3034
```
3135
32-
By default, submit_file() will only send the first 32 MB (32,000,000 bytes) of a file, which is the API limit, but this can be configured by setting the "file_size_limit" option to any positive integer, where the unit is bytes. While you can send more than 32 MB, the API will only use the first 32 MB itself, so this option will save network bandwidth.
33-
```
34-
# Send the first 10 MB of the file
35-
result = detection.submit_file(file_name="myfile.txt", contents=open("path/to/myfile.txt", "rb"), file_size_limit=10000000)
36+
Optionally, you can send body parameters:
37+
```python
38+
result = detection.submit_file(
39+
body={
40+
"file_name": "different_name.txt",
41+
"screenshot": true
42+
},
43+
files={
44+
"file": ('filename', open('./path/to/filename', 'rb'))
45+
}
46+
)
3647
```
3748
------------------------------
3849
@@ -63,8 +74,20 @@ class Detection:
6374
detection = fireeyepy.Detection(key="yourapikeyhere")
6475
6576
result = detection.get_hash_lookup(hash="md5sumhashhere")
77+
```
78+
------------------------------
79+
80+
Example of getting an artifact from a report.
81+
82+
```python
83+
import fireeyepy
84+
85+
detection = fireeyepy.Detection(key="yourapikeyhere")
86+
87+
result = detection.get_artifact(report_id="8d0aa90b-8bf3-4483-ae3b-0ded00d157ab", artifact_type="screenshot")
6688
```
6789
"""
90+
6891
def __init__(self,key=None):
6992
self.api_key = key or os.environ.get("FIREEYE_API_KEY", None)
7093
self.api_host = "feapi.marketplace.apps.fireeye.com"
@@ -74,23 +97,17 @@ def __init__(self,key=None):
7497
self.headers = {"User-Agent": user_agent, "feye-auth-key": key}
7598
self.session = requests.Session()
7699

77-
def submit_file(self, file_name, contents, file_size_limit=32000000):
78-
"""Allows you to submit a binary file object for malware analysis.
100+
def submit_file(self, body=None, files=None):
101+
"""Allows you to submit a file object for malware analysis.
79102
80103
Keyword Arguments:
81-
file_name {string} -- The name of the file
82-
contents {io.BufferedIOBase} -- The contents of the file in binary
83-
file_size_limit {integer} -- The number of bytes to send to the detection service from the beginning of the file. Files that are smaller than the limit will be sent in their entirety. Files that are larger than this limit will only have the first 'n' bytes sent. Default is 32 MB (32,000,000 bytes).
104+
body {dict} -- The body of your http request. This is optional. (default: {None})
105+
files {io.TextIOWrapper} -- The file you will be submitting for analysis. (default: {None})
84106
85107
Returns:
86108
dict -- Returns a dict of the http response.
87109
"""
88-
contents.seek(0) # Make sure the file handler is at byte 0 so we can read the next 'n' bytes
89-
files = {
90-
"file": (file_name, contents.read(file_size_limit))
91-
}
92-
93-
return self.post(self.api_host, "/files", None, files)
110+
return self.post(self.api_host, "/files", body, files)
94111

95112
def get_report(self, report_id, extended=False):
96113
"""Allows you to get the report details for a file or hash submission.
@@ -119,6 +136,18 @@ def get_hash(self, hash):
119136
"""
120137
return self.get(self.api_host, "/hashes/{}".format(hash))
121138

139+
def get_artifact(self, report_id, artifact_type):
140+
"""This endpoint fetches the screenshot gif file for the given report_id
141+
142+
Arguments:
143+
report_id {string} -- The ID of the report to get artifacts for
144+
artifact_type {string} -- The type of artifact to get. ex. 'screenshot'
145+
146+
Returns:
147+
dict -- Returns a dict of the http response.
148+
"""
149+
return self.get(self.api_host, "/artifacts/{}?type={}".format(report_id,artifact_type))
150+
122151
def get(self, host, request_uri, params=None):
123152
uri = "https://{host}{request_uri}".format(host=host, request_uri=request_uri)
124153
headers = self.headers

setup.py

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

77
setup(
88
name="fireeyepy",
9-
version="1.0.2",
9+
version="1.1.0",
1010
description="FireEye Client Library for Python",
1111
long_description=long_description,
1212
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)