#![allow(dead_code)]
pub mod smb;
pub mod gss;
pub mod kerberos;
use anyhow::Result;
use log::debug;
use smb2_client::SmbClient;
#[derive(Clone)]
pub enum AuthConfig {
Password(String),
Hash([u8; 16]),
Kerberos { ccache: String, kdc: String },
}
impl std::fmt::Debug for AuthConfig {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Password(_) => f.write_str("Password(<redacted>)"),
Self::Hash(_) => f.write_str("Hash(<redacted>)"),
Self::Kerberos { ccache, kdc } => {
write!(f, "Kerberos {{ ccache: {ccache:?}, kdc: {kdc:?} }}")
}
}
}
}
impl AuthConfig {
pub fn label(&self) -> String {
match self {
Self::Password(_) => "NTLMv2 password".to_string(),
Self::Hash(h) => format!("NTLMv2 PTH [{:02x}{:02x}{:02x}…]", h[0], h[1], h[2]),
Self::Kerberos { ccache, kdc } => {
format!("Kerberos pass-the-ticket (ccache: {ccache}, kdc: {kdc})")
}
}
}
}
pub async fn connect_ipc_with(
host: &str,
domain: &str,
user: &str,
auth: &AuthConfig,
) -> Result<SmbClient> {
match auth {
AuthConfig::Kerberos { ccache, kdc } => {
let spn = format!("cifs/{host}");
debug!("[{host}] Kerberos: requesting {spn} from {kdc}");
let (gss_blob, session_key) =
kerberos::kerberos_material_for(ccache, &spn, kdc).await?;
let a = smb::SmbAuth::Kerberos {
gss_blob: &gss_blob,
session_key: &session_key,
};
smb::connect_ipc(host, domain, user, a).await
}
AuthConfig::Hash(h) => smb::connect_ipc(host, domain, user, smb::SmbAuth::Hash(h)).await,
AuthConfig::Password(p) => {
smb::connect_ipc(host, domain, user, smb::SmbAuth::Password(p)).await
}
}
}