tenable / pyTenable

Python Library for interfacing into Tenable's platform APIs
https://pytenable.readthedocs.io
MIT License
354 stars 173 forks source link

Vulnerabilities using Tags Doesn't Appear to be Working #717

Closed Sinpoder closed 1 year ago

Sinpoder commented 1 year ago

It appears that Vulnerability Export using Tags Doesn't appear to be working properly based on the documentation.

`from tenable.io import TenableIO import json

tio = TenableIO()

with open("assets.json", 'w+', encoding='utf-8') as outfile: for vuln in tio.exports.vulns(): vunls = tio.exports.vulns( tags=[('Group Name','External Servers')] ) print(vunls)`

Here is an example of what I am looking for inside the JSON file

"tags": [
    {
        "uuid": "Redacted",
        "key": "Redacted",
        "value": "Redacted",
        "added_by": "Redacted",
        "added_at": "Redacted"
    },
    {
        "uuid": "Redacted",
        "key": "Redacted",
        "value": "Redacted",
        "added_by": "Redacted",
        "added_at": "Redacted"
    },
    {
        "uuid": "e9d27baa-40cf-4f64-96a6-0b6e99f5c1e4",
        "key": "Group Name",
        "value": "External Servers",
        "added_by": "Redacted",
        "added_at": "Redacted"
    },
    {
        "uuid": "Redacted",
        "key": "Redacted",
        "value": "Redacted",
        "added_by": "Redacted",
        "added_at": "Redacted"
    }

Here is the error code I get `module> for d in jsondata["tags"]:


TypeError: list indices must be integers or slices, not str
Press any key to continue . . .`
aseemsavio commented 1 year ago

I see a few problems in the snippet you've shared.

  1. The error is thrown from a piece of code that isn't shared here. There should be a place in your code where you're trying to access a property named "tags" from a variable named jsondata. It looks like jsondata is a list and not a dictionary. Hence you can only access data with indices.
  2. The tio.exports.vulns() method returns an iterator. Iterating over it would the right way to extract data out of it.
  3. You seem to be writing the vulnerabilities to an "assets.json" file. I cannot comment on the correctness of the logic as it isn't shared here.
Sinpoder commented 1 year ago

Hello,

Alright. I will sent more simple version of this as the writing the vulnerabilities to a file can be done later and I can get that to work.

`from tenable.io import TenableIO

Imports the needed API Key Information

tio = TenableIO()

Iterating through the JSON Output printing the vuln

for vuln in tio.exports.vulns(tags=[('Group Name','External Servers')]): print(vuln)`

This gives me no output, as if those tags do not exist while if I do the same thing without the tags I get a massive output of all my vulnerabilities, like I expected to get.

SteveMcGrath commented 1 year ago

Can you try a tag w/o any spaces?

Sinpoder commented 1 year ago

{'uuid': 'b0d4ae43-88a6-4bc0-a89c-5347ae108fa4', 'key': 'Group Name', 'value': 'Field', 'added_by': 'f5927ca8-1587-415e-9b58-aac6d44455b8', 'added_at': '2023-07-27T12:36:07.483Z'}, changing External Servers to Field, and I get the same response of nothing.