Skip to content

Commit

Permalink
Merge pull request #753 from saizinbud/BOX-10775
Browse files Browse the repository at this point in the history
bugfix: pyTenable crashes if srcInterface or dstInterface not null
  • Loading branch information
aseemsavio authored Feb 13, 2024
2 parents 3926f08 + 924afd0 commit 3a7d379
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 31 deletions.
15 changes: 15 additions & 0 deletions tenable/ot/graphql/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,21 @@
}
dstInterface{
id
lastSeen
firstSeen
mac
ips {
nodes{
ip
}
}
dnsNames{
nodes
}
family
directAsset {
id
}
}
dstNames{
nodes
Expand Down
36 changes: 29 additions & 7 deletions tenable/ot/graphql/schema/events.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from marshmallow import fields

from tenable.ot.graphql.definitions import NodesSchema, SchemaBase
from tenable.ot.graphql.schema.assets import Asset
from tenable.ot.schema.assets import NetworkInterface
from tenable.ot.schema.base import NodesList, AssetInfoList, AssetInfo
from tenable.ot.schema.base import (
NodesList,
AssetInfoList,
AssetInfo,
IP,
IPList,
ID,
IDList
)
from tenable.ot.schema.events import (
Event,
EventTypeDetails,
Expand All @@ -17,8 +24,6 @@
RackSlot,
ActionList,
Action,
ID,
IDList,
)


Expand All @@ -32,6 +37,16 @@ class IDListSchema(SchemaBase):
nodes = fields.Nested(IDSchema, required=True, many=True)


class IPSchema(SchemaBase):
dataclass = IP
ip = fields.IPv4(required=True)


class IPListSchema(SchemaBase):
dataclass = IPList
nodes = fields.Nested(IPSchema, required=True, many=True)


class ActionSchema(SchemaBase):
dataclass = Action
aid = fields.UUID(required=True)
Expand Down Expand Up @@ -187,16 +202,23 @@ class PolicySchema(SchemaBase):
)


class DnsListSchema(SchemaBase):
dataclass = NodesList

nodes = fields.List(fields.String(required=True), required=True)


class NetworkInterfaceSchema(SchemaBase):
dataclass = NetworkInterface

id = fields.UUID(required=True)
last_seen = fields.DateTime(allow_none=True, data_key="lastSeen")
first_seen = fields.DateTime(allow_none=True, data_key="firstSeen")
mac = fields.String(allow_none=True)

ips = fields.IPv4(required=True)
ips = fields.Nested(IPListSchema, required=True)
family = fields.String(required=True)
direct_asset = fields.Nested(Asset, allow_none=True, data_key="directAsset")
direct_asset = fields.Nested(IDSchema, allow_none=True, data_key="directAsset")
dns_names = fields.Nested(DnsListSchema, required=True, data_key="dnsNames")


class AssetInfoSchema(SchemaBase):
Expand Down
12 changes: 7 additions & 5 deletions tenable/ot/schema/assets.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import datetime
import ipaddress
import typing
import uuid
from typing import List, Optional

from dataclasses import dataclass

from tenable.ot.schema.base import NodesList
from tenable.ot.schema.base import NodesList, IPList, ID
from tenable.ot.schema.plugins import Plugin, Plugins


Expand Down Expand Up @@ -150,10 +151,11 @@ class NetworkInterface:
This class holds a network interface's information.
"""

direct_asset: Asset
family: str
first_seen: datetime.datetime
id: uuid.UUID
ips: str
last_seen: datetime.datetime
first_seen: datetime.datetime
mac: str
family: str
direct_asset: ID
ips: IPList
dns_names: NodesList
21 changes: 21 additions & 0 deletions tenable/ot/schema/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ipaddress
import uuid
from dataclasses import dataclass
from typing import List
Expand Down Expand Up @@ -32,3 +33,23 @@ class AssetInfo:
@dataclass
class AssetInfoList(NodesList):
nodes: List[AssetInfo]


@dataclass
class IP:
ip: ipaddress.IPv4Address


@dataclass
class IPList:
nodes: List[IP]


@dataclass
class ID:
id: uuid.UUID


@dataclass
class IDList:
nodes: List[ID]
20 changes: 7 additions & 13 deletions tenable/ot/schema/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@
from typing import List, Optional

from tenable.ot.schema.assets import NetworkInterface
from tenable.ot.schema.base import NodesList, AssetInfoList


@dataclass
class ID:
id: uuid.UUID


@dataclass
class IDList:
nodes: List[ID]
from tenable.ot.schema.base import (
NodesList,
AssetInfoList,
IDList
)


@dataclass
Expand Down Expand Up @@ -141,12 +135,12 @@ class Event:
time: datetime.datetime
type: str
comment: Optional[str] = None
dst_interface: Optional[List[NetworkInterface]] = None
dst_interface: Optional[NetworkInterface] = None
dst_mac: Optional[str] = None
protocol_nice_name: Optional[str] = None
resolved_ts: Optional[datetime.datetime] = None
resolved_user: Optional[str] = None
src_interface: Optional[List[NetworkInterface]] = None
src_interface: Optional[NetworkInterface] = None
src_mac: Optional[str] = None


Expand Down
105 changes: 99 additions & 6 deletions tests/ot/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,26 @@

import pytest
import responses
from tenable.ot.schema.assets import NetworkInterface

from tenable.ot.graphql.iterators import OTGraphIterator
from tenable.ot.schema.base import AssetInfo, NodesList, AssetInfoList
from tenable.ot.schema.base import (
AssetInfo,
NodesList,
AssetInfoList,
IPList,
IP,
IDList,
ID,
)
from tenable.ot.schema.events import (
Event,
EventTypeDetails,
Policy,
GroupMember,
Group,
EventCount,
ActionList, IDList,
ActionList
)


Expand Down Expand Up @@ -150,7 +159,26 @@ def test_list(fixture_ot):
}
]
},
"srcInterface": None,
"srcInterface": {
"id": "71d1edd9-bdce-4a59-96f7-7f041baa7680",
"lastSeen": "2024-02-12T12:29:11.75946Z",
"firstSeen": "2024-02-05T16:36:32.946517Z",
"mac": "00:50:56:83:6c:23",
"ips": {
"nodes": [
{
"ip": "10.100.20.17"
}
]
},
"dnsNames": {
"nodes": []
},
"family": "VMware",
"directAsset": {
"id": "b1158857-b9fe-41ac-ba50-db17ecfd5746"
}
},
"srcNames": {"nodes": ["Eng. Station #100"]},
"dstAssets": {
"nodes": [
Expand All @@ -160,7 +188,26 @@ def test_list(fixture_ot):
}
]
},
"dstInterface": None,
"dstInterface": {
"id": "56044b78-d307-467d-a5ba-eb1c522b73af",
"lastSeen": "2024-02-12T12:29:09.568506Z",
"firstSeen": "2024-02-05T16:36:32.747096Z",
"mac": "00:09:91:06:4f:9a",
"ips": {
"nodes": [
{
"ip": "10.100.103.20"
}
]
},
"dnsNames": {
"nodes": []
},
"family": "GE",
"directAsset": {
"id": "1ab1220a-479e-4ce8-ba2a-e1b2b63d8345"
}
},
"dstNames": {"nodes": ["CPU 412-2 PN/DP"]},
"hasDetails": False,
"payloadSize": 0,
Expand Down Expand Up @@ -299,7 +346,30 @@ def test_list(fixture_ot):
)
]
),
src_interface=None,
src_interface=NetworkInterface(
id=uuid.UUID('71d1edd9-bdce-4a59-96f7-7f041baa7680'),
last_seen=datetime.datetime(
2024, 2, 12, 12, 29, 11, 759460, tzinfo=datetime.timezone.utc
),
first_seen=datetime.datetime(
2024, 2, 5, 16, 36, 32, 946517, tzinfo=datetime.timezone.utc
),
mac='00:50:56:83:6c:23',
family='VMware',
direct_asset=ID(
id=uuid.UUID('b1158857-b9fe-41ac-ba50-db17ecfd5746')
),
ips=IPList(
nodes=[
IP(
ip=IPv4Address('10.100.20.17')
)
]
),
dns_names=NodesList(
nodes=[]
)
),
src_names=NodesList(nodes=["Eng. Station #100"]),
dst_assets=AssetInfoList(
nodes=[
Expand All @@ -309,7 +379,30 @@ def test_list(fixture_ot):
)
]
),
dst_interface=None,
dst_interface=NetworkInterface(
id=uuid.UUID('56044b78-d307-467d-a5ba-eb1c522b73af'),
last_seen=datetime.datetime(
2024, 2, 12, 12, 29, 9, 568506, tzinfo=datetime.timezone.utc
),
first_seen=datetime.datetime(
2024, 2, 5, 16, 36, 32, 747096, tzinfo=datetime.timezone.utc
),
mac='00:09:91:06:4f:9a',
family='GE',
direct_asset=ID(
id=uuid.UUID('1ab1220a-479e-4ce8-ba2a-e1b2b63d8345')
),
ips=IPList(
nodes=[
IP(
ip=IPv4Address('10.100.103.20')
)
]
),
dns_names=NodesList(
nodes=[]
)
),
dst_names=NodesList(nodes=["CPU 412-2 PN/DP"]),
has_details=False,
payload_size=0,
Expand Down

0 comments on commit 3a7d379

Please sign in to comment.