tech:samba-client_smb_cifs
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| tech:samba-client_smb_cifs [2025/05/06 16:27] – Jean-Baptiste | tech:samba-client_smb_cifs [2026/06/30 21:53] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag>FS Windows Réseau}} | ||
| + | |||
| + | # Client Samba SMB CIFS | ||
| + | |||
| + | Voir aussi | ||
| + | * [[Serveur Samba SMB CIFS]] | ||
| + | * CIFS Unix Extensions / Services for Unix (SFU) | ||
| + | |||
| + | |||
| + | Voir : | ||
| + | * rclone | ||
| + | * curl smb / smbs | ||
| + | |||
| + | |||
| + | ## Install | ||
| + | |||
| + | ~~~bash | ||
| + | apt-get install cifs-utils smbclient | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Exemple | ||
| + | |||
| + | `auth.cfg` | ||
| + | ~~~ini | ||
| + | username=jean | ||
| + | password=P@ssw0rd | ||
| + | domain=D$ | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | smbclient -A auth.cfg // | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Lister les partages | ||
| + | |||
| + | Anonymement | ||
| + | ~~~bash | ||
| + | smbclient -N -L 127.0.0.1 | ||
| + | ~~~ | ||
| + | |||
| + | Avec un compte | ||
| + | ~~~bash | ||
| + | smbclient -U utilisateur%mdp -L 127.0.0.1 | ||
| + | ~~~ | ||
| + | |||
| + | Ou (debug) | ||
| + | ~~~bash | ||
| + | smbtree -N -d3 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Se connecter | ||
| + | |||
| + | #### smbclient | ||
| + | |||
| + | ~~~bash | ||
| + | smbclient -U utilisateur%mdp ' | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | #### gvfs-mount | ||
| + | |||
| + | ~~~bash | ||
| + | gvfs-mount smb:// | ||
| + | ~~~ | ||
| + | |||
| + | #### libpam-mount | ||
| + | |||
| + | ~~~bash | ||
| + | apt-get install libpam-mount | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | `/ | ||
| + | ~~~xml | ||
| + | <volume options= " | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Sécurité / Hardening / pentest | ||
| + | |||
| + | Voir nmap, smbmap, rpcclient, nbtscan, enum4linux | ||
| + | * https:// | ||
| + | |||
| + | Pour tester | ||
| + | ~~~bash | ||
| + | nmap -A 127.0.0.1 | ||
| + | |||
| + | nmap --script smb-os-discovery.nse -p445 127.0.0.1 | ||
| + | sudo nmap -sU -sS --script smb-os-discovery.nse -p U:137,T:139 127.0.0.1 | ||
| + | |||
| + | nmap --script smb-enum-shares.nse -p445 < | ||
| + | sudo nmap -sU -sS --script smb-enum-shares.nse -p U:137,T:139 127.0.0.1 | ||
| + | |||
| + | nmap --script smb-enum-users.nse -p445 < | ||
| + | sudo nmap -sU -sS --script smb-enum-users.nse -p U:137,T:139 127.0.0.1 | ||
| + | ~~~ | ||
| + | |||
| + | Disable less secure legacy dialects | ||
| + | |||
| + | `/ | ||
| + | ~~~bash | ||
| + | options cifs disable_legacy_dialects=1 | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | echo 1 > / | ||
| + | |||
| + | # Y or 1 stands for enabled | ||
| + | # N or 0 stands for disabled | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Autres clients | ||
| + | |||
| + | Display CIFS statics with Mega bytes per a 1 second 3 times (sysstat) | ||
| + | ~~~bash | ||
| + | cifsiostat -m 1 3 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ### Userland | ||
| + | |||
| + | Equiv : | ||
| + | ~~~ | ||
| + | mount.cifs -o credentials=/ | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | #sudo apt-get install fusesmb | ||
| + | sudo apt-get install smbnetfs | ||
| + | |||
| + | mkdir .smb | ||
| + | cp / | ||
| + | chmod 600 ~/ | ||
| + | cp / | ||
| + | mkdir -p Network | ||
| + | smbnetfs Network | ||
| + | |||
| + | cd Network/ | ||
| + | |||
| + | |||
| + | cd Network/ | ||
| + | ~~~ | ||
| + | |||
| + | `~/ | ||
| + | ~~~ | ||
| + | log_file | ||
| + | show_$_shares | ||
| + | show_hidden_hosts | ||
| + | auth " | ||
| + | include | ||
| + | ~~~ | ||
| + | |||
| + | `~/ | ||
| + | ~~~ | ||
| + | auth " | ||
| + | auth " | ||
| + | auth " | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | chmod 600 ~/ | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Cache avec cachefilesd / FS-Cache | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | ## Autres | ||
| + | |||
| + | |||
| + | ~~~bash | ||
| + | findmnt -n -s -t cifs | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | mkdir / | ||
| + | ~~~ | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | // | ||
| + | |||
| + | // | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | mount -t cifs // | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | `/ | ||
| + | ~~~bash | ||
| + | # Disable caching and the CIFS oplog for stable NTFS network shares | ||
| + | options cifs enable_oplocks=0 | ||
| + | |||
| + | install cifs / | ||
| + | remove cifs / | ||
| + | ~~~ | ||
| + | |||
| + | Fichiers contenant les identifiants en clair (pour ne pas les mettre dans le fstab) | ||
| + | |||
| + | `/ | ||
| + | ~~~ini | ||
| + | # | ||
| + | username=utilisateur | ||
| + | password=motdepasse | ||
| + | ~~~ | ||
| + | |||
| + | `/ | ||
| + | ~~~ini | ||
| + | username=utilisateur | ||
| + | password=motdepasse | ||
| + | ~~~ | ||
| + | |||
| + | Vous pouvez éventuellement ajouter : \ | ||
| + | `domain=MONDOMAINE` | ||
| + | |||
| + | Ou encore le mettre après le " | ||
| + | `username=utilisateur@MONDOMAINE` | ||
| + | |||
| + | ou bien \ | ||
| + | `username=MONDOMAINE\utilisateur` | ||
| + | |||
| + | ~~~bash | ||
| + | chmod 600 / | ||
| + | ~~~ | ||
| + | |||
| + | Puis | ||
| + | ~~~bash | ||
| + | mount / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Pb | ||
| + | |||
| + | ### Démonter / libérer les partitions CIFS en erreur (ou non) | ||
| + | |||
| + | |||
| + | ~~~ | ||
| + | # mount | grep /mnt/shared | ||
| + | systemd-1 on /mnt/shared type autofs (rw, | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ~~~bash | ||
| + | sudo umount -a -t cifs -l | ||
| + | sudo umount -a -t autofs -l | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Err NT_STATUS_LOGON_FAILURE (with authfile only) | ||
| + | |||
| + | Voir https:// | ||
| + | |||
| + | |||
| + | ~~~ | ||
| + | # smbclient -A /etc/.creds // | ||
| + | session setup failed: NT_STATUS_LOGON_FAILURE | ||
| + | ~~~ | ||
| + | |||
| + | ~~~ | ||
| + | # rpcclient vmx-gspl -d 1 -A /etc/.creds -c " | ||
| + | Cannot connect to server. | ||
| + | ~~~ | ||
| + | |||
| + | ~~~ | ||
| + | # smbclient -U jean -W DOMAIN // | ||
| + | Enter jean's password: | ||
| + | Domain=[ACME] OS=[Unix] Server=[Samba 3.6.6] | ||
| + | smb: \> | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Err NT_STATUS_CONNECTION_DISCONNECTED | ||
| + | |||
| + | ~~~ | ||
| + | $ smbclient -U user%' | ||
| + | WARNING: The " | ||
| + | protocol negotiation failed: NT_STATUS_CONNECTION_DISCONNECTED | ||
| + | ~~~ | ||
| + | |||
| + | #### Solution | ||
| + | |||
| + | Ajouter `-m SMB3` ou ajouter `--option=' | ||
| + | |||
| + | ~~~bash | ||
| + | smbclient -U user%' | ||
| + | |||
| + | smbclient -U user%' | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Pb temps de connexion long - NTLMSSP | ||
| + | |||
| + | ~~~ | ||
| + | plop@portable: | ||
| + | lp_load_ex: refreshing parameters | ||
| + | Initialising global parameters | ||
| + | rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384) | ||
| + | Processing section " | ||
| + | WARNING: The " | ||
| + | added interface wlan0 ip=2a01: | ||
| + | added interface docker0 ip=172.17.42.1 bcast=172.17.255.255 netmask=255.255.0.0 | ||
| + | added interface wlan0 ip=192.168.1.12 bcast=192.168.1.255 netmask=255.255.255.0 | ||
| + | Client started (version 4.5.16-Debian). | ||
| + | Connecting to 127.0.0.1 at port 1445 | ||
| + | Doing spnego session setup (blob length=398) | ||
| + | got OID=1.3.6.1.4.1.311.2.2.30 | ||
| + | got OID=1.2.840.48018.1.2.2 | ||
| + | got OID=1.2.840.113554.1.2.2 | ||
| + | got OID=1.2.840.113554.1.2.2.3 | ||
| + | got OID=1.3.6.1.4.1.311.2.2.10 | ||
| + | got principal=not_defined_in_RFC4178@please_ignore | ||
| + | GENSEC backend ' | ||
| + | GENSEC backend ' | ||
| + | GENSEC backend ' | ||
| + | GENSEC backend ' | ||
| + | GENSEC backend ' | ||
| + | GENSEC backend ' | ||
| + | GENSEC backend ' | ||
| + | GENSEC backend ' | ||
| + | GENSEC backend ' | ||
| + | GENSEC backend ' | ||
| + | GENSEC backend ' | ||
| + | GENSEC backend ' | ||
| + | GENSEC backend ' | ||
| + | Got challenge flags: | ||
| + | Got NTLMSSP neg_flags=0x62898215 | ||
| + | NTLMSSP: Set final flags: | ||
| + | Got NTLMSSP neg_flags=0x62088215 | ||
| + | NTLMSSP Sign/Seal - Initialising with flags: | ||
| + | Got NTLMSSP neg_flags=0x62088215 | ||
| + | |||
| + | |||
| + | |||
| + | NTLMSSP Sign/Seal - Initialising with flags: | ||
| + | Got NTLMSSP neg_flags=0x62088215 | ||
| + | Domain=[PLOP] OS=[] Server=[] | ||
| + | smb: \> | ||
| + | ~~~ | ||
| + | |||
| + | Où il y a trois lignes vides, ça a mis plusieurs secondes. \ | ||
| + | Dans le cas présent le contrôleur de domaine n'est pas joignable et nous utilisons un compte local. | ||
| + | |||
| + | |||
| + | #### Solution | ||
| + | |||
| + | Spécifier le domaine " | ||
| + | Le point indique un compte local (hors du domaine) \ | ||
| + | Vous pouvez utiliser l' | ||
| + | |||
| + | ~~~bash | ||
| + | smbclient -U user%' | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | #### Solution | ||
| + | |||
| + | Mettre à jour smbclient et ses dépendances | ||
| + | ~~~ | ||
| + | # apt-get install smbclient | ||
| + | The following extra packages will be installed: | ||
| + | libldb1 libsmbclient samba-common samba-libs | ||
| + | ~~~ | ||
| + | |||
| + | ### Pb CIFS VFS: cifs_mount failed w/return code = -61 - NT_STATUS_PATH_NOT_COVERED | ||
| + | |||
| + | Erreur | ||
| + | ~~~ | ||
| + | # dmesg | ||
| + | [1231082.766925] CIFS VFS: cifs_mount failed w/return code = -61 | ||
| + | ~~~ | ||
| + | |||
| + | Diag | ||
| + | ~~~ | ||
| + | # smbclient -U jean -W ACME \\partages\images | ||
| + | |||
| + | smb: \> cd REP\ | ||
| + | Connection to pc1111 failed (Error NT_STATUS_BAD_NETWORK_NAME) | ||
| + | Unable to follow dfs referral [\pc1111\REP$] | ||
| + | cd \REP\: NT_STATUS_PATH_NOT_COVERED | ||
| + | |||
| + | |||
| + | # ping pc1111 | ||
| + | ping: unknown host pc1111 | ||
| + | ~~~ | ||
| + | |||
| + | ##### Solution | ||
| + | |||
| + | Modifier le `/ | ||
| + | |||
| + | ### Pb error(22): Invalid argument | ||
| + | |||
| + | ~~~ | ||
| + | # mount -t cifs -o rw, | ||
| + | mount error(22): Invalid argument | ||
| + | Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) and kernel log messages (dmesg) | ||
| + | |||
| + | # dmesg -T | tail | ||
| + | [Wed Dec 23 11:31:16 2020] CIFS: Attempting to mount // | ||
| + | [Wed Dec 23 11:31:16 2020] CIFS: VFS: cifs_mount failed w/return code = -22 | ||
| + | ~~~ | ||
| + | |||
| + | #### Solution | ||
| + | |||
| + | Spécifier la version souhaitée | ||
| + | |||
| + | Exemple : `vers=2.0` | ||
| + | |||
| + | ~~~bash | ||
| + | mount -t cifs -o rw, | ||
| + | ~~~ | ||
| + | |||
| + | ### Err NT_STATUS_LOGON_FAILURE | ||
| + | |||
| + | ~~~ | ||
| + | $ smbclient -U user1%' | ||
| + | session setup failed: NT_STATUS_LOGON_FAILURE | ||
| + | |||
| + | $ smbclient -U user1%' | ||
| + | Domain=[localhost] OS=[Unix] Server=[Samba 3.0.33-3.7.el5] | ||
| + | tree connect failed: NT_STATUS_BAD_NETWORK_NAME | ||
| + | ~~~ | ||
| + | |||
| + | #### Solution | ||
| + | |||
| + | Le partage pointait vers un dossier non existant. | ||
| + | |||
| + | |||
| + | ## Notes | ||
| + | |||
| + | Exemple options de montage | ||
| + | |||
| + | ~~~ | ||
| + | on / | ||
| + | ~~~ | ||
| + | |||
