Skip to content

Impacket exchanger.py

Back to the Category Index / Back to the Command Index

Connects to Exchange NSPI over RPC to enumerate the address book and search by GUID or DNT.

ItemDetails
Implementationexamples/exchanger.py
CategoryMSSQL / Exchange / MQTT
Size1078 lines
DistributionInstalled as a script through scripts=examples/*.py in setup.py

Check python examples/exchanger.py -h for the current option definitions.

Subcommands: nspi, list-tables, dump-tables, guid-known, dnt-lookup

ArgumentDescription
target[[domain/]username[:password]@]<targetName or address>
-debugEnable debug and extended output.
-tsAdd timestamps to log output.
-rpc-hostnameServer name in GUID format (preferred) or as a NetBIOS name; see the description at the start of the script.
-hashesNTLM hashes in LMHASH:NTHASH format.
-countRequest the total number of records in each table.
-basicUse Basic authentication instead of NTLM.
-lookup-typeLookup type: MINIMAL requests limited fields (default); EXTENDED requests more fields; FULL requests all fields for each row; GUIDS requests GUIDs only (choices: MINIMAL, EXTENDED, FULL, GUIDS).
-rows-per-requestMaximum rows per request (default: 50).
-guidDump the table with the specified GUID.
-output-typeBinary-object output format (choices: hex, base64; default: hex).
-output-fileOutput filename.
-guid-fileDump objects using GUIDs from a file.
-start-dntStarting DNT (default: 500000).
-stop-dntDNT at which to stop the lookup.
-nameDump the table with the specified name, including the GAL.

The command builds an RPC transport from autodiscovery or an explicit hostname and credentials, then binds to NSPI and initializes STAT. nspi list-tables, dump-tables, guid-known, and dnt-lookup select tables or containers. It retrieves property rows in pages and writes them as tables, hex, CSV, or other formats.

NSPI exposes the Exchange Address Book’s table and property model over RPC. Exchanger determines the RPC endpoint and HTTP proxy information through autodiscovery or a specified hostname, then sets credentials on the transport. After NSPI bind, the STAT structure is a cursor containing the current container, code page, and row position.

list-tables reads the hierarchy/container table and maps address book container IDs to names. dump-tables specifies a property-tag set for the selected container and repeats QueryRows in pages. Each property is decoded according to its MAPI type as a string, integer, binary value, multivalue, or other form. Failing to advance the row count and STAT position repeats the same page.

GUID and DNT lookups use NSPI requests and identifiers that differ from ordinary table scans. When converting between GUID, DN, and DNT, account for absent properties and code pages returned by the server. Keep output type and file handling separate from the protocol layer so binary properties remain available for later analysis, rather than becoming only lossy display strings.

SymbolLocationEntry Point for Tracing Behavior
Exchanger63__init__(), conenct_mapi(), connect_rpc(), load_autodiscover(), set_credentials(), set_extended_output(), set_output_type(), set_output_file(), print()
NSPIAttacks135__init__(), connect_rpc(), update_stat(), load_htable(), load_htable_stat(), load_htable_containerid(), print_htable(), disconnect(), print_row(), load_props(), req_print_table_rows(), req_print_guid(), and others
ExchangerHelper721__init__(), run(), nspi_run(), nspi_check(), nspi_list_tables(), nspi_dump_tables(), nspi_guid_known(), nspi_dnt_lookup()
ModuleMain Names Used
impacketuuid, version
impacket.httpAUTH_BASIC
impacket.exampleslogger
impacket.examples.utilsparse_target
impacket.structureparse_bitmask
impacket.dcerpc.v5nspi, transport
impacket.mapi_constantsMAPI_PROPERTIES, PR_CONTAINER_FLAGS_VALUES
impacket.dcerpc.v5.nspiCP_TELETEX, ExchBinaryObject, get_dn_from_guid, get_guid_from_dn
impacket.dcerpc.v5.rpchRPC_PROXY_CONN_A1_0X6BA_ERR, RPC_PROXY_CONN_A1_401_ERR, RPC_PROXY_CONN_A1_404_ERR, RPC_PROXY_HTTP_IN_DATA_401_ERR, RPC_PROXY_REMOTE_NAME_NEEDED_ERR, RPC_PROXY_RPC_OUT_DATA_404_ERR
Import NameDistribution PackageUsage / Declaration Status
sixsixImported directly; declared dependency

Output, Side Effects, and Required Privileges

Section titled “Output, Side Effects, and Required Privileges”
  • Primarily queries and authentication attempts. Repeated runs can affect audit logs, account lockouts, and target load.
  • Depending on options, creates or updates a local file. Check how existing files are handled and the permissions on output containing secrets.
  • On failure, use protocol status to determine whether name resolution, connection, authentication, service state, or permissions stopped the operation.
  • disconnect() handles cleanup. Check that new early returns and exception paths still reach it.

This command depends on dcerpc.v5.nspi / transport / rpch, mapi_constants, and HTTP Basic/NTLM. Exchanger handles connections, NSPIAttacks handles requests and row parsing, and ExchangerHelper dispatches CLI subcommands.