Beispiel #1
0
    def ratingInput(self, strInput):
        dataParser = Parser()
        dataType, strStringToScan = dataParser.classify(strInput)
        dictReturn = {}
        dictReturn['Enable'] = False
        dictReturn['Message'] = 'No Threat Found'
        dictReturn['type'] = DATA_TYPE.TYPE_UNDEFINE

        if dataType == DATA_TYPE.TYPE_URL:
            virustotal = VirusTotalAPI()
            returnCode, totalscaned, positive = virustotal.scanURL(strStringToScan)
            dictReturn['Enable'] = True
            dictReturn['type'] = dataType
            dictReturn['data'] = strStringToScan


            dictReturn['Message'] = '%s be considered as SAFE in %s scanners(total %s)'%(strStringToScan, totalscaned-positive, totalscaned)
            if RATE_RESULT.NOT_FOUND == returnCode:
                dictReturn['Message'] = REPLY_MESSAGE.UNKNOWN_URL%strStringToScan
            elif RATE_RESULT.FOUND == returnCode:
                if positive > 5 :
                    dictReturn['Message'] = REPLY_MESSAGE.DANGER_URL%strStringToScan
                else:
                    dictReturn['Message'] = REPLY_MESSAGE.NORMAL_URL%strStringToScan

        return dictReturn
Beispiel #2
0
 def test_url_scan_invalid_api_key(self):
     """Проверка метода 'url_scan' при неверном ключе доступа к API.
     """
     vt_invalid_api_key = VirusTotalAPI()
     time.sleep(TIME_DELAY)
     response = vt_invalid_api_key.url_scan(TEST_URL)
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_invalid_api_key.ERROR_HTTP)
Beispiel #3
0
 def test_file_report_connection_error(self):
     """Проверка метода 'file_report' при ошибке соединения с сервером.
     """
     vt_api = VirusTotalAPI(API_KEY)
     time.sleep(TIME_DELAY)
     response = vt_api.file_report(TEST_HASH, None, TEST_PROXI)
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_api.ERROR_CONNECT)
Beispiel #4
0
 def test_domain_report_correct_param(self):
     """Проверка метода 'domain_report' при корректных входных параметрах.
     """
     vt_api = VirusTotalAPI(API_KEY)
     time.sleep(TIME_DELAY)
     response = vt_api.domain_report(TEST_DOMAIN)
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_api.ERROR_SUCCESS)
Beispiel #5
0
 def test_file_report_correct_param(self):
     """Проверка метода 'file_report' с корректными входными параметрами.
     """
     vt_api = VirusTotalAPI(API_KEY)
     time.sleep(TIME_DELAY)
     response = vt_api.file_report(TEST_HASH)
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_api.ERROR_SUCCESS)
Beispiel #6
0
 def test_domain_report_invalid_api_key(self):
     """Проверка метода 'domain_report' при неверном ключе доступа к API.
     """
     vt_invalid_api_key = VirusTotalAPI()
     time.sleep(TIME_DELAY)
     response = vt_invalid_api_key.domain_report(TEST_DOMAIN)
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_invalid_api_key.ERROR_HTTP)
Beispiel #7
0
 def test_url_scan_correct_param(self):
     """Проверка метода 'url_scan' при корректных входных параметрах.
     """
     vt_api = VirusTotalAPI(API_KEY)
     time.sleep(TIME_DELAY)
     response = vt_api.url_scan(TEST_URL)
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_api.ERROR_SUCCESS)
Beispiel #8
0
 def test_ip_report_incorrect_param(self):
     """Проверка метода 'url_report' при некорректных входных параметрах.
     """
     vt_api = VirusTotalAPI(API_KEY)
     time.sleep(TIME_DELAY)
     response = vt_api.ip_report('This is an invalid IP value')
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_api.ERROR_SUCCESS)
Beispiel #9
0
 def test_url_scan_connect_error(self):
     """Проверка метода 'url_scan' при ошибке соединения с сервером.
     """
     vt_api = VirusTotalAPI(API_KEY)
     time.sleep(TIME_DELAY)
     response = vt_api.url_scan(TEST_URL, None, TEST_PROXI)
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_api.ERROR_CONNECT)
Beispiel #10
0
 def test_file_scan_file_size_error(self):
     """Проверка метода 'file_scan' при отправке файла размером
        более 32 MB.
     """
     vt_api = VirusTotalAPI(API_KEY)
     time.sleep(TIME_DELAY)
     response = vt_api.file_scan('d:/test_file.zip')  ## файл более 32 MB
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_api.ERROR_HTTP)
Beispiel #11
0
 def test_file_report_invalid_api_key(self):
     """Проверка метода 'file_report' с использованием неверного
        ключа доступа к API.
     """
     vt_invalid_api_key = VirusTotalAPI()
     time.sleep(TIME_DELAY)
     response = vt_invalid_api_key.file_report(TEST_HASH)
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_invalid_api_key.ERROR_HTTP)
Beispiel #12
0
 def test_url_scan_timeout(self):
     """Проверка метода 'url_scan' при превышении времени ожидания
        ответа от сервера.
     """
     vt_api = VirusTotalAPI(API_KEY)
     time.sleep(TIME_DELAY)
     response = vt_api.url_scan(TEST_URL, TEST_TIMEOUT)
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_api.ERROR_TIMEOUT)
Beispiel #13
0
 def test_url_report_correct_param_list(self):
     """Проверка метода 'url_report' при корректных входных параметрах
        в виде списка из 4-х URL-адресов.
     """
     vt_api = VirusTotalAPI(API_KEY)
     time.sleep(TIME_DELAY)
     response = vt_api.url_report(TEST_URL_LIST)
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_api.ERROR_SUCCESS)
Beispiel #14
0
 def test_url_report_correct_param_scan(self):
     """Проверка метода 'url_report' при корректных входных параметрах
        с использованием параметра 'scan'.
     """
     vt_api = VirusTotalAPI(API_KEY)
     time.sleep(TIME_DELAY)
     response = vt_api.url_report(TEST_URL, '1')
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_api.ERROR_SUCCESS)
Beispiel #15
0
 def test_file_scan_file_name_error(self):
     """Проверка метода 'file_scan' при некорректных входных параметрах
       (невалидный путь к сканируемому файлу).
     """
     vt_api = VirusTotalAPI(API_KEY)
     time.sleep(TIME_DELAY)
     response = vt_api.file_scan(' ')
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_api.ERROR_FILE)
Beispiel #16
0
 def test_file_report_timeout(self):
     """Проверка метода 'file_report' при превышении времени ожидании
        ответа от сервера.
     """
     vt_api = VirusTotalAPI(API_KEY)
     time.sleep(TIME_DELAY)
     response = vt_api.file_report(TEST_HASH, TEST_TIMEOUT)
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_api.ERROR_TIMEOUT)
Beispiel #17
0
 def test_file_scan_correct_param(self):
     """Проверка метода 'file_scan' при корректных входных параметрах
        (валидный путь к сканируемому файлу).
     """
     vt_api = VirusTotalAPI(API_KEY)
     time.sleep(TIME_DELAY)
     response = vt_api.file_scan(TEST_FILE_PATH)
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_api.ERROR_SUCCESS)
Beispiel #18
0
 def test_domain_report_limit(self):
     """Проверка метода 'idomain_report' при превышении лмита запросов
        (более 4-х запросов в минуту).
     """
     vt_api = VirusTotalAPI(API_KEY)
     time.sleep(TIME_DELAY)
     response = vt_api.domain_report(TEST_DOMAIN)
     response = vt_api.domain_report(TEST_DOMAIN)
     response = vt_api.domain_report(TEST_DOMAIN)
     response = vt_api.domain_report(TEST_DOMAIN)
     response = vt_api.domain_report(TEST_DOMAIN)
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_api.ERROR_HTTP)
Beispiel #19
0
 def test_url_scan_limit(self):
     """Проверка метода 'url_scan' при превышении лмита запросов
        (более 4-х запросов в минуту).
     """
     vt_api = VirusTotalAPI(API_KEY)
     time.sleep(TIME_DELAY)
     response = vt_api.url_scan(TEST_URL)
     response = vt_api.url_scan(TEST_URL)
     response = vt_api.url_scan(TEST_URL)
     response = vt_api.url_scan(TEST_URL)
     response = vt_api.url_scan(TEST_URL)
     time.sleep(TIME_DELAY)
     self.assertEqual(response['error_code'], vt_api.ERROR_HTTP)
Beispiel #20
0
from virustotalapi import VirusTotalAPI

vt = VirusTotalAPI(
    '1a9ab77640f8f5a1c955319c646f0f6138c110cce550676f8f7fdd9a9dd4c571')

print vt.url_report("https://askldaskljdlaskjd.com/test/est")