Skip to content

Commit

Permalink
Proxy support - 0.0.5 (#8)
Browse files Browse the repository at this point in the history
* Dependencies for requests[socks].

* Updated example and changelog.

* Bumped version, added proxy support.

* Bumped version.

* Updated example with proxy usage.

* Added PR #

* Fixed markdown.
  • Loading branch information
Dextroz authored May 5, 2019
1 parent 45b9380 commit 89e53c8
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ black = "*"
twine = "*"

[packages]
requests = "*"
requests = {extras = ["socks"],version = "*"}

[requires]
python_version = "3.7"
Expand Down
15 changes: 14 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,19 @@ Or
from virustotal import Virustotal
from pprint import pprint

# Normal Initialisation.
vtotal = Virustotal("Insert API Key Here.")

# NEW as of version 0.0.5: Proxy support.
# Example Usage: Using HTTP(S)
vtotal = Virustotal(
"Insert API Key Here.",
{"http": "http://10.10.1.10:3128", "https": "http://10.10.1.10:1080"})
# Or using SOCKS
vtotal = Virustotal(
"Insert API Key Here.",
{"http": "socks5://user:pass@host:port", "https": "socks5://user:pass@host:port"})

# NOTE: Check virustotal.py for docstrings containing full parameter descriptions.

# Send a file to Virustotal for analysis.
Expand Down Expand Up @@ -119,6 +130,8 @@ pprint(resp)

## Changelog

* 0.0.5 - Added Proxy support. Via HTTP(S) or using SOCKS: See [#8](https://github.com/Dextroz/virustotal-python/pull/8).

* 0.0.4 - README.md updated; dependencies updated.

* 0.0.3 - Updated dependencies for urllib3 security vulnerability.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="virustotal-python",
version="0.0.4",
version="0.0.5",
author="Dextroz",
author_email="[email protected]",
description="A light wrapper around the public VirusTotal API.",
Expand Down
11 changes: 11 additions & 0 deletions virustotal_python/examples.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
from virustotal import Virustotal
from pprint import pprint

# Normal Initialisation.
vtotal = Virustotal("Insert API Key Here.")

# NEW as of version 0.0.5: Proxy support.
# Example Usage: Using HTTP(S)
vtotal = Virustotal(
"Insert API Key Here.",
{"http": "http://10.10.1.10:3128", "https": "http://10.10.1.10:1080"})
# Or using SOCKS
vtotal = Virustotal(
"Insert API Key Here.",
{"http": "socks5://user:pass@host:port", "https": "socks5://user:pass@host:port"})

# NOTE: Check virustotal.py for docstrings containing full parameter descriptions.

# Send a file to Virustotal for analysis.
Expand Down
43 changes: 32 additions & 11 deletions virustotal_python/virustotal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@


class Virustotal(object):
"""Base class for interacting with the Virustotal Public API. (https://www.virustotal.com/en/documentation/public-api/)
"""
Base class for interacting with the Virustotal Public API. (https://www.virustotal.com/en/documentation/public-api/)
"""

def __init__(self, API_KEY=None):
def __init__(self, API_KEY=None, PROXIES=None):
self.API_KEY = API_KEY
self.PROXIES = PROXIES
self.BASEURL = "https://www.virustotal.com/vtapi/v2/"
self.VERSION = "0.0.4"
self.VERSION = "0.0.5"
self.headers = {
"Accept-Encoding": "gzip, deflate",
"User-Agent": f"gzip, virustotal-python {self.VERSION}",
Expand All @@ -52,7 +54,9 @@ def file_scan(self, file):
"""
params = {"apikey": self.API_KEY}
files = {"file": (basename(file), open(abspath(file), "rb"))}
resp = self.make_request(f"{self.BASEURL}file/scan", params=params, files=files)
resp = self.make_request(
f"{self.BASEURL}file/scan", params=params, files=files, proxies=self.PROXIES
)
return resp

def file_rescan(self, *resource: list):
Expand All @@ -62,7 +66,9 @@ def file_rescan(self, *resource: list):
:rtype: A dictionary containing the resp_code and JSON response.
"""
params = {"apikey": self.API_KEY, "resource": ",".join(*resource)}
resp = self.make_request(f"{self.BASEURL}file/rescan", params=params)
resp = self.make_request(
f"{self.BASEURL}file/rescan", params=params, proxies=self.PROXIES
)
return resp

def file_report(self, *resource: list):
Expand All @@ -73,7 +79,10 @@ def file_report(self, *resource: list):
"""
params = {"apikey": self.API_KEY, "resource": ",".join(*resource)}
resp = self.make_request(
f"{self.BASEURL}file/report", params=params, method="GET"
f"{self.BASEURL}file/report",
params=params,
method="GET",
proxies=self.PROXIES,
)
return resp

Expand All @@ -84,7 +93,9 @@ def url_scan(self, *url: list):
:rtype: A dictionary containing the resp_code and JSON response.
"""
params = {"apikey": self.API_KEY, "url": "\n".join(*url)}
resp = self.make_request(f"{self.BASEURL}url/scan", params=params)
resp = self.make_request(
f"{self.BASEURL}url/scan", params=params, proxies=self.PROXIES
)
return resp

def url_report(self, *resource: list, scan=None):
Expand All @@ -97,7 +108,9 @@ def url_report(self, *resource: list, scan=None):
params = {"apikey": self.API_KEY, "resource": "\n".join(*resource)}
if scan is not None:
params["scan"] = scan
resp = self.make_request(f"{self.BASEURL}url/report", params=params)
resp = self.make_request(
f"{self.BASEURL}url/report", params=params, proxies=self.PROXIES
)
return resp

def ipaddress_report(self, ip):
Expand All @@ -108,7 +121,10 @@ def ipaddress_report(self, ip):
"""
params = {"apikey": self.API_KEY, "ip": ip}
resp = self.make_request(
f"{self.BASEURL}ip-address/report", params=params, method="GET"
f"{self.BASEURL}ip-address/report",
params=params,
method="GET",
proxies=self.PROXIES,
)
return resp

Expand All @@ -120,7 +136,10 @@ def domain_report(self, domain):
"""
params = {"apikey": self.API_KEY, "domain": domain}
resp = self.make_request(
f"{self.BASEURL}domain/report", params=params, method="GET"
f"{self.BASEURL}domain/report",
params=params,
method="GET",
proxies=self.PROXIES,
)
return resp

Expand All @@ -132,7 +151,9 @@ def put_comment(self, resource, comment):
:rtype: A dictionary containing the resp_code and JSON response.
"""
params = {"apikey": self.API_KEY, "resource": resource, "comment": comment}
resp = self.make_request(f"{self.BASEURL}comments/put", params=params)
resp = self.make_request(
f"{self.BASEURL}comments/put", params=params, proxies=self.PROXIES
)
return resp

def make_request(self, endpoint, params, method="POST", **kwargs):
Expand Down

0 comments on commit 89e53c8

Please sign in to comment.