Skip to content

Impacket sambaPipe.py

Back to the category index / Back to the command index

Places a .so file on a share and opens a named pipe to test whether Samba loads external pipe modules.

ItemDetails
Implementationexamples/sambaPipe.py
CategorySMB / MSRPC / NTLM
Size281 lines
DistributionInstalled as a script through scripts=examples/*.py in setup.py

Run python examples/sambaPipe.py -h for the current option definitions.

ArgumentDescription
target[[domain/]username[:password]@]
-soShared object (.so) filename to upload and load (required)
-debugEnable debug output.
-tsAdd a timestamp to each log message.
-hashesNTLM hashes in LMHASH:NTHASH format.
-no-passDo not prompt for a password (useful with -k).
-kUse Kerberos authentication. Read credentials from the ccache file named by KRB5CCNAME, based on the target parameters; if no valid credentials are found, use those supplied on the command line.
-aesKeyAES key for Kerberos authentication (128 or 256 bits).
-dc-ipDomain controller IP address; if omitted, use the domain portion (FQDN) of the target.
-target-ipTarget IP address; if omitted, use the target value. Useful when the target is a NetBIOS name that cannot be resolved.
-portDestination SMB server port (choices: 139, 445; default: 445)

After connecting over SMB, the tool finds or selects a writable share and uploads the specified shared object. It opens the pipe module name with an SMB1 or SMB2 create request and checks the response status. Afterward, it removes the uploaded file where possible.

In some Samba configurations, named pipe names affect how external RPC module libraries are resolved. This creates a path through which a shared object placed on a writable share can be loaded. The command first establishes an SMB session, enumerates shares, checks for a writable location, and transfers the specified .so file to a remote path.

It then constructs a low-level SMB1 or SMB2 packet for the pipe create/open request. Opening a regular file and opening a named pipe differ in path namespace, create options, and impersonation level, so it sets the structure for each dialect explicitly. The server status code shows how far module lookup or opening proceeded.

Successful upload and successful pipe opening are separate stages; the placed file can remain after a failure in between. The writable-share check includes creating and deleting a temporary file, without overwriting an existing file. Behavior depends on the target Samba version and configuration, so a rejection may indicate mitigation or an inapplicable target, not just failed credentials.

SymbolLocationWhere to trace its responsibility
PIPEDREAM50__init__(), isShareWritable(), findSuitableShare(), uploadSoFile(), create(), openPipe(), run()
ModuleMain names used
impacketversion
impacket.exampleslogger
impacket.examples.utilsparse_target
impacket.nt_errorsSTATUS_SUCCESS
impacket.smbFILE_DIRECTORY_FILE, FILE_NON_DIRECTORY_FILE, FILE_OPEN, FILE_READ_DATA, FILE_SHARE_READ, FILE_WRITE_DATA, SMB, SMBCommand, SMBNtCreateAndX_Data, SMBNtCreateAndX_Parameters, SMB_DIALECT
impacket.smb3structsSMB2Create, SMB2Create_Response, SMB2Packet, SMB2_CREATE, SMB2_FLAGS_DFS_OPERATIONS, SMB2_IL_IMPERSONATION, SMB2_OPLOCK_LEVEL_NONE, SMB2_SESSION_FLAG_ENCRYPT_DATA
impacket.smbconnectionSMBConnection
impacket.dcerpc.v5srvs, transport

Output, side effects, and required privileges

Section titled “Output, side effects, and required privileges”
  • Some operations change the target’s state. Check the target name, SID, and path before making changes.
  • Some paths use temporary resources such as remote services, tasks, files, shares, or WMI/RPC resources. Recovery after an abnormal exit is part of the behavior contract.
  • On failure, use protocol status codes to determine whether name resolution, connection, authentication, service state, or permissions caused the stop.
  • Even without an explicitly named cleanup function, check for a finally-equivalent path and closure or deletion of protocol handles.

The code depends on low-level smb and smb3structs as well as SMBConnection. PIPEDREAM handles share probing, upload, and create/open requests. Check dialect and path semantics and cleanup on failure.