how the leopard hides his spots

69
How the Leopard hides his Spots OS X Anti-Forensics [email protected]

Upload: others

Post on 10-Feb-2022

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: How the Leopard hides his Spots

How the Leopard hides his SpotsOS X Anti-Forensics

[email protected]

Page 2: How the Leopard hides his Spots

Overview

• Introduction

• Strategies

• Tactics

• Conclusion

Page 3: How the Leopard hides his Spots

Introduction

• the grugq <[email protected]>

• Anti forensic researcher since 1999

• Independent security researcher

• Based in Thailand

Page 4: How the Leopard hides his Spots

Why Anti Forensics?

• Forensics is integral to infosec spectrum

• No research => no fixes

• Forensics remains vulnerable and insecure

• Still “green field” research

Page 5: How the Leopard hides his Spots

Forensics (in 1 slide)

• Forensics only exists within an investigation

• Preserve data in original state

• Extract evidentiary data from snapshot

• Present evidence

Page 6: How the Leopard hides his Spots

Anti Forensics

Page 7: How the Leopard hides his Spots

Data is evidence

Page 8: How the Leopard hides his Spots

Reduce the quantity and quality of evidentiary data

Page 9: How the Leopard hides his Spots

Strategies

Page 10: How the Leopard hides his Spots

Data DestructionThey can’t find what isn’t there

Page 11: How the Leopard hides his Spots

• Remove evidentiary data ex post facto

• Difficult to do properly

• Systems scatter data everywhere

• Scorched earth is the best policy

Page 12: How the Leopard hides his Spots

Data HidingThey can’t find what they can’t see

Page 13: How the Leopard hides his Spots

• Store data outside scope of tools

• Not a long term solution

• Suffers from bug death

• Don’t forget to encrypt

Page 14: How the Leopard hides his Spots

Data ContraceptionThey can’t find what was never there

Page 15: How the Leopard hides his Spots

• Don’t create evidentiary data

• Avoid contact with the disk

• Requires planning and discipline

• see haxh, hacking harness*

* http://www.tacvoip.com/tools.html

Page 16: How the Leopard hides his Spots

Tactics

Page 17: How the Leopard hides his Spots

Data Hiding Tactics

• Requirements:

• Hidden - obviously

• Robust - don’t want data to vanish

• Exploit structured storage bugs

Page 18: How the Leopard hides his Spots

Structured Storage

Page 19: How the Leopard hides his Spots

File System Fundamentals

• Comprised of data and metadata

• Pair data streams with readable names

• Internal structured metadata organises:

• System level metadata/data

• User level metadata/data

• OS level CRUD

Page 20: How the Leopard hides his Spots

• Header - Global FS layout / properties

• Block - Smallest atomic component

• Node - Metadata for a single file + block list(s)

• Map - Link names to nodes

Components

Page 21: How the Leopard hides his Spots

• Header - Boot Block

• Block - Cluster

• Node - Master File Table entry (File)

• Map - Master File Table Directory (Folder)

Example: NTFS

Page 22: How the Leopard hides his Spots

• Header - Boot Block

• Block - Cluster

• Node - Directory entry + FAT chain

• Map - Directory file

Example: FAT

Page 23: How the Leopard hides his Spots

Attacking Structured Storage

• Allocate space

• Exploit bugs

• Parsing

• Interpretation

• Presentation

• Inject data into that space

Page 24: How the Leopard hides his Spots

FISTing

• File system Insertion and Subversion Technique

• Generic technique for exploit structure storage

• Find a hole and FIST it

Page 25: How the Leopard hides his Spots

What holes can I FIST?

Page 26: How the Leopard hides his Spots

FIST sized Holes

• Special files

• Handled implicitly

• Slack space

• Typically inaccessible

• reserved

• reserved for hacker use, only!

Page 27: How the Leopard hides his Spots

• Incomplete/Ignorant implementations

• Unused structured storage “features”

• Logic bugs

• Edge cases get ignored

• Security bugs

• buffer overflows, int wraps, etc.

Forensic Tool Bugs

Page 28: How the Leopard hides his Spots

FISTing for All

• Any structured data storage can be FISTed

• File Systems

• Application file formats

Page 29: How the Leopard hides his Spots

Assaulting OS X

Page 30: How the Leopard hides his Spots

OS X Attacks

• File system attacks

• HFS+

• Application file format attacks

Page 31: How the Leopard hides his Spots

HFS+ Induction

Page 32: How the Leopard hides his Spots

HFS+

• Hierarchical File System Plus (HFS+)

• Introduced with OS X

• Strongly influenced by HFS

• Complex on-disk structure

• B*trees

• Technical Note 1150

Page 33: How the Leopard hides his Spots
Page 34: How the Leopard hides his Spots

Components

• Header - Volume Header

• Block - Block

• Node -

• block lists in extents

• meta data in catalog file entries

• Map - catalog file entries

Page 35: How the Leopard hides his Spots

HFS+ Core Concepts

• Data Forks

• Extents

• B*trees

• Nodes

Page 36: How the Leopard hides his Spots

Data Forks

• Store data stream location information

• Size of user data

• Block location + order

Page 37: How the Leopard hides his Spots

struct HFSPlusForkData {    UInt64                  logicalSize;    UInt32                  clumpSize;    UInt32                  totalBlocks;    HFSPlusExtentDescriptor extents[8];};

struct HFSPlusExtentDescriptor {    UInt32                  startBlock;    UInt32                  blockCount;};

Data Forks

Page 38: How the Leopard hides his Spots

Special Files

• allocationFile - block allocation bitmap

• catalogFile - file/directory meta data

• extentsFile - fragmented file block lists

• startupFile - (optional) kernel loader

• attributesFile - extended attributes

Page 39: How the Leopard hides his Spots

B*trees

• Used for most file system meta data

• Binary tree

• Stored on disk within a “special file”

• File is divided into equal sized nodes

• Node address == index

Page 40: How the Leopard hides his Spots

B*tree Nodes

• Header node - B*tree metadata

• Map nodes - node allocation bitmap

• Index nodes - key:node pointer

• Leaf nodes - key:data record

Page 41: How the Leopard hides his Spots

B*tree Node

Page 42: How the Leopard hides his Spots

B*treeFIRST LEAF NODE

POINTER

ROOT NODE

POINTER

LEAF NODE

POINTER

8 POINTER 18 POINTER

8 POINTER 13 POINTER 18 POINTER 20 POINTER 23 POINTER

8 DATA 10 DATA 13 DATA 15 DATA 18 DATA 20 DATA 22 DATA 23 DATA

HE

AD

ER

MO

DE

IND

EX

MO

DE

SL

EA

F M

OD

ES

Page 43: How the Leopard hides his Spots

HFS+ Attacks

Page 44: How the Leopard hides his Spots

File Allocation Attacks

Page 45: How the Leopard hides his Spots

Bad Blocks File

• Allocated extents within the extentsFile

• Special CNID => 5

• Prevents kernel allocating bad blocks for userfiles

• Lame attack, way too obvioous

Page 46: How the Leopard hides his Spots

startupFile

• Used for certain (archaic) systems

• Typically 0 length file

• Can be arbitrary size

• Kinda like bad blocks file, only more explicit

Page 47: How the Leopard hides his Spots

HFS Wrapper

• HFS+ volumes embedded within HFS

• HFS volume marks HFS+ space in “bad blocks file”

• Slack space after embedded HFS+ volume

Page 48: How the Leopard hides his Spots

B*tree Internals Attacks

Page 49: How the Leopard hides his Spots

Excessive Map Nodes

• Map nodes contain node allocation bitmap

• Stored as linked list of nodes

• Can exceed the size required for all nodes

Page 50: How the Leopard hides his Spots

B*tree Free Space

• B*tree nodes can contain free space

• Use freespace for data storage

Page 51: How the Leopard hides his Spots

When Unicode Attacks

Page 52: How the Leopard hides his Spots

Zero Width Unicode

• UTF-16 has non-glyph characters

•\x00\x00 NULL CHARACTER

•\x20\0B ZERO WIDTH SPACE

• Invisible data storage

Page 53: How the Leopard hides his Spots

UTF-16 is where?

• iPod iTunes db (mhbd), extensive UTF16

• File names: HFS+, NTFS, FAT32

• Inside documents

• … etc.

Page 54: How the Leopard hides his Spots

ZWU

• (Z triple U) iPod mhbd attack

• Max size is 255 UTF-16 chars

• 8 chars per byte

• ~31 bytes per string (theoretical max)

• approx 100k per 1k tracks

Page 55: How the Leopard hides his Spots

>>> import utfool>>> s = "hello world">>> u = utfool.tounicode(s)>>> print u'"%s"' % u"">>> len(u)88>>> s == utfool.fromunicode(u)True

Page 56: How the Leopard hides his Spots

Application File Formats

Page 57: How the Leopard hides his Spots

Browser Cookies

Page 58: How the Leopard hides his Spots

Browser Cookies

• What is a cookie? url: { key: value }

• value is a base64 encoded encrypted binary blob

Page 59: How the Leopard hides his Spots

Browser Cookies

• What is a cookie? url: { key: value }

• value is a base64 encoded encrypted binary blob

• What do we want to store?

• encrypted binary blobs…

Page 60: How the Leopard hides his Spots

Mozilla Cookies File

• Stored in an SQLite database

• Can access with sqlite3 tool

• Very simple schema

Page 61: How the Leopard hides his Spots

moz_cookies SchemaCREATE TABLE moz_cookies (

id INTEGER PRIMARY KEY,name TEXT, value TEXT, host TEXT, path TEXT,expiry INTEGER, isSecure INTEGER, isHttpOnly INTEGER, lastAccessed INTEGER)

Page 62: How the Leopard hides his Spots

Cookies HOWTO

sqlite> insert into moz_cookies host,value ('www.lolitapictures.com', 'eW91J3JlIGxlZXQ=');

Page 63: How the Leopard hides his Spots

SQLite

Page 64: How the Leopard hides his Spots

File Format

• File is an array of pages

• Header stored in first page

• Free pages in a linked list

• Pages contain cells

• Cells linked in b-trees

Page 65: How the Leopard hides his Spots

SQLeez

• Free space within SQLite files

• Expand in size, shrink after vacuum

• AUTO-VACUUM can destroy

Page 66: How the Leopard hides his Spots

SQLeez

• Demo

Page 67: How the Leopard hides his Spots

Future

• Out of the file system, into the files

• Application specific attacks are harder to detect

• More diverse attack space

Page 68: How the Leopard hides his Spots

Q & A

Page 69: How the Leopard hides his Spots

Thank you.