port refactor - eod commit, airspace still broken
This commit is contained in:
@@ -70,15 +70,15 @@ class Frame(BaseModel):
|
||||
msg = "Network Frame cannot have both a TCP header and a UDP header"
|
||||
_LOGGER.error(msg)
|
||||
raise ValueError(msg)
|
||||
if kwargs["ip"].protocol == IPProtocol.TCP and not kwargs.get("tcp"):
|
||||
if kwargs["ip"].protocol == IPProtocol["TCP"] and not kwargs.get("tcp"):
|
||||
msg = "Cannot build a Frame using the TCP IP Protocol without a TCPHeader"
|
||||
_LOGGER.error(msg)
|
||||
raise ValueError(msg)
|
||||
if kwargs["ip"].protocol == IPProtocol.UDP and not kwargs.get("udp"):
|
||||
if kwargs["ip"].protocol == IPProtocol["UDP"] and not kwargs.get("udp"):
|
||||
msg = "Cannot build a Frame using the UDP IP Protocol without a UDPHeader"
|
||||
_LOGGER.error(msg)
|
||||
raise ValueError(msg)
|
||||
if kwargs["ip"].protocol == IPProtocol.ICMP and not kwargs.get("icmp"):
|
||||
if kwargs["ip"].protocol == IPProtocol["ICMP"] and not kwargs.get("icmp"):
|
||||
msg = "Cannot build a Frame using the ICMP IP Protocol without a ICMPPacket"
|
||||
_LOGGER.error(msg)
|
||||
raise ValueError(msg)
|
||||
@@ -165,7 +165,7 @@ class Frame(BaseModel):
|
||||
|
||||
:return: True if the Frame is an ARP packet, otherwise False.
|
||||
"""
|
||||
return self.udp.dst_port == Port.ARP
|
||||
return self.udp.dst_port == Port["ARP"]
|
||||
|
||||
@property
|
||||
def is_icmp(self) -> bool:
|
||||
|
||||
@@ -9,25 +9,32 @@ from primaite.utils.validators import IPV4Address
|
||||
_LOGGER = getLogger(__name__)
|
||||
|
||||
|
||||
class IPProtocol(Enum):
|
||||
"""
|
||||
Enum representing transport layer protocols in IP header.
|
||||
IPProtocol : dict[str, str] = dict(
|
||||
NONE = "none",
|
||||
TCP = "tcp",
|
||||
UDP = "udp",
|
||||
ICMP = "icmp",
|
||||
)
|
||||
|
||||
.. _List of IPProtocols:
|
||||
"""
|
||||
# class IPProtocol(Enum):
|
||||
# """
|
||||
# Enum representing transport layer protocols in IP header.
|
||||
|
||||
NONE = "none"
|
||||
"""Placeholder for a non-protocol."""
|
||||
TCP = "tcp"
|
||||
"""Transmission Control Protocol."""
|
||||
UDP = "udp"
|
||||
"""User Datagram Protocol."""
|
||||
ICMP = "icmp"
|
||||
"""Internet Control Message Protocol."""
|
||||
# .. _List of IPProtocols:
|
||||
# """
|
||||
|
||||
def model_dump(self) -> str:
|
||||
"""Return as JSON-serialisable string."""
|
||||
return self.name
|
||||
# NONE = "none"
|
||||
# """Placeholder for a non-protocol."""
|
||||
# TCP = "tcp"
|
||||
# """Transmission Control Protocol."""
|
||||
# UDP = "udp"
|
||||
# """User Datagram Protocol."""
|
||||
# ICMP = "icmp"
|
||||
# """Internet Control Message Protocol."""
|
||||
|
||||
# def model_dump(self) -> str:
|
||||
# """Return as JSON-serialisable string."""
|
||||
# return self.name
|
||||
|
||||
|
||||
class Precedence(Enum):
|
||||
@@ -81,7 +88,7 @@ class IPPacket(BaseModel):
|
||||
>>> ip_packet = IPPacket(
|
||||
... src_ip_address=IPv4Address('192.168.0.1'),
|
||||
... dst_ip_address=IPv4Address('10.0.0.1'),
|
||||
... protocol=IPProtocol.TCP,
|
||||
... protocol=IPProtocol["TCP"],
|
||||
... ttl=64,
|
||||
... precedence=Precedence.CRITICAL
|
||||
... )
|
||||
@@ -91,7 +98,7 @@ class IPPacket(BaseModel):
|
||||
"Source IP address."
|
||||
dst_ip_address: IPV4Address
|
||||
"Destination IP address."
|
||||
protocol: IPProtocol = IPProtocol.TCP
|
||||
protocol: str = IPProtocol["TCP"]
|
||||
"IPProtocol."
|
||||
ttl: int = 64
|
||||
"Time to Live (TTL) for the packet."
|
||||
|
||||
@@ -5,76 +5,112 @@ from typing import List, Union
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Port(Enum):
|
||||
"""
|
||||
Enumeration of common known TCP/UDP ports used by protocols for operation of network applications.
|
||||
Port: dict[str, int] = dict(
|
||||
UNUSED = -1,
|
||||
NONE = 0,
|
||||
WOL = 9,
|
||||
FTP_DATA = 20,
|
||||
FTP = 21,
|
||||
SSH = 22,
|
||||
SMTP = 25,
|
||||
DNS = 53,
|
||||
HTTP = 80,
|
||||
POP3 = 110,
|
||||
SFTP = 115,
|
||||
NTP = 123,
|
||||
IMAP = 143,
|
||||
SNMP = 161,
|
||||
SNMP_TRAP = 162,
|
||||
ARP = 219,
|
||||
LDAP = 389,
|
||||
HTTPS = 443,
|
||||
SMB = 445,
|
||||
IPP = 631,
|
||||
SQL_SERVER = 1433,
|
||||
MYSQL = 3306,
|
||||
RDP = 3389,
|
||||
RTP = 5004,
|
||||
RTP_ALT = 5005,
|
||||
DNS_ALT = 5353,
|
||||
HTTP_ALT = 8080,
|
||||
HTTPS_ALT = 8443,
|
||||
POSTGRES_SERVER = 5432,
|
||||
)
|
||||
|
||||
.. _List of Ports:
|
||||
"""
|
||||
# class Port():
|
||||
# def __getattr__()
|
||||
|
||||
UNUSED = -1
|
||||
"An unused port stub."
|
||||
|
||||
NONE = 0
|
||||
"Place holder for a non-port."
|
||||
WOL = 9
|
||||
"Wake-on-Lan (WOL) - Used to turn or awaken a computer from sleep mode by a network message."
|
||||
FTP_DATA = 20
|
||||
"File Transfer [Default Data]"
|
||||
FTP = 21
|
||||
"File Transfer Protocol (FTP) - FTP control (command)"
|
||||
SSH = 22
|
||||
"Secure Shell (SSH) - Used for secure remote access and command execution."
|
||||
SMTP = 25
|
||||
"Simple Mail Transfer Protocol (SMTP) - Used for email delivery between servers."
|
||||
DNS = 53
|
||||
"Domain Name System (DNS) - Used for translating domain names to IP addresses."
|
||||
HTTP = 80
|
||||
"HyperText Transfer Protocol (HTTP) - Used for web traffic."
|
||||
POP3 = 110
|
||||
"Post Office Protocol version 3 (POP3) - Used for retrieving emails from a mail server."
|
||||
SFTP = 115
|
||||
"Secure File Transfer Protocol (SFTP) - Used for secure file transfer over SSH."
|
||||
NTP = 123
|
||||
"Network Time Protocol (NTP) - Used for clock synchronization between computer systems."
|
||||
IMAP = 143
|
||||
"Internet Message Access Protocol (IMAP) - Used for retrieving emails from a mail server."
|
||||
SNMP = 161
|
||||
"Simple Network Management Protocol (SNMP) - Used for network device management."
|
||||
SNMP_TRAP = 162
|
||||
"SNMP Trap - Used for sending SNMP notifications (traps) to a network management system."
|
||||
ARP = 219
|
||||
"Address resolution Protocol - Used to connect a MAC address to an IP address."
|
||||
LDAP = 389
|
||||
"Lightweight Directory Access Protocol (LDAP) - Used for accessing and modifying directory information."
|
||||
HTTPS = 443
|
||||
"HyperText Transfer Protocol Secure (HTTPS) - Used for secure web traffic."
|
||||
SMB = 445
|
||||
"Server Message Block (SMB) - Used for file sharing and printer sharing in Windows environments."
|
||||
IPP = 631
|
||||
"Internet Printing Protocol (IPP) - Used for printing over the internet or an intranet."
|
||||
SQL_SERVER = 1433
|
||||
"Microsoft SQL Server Database Engine - Used for communication with the SQL Server."
|
||||
MYSQL = 3306
|
||||
"MySQL Database Server - Used for MySQL database communication."
|
||||
RDP = 3389
|
||||
"Remote Desktop Protocol (RDP) - Used for remote desktop access to Windows machines."
|
||||
RTP = 5004
|
||||
"Real-time Transport Protocol (RTP) - Used for transmitting real-time media, e.g., audio and video."
|
||||
RTP_ALT = 5005
|
||||
"Alternative port for RTP (RTP_ALT) - Used in some configurations for transmitting real-time media."
|
||||
DNS_ALT = 5353
|
||||
"Alternative port for DNS (DNS_ALT) - Used in some configurations for DNS service."
|
||||
HTTP_ALT = 8080
|
||||
"Alternative port for HTTP (HTTP_ALT) - Often used as an alternative HTTP port for web applications."
|
||||
HTTPS_ALT = 8443
|
||||
"Alternative port for HTTPS (HTTPS_ALT) - Used in some configurations for secure web traffic."
|
||||
POSTGRES_SERVER = 5432
|
||||
"Postgres SQL Server."
|
||||
# class Port(Enum):
|
||||
# """
|
||||
# Enumeration of common known TCP/UDP ports used by protocols for operation of network applications.
|
||||
|
||||
def model_dump(self) -> str:
|
||||
"""Return a json-serialisable string."""
|
||||
return self.name
|
||||
# .. _List of Ports:
|
||||
# """
|
||||
|
||||
# UNUSED = -1
|
||||
# "An unused port stub."
|
||||
|
||||
# NONE = 0
|
||||
# "Place holder for a non-port."
|
||||
# WOL = 9
|
||||
# "Wake-on-Lan (WOL) - Used to turn or awaken a computer from sleep mode by a network message."
|
||||
# FTP_DATA = 20
|
||||
# "File Transfer [Default Data]"
|
||||
# FTP = 21
|
||||
# "File Transfer Protocol (FTP) - FTP control (command)"
|
||||
# SSH = 22
|
||||
# "Secure Shell (SSH) - Used for secure remote access and command execution."
|
||||
# SMTP = 25
|
||||
# "Simple Mail Transfer Protocol (SMTP) - Used for email delivery between servers."
|
||||
# DNS = 53
|
||||
# "Domain Name System (DNS) - Used for translating domain names to IP addresses."
|
||||
# HTTP = 80
|
||||
# "HyperText Transfer Protocol (HTTP) - Used for web traffic."
|
||||
# POP3 = 110
|
||||
# "Post Office Protocol version 3 (POP3) - Used for retrieving emails from a mail server."
|
||||
# SFTP = 115
|
||||
# "Secure File Transfer Protocol (SFTP) - Used for secure file transfer over SSH."
|
||||
# NTP = 123
|
||||
# "Network Time Protocol (NTP) - Used for clock synchronization between computer systems."
|
||||
# IMAP = 143
|
||||
# "Internet Message Access Protocol (IMAP) - Used for retrieving emails from a mail server."
|
||||
# SNMP = 161
|
||||
# "Simple Network Management Protocol (SNMP) - Used for network device management."
|
||||
# SNMP_TRAP = 162
|
||||
# "SNMP Trap - Used for sending SNMP notifications (traps) to a network management system."
|
||||
# ARP = 219
|
||||
# "Address resolution Protocol - Used to connect a MAC address to an IP address."
|
||||
# LDAP = 389
|
||||
# "Lightweight Directory Access Protocol (LDAP) - Used for accessing and modifying directory information."
|
||||
# HTTPS = 443
|
||||
# "HyperText Transfer Protocol Secure (HTTPS) - Used for secure web traffic."
|
||||
# SMB = 445
|
||||
# "Server Message Block (SMB) - Used for file sharing and printer sharing in Windows environments."
|
||||
# IPP = 631
|
||||
# "Internet Printing Protocol (IPP) - Used for printing over the internet or an intranet."
|
||||
# SQL_SERVER = 1433
|
||||
# "Microsoft SQL Server Database Engine - Used for communication with the SQL Server."
|
||||
# MYSQL = 3306
|
||||
# "MySQL Database Server - Used for MySQL database communication."
|
||||
# RDP = 3389
|
||||
# "Remote Desktop Protocol (RDP) - Used for remote desktop access to Windows machines."
|
||||
# RTP = 5004
|
||||
# "Real-time Transport Protocol (RTP) - Used for transmitting real-time media, e.g., audio and video."
|
||||
# RTP_ALT = 5005
|
||||
# "Alternative port for RTP (RTP_ALT) - Used in some configurations for transmitting real-time media."
|
||||
# DNS_ALT = 5353
|
||||
# "Alternative port for DNS (DNS_ALT) - Used in some configurations for DNS service."
|
||||
# HTTP_ALT = 8080
|
||||
# "Alternative port for HTTP (HTTP_ALT) - Often used as an alternative HTTP port for web applications."
|
||||
# HTTPS_ALT = 8443
|
||||
# "Alternative port for HTTPS (HTTPS_ALT) - Used in some configurations for secure web traffic."
|
||||
# POSTGRES_SERVER = 5432
|
||||
# "Postgres SQL Server."
|
||||
|
||||
# def model_dump(self) -> str:
|
||||
# """Return a json-serialisable string."""
|
||||
# return self.name
|
||||
|
||||
|
||||
class UDPHeader(BaseModel):
|
||||
@@ -87,13 +123,13 @@ class UDPHeader(BaseModel):
|
||||
:Example:
|
||||
|
||||
>>> udp_header = UDPHeader(
|
||||
... src_port=Port.HTTP_ALT,
|
||||
... dst_port=Port.HTTP,
|
||||
... src_port=Port["HTTP_ALT"],
|
||||
... dst_port=Port["HTTP"],
|
||||
... )
|
||||
"""
|
||||
|
||||
src_port: Union[Port, int]
|
||||
dst_port: Union[Port, int]
|
||||
src_port: int
|
||||
dst_port: int
|
||||
|
||||
|
||||
class TCPFlags(Enum):
|
||||
@@ -126,12 +162,12 @@ class TCPHeader(BaseModel):
|
||||
:Example:
|
||||
|
||||
>>> tcp_header = TCPHeader(
|
||||
... src_port=Port.HTTP_ALT,
|
||||
... dst_port=Port.HTTP,
|
||||
... src_port=Port["HTTP_ALT"],
|
||||
... dst_port=Port["HTTP"],
|
||||
... flags=[TCPFlags.SYN, TCPFlags.ACK]
|
||||
... )
|
||||
"""
|
||||
|
||||
src_port: Port
|
||||
dst_port: Port
|
||||
src_port: int
|
||||
dst_port: int
|
||||
flags: List[TCPFlags] = [TCPFlags.SYN]
|
||||
|
||||
Reference in New Issue
Block a user