viper-framework / viper-web

BSD 3-Clause "New" or "Revised" License
8 stars 9 forks source link

401 Error when submitting files to Cuckoo #15

Closed acd62081 closed 3 years ago

acd62081 commented 3 years ago

I am using Cuckoo Version 2.0.7 and I am getting an error of Unable to Submit File with a 401 Unauthorized error code when submitting to Cuckoo from Viper Web. Newer versions of Cuckoo requires an API token in the header to access the API according to the Cuckoo Docs https://cuckoo.readthedocs.io/en/latest/usage/api/#starting-the-api-server

To fix this, I had to replace this line (line 711) in views.py: cuckoo_response = requests.post(uri, files=options)

with this

if cfg.cuckoo.cuckoo_modified:
    cuckoo_response = requests.post(uri, files=options)
else:
    auth_headers = {'Authorization': "Bearer {0}".format(cfg.cuckoo.auth_token)}
    cuckoo_response = requests.post(uri, headers=auth_headers, files=options)

Then I had to add an auth_token line to the cuckoo section of viper.conf

[cuckoo]
cuckoo_modified = False
cuckoo_host = http://localhost:8090
cuckoo_web = http://localhost:8000
auth_token = <Cuckoo API Key goes Here>
frennkie commented 3 years ago

I assume this is similar or the same as this issue: https://github.com/viper-framework/viper/issues/785 right?

acd62081 commented 3 years ago

Yes, that is the same issue. For the module, you would need to edit cuckoo.py to something like this starting at line 65 :

if files:
    if cfg.cuckoo.cuckoo_modified:
            try:
                response = requests.post(api_uri, files=files, data=params,
                                         proxies=cfg.cuckoo.proxies, verify=cfg.cuckoo.verify, cert=cfg.cuckoo.cert)
    else:
        auth_headers = {'Authorization': "Bearer {0}".format(cfg.cuckoo.auth_token)}
        response = requests.post(uri, headers=auth_headers, files=options)

viper.conf file edit is listed above.

I haven't tested the module functionality with this config yet though.

siftuser commented 3 years ago

Hi @acd62081 ,

Thanks for sharing your experience. Greatly appreciated!

Yes, that is the same issue. For the module, you would need to edit cuckoo.py to something like this starting at line 65 :

if files:
    if cfg.cuckoo.cuckoo_modified:
            try:
                response = requests.post(api_uri, files=files, data=params,
                                         proxies=cfg.cuckoo.proxies, verify=cfg.cuckoo.verify, cert=cfg.cuckoo.cert)
    else:
        auth_headers = {'Authorization': "Bearer {0}".format(cfg.cuckoo.auth_token)}
        response = requests.post(uri, headers=auth_headers, files=options)

viper.conf file edit is listed above.

I haven't tested the module functionality with this config yet though.

I tested above changes & had to update cuckoo.py as follows

 65         if files:
 66             if cfg.cuckoo.cuckoo_modified:
 67                 try:
 68                      response = requests.post(api_uri, files=files, data=params,
 69                                          proxies=cfg.cuckoo.proxies, verify=cfg.cuckoo.verify, cert=cfg.cuckoo.cert)
 70                 except requests.ConnectionError:
 71                      self.log('error', "Unable to connect to Cuckoo API at '{0}'.".format(api_uri))
 72                      return
 73                 except Exception as e:
 74                      self.log('error', "Failed performing request at '{0}': {1}".format(api_uri, e))
 75                      return
 76             else:
 77                 auth_headers = {'Authorization': "Bearer {0}".format(cfg.cuckoo.auth_token)}
 78                 response = requests.post(uri, headers=auth_headers, files=options)