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 socks;
14pub mod spnego;
15pub mod transport;
16
17pub use client::{Cred, SmbClient};
18
19#[derive(Debug, thiserror::Error)]
20pub enum SmbError {
21    #[error("truncated SMB2 message")]
22    Truncated,
23    #[error("bad protocol id")]
24    BadProtocol,
25    #[error("SMB2 status {0:#010x} for command {1:#06x}")]
26    Status(u32, u16),
27    #[error("unexpected security token")]
28    BadToken,
29    #[error("ntlm: {0}")]
30    Ntlm(String),
31    #[error(transparent)]
32    Io(#[from] std::io::Error),
33}
34
35pub type Result<T> = std::result::Result<T, SmbError>;
36
37/// SMB2 status codes we branch on.
38pub mod status {
39    pub const SUCCESS: u32 = 0x0000_0000;
40    pub const PENDING: u32 = 0x0000_0103; // interim async response; the real one follows
41    pub const MORE_PROCESSING_REQUIRED: u32 = 0xC000_0016;
42    pub const END_OF_FILE: u32 = 0xC000_0011;
43    pub const OBJECT_NAME_NOT_FOUND: u32 = 0xC000_0034;
44    pub const SHARING_VIOLATION: u32 = 0xC000_0043;
45}