Skip to main content

smb2_client/
lib.rs

1//! A minimal SMB2 client — the impacket `smb3`/`smbconnection` equivalent, scoped to what
2//! named-pipe DCE/RPC needs: negotiate (dialect 2.1.0), NTLM session setup, tree-connect to
3//! IPC$, create a pipe, and FSCTL_PIPE_TRANSCEIVE to carry RPC PDUs.
4//!
5//! Raw NTLMSSP is placed directly in the session-setup security buffer (Windows accepts it
6//! without a SPNEGO wrapper). SMB 2.x message signing (HMAC-SHA256, truncated to 16 bytes)
7//! is applied once a session key is established, since DCs require signing on IPC$.
8
9pub mod client;
10pub mod header;
11pub mod msg;
12pub mod server;
13pub mod spnego;
14pub mod transport;
15
16pub use client::{Cred, SmbClient};
17
18#[derive(Debug, thiserror::Error)]
19pub enum SmbError {
20    #[error("truncated SMB2 message")]
21    Truncated,
22    #[error("bad protocol id")]
23    BadProtocol,
24    #[error("SMB2 status {0:#010x} for command {1:#06x}")]
25    Status(u32, u16),
26    #[error("unexpected security token")]
27    BadToken,
28    #[error("ntlm: {0}")]
29    Ntlm(String),
30    #[error(transparent)]
31    Io(#[from] std::io::Error),
32}
33
34pub type Result<T> = std::result::Result<T, SmbError>;
35
36/// SMB2 status codes we branch on.
37pub mod status {
38    pub const SUCCESS: u32 = 0x0000_0000;
39    pub const PENDING: u32 = 0x0000_0103; // interim async response; the real one follows
40    pub const MORE_PROCESSING_REQUIRED: u32 = 0xC000_0016;
41    pub const END_OF_FILE: u32 = 0xC000_0011;
42    pub const OBJECT_NAME_NOT_FOUND: u32 = 0xC000_0034;
43    pub const SHARING_VIOLATION: u32 = 0xC000_0043;
44}