# fortra/impacket architecture

> Architecture diagram of the GitHub repository fortra/impacket, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fortra/impacket
- Repository: https://github.com/fortra/impacket

## Overview

Impacket is a Python networking-protocol library: callers construct protocol objects or parse raw packets, then use protocol implementations and transports to communicate with network peers. Its main branches cover packet-level protocols, SMB, MSRPC, and authentication/security, with LDAP and TDS as additional protocol implementations. The README documents the capabilities; source-index references support several internal dependencies. Unsampled implementations are represented at their exact file or enclosing-directory paths, so their internal call flows are not inferred.

Main entry points: [`impacket/dcerpc/v5/rpcrt.py`](https://github.com/fortra/impacket/blob/master/impacket/dcerpc/v5/rpcrt.py) (RPC runtime), [`impacket/smbconnection.py`](https://github.com/fortra/impacket/blob/master/impacket/smbconnection.py) (SMB connection API), [`impacket/spnego.py`](https://github.com/fortra/impacket/blob/master/impacket/spnego.py) (SPNEGO negotiation), [`impacket/smb.py`](https://github.com/fortra/impacket/blob/master/impacket/smb.py) (SMB1–3 protocol)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_packets["Packets and protocols"]
  node_packet_codecs["Packet encode and decode<br/>[ImpactPacket.py]"]
  node_packet_decoder["Packet decoder<br/>[ImpactDecoder.py]"]
  node_internet_protocols["IP and network protocols<br/>[IP6.py]"]
  node_other_protocols["Other protocol modules<br/>[dns.py]"]
  node_structure["Structure serialization<br/>[structure.py]"]
end

subgraph group_smb["SMB networking"]
  node_smb_protocol["SMB1–3 protocol<br/>[smb.py]"]
  node_smb3_protocol["SMB2–3 implementation<br/>[smb3.py]"]
  node_smb_connection["SMB connection API<br/>[smbconnection.py]"]
  node_netbios["NetBIOS session transport<br/>[nmb.py]"]
end

subgraph group_rpc["MSRPC"]
  node_rpc_transport["RPC transports<br/>[transport.py]"]
  node_rpc_runtime["RPC runtime<br/>[rpcrt.py]"]
  node_ndr["NDR serialization<br/>[ndr.py]"]
  node_rpc_interfaces["RPC interface modules"]
  node_dcom_runtime["DCOM runtime<br/>[dcomrt.py]"]
end

subgraph group_security["Authentication and security"]
  node_ntlm["NTLM authentication<br/>[ntlm.py]"]
  node_kerberos["Kerberos authentication<br/>[kerberosv5.py]"]
  node_spnego["SPNEGO negotiation<br/>[spnego.py]"]
end

subgraph group_data["Directory and database protocols"]
  node_ldap["LDAP protocol<br/>[ldap.py]"]
  node_tds["TDS protocol<br/>[tds.py]"]
end

node_caller(("Library caller"))
node_peer(("Network peer"))

node_caller -->|"constructs packets"| node_packet_codecs
node_caller -->|"parses packets"| node_packet_decoder
node_packet_decoder -.->|"decodes packet objects"| node_packet_codecs
node_packet_codecs -.->|"uses serialization"| node_structure
node_caller -->|"uses SMB API"| node_smb_connection
node_smb_connection -->|"uses SMB"| node_smb_protocol
node_smb_connection -.->|"uses SMB3"| node_smb3_protocol
node_smb_protocol -->|"uses sessions"| node_netbios
node_smb_protocol -->|"uses authentication"| node_ntlm
node_caller -->|"selects transport"| node_rpc_transport
node_rpc_transport -->|"creates RPC client"| node_rpc_runtime
node_rpc_runtime -->|"serializes calls"| node_ndr
node_rpc_runtime -->|"supports authentication"| node_ntlm
node_rpc_runtime -->|"supports authentication"| node_kerberos
node_caller -->|"invokes interfaces"| node_rpc_interfaces
node_rpc_interfaces -.->|"uses RPC runtime"| node_rpc_runtime
node_dcom_runtime -->|"uses RPC runtime"| node_rpc_runtime
node_caller -->|"uses LDAP"| node_ldap
node_ldap -->|"uses negotiation"| node_spnego
node_caller -->|"uses TDS"| node_tds
node_tds -->|"uses negotiation"| node_spnego
node_spnego -->|"supports NTLM"| node_ntlm
node_spnego -.->|"supports Kerberos"| node_kerberos
node_smb_connection -.->|"communicates with"| node_peer
node_rpc_transport -->|"communicates with"| node_peer
node_ldap -.->|"communicates with"| node_peer
node_tds -.->|"communicates with"| node_peer

click node_packet_codecs "https://github.com/fortra/impacket/blob/master/impacket/ImpactPacket.py"
click node_packet_decoder "https://github.com/fortra/impacket/blob/master/impacket/ImpactDecoder.py"
click node_internet_protocols "https://github.com/fortra/impacket/blob/master/impacket/IP6.py"
click node_other_protocols "https://github.com/fortra/impacket/blob/master/impacket/dns.py"
click node_structure "https://github.com/fortra/impacket/blob/master/impacket/structure.py"
click node_smb_protocol "https://github.com/fortra/impacket/blob/master/impacket/smb.py"
click node_smb3_protocol "https://github.com/fortra/impacket/blob/master/impacket/smb3.py"
click node_smb_connection "https://github.com/fortra/impacket/blob/master/impacket/smbconnection.py"
click node_netbios "https://github.com/fortra/impacket/blob/master/impacket/nmb.py"
click node_rpc_transport "https://github.com/fortra/impacket/blob/master/impacket/dcerpc/v5/transport.py"
click node_rpc_runtime "https://github.com/fortra/impacket/blob/master/impacket/dcerpc/v5/rpcrt.py"
click node_ndr "https://github.com/fortra/impacket/blob/master/impacket/dcerpc/v5/ndr.py"
click node_rpc_interfaces "https://github.com/fortra/impacket/tree/master/impacket/dcerpc/v5"
click node_dcom_runtime "https://github.com/fortra/impacket/blob/master/impacket/dcerpc/v5/dcomrt.py"
click node_ntlm "https://github.com/fortra/impacket/blob/master/impacket/ntlm.py"
click node_kerberos "https://github.com/fortra/impacket/blob/master/impacket/krb5/kerberosv5.py"
click node_spnego "https://github.com/fortra/impacket/blob/master/impacket/spnego.py"
click node_ldap "https://github.com/fortra/impacket/blob/master/impacket/ldap/ldap.py"
click node_tds "https://github.com/fortra/impacket/blob/master/impacket/tds.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_packet_codecs,node_packet_decoder,node_internet_protocols,node_other_protocols,node_structure toneBlue
class node_smb_protocol,node_smb3_protocol,node_smb_connection,node_netbios toneAmber
class node_rpc_transport,node_rpc_runtime,node_ndr,node_rpc_interfaces,node_dcom_runtime toneMint
class node_ntlm,node_kerberos,node_spnego toneRose
class node_ldap,node_tds,node_caller,node_peer toneIndigo
```

## Components

### Packets and protocols

- [Packet encode and decode](https://github.com/fortra/impacket/blob/master/impacket/ImpactPacket.py): `impacket/ImpactPacket.py`
- [Packet decoder](https://github.com/fortra/impacket/blob/master/impacket/ImpactDecoder.py): `impacket/ImpactDecoder.py`
- [IP and network protocols](https://github.com/fortra/impacket/blob/master/impacket/IP6.py): `impacket/IP6.py`
- [Other protocol modules](https://github.com/fortra/impacket/blob/master/impacket/dns.py): `impacket/dns.py`
- [Structure serialization](https://github.com/fortra/impacket/blob/master/impacket/structure.py): `impacket/structure.py`

### SMB networking

- [SMB1–3 protocol](https://github.com/fortra/impacket/blob/master/impacket/smb.py): `impacket/smb.py`
- [SMB2–3 implementation](https://github.com/fortra/impacket/blob/master/impacket/smb3.py): `impacket/smb3.py`
- [SMB connection API](https://github.com/fortra/impacket/blob/master/impacket/smbconnection.py): `impacket/smbconnection.py`
- [NetBIOS session transport](https://github.com/fortra/impacket/blob/master/impacket/nmb.py): `impacket/nmb.py`

### MSRPC

- [RPC transports](https://github.com/fortra/impacket/blob/master/impacket/dcerpc/v5/transport.py): `impacket/dcerpc/v5/transport.py`
- [RPC runtime](https://github.com/fortra/impacket/blob/master/impacket/dcerpc/v5/rpcrt.py): `impacket/dcerpc/v5/rpcrt.py`
- [NDR serialization](https://github.com/fortra/impacket/blob/master/impacket/dcerpc/v5/ndr.py): `impacket/dcerpc/v5/ndr.py`
- [RPC interface modules](https://github.com/fortra/impacket/tree/master/impacket/dcerpc/v5): `impacket/dcerpc/v5`
- [DCOM runtime](https://github.com/fortra/impacket/blob/master/impacket/dcerpc/v5/dcomrt.py): `impacket/dcerpc/v5/dcomrt.py`

### Authentication and security

- [NTLM authentication](https://github.com/fortra/impacket/blob/master/impacket/ntlm.py): `impacket/ntlm.py`
- [Kerberos authentication](https://github.com/fortra/impacket/blob/master/impacket/krb5/kerberosv5.py): `impacket/krb5/kerberosv5.py`
- [SPNEGO negotiation](https://github.com/fortra/impacket/blob/master/impacket/spnego.py): `impacket/spnego.py`

### Directory and database protocols

- [LDAP protocol](https://github.com/fortra/impacket/blob/master/impacket/ldap/ldap.py): `impacket/ldap/ldap.py`
- [TDS protocol](https://github.com/fortra/impacket/blob/master/impacket/tds.py): `impacket/tds.py`

### Other components

- **Library caller**
- **Network peer**

## Connections

- Library caller → Packet encode and decode: constructs packets (evidence: `README.md`)
- Library caller → Packet decoder: parses packets (evidence: `README.md`)
- Packet decoder → Packet encode and decode: decodes packet objects
- Packet encode and decode → Structure serialization: uses serialization
- Library caller → SMB connection API: uses SMB API (evidence: `README.md`)
- SMB connection API → SMB1–3 protocol: uses SMB
- SMB connection API → SMB2–3 implementation: uses SMB3
- SMB1–3 protocol → NetBIOS session transport: uses sessions (evidence: `impacket/smb.py`)
- SMB1–3 protocol → NTLM authentication: uses authentication (evidence: `impacket/smb.py`)
- Library caller → RPC transports: selects transport (evidence: `README.md`)
- RPC transports → RPC runtime: creates RPC client (evidence: `impacket/dcerpc/v5/transport.py`)
- RPC runtime → NDR serialization: serializes calls (evidence: `impacket/dcerpc/v5/rpcrt.py`)
- RPC runtime → NTLM authentication: supports authentication (evidence: `impacket/dcerpc/v5/rpcrt.py`)
- RPC runtime → Kerberos authentication: supports authentication (evidence: `impacket/dcerpc/v5/rpcrt.py`)
- Library caller → RPC interface modules: invokes interfaces (evidence: `README.md`)
- RPC interface modules → RPC runtime: uses RPC runtime (evidence: `impacket/dcerpc/v5/tsts.py`)
- DCOM runtime → RPC runtime: uses RPC runtime (evidence: `impacket/dcerpc/v5/dcomrt.py`)
- Library caller → LDAP protocol: uses LDAP (evidence: `README.md`)
- LDAP protocol → SPNEGO negotiation: uses negotiation (evidence: `impacket/ldap/ldap.py`)
- Library caller → TDS protocol: uses TDS (evidence: `README.md`)
- TDS protocol → SPNEGO negotiation: uses negotiation (evidence: `impacket/tds.py`)
- SPNEGO negotiation → NTLM authentication: supports NTLM (evidence: `impacket/spnego.py`)
- SPNEGO negotiation → Kerberos authentication: supports Kerberos (evidence: `impacket/krb5/kerberosv5.py`)
- SMB connection API → Network peer: communicates with
- RPC transports → Network peer: communicates with (evidence: `README.md`)
- LDAP protocol → Network peer: communicates with
- TDS protocol → Network peer: communicates with
