Reconstructing the Scene of the Crime Reconstructing the Scene of - - PowerPoint PPT Presentation

reconstructing the scene of the crime reconstructing the
SMART_READER_LITE
LIVE PREVIEW

Reconstructing the Scene of the Crime Reconstructing the Scene of - - PowerPoint PPT Presentation

Reconstructing the Scene of the Crime Reconstructing the Scene of the Crime Who are they? STEVE DAVIS PETER SILBERMAN STEVE DAVIS PETER SILBERMAN Security Consultant / Engineer / Researcher Security Consultant / Engineer / Researcher


slide-1
SLIDE 1

Reconstructing the Scene of the Crime Reconstructing the Scene of the Crime

slide-2
SLIDE 2

Who are they?

STEVE DAVIS STEVE DAVIS PETER SILBERMAN PETER SILBERMAN

  • Security Consultant /

Security Consultant / Researcher Researcher at MANDIANT at MANDIANT

  • Engineer / Researcher

Engineer / Researcher at MANDIANT at MANDIANT

slide-3
SLIDE 3

Agenda

  • ½

½ Demo Demo

- - Pop it like its

Pop it like its hotttt hotttt

  • Problem / Solution

Problem / Solution

  • Process Acquisition

Process Acquisition

  • Metasploit

Metasploit

  • Meterpreter Communication

Meterpreter Communication

  • Metasploit Forensic Framework (MSFF)

Metasploit Forensic Framework (MSFF)

  • ½ Demo

½ Demo

- - Reconstructing it like its

Reconstructing it like its hotttt hotttt

slide-4
SLIDE 4

Demo Part 1

  • Box Windows XP Fresh SP3

Box Windows XP Fresh SP3 Same box that our slides are running from Same box that our slides are running from… … Oh Oh noes noes! !

  • MS08-067 meterpreter bind tcp

MS08-067 meterpreter bind tcp

slide-5
SLIDE 5

Back to our regularly scheduled slides...

slide-6
SLIDE 6

Problem

  • Meterpreter

Meterpreter

- - Traditional disk forensics is helpless

Traditional disk forensics is helpless

  • Attack vector may never touch disk

Attack vector may never touch disk

- - No way to determine what happened

No way to determine what happened

  • Goal

Goal

- - Reconstruct attacker

Reconstruct attacker’ ’s Meterpreter sessions s Meterpreter sessions with as much reliability as possible with as much reliability as possible

slide-7
SLIDE 7

Solution

  • Acquire exploited processes

Acquire exploited processes’ ’ address address space space

  • Parse out meterpreter protocol from

Parse out meterpreter protocol from acquired memory sections acquired memory sections

- - Reconstruct meterpreter sessions

Reconstruct meterpreter sessions

slide-8
SLIDE 8

MANDIANT Memoryze

ENUMERATION ENUMERATION ACQUISITION ACQUISITION

  • All running processes

All running processes

- - Handle table

Handle table

- - Memory sections

Memory sections

- - Ports

Ports

- - Strings

Strings

  • Drivers

Drivers

- - Including layered ones

Including layered ones

  • Certain kernel hooks

Certain kernel hooks

  • Physical memory image

Physical memory image

  • Running process

Running process’ ’s s memory space memory space

- - Binary

Binary

- - Loaded DLL

Loaded DLL’ ’s s

- - Stacks

Stacks

- - Heaps

Heaps

- - Data sections

Data sections

  • Drivers

Drivers

slide-9
SLIDE 9

MANDIANT Memoryze

  • Can analyze memory live, or from image

Can analyze memory live, or from image

- - Live analysis can use paging file for a more

Live analysis can use paging file for a more complete picture of memory complete picture of memory

  • Supported platforms

Supported platforms

- - 32-bit Windows 2000, XP, 2003 Server

32-bit Windows 2000, XP, 2003 Server

- - Beta support for Vista

Beta support for Vista

  • Download at

Download at

- - http://www.mandiant.com/

http://www.mandiant.com/

slide-10
SLIDE 10

Process Acquisition

slide-11
SLIDE 11

Why Process Acquisition?

  • Acquisition was originally used mostly for

Acquisition was originally used mostly for malware analysis malware analysis

- - Acquire packed binaries running in memory

Acquire packed binaries running in memory

  • Usually utilized debuggers

Usually utilized debuggers

  • Can defeat most packers

Can defeat most packers

  • Acquisition has other uses:

Acquisition has other uses:

- - Acquire unknown binaries for

Acquire unknown binaries for Virustotal Virustotal

- - Acquire memory to look for protocol strings

Acquire memory to look for protocol strings

  • Encrypted strings are

Encrypted strings are unecrypted unecrypted in memory in memory

slide-12
SLIDE 12

Classic Process Acquisition

  • Current Methodology

Current Methodology

- - Open handle to process, OR

Open handle to process, OR

- - Attach to process

Attach to process

  • ReadProcessMemory

ReadProcessMemory( (hProc hProc,
 ,
ImageBase ImageBase, , buffer,
 buffer,
ImageSize ImageSize,
 ,
BytesRead BytesRead) )

  • Current drawbacks

Current drawbacks

- - Requires

Requires “ “touching touching” ” a process a process

- - Detecting debuggers is trivial

Detecting debuggers is trivial

- - Gives an incomplete picture of memory

Gives an incomplete picture of memory

slide-13
SLIDE 13

Process Acquisition: Memoryze

RELIES ON RELIES ON DOES NOT RELY ON DOES NOT RELY ON

  • Physical memory access

Physical memory access

  • Virtual to physical

Virtual to physical address translation address translation

  • Attaching to a process

Attaching to a process with a debugger with a debugger

  • Opening handles to

Opening handles to processes or threads processes or threads

  • API calls

API calls

  • The OS

The OS’ ’s Virtual Memory s Virtual Memory Manager Manager

slide-14
SLIDE 14

Memoryze: Process Acquisition

  • Accessing Physical Memory

Accessing Physical Memory

- - Live analysis

Live analysis

- - Acquisition

Acquisition

  • \Device\

\Device\PhysicalMemory PhysicalMemory

- - Section object exposed by Windows

Section object exposed by Windows

- - Reading from handle allows application to

Reading from handle allows application to read physical memory read physical memory

- - Every virtual address must be translated to a

Every virtual address must be translated to a physical offset within the section object physical offset within the section object

slide-15
SLIDE 15

Virtual Address Page Tables

Byte Index (4096) Page Table Index (512) Page Directory Index (512)

KPROCESS

Page Dir Individual page table

PDE PTE

Physical address

Physical Memory

Page Frame 9 bits 9 bits 12 bits

CR3

Page Dir Pointers

PDP

2 bits

PDP index (4)

PAE

slide-16
SLIDE 16

Memoryze: Process Acquisition

  • Map physical memory into buffer

Map physical memory into buffer

  • Acquisition:

Acquisition:

- - Write buffer to disk (

Write buffer to disk (dd dd) )

  • Analysis:

Analysis:

- - Scan buffer for known signatures of kernel

Scan buffer for known signatures of kernel structures, e.g. structures, e.g. EPROCESS EPROCESS

slide-17
SLIDE 17

New Process Acquisition

  • Find all processes (EPROCESS) in physical

Find all processes (EPROCESS) in physical memory memory

- - VadRoot

VadRoot within the EPROCESS structure within the EPROCESS structure

- - The

The VadRoot VadRoot is the top node of a tree of Memory is the top node of a tree of Memory Manager Virtual Address Descriptor (MMVAD) Manager Virtual Address Descriptor (MMVAD) entries entries

- - MMVAD entries contain the virtual start address

MMVAD entries contain the virtual start address and size of each memory section within a process and size of each memory section within a process

- - MMVAD entries containing mapped DLL

MMVAD entries containing mapped DLL’ ’s or s or EXE EXE’ ’s will have a pointer to the path of the binary s will have a pointer to the path of the binary

  • Helps manage process

Helps manage process’ ’ virtual address space virtual address space

slide-18
SLIDE 18

Memoryze: Process Acquisition

  • OllyDbg

OllyDbg’ ’s s memory map view shows the memory map view shows the different sections different sections

  • Each address range is an entry in

Each address range is an entry in VadRoot VadRoot, represented by a MMVAD , represented by a MMVAD structure structure

  • Enumeration of

Enumeration of VadRoot VadRoot allows access to allows access to heaps, stacks, and binary images heaps, stacks, and binary images

slide-19
SLIDE 19

Finding Processes

Kernel Address Space

0x8aadb830 0x8aadb834 0x8aadb838 0x8aadb83C 0x8aadb840 0x8aadb844 0x8aadb848 0x8aadb84C … 0x8aadb850

slide-20
SLIDE 20

Finding Processes

Kernel Address Space

0x8aadb830 0x8aadb834 0x8aadb838 0x8aadb83C 0x8aadb840 0x8aadb844 0x8aadb848 0x8aadb84C … 0x8aadb850 0x001b0003 0x00000000 0x8aadb838 0x8aadb838 0x8aadb840 0x8aadb840 0x0b100020 0x0000b084 0x00000000

slide-21
SLIDE 21

Finding Processes

Kernel Address Space

0x8aadb830 0x8aadb834 0x8aadb838 0x8aadb83C 0x8aadb840 0x8aadb844 0x8aadb848 0x8aadb84C … 0x8aadb850 0x001b0003 0x00000000 0x8aadb838 0x8aadb838 0x8aadb840 0x8aadb840 0x0b100020 0x0000b084 0x00000000

Indicates EPROCESS, DISPATCH_HEADER, further checks are needed

slide-22
SLIDE 22

Finding Processes

PCB

EPROCESS

0x00 ObjectTable 0xC4 VadRoot 0x11C ImageFileName 0x174 Cookie 0x258 …

Kernel Address Space

0x8aadb830 0x8aadba88 0x8aadba8C 0x8aadba90 … 0x8aadba94

“calc.exe” _MMVAD HANDLE_TABLE Found an EPROCESS structure

slide-23
SLIDE 23

Parsing MMVAD

PCB

EPROCESS

0x00 ObjectTable 0xC4 VadRoot 0x11C ImageFileName 0x174 Cookie 0x258 StartingVPN

_MMVAD

Parent LeftChild RightChild EndingVPN StartingVPN

_MMVAD

Parent LeftChild RightChild EndingVPN StartingVPN

_MMVAD

Parent LeftChild RightChild EndingVPN

slide-24
SLIDE 24

Writing VADs to disk

PCB

EPROCESS

0x00 ObjectTable 0xC4 VadRoot 0x11C ImageFileName 0x174 Cookie 0x258 StartingVPN

_MMVAD

Parent LeftChild RightChild EndingVPN StartingVPN

_MMVAD

Parent LeftChild RightChild EndingVPN StartingVPN

_MMVAD

Parent LeftChild RightChild EndingVPN

For each VAD write to disk: StartVPN to StartVPN+EndingVPN

slide-25
SLIDE 25
slide-26
SLIDE 26

New Process Acquisition

  • Allows dumping of full address space

Allows dumping of full address space

  • Overcomes most binary packing

Overcomes most binary packing

  • Captures communication protocol strings

Captures communication protocol strings

  • Bypasses any anti-debugging techniques

Bypasses any anti-debugging techniques

  • Acquire(s):

Acquire(s):

- - DLL

DLL’ ’s that are only in memory s that are only in memory

- - Code corresponding to injected threads or

Code corresponding to injected threads or shellcode shellcode

slide-27
SLIDE 27

Have YOU read the developer docs? Have YOU read the developer docs?

Metasploit

slide-28
SLIDE 28

Metasploit

  • Open source exploit framework originally

Open source exploit framework originally developed in Perl (1.x, 2.x) by HD Moore developed in Perl (1.x, 2.x) by HD Moore et al. et al.

- - Currently

Currently Ruby (3.x) Ruby (3.x)

  • Platform independent

Platform independent

  • Multiple payloads

Multiple payloads

slide-29
SLIDE 29

Meterpreter

  • The next generation of post-exploitation

The next generation of post-exploitation payloads payloads

- - Forget

Forget /bin/ /bin/sh sh and and cmd.exe cmd.exe

  • Limited to

Limited to stdin,stderr,stdout stdin,stderr,stdout

  • Non-interactive

Non-interactive

  • Full functioning client

Full functioning client → → server interpreter server interpreter

- - File upload / download

File upload / download

- - Key logging

Key logging

- - Simple extension addition

Simple extension addition

  • Can be completely memory resident

Can be completely memory resident

slide-30
SLIDE 30

Under the Meterpreter Hood

  • DLL gets injected into exploited process

DLL gets injected into exploited process

  • Hooks

Hooks LoadLibrary LoadLibrary (on Windows) (on Windows)

- - Applies hook to Win32 API

Applies hook to Win32 API LoadLibrary LoadLibrary

- - Changes lower level API

Changes lower level API’ ’s behavior to allow s behavior to allow LoadLibrary LoadLibrary to load a DLL from memory to load a DLL from memory

  • Hooked API

Hooked API’ ’s to allow loading of s to allow loading of metsrv.dll metsrv.dll from memory from memory

- - NtOpenSection

NtOpenSection,
 ,
NtCreateSection NtCreateSection

- - NtQueryAttributesFile

NtQueryAttributesFile

- - NtOpenFile

NtOpenFile,
 ,
NtMapViewOfSection NtMapViewOfSection

slide-31
SLIDE 31

Meterpreter Communication

  • TLV (really LTV) Structures

TLV (really LTV) Structures

- - Provide communication protocol for

Provide communication protocol for meterpreter server and client meterpreter server and client

- - 32 bit Length and Type Fields

32 bit Length and Type Fields

- - n

n bits Value Field bits Value Field

slide-32
SLIDE 32

Meterpreter Communication

Attacker Victim Sends Exploit Payload Meterpreter bind_tcp

slide-33
SLIDE 33

Meterpreter Communication

Attacker Victim Meterpreter Attacker executes “getpid”

slide-34
SLIDE 34

Meterpreter Communication

Attacker Victim Meterpreter

Type TLV Packet Length Value PACKET_TYPE_REQUEST

stdapi_sys_process_getpi d

Sizeof(TLV
Packet)

Request sent when attacker executes getpid

slide-35
SLIDE 35

Meterpreter Communication

Attacker Victim Meterpreter Meterpreter does an internal lookup for the method requested: stdapi_sys_process_getpid

Dispatch Lookup Table stdapi_sys_process_getpid

stdapi_sys_process_get_processe s

stdapi_sys_process_get_info

Victim

slide-36
SLIDE 36

Meterpreter Communication

Attacker Victim Meterpreter Victim

Response

Meterpreter builds a response on the heap; response includes the result of GetCurrentProcessId

slide-37
SLIDE 37

Meterpreter Communication

Attacker Victim Meterpreter Victim

Response Response

Response is sent back to the attacker

slide-38
SLIDE 38

Meterpreter Communication

Attacker Victim Meterpreter Victim

Response Response

Response packet is freed by meterpreter

X

slide-39
SLIDE 39

Response Packet Structure (1 of 4)

Response Packet Length sizeof(Response
Packet) Type PACKET_TLV_TYPE_PLAIN_RESPONSE Value

Length sizeof(this
tlv) Type TLV_TYPE_METHOD Value stdapi_sys_process_getpid

slide-40
SLIDE 40

Response Packet Structure (2 of 4)

Response Packet Length sizeof(Response
Packet) Type PACKET_TLV_TYPE_PLAIN_RESPONSE Value

Length sizeof(this
tlv) Type TLV_TYPE_REQUEST_ID Value 3164813846702899128916537536399

slide-41
SLIDE 41

Response Packet Structure (3 of 4)

Response Packet Length sizeof(Response
Packet) Type PACKET_TLV_TYPE_PLAIN_RESPONSE Value

Length sizeof(this
tlv) Type TLV_TYPE_PID Value 0x000003EC

slide-42
SLIDE 42

Response Packet Structure (4 of 4)

Response Packet Length sizeof(Response
Packet) Type PACKET_TLV_TYPE_PLAIN_RESPONSE Value

Length sizeof(this
tlv) Type TLV_TYPE_RESULT Value 0x00000000

slide-43
SLIDE 43

Response Packet Structure

Response Packet Length sizeof(Response
Packet) Type PACKET_TLV_TYPE_PLAIN_RESPONSE Value

Length sizeof(this
tlv) Type TLV_TYPE_REQUEST_ID Value 3164813846702899128916537536399 Length sizeof(this
tlv) Type TLV_TYPE_PID Value 0x000003EC Length sizeof(this
tlv) Type TLV_TYPE_RESULT Value 0x00000000 Length sizeof(this
tlv) Type TLV_TYPE_METHOD Value stdapi_sys_process_getpid

slide-44
SLIDE 44

Response Packet from Memory

TLV Packet Length Doesn’t exist do to free() Type: TLV_TYPE_METHOD 0x00010001 Value: stdapi_sys_process_getpid

slide-45
SLIDE 45

Response Packet from Memory

TLV Packet Length 0x29 Type: TLV_TYPE_REQUEST_ID 0x00010002 Value: 3164813846702899128916537536399

slide-46
SLIDE 46

Response Packet from Memory

TLV Packet Length 0x0C Type: TLV_TYPE_PID 0x000208FC Value: 0x000003EC

slide-47
SLIDE 47

Response Packet from Memory

TLV Packet Length 0x0C Type: TLV_TYPE_RESULT 0x00020004 Value: 0x00000000

slide-48
SLIDE 48

Meterpreter Communication

  • The response packet is freed by

The response packet is freed by meterpreter meterpreter

  • However

However… …

  • When Windows

When Windows’ ’ memory manager frees memory manager frees memory, it is not memory, it is not immediately immediately reused. reused.

- - It can take hours for memory to be reclaimed

It can take hours for memory to be reclaimed after it has been freed. after it has been freed.

slide-49
SLIDE 49

Finding one Finding one pwned pwned system at a time system at a time

Metasploit Forensic Framework

slide-50
SLIDE 50

Metasploit Forensic Framework

  • Scan acquired VADs looking for:

Scan acquired VADs looking for:

- - Strings containing meterpreter methods

Strings containing meterpreter methods

  • This indicates a TLV response to a specific

This indicates a TLV response to a specific method method

  • Parsing out the response TLV gives analysts the

Parsing out the response TLV gives analysts the data attackers received data attackers received

  • Also indicates what commands were executed on

Also indicates what commands were executed on the machine the machine

slide-51
SLIDE 51

Conclusion

  • Windows memory manager gives analysts

Windows memory manager gives analysts a chance to see artifact memory a chance to see artifact memory

  • Large impact for forensics

Large impact for forensics

- - Not so large on Metasploit project

Not so large on Metasploit project

  • Combining memory analysis with further

Combining memory analysis with further research will lead to better and more research will lead to better and more effective projects effective projects

slide-52
SLIDE 52

DEMO

slide-53
SLIDE 53

Demo Part 3

  • Acquire

Acquire svchost.exe svchost.exe

- - Remember attacker terminated connection

Remember attacker terminated connection roughly roughly 30 minutes ago 30 minutes ago

- - Run Metasploit Forensic Framework (

Run Metasploit Forensic Framework (msff msff) )

slide-54
SLIDE 54

Questions???

  • stephen.davis@mandiant.com

stephen.davis@mandiant.com

  • peter.silberman@mandiant.com

peter.silberman@mandiant.com