Upload
others
View
0
Download
0
Embed Size (px)
Citation preview
Macoun⌘
1 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
APFSThomas Tempelmann & Jonas Plum
2 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
AblaufAPFS Aufbau
• Das Problem
• Reverse Engineering
• Struktur
• Entdeckungen
APFS Anwendung
• Interessantes für Anwender
• Spezielles für Entwickler
• Demo
3 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Das Problem
4 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
IT-Forensik
5 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Datum Ereignis Status APFS
14.06.2016 WWCD 2016 Vorstellung
24.10.2016 iOS 10.1 Test
12.12.2016 iOS 10.2 Test
27.03.2017 iOS 10.3 Umstellung iOS
25.09.2017 macOS High Sierra (10.13) Umstellung macOS
6 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Datum Ereignis Status01.08.2012 Windows Server 2012 ReFS Veröffentlichung
14.06.2016 WWCD 2016 APFS Vorstellung
24.10.2016 iOS 10.1 APFS Test
12.12.2016 iOS 10.2 APFS Test
27.03.2017 iOS 10.3 APFS Umstellung iOS
25.09.2017 macOS High Sierra (10.13) APFS Umstellung macOS
??? ??? REFS Umstellung
7 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
8 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Reverse Engineering
9 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Dokumentation
https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/APFS_Guide/Introduction/Introduction.html
10 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Features
• File-IDs: 64bit
• Filesize: 263 bytes
• Timestamps in nanoseconds
• Copy-on-write
• Space sharing
• Native encryption
• Sparse files
• Fast directory sizing
• UTF-8 filenames
• case-insensitive or case-sensitive
• Fletcher's checksum algorithm (for metadata)
11 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Tools
• fsck_apfs• apfs_hfs_convert• diskutil apfs …• hdiutil create -fs APFS …
12 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
„Reverse Engineering“ der Tools$ strings -10 /sbin/fsck_apfs …
checkpoint<->superblock mismatch on uuid…
checkpoint<->superblock mismatch on checkpoint descriptor block count: %d %d…
spaceman fast chunk count is bad: %lldspaceman fast cib count is bad: %dspaceman fast cab count is bad: %d…
13 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Auf Bytes starren$ hdiutil create -fs APFS -size 10MB \ -volname myvolume -quiet a$ cp a.dmg b.dmg$ hdiutil attach b.dmg
$ echo "Lorem ipsum" > /Volumes/myvolume/test.txt
$ hdiutil detach /dev/disk2
# Vergleichen
14 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
iBored
15 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Kaitai
• kaitai.io
• Deklarative Beschreibung von Strukturen
• Erzeugen von Parsern
• C++, Python, Ruby, Graphviz, …
16 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Beispiel .ksy … containersuperblock: seq: - id: magic size: 4 contents: [NXSB] - id: block_size type: u4 - id: num_blocks type: u8 - id: padding size: 16 …
17 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Parser … class Containersuperblock(KaitaiStruct): def __init__(self, _io, _parent=None, _root=None): self._io = _io self._parent = _parent self._root = _root if _root else self self.magic = self._io.ensure_fixed_contents(
struct.pack('4b', 78, 88, 83, 66) ) self.block_size = self._io.read_u4le() self.num_blocks = self._io.read_u8le() self.padding = self._io.read_bytes(16) …
18 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
19 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Das Ergebnis
github.com/cugu/apfs.ksy
20 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Struktur
21 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Container und Volumes
APFS ContainerHFS+
MBR / GPT
HFS+ NTFS
GPT
NTFS
APFS VolumeAPFS Volume
22 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Space-manager
Volume Superblock
Container Superblock
Root Directory Node
Block Map B-Tree
Block Map Root Node
Block Map B-Tree
Block Map Root Node
…
Allocation Info File
Allocation File
APFS Aufbau
23 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Space-manager
Volume Superblock
Container Superblock
Root Directory Node
Block Map B-Tree
Block Map Root Node
Block Map B-Tree
Block Map Root Node
…
Allocation Info File
Allocation File
APFS Aufbau
24 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Space-manager
Volume Superblock
Container Superblock
Root Directory Node
Block Map B-Tree
Block Map Root Node
Block Map B-Tree
Block Map Root Node
…
Allocation Info File
Allocation File
APFS Aufbau
25 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Space-manager
Volume Superblock
Container Superblock
Root Directory Node
Block Map B-Tree
Block Map Root Node
Block Map B-Tree
Block Map Root Node
…
Allocation Info File
Allocation File
APFS Aufbau
26 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Metadata Block Headerstruct block_header{ uint64 checksum; uint64 block_id; uint64 version; uint16 block_type; uint16 flags; uint16 content_type; uint16 padding;};
27 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Entdeckungen
28 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Checksum
• 64bit Fletcher's Checksum
• Nur für Metadata-Strukturen
• Code: https://github.com/cugu/apfs.ksy
29 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Timestamps
• 64bit
• Nanosekunden
• Seit 1.1.1970
• Jahr-2554-Problem
30 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
APFS für EntwicklerThomas Tempelmann
31 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Ablauf
• Was gibt’s für Anwender zu beachten?
• Wie betrifft APFS uns als Entwickler?
• Demos: iBored, APFS Explorer
32 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Was gibt’s für Anwenderzu beachten?
33 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Kompatibilität
• APFS-Volumes nicht lesbar mit OS X 10.11 und älter.
• Selbst mit 10.12.6 gibt’s Einschränkungen:
• Files, die Hard Links verwenden, sind nicht lesbar.
• Verschlüsselte Volumes (und Files?) nicht lesbar.
• Boot Camp: Von Windows aus kann man HFS+ aber nicht APFS lesen.
• Keine Directory-Hard Links verfügbar (betrifft v.A. Time Machine).
34 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Details des Formats
• Keine NUL-Zeichen in Dateinamen mehr, da nun String-Terminator.
• APFS hat ein Block-zu-inode-Mapping, d.h. man kann nun praktisch ohne Verzögerung rausfinden, welcher Datei ein Block auf der Disk gehört.
• Kein Journaling-File wie bei HFS+. Stattdessen gibt’s Checkpoint-Blocks, die eine kleine Anzahl der letzten Zustände beschreiben.
• Mehr Redundanz als bei HFS+ (Vor-/Rückverlinkung, Dateinamen erscheinen doppelt, Revisionsnummern)
35 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Probleme…• Kein Zurück von APFS zu HFS+
• Time Machine-Vol nicht nach APFS konvertieren!
• Aktivieren der Disk-Verschlüsselung konvertiert nach APFS!
• Drobo (NAS) hat angeblich Probleme mit APFS-Format.
• High Sierra o. APFS evtl. nicht auf AppleRAID / SoftRAID installierbar.
• Disk Utility erkennt keine unformatierten Disks.
• Finder erzeugt Clones beim Duplizieren, aber cp nicht.
36 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Wie betrifft APFSuns als Entwickler?
37 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
API-Unterschiede• Gelesene Dateinamen sind nicht mehr normalisiert (ä ≠ ä).
• CNIDs sind 64 (60) bit lang, und kommen auch vor.
• Carbon FileMgr liefert weiterhin 32 Bit CNIDs (nicht-permanent). Ausnahme: FSCatalogSearch nicht verfügbar auf APFS-Volumes.
• Kein Backup-Timestamp mehr vorhanden.
• exchangedata() nicht mehr nutzbar. Ersatz: renamex_np(), aber erst ab 10.12 und nicht für HFS+.
38 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
typedef struct {unsigned int size;vol_capabilities_attr_t attributes;
} volinfo_buf_t;void getVolInfo (const char *volPath){
struct attrlist attrlist = {0};attrlist.bitmapcount = ATTR_BIT_MAP_COUNT;attrlist.volattr = ATTR_VOL_CAPABILITIES;volinfo_buf_t info;if (getattrlist(volPath, &attrlist, &info, sizeof(info), 0) == 0) {
vol_capabilities_attr_t *attr = &info.attributes;u_int32_t capab = attr->capabilities[VOL_CAPABILITIES_FORMAT];u_int32_t valid = attr->valid[VOL_CAPABILITIES_FORMAT];has64BitCNIDs = (capab & valid & VOL_CAP_FMT_64BIT_OBJECT_IDS) != 0;
}}
Abfrage auf 64 Bit-CNIDs
39 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Unicode-Normalisierung
Not Equal!
40 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Unicode-Normalisierung• Beispiel: Knörz
• Composed: ö (F6)
• Decomposed: o (6F) + ¨ (0308)
• Bei HFS+ kommt nur Decomposed zurück, bei APFS kann beides kommen.
• Bei Suche nach Dateinamen, die Knörz enthalten, kann es auf APFS leicht schief gehen. Daher die Namen vorher normalisieren.
4B 6E C3 B6 72 7A
4B 6E 6F CC 88 72 7A
41 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Unicode-Normalisierung
42 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Verzeichnisse lesen
• Für Vergleich oder Speichern von Dateinamen diese zuvor per fileSystemRepresentation() normalisieren!
• Es gibt m.W. keine ObjC-Funktion für einen normalization-insensitive Vergleich von Texten. Bei Swift geht es angeblich aber mit “==” – allerdings ist das nicht case-insensitive. Was fehlt, ist eine Vergleichsfunktion, die auf die Regeln des betroffenen Dateisystems angepaßt ist.
• readdir() liefert Einträge in wilder Reihenfolge, d.h. unsortiert.
43 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Neue und optimierte Funktionen• Optimiert für APFS Cloning:
• copyItem, replaceItem
• copyfile, fcopyfile
• Neu seit 10.12:
• renamex_np, renameatx_np
• clonefileat, fclonefileat, clonefile
• Siehe WWDC 2016, Session 701, Introducing Apple File System
44 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Volume Capabilities (getattrlist)HFS+ (aber nicht APFS):
VOL_CAP_FMT_DIR_HARDLINKS VOL_CAP_INT_NFSEXPORT VOL_CAP_INT_READDIRATTR VOL_CAP_INT_EXCHANGEDATA
APFS (aber nicht HFS+):
VOL_CAP_FMT_SPARSE_FILESVOL_CAP_FMT_64BIT_OBJECT_IDSVOL_CAP_INT_COPYFILEVOL_CAP_INT_CLONEVOL_CAP_INT_RENAME_SWAP
45 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Demo
46 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
github.com/cugu/apfs.ksy
Mitmachen
47 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Fragen?
48 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Vielen DankThomas Tempelmann
- www.tempel.org
- @tempelorg
- github.com/tempelmann
Jonas Plum
- blog.cugu.eu
- @cugu_pio
- github.com/cugu
49 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017
Macoun⌘
50 Macoun 2017 APFS – J. Plum & T. Tempelmann.key - 8. October 2017