Esempio n. 1
0
    def __init__(self, throttle_per_min=50, api_key=None):

        if api_key:
            self.api = virustotal_python.Virustotal(API_VERSION="v2",
                                                    API_KEY=api_key)
        else:
            self.api = virustotal_python.Virustotal(API_VERSION="v2")

        self.throttle_per_min = throttle_per_min
        self.db = TrackingDb()
Esempio n. 2
0
def test_compatibility():
    """
    Test COMPATIBILITY_ENABLED parameter on Virustotal class.
    """
    vtotal = virustotal_python.Virustotal(API_VERSION="v3", COMPATIBILITY_ENABLED=True)
    resp = vtotal.request(f"files/{FILE_ID}")
    assert resp["status_code"] == 200
    assert resp["json_resp"]["data"]["type"] == "file"
    assert resp["json_resp"]["data"]["attributes"]
Esempio n. 3
0
def vtotal_v3(request):
    yield virustotal_python.Virustotal(API_VERSION="v3")

    def fin():
        """
        Helper function which sleeps for 15 seconds between each test. This is to avoid VirusTotal 403 rate quota limits.
        """
        print("Sleeping for 15 seconds to avoid VirusTotal 403 rate quota limits...")
        sleep(15)

    request.addfinalizer(fin)
Esempio n. 4
0
def test_contextmanager_v2():
    """
    Test basic Context Manager support.
    """
    with virustotal_python.Virustotal() as vtotal:
        # Retrieve information about an IP address
        resp = vtotal.request("ip-address/report", params={"ip": IP})
        assert resp.status_code == 200
        data = resp.json()
        assert data["as_owner"] == "Google LLC"
        assert data["country"] == "US"
Esempio n. 5
0
def test_contextmanager_v3():
    """
    Test basic Context Manager support.
    """
    with virustotal_python.Virustotal(API_VERSION="v3") as vtotal:
        # Retrieve information about an IP address
        resp = vtotal.request(f"ip_addresses/{IP}")
        assert resp.status_code == 200
        data = resp.data
        assert data["id"] == IP
        assert data["attributes"]["as_owner"] == "Google LLC"
        assert data["attributes"]["country"] == "US"
Esempio n. 6
0
def test_single_url():

    URL_DOMAIN = 'www.elementor.com'
    vtotal_v2 = virustotal_python.Virustotal(API_VERSION="v2")
    resp = vtotal_v2.request("url/scan",
                             params={"url": URL_DOMAIN},
                             method="POST")
    assert resp.status_code == 200
    data = resp.json()
    # Obtain scan_id
    scan_id = data["scan_id"]
    # Request report for URL analysis
    analysis_resp = vtotal_v2.request("url/report",
                                      params={"resource": scan_id})
    assert analysis_resp.status_code == 200
    assert analysis_resp.response_code == 1
    data = analysis_resp.json()
    assert data["scan_id"]
    assert data["verbose_msg"]
    assert data["url"] == f"http://{URL_DOMAIN}/"
    assert data["scan_date"]