Repository: OpenCTI-Platform/connectors

Issue:
VirusTotal Connector error
Please replace every line in curly brackets { like this } with an appropriate answer, and remove this line.

## Description

When trying to enrich a artefact, VirusTotal report the following error every time 
<img width="1022" alt="Screenshot 2021-07-05 at 6 55 12 PM" src="https://user-images.githubusercontent.com/79446411/124463810-fc880300-ddc5-11eb-9564-2a8bded488cc.png">


When I access to the log, it shows the following error
`ERROR:root:Error in message processing, reporting error to API
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pycti/connector/opencti_connector_helper.py", line 152, in _data_handler
    message = self.callback(json_data["event"])
  File "/opt/opencti-connector-virustotal/virustotal.py", line 116, in _process_message
    return self._process_file(observable)
  File "/opt/opencti-connector-virustotal/virustotal.py", line 71, in _process_file
    if observable["name"] is None and len(attributes["names"]) > 0:
KeyError: 'name'
INFO:root:Reporting work update_received opencti-work--c2b1ef93-8b44-4915-b418-f759ee262f53
INFO:root:Message (delivery_tag=1) processed, thread terminated`

## Environment

1. AWS ubuntu-bionic-18.04-amd64-server
2. OpenCTI Version 4.5.5
3. OpenCTI client:  frontend
4. Other environment details: VirusTotal connector version : opencti/connector-virustotal:latest

## Reproducible Steps

Steps to create the smallest reproducible scenario:

## Expected Output

Successfully extract information from VirusTotal 

## Actual Output

Error occurred as mentioned above.
 
## Additional information

{ Any additional information, including logs or screenshots if you have any. }



Discussion:
Hey @realzacharycheng 

Thanks for the creating this issue! Could you please share the observable you were trying to enrich with virus total?

Thanks
> Hey @realzacharycheng
> 
> Thanks for the creating this issue! Could you please share the observable you were trying to enrich with virus total?
> 
> Thanks

I was testing using the latest version of mimikatz.exe from github

<img width="887" alt="Screenshot 2021-07-06 at 12 29 02 PM" src="https://user-images.githubusercontent.com/79446411/124542315-c2664200-de55-11eb-8b0a-267dc83cd276.png">

Thanks for the info. I'll have a look at it
Could you please share the SDO/SCO as a STIX2 file? That would help me when trying to reproduce the error. Thanks!
Hi @nor3th I exported the file, please help checking if this is correct and able to help you reproducing the error. Thank you so much.
[mimikatz.txt](https://github.com/OpenCTI-Platform/connectors/files/6974324/mimikatz.txt)


Resolving patch:
diff --git a/virustotal/src/virustotal.py b/virustotal/src/virustotal.py
--- a/virustotal/src/virustotal.py
+++ b/virustotal/src/virustotal.py
@@ -1,10 +1,9 @@
-from time import sleep
-import yaml
+import json
 import os
 import requests
-import json
-
+import yaml
 from pycti import OpenCTIConnectorHelper, get_config_variable
+from time import sleep
 
 
 class VirusTotalConnector:
@@ -68,17 +67,20 @@ def _process_file(self, observable):
                     key="size",
                     value=str(attributes["size"]),
                 )
-            if observable["name"] is None and len(attributes["names"]) > 0:
-                self.helper.api.stix_cyber_observable.update_field(
-                    id=final_observable["id"], key="name", value=attributes["names"][0]
-                )
-                del attributes["names"][0]
-                if len(attributes["names"]) > 0:
+                if observable["name"] is None and len(attributes["names"]) > 0:
                     self.helper.api.stix_cyber_observable.update_field(
                         id=final_observable["id"],
-                        key="x_opencti_additional_names",
-                        value=attributes["names"],
+                        key="name",
+                        value=attributes["names"][0],
                     )
+                    del attributes["names"][0]
+
+            if len(attributes["names"]) > 0:
+                self.helper.api.stix_cyber_observable.update_field(
+                    id=final_observable["id"],
+                    key="x_opencti_additional_names",
+                    value=attributes["names"],
+                )
 
             # Create external reference
             external_reference = self.helper.api.external_reference.create(


Test patch: