71
One FlAw over the Cuckoo’s Nest naki Rodr´ ıguez-Gast´ on , Ricardo J. Rodr´ ıguez All wrongs reversed [email protected], rjrodriguez@fi.upm.es @virtualminds es @RicardoJRdez SensePost Universidad Polit´ ecnica de Madrid London, UK Madrid, Spain 1 de Noviembre, 2013 No cON Name 2013 Barcelona (Espa˜ na)

One Flaw over the Cuckoo's Nest

Embed Size (px)

DESCRIPTION

Talk about how could be possible to improve Cuckoo integrating instrumentalization tools like PIN (Intel) and evade some anti-vm malware.

Citation preview

Page 1: One Flaw over the Cuckoo's Nest

One FlAw over the Cuckoo’s Nest

Inaki Rodrıguez-Gaston†, Ricardo J. Rodrıguez‡

« All wrongs reversed

[email protected], [email protected]

@virtualminds es ※ @RicardoJRdez

†SensePost ‡Universidad Politecnica de MadridLondon, UK Madrid, Spain

1 de Noviembre, 2013

No cON Name 2013

Barcelona (Espana)

Page 2: One Flaw over the Cuckoo's Nest

$whoarewe

$whoarewe: command not found

CLS member (2001)

Ph.D. by UZ (2013)

Working for UPM

Trainee @ NcN, RootedCON,HIP

Speaker @ NcN, HackLU,RootedCON, STIC CCN, HIP

CISSP, CEH, GWAPT

Security analyst @ SensePost

Malware lover

mlw.re staff

Trainee @ 44CON

. . .

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 2 / 39

Page 3: One Flaw over the Cuckoo's Nest

Agenda

Outline

1 Motivation

2 Previous ConceptsCuckoo SandboxDynamic Binary Instrumentation: The Pin Framework

3 On the Anti-VMs & Anti-Sandboxing TechniquesVM DetectionSandboxing detection

4 Mixing Cuckoo Sandbox and Pin DBISticking both ProgramsIntroducing PinVMShield

5 Case Study: the pafish tool

6 Related Work

7 Conclusions and Future Work

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 3 / 39

Page 4: One Flaw over the Cuckoo's Nest

Motivation

Outline

1 Motivation

2 Previous ConceptsCuckoo SandboxDynamic Binary Instrumentation: The Pin Framework

3 On the Anti-VMs & Anti-Sandboxing TechniquesVM DetectionSandboxing detection

4 Mixing Cuckoo Sandbox and Pin DBISticking both ProgramsIntroducing PinVMShield

5 Case Study: the pafish tool

6 Related Work

7 Conclusions and Future Work

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 4 / 39

Page 5: One Flaw over the Cuckoo's Nest

Motivation

Motivation (I)

Malware are increasing in number and complexity

Targeted attacks also grown (specially industry and governmentespionage)

How do we currently fight against malware?

Firstly, to understand how a sample works (what is it doing?)

Then, to figure out how it can be removed

Lastly, to avoid future infections (can we detect it again?)

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 5 / 39

Page 6: One Flaw over the Cuckoo's Nest

Motivation

Motivation (II)

Figuring out what it is doing. . .

Manual analysis

IntensiveTime-consuming

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 6 / 39

Page 7: One Flaw over the Cuckoo's Nest

Motivation

Motivation (II)

Figuring out what it is doing. . .

Manual analysis

IntensiveTime-consumingGood if you are paid per working hour ⌣

Automatic analysis

Just take a seat, and relax. . .Real problem here: automation of malware analysis tasks

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 6 / 39

Page 8: One Flaw over the Cuckoo's Nest

Motivation

Motivation (II)

Figuring out what it is doing. . .

Manual analysis

IntensiveTime-consumingGood if you are paid per working hour ⌣

Automatic analysis

Just take a seat, and relax. . .Real problem here: automation of malware analysis tasksOnly manual analysis for weird (or interesting) samples

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 6 / 39

Page 9: One Flaw over the Cuckoo's Nest

Motivation

Motivation (III)

Sandbox Environments

Computer resources are tightly controlled and monitored

Current trending of malware analysis

Commercial and free-license solutions

Sandboxie

JoeBox

CWSandbox

Cuckoo Sandbox

PyBox

Virtual Machine and Sandbox: a good combination

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 7 / 39

Page 10: One Flaw over the Cuckoo's Nest

Motivation

Motivation (III)

Sandbox Environments

Computer resources are tightly controlled and monitored

Current trending of malware analysis

Commercial and free-license solutions

Sandboxie

JoeBox

CWSandbox

Cuckoo Sandbox

PyBox

Virtual Machine and Sandbox: a good combination

Do malware samples detect VMs/sandbox environments?

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 7 / 39

Page 11: One Flaw over the Cuckoo's Nest

Motivation

Motivation (III)

Sandbox Environments

Computer resources are tightly controlled and monitored

Current trending of malware analysis

Commercial and free-license solutions

Sandboxie

JoeBox

CWSandbox

Cuckoo Sandbox

PyBox

Virtual Machine and Sandbox: a good combination

Do malware samples detect VMs/sandbox environments?Yes, they do.

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 7 / 39

Page 12: One Flaw over the Cuckoo's Nest

Motivation

Motivation (IV)

Can we avoid the detection of a VMs/sandbox environment?

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 8 / 39

Page 13: One Flaw over the Cuckoo's Nest

Motivation

Motivation (IV)

Can we avoid the detection of a VMs/sandbox environment?Yes, we can! (at least, we should try. . . )

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 8 / 39

Page 14: One Flaw over the Cuckoo's Nest

Motivation

Motivation (IV)

Can we avoid the detection of a VMs/sandbox environment?Yes, we can! (at least, we should try. . . )

We’re gonna do it in a fancy way. . .

using Dynamic Binary Instrumentation ⌣

Dynamic Binary Instrumentation (DBI)

Analyse the runtime behaviour of a binary

Executes arbitrary code during normal execution of a binary

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 8 / 39

Page 15: One Flaw over the Cuckoo's Nest

Motivation

Motivation (V)Why DBI? Its advantages

Binary instrumentation: advantages

Programming language (totally) independent

Machine-mode vision

We can instrument proprietary software

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 9 / 39

Page 16: One Flaw over the Cuckoo's Nest

Motivation

Motivation (V)Why DBI? Its advantages

Binary instrumentation: advantages

Programming language (totally) independent

Machine-mode vision

We can instrument proprietary software

Dynamic Instrumentation: advantages

No need to recompile/relink each time

Allow to find on-the-fly code

Dynamically generated code

Allow to instrument a process in execution already (attach)

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 9 / 39

Page 17: One Flaw over the Cuckoo's Nest

Motivation

Motivation (VI)Why DBI? Its disadvantages

Main disadvantages

Overhead (by the instrumentation during execution)

⇓ performance (analyst hopelessness!)

Single execution path analysed

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 10 / 39

Page 18: One Flaw over the Cuckoo's Nest

Motivation

Motivation (VII)Summary of contributions

Our goal in this work

Develop a Dynamic Binary Analysis (DBA) tool

Integrated with Cuckoo Sandbox

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 11 / 39

Page 19: One Flaw over the Cuckoo's Nest

Motivation

Motivation (VII)Summary of contributions

Our goal in this work

Develop a Dynamic Binary Analysis (DBA) tool

Integrated with Cuckoo SandboxProtects Cuckoo for being detected. . .

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 11 / 39

Page 20: One Flaw over the Cuckoo's Nest

Motivation

Motivation (VII)Summary of contributions

Our goal in this work

Develop a Dynamic Binary Analysis (DBA) tool

Integrated with Cuckoo SandboxProtects Cuckoo for being detected. . .. . . and also for (some) VMs detection

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 11 / 39

Page 21: One Flaw over the Cuckoo's Nest

Previous Concepts

Outline

1 Motivation

2 Previous ConceptsCuckoo SandboxDynamic Binary Instrumentation: The Pin Framework

3 On the Anti-VMs & Anti-Sandboxing TechniquesVM DetectionSandboxing detection

4 Mixing Cuckoo Sandbox and Pin DBISticking both ProgramsIntroducing PinVMShield

5 Case Study: the pafish tool

6 Related Work

7 Conclusions and Future Work

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 12 / 39

Page 22: One Flaw over the Cuckoo's Nest

Previous Concepts Cuckoo Sandbox

Cuckoo Sandbox (I)

What is Cuckoo Sandbox?

Automated malware analysis tool

Written in Python

Reporting system (API calls, registry access, network activity)

Extensible

OpenSource

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 13 / 39

Page 23: One Flaw over the Cuckoo's Nest

Previous Concepts Cuckoo Sandbox

Cuckoo Sandbox (II)

Sample.exe

(Suspended)

cuckoo.py

agent.py

analyzer.py

TCP socket (8000) Drop file

submit.py web.py api.py

packages

(exe.py)

Executes procces and injects cuckoomon.dll

Sample.exe

Cuckoomon.dll

(Random name)

\\.\PIPE\random string

API call

resultserver

Results from the analysis

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 14 / 39

Page 24: One Flaw over the Cuckoo's Nest

Previous Concepts Dynamic Binary Instrumentation: The Pin Framework

Dynamic Binary Instrumentation: The Pin Framework (I)

http://www.pintools.org

What is Pin?

Framework designed by Intel

Allows to build easy-to-use, portable, transparent and efficientinstrumentation tools (DBA, or Pintools)

Recall: instrumentation enables the execution of arbitrary code duringrun-time of a binary

Extensive API for doing whatever you can imagine

Used for things like:

Instruction profilingPerformance evaluationBug detectionAnd malware analysis (here we are ⌣)

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 15 / 39

Page 25: One Flaw over the Cuckoo's Nest

Previous Concepts Dynamic Binary Instrumentation: The Pin Framework

Dynamic Binary Instrumentation: The Pin Framework (II)How does Pin work?

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 16 / 39

Page 26: One Flaw over the Cuckoo's Nest

On the Anti-VMs & Anti-Sandboxing Techniques

Outline

1 Motivation

2 Previous ConceptsCuckoo SandboxDynamic Binary Instrumentation: The Pin Framework

3 On the Anti-VMs & Anti-Sandboxing TechniquesVM DetectionSandboxing detection

4 Mixing Cuckoo Sandbox and Pin DBISticking both ProgramsIntroducing PinVMShield

5 Case Study: the pafish tool

6 Related Work

7 Conclusions and Future Work

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 17 / 39

Page 27: One Flaw over the Cuckoo's Nest

On the Anti-VMs & Anti-Sandboxing Techniques VM Detection

On the Anti-VMs & Anti-Sandboxing Techniques (I)

How can an execution inside a VM be detected?

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 18 / 39

Page 28: One Flaw over the Cuckoo's Nest

On the Anti-VMs & Anti-Sandboxing Techniques VM Detection

On the Anti-VMs & Anti-Sandboxing Techniques (I)

How can an execution inside a VM be detected?

Detection ways

Seek VME artifacts in processes, system files and/or registry

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 18 / 39

Page 29: One Flaw over the Cuckoo's Nest

On the Anti-VMs & Anti-Sandboxing Techniques VM Detection

On the Anti-VMs & Anti-Sandboxing Techniques (I)

How can an execution inside a VM be detected?

Detection ways

Seek VME artifacts in processes, system files and/or registry

Seek VME artifacts in memory

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 18 / 39

Page 30: One Flaw over the Cuckoo's Nest

On the Anti-VMs & Anti-Sandboxing Techniques VM Detection

On the Anti-VMs & Anti-Sandboxing Techniques (I)

How can an execution inside a VM be detected?

Detection ways

Seek VME artifacts in processes, system files and/or registry

Seek VME artifacts in memory

Seek specific features of virtualised hardware

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 18 / 39

Page 31: One Flaw over the Cuckoo's Nest

On the Anti-VMs & Anti-Sandboxing Techniques VM Detection

On the Anti-VMs & Anti-Sandboxing Techniques (I)

How can an execution inside a VM be detected?

Detection ways

Seek VME artifacts in processes, system files and/or registry

Seek VME artifacts in memory

Seek specific features of virtualised hardware

Seek CPU instructions specific to VME

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 18 / 39

Page 32: One Flaw over the Cuckoo's Nest

On the Anti-VMs & Anti-Sandboxing Techniques VM Detection

On the Anti-VMs & Anti-Sandboxing Techniques (II)Artifacts in processes, system files and/or registry

Some examples

VMWare

“VMTools” serviceReferences in system files to “VMWare” and vmxReferences in the registry to “VMWare”

VirtualBox

VBoxService.exe process (“VirtualBoxGuestAdditions”)References in the registry to “VBox”

MS Virtual PC

vmsrvc.exe, vpcmap.exe, vmusrvc.exe processesReferences in the registry to “Virtual”

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 19 / 39

Page 33: One Flaw over the Cuckoo's Nest

On the Anti-VMs & Anti-Sandboxing Techniques VM Detection

On the Anti-VMs & Anti-Sandboxing Techniques (III)Artifacts in memory

The Red Pill

Software developed by Joanna Rutkwoska, 2004

Uses the SIDT instruction (Store Interrupt Descriptor Table)

VMWare: IDT in 0xFFxxxxxx

VirtualPC: IDT in 0xE8xxxxxx

In real machines: Windows (0x80FFFFFF), Linux (0xC0FFFFFF)

Other options: GDT, LDT

GDT, LDT also displaced in virtual environments

Scoopy tool (http://www.trapkit.de)

(IDT == 0xC0) || IDT == 0x80

GDT == 0xC0

LDT == 0x00

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 20 / 39

Page 34: One Flaw over the Cuckoo's Nest

On the Anti-VMs & Anti-Sandboxing Techniques VM Detection

On the Anti-VMs & Anti-Sandboxing Techniques (V)Specific features of virtualised hardware

Specific virtualised hardware

Network controllerUSBs controllerHost controller. . .

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 21 / 39

Page 35: One Flaw over the Cuckoo's Nest

On the Anti-VMs & Anti-Sandboxing Techniques VM Detection

On the Anti-VMs & Anti-Sandboxing Techniques (V)Specific features of virtualised hardware

Specific virtualised hardware

Network controllerUSBs controllerHost controller. . .

Seek specific “fingerprints”

SCSI device typeNetwork controller MACHost controller type. . .

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 21 / 39

Page 36: One Flaw over the Cuckoo's Nest

On the Anti-VMs & Anti-Sandboxing Techniques VM Detection

On the Anti-VMs & Anti-Sandboxing Techniques (V)Specific features of virtualised hardware

Specific virtualised hardware

Network controllerUSBs controllerHost controller. . .

Seek specific “fingerprints”

SCSI device typeNetwork controller MACHost controller type. . .

Doo tool (also seeks Class IDs in the registry)

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 21 / 39

Page 37: One Flaw over the Cuckoo's Nest

On the Anti-VMs & Anti-Sandboxing Techniques VM Detection

On the Anti-VMs & Anti-Sandboxing Techniques (VI)CPU instructions specific to VME

Some VMs add/use own instructions to communicate host/guest

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 22 / 39

Page 38: One Flaw over the Cuckoo's Nest

On the Anti-VMs & Anti-Sandboxing Techniques VM Detection

On the Anti-VMs & Anti-Sandboxing Techniques (VI)CPU instructions specific to VME

Some VMs add/use own instructions to communicate host/guest

Seek host/guest communication channel

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 22 / 39

Page 39: One Flaw over the Cuckoo's Nest

On the Anti-VMs & Anti-Sandboxing Techniques VM Detection

On the Anti-VMs & Anti-Sandboxing Techniques (VI)CPU instructions specific to VME

Some VMs add/use own instructions to communicate host/guest

Seek host/guest communication channel

Jerry tool

VMDetect tool

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 22 / 39

Page 40: One Flaw over the Cuckoo's Nest

On the Anti-VMs & Anti-Sandboxing Techniques VM Detection

On the Anti-VMs & Anti-Sandboxing Techniques (VI)CPU instructions specific to VME

Some VMs add/use own instructions to communicate host/guest

Seek host/guest communication channel

Jerry tool

VMDetect tool

Magic number. . . CONSTANT (WTF!)

mov eax, 564D5868h ; “VMXh”mov ebx, 0mov ecx, 0Ahmov edx, 5658 ; “VX”in eax, dxcmp ebx, 564D5868h

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 22 / 39

Page 41: One Flaw over the Cuckoo's Nest

On the Anti-VMs & Anti-Sandboxing Techniques Sandboxing detection

On the Anti-VMs & Anti-Sandboxing Techniques (VIII)

Sandbox

Binary execution in controlled environment

Examples: Sandboxie, Norman Sandbox Analyser, Anubis, Cuckoo,WinJail. . .

They have some common and recognisable issues:

DLLs loadedRead of ProductID keyWindows username (API GetUserName)Window handle (API FindWindow)

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 23 / 39

Page 42: One Flaw over the Cuckoo's Nest

Mixing Cuckoo Sandbox and Pin DBI

Outline

1 Motivation

2 Previous ConceptsCuckoo SandboxDynamic Binary Instrumentation: The Pin Framework

3 On the Anti-VMs & Anti-Sandboxing TechniquesVM DetectionSandboxing detection

4 Mixing Cuckoo Sandbox and Pin DBISticking both ProgramsIntroducing PinVMShield

5 Case Study: the pafish tool

6 Related Work

7 Conclusions and Future Work

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 24 / 39

Page 43: One Flaw over the Cuckoo's Nest

Mixing Cuckoo Sandbox and Pin DBI Sticking both Programs

Mixing Cuckoo Sandbox and Pin DBI (I)

Every file has a package

Best place for the integration:

Attaching Pin to the suspended processDirectly executing the sample with Pin

Pin and cuckoomon together

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 25 / 39

Page 44: One Flaw over the Cuckoo's Nest

Mixing Cuckoo Sandbox and Pin DBI Sticking both Programs

Mixing Cuckoo Sandbox and Pin DBI (II)Attach to suspended process

agent.py

analyzer.py

Drop file

packages

(exe.py)

Executes procces and injects cuckoomon.dll

\\.\PIPE\random string

API call

PIN

(Attach)

Sample.exe

PIN

Cuckoomon.dll

(Random name)

Sample.exe

(Suspended)

Attach PIN to the sample

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 26 / 39

Page 45: One Flaw over the Cuckoo's Nest

Mixing Cuckoo Sandbox and Pin DBI Sticking both Programs

Mixing Cuckoo Sandbox and Pin DBI (III)Pin integrated into a package

agent.py

analyzer.py

Drop file

packages

(exe.py)

Executes procces and injects cuckoomon.dll

\\.\PIPE\random string

API call

PIN

(Suspended)

Sample.exe Sample.exe

PIN

Cuckoomon.dll

(Random name)

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 27 / 39

Page 46: One Flaw over the Cuckoo's Nest

Mixing Cuckoo Sandbox and Pin DBI Introducing PinVMShield

Mixing Cuckoo Sandbox and Pin DBI (IV)Introducing PinVMShield (1)

main(argc : int, argv[] : char*) : int

Fini(code : INT32, *v : void) : void

<<Interface>>

Pin

Image(img : IMG, *v : void)

PinVMShield #funcName[MAX_LENGTH_FUNCNAME] : char

#isTryingToDetectVMs(*s : char) : bool

#FindRTNByNameA(img : IMG) : RTN

#FindRTNByNameW(img : IMG) : RTN

#GetPrototypeFunctionA() : PROTO

#GetPrototypeFunctionW() : PROTO

#GetPrototypeFunction(*funcName : char) : PROTO

#ReplaceFunctionSignature(rtn: RTN, proto: PROTO) : void

PinWrapperWinAPI

logFilename : char* = "file.out"

logFile : FILE*

stristr(*s1 : char, *s2 : char) : *char

printMessage(*msg : char) : void

common

0..*

vWinAPIs

-myGetModuleHandle(orig: AFUNPTR, lpModuleName: LPCTSTR, *ctx: CONTEXT): HMODULE

WrapperGetModuleHandle

-myProcess32FirstAndNext(orig: AFUNPTR, hSnapshot: HANDLE, *ctx: CONTEXT, lppe: LPPROCESSENTRY32) : bool

WrapperProcess32FirstAndNext

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 28 / 39

Page 47: One Flaw over the Cuckoo's Nest

Mixing Cuckoo Sandbox and Pin DBI Introducing PinVMShield

Mixing Cuckoo Sandbox and Pin DBI (...): our ToolIntroducing PinVMShield (2)

APIs fooled

GetUserNameA/W

GetUserNameExA/W

RegQueryValueA/W

RegQueryValueExA/W

RegOpenKeyA/W

RegOpenKeyExA/W

GetModuleHandleA/W

GetModuleHandleExA/W

GetFileAttributesA/W

Process32First /

Process32Next

FindWindowA/W

FindWindowExA/W

CreateFileA/W

CreateNamedPipeA/W

GetCursorPos

Alpha version available for download: (soon)https://bitbucket.org/rjrodriguez/pinvmshield/

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 29 / 39

Page 48: One Flaw over the Cuckoo's Nest

Case Study: the pafish tool

Outline

1 Motivation

2 Previous ConceptsCuckoo SandboxDynamic Binary Instrumentation: The Pin Framework

3 On the Anti-VMs & Anti-Sandboxing TechniquesVM DetectionSandboxing detection

4 Mixing Cuckoo Sandbox and Pin DBISticking both ProgramsIntroducing PinVMShield

5 Case Study: the pafish tool

6 Related Work

7 Conclusions and Future Work

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 30 / 39

Page 49: One Flaw over the Cuckoo's Nest

Case Study: the pafish tool

Case Study: the pafish tool (I)

Tool that incorporates severaldetections for vms andsandboxing

Developed by Alberto Ortega

In v.0.2.5.1 (the one of casestudy):

Generic SandboxSandboxieQEMUWineVirtualBoxVMWare

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 31 / 39

Page 50: One Flaw over the Cuckoo's Nest

Case Study: the pafish tool

Case Study: the pafish tool (I)

Tool that incorporates severaldetections for vms andsandboxing

Developed by Alberto Ortega

In v.0.2.5.1 (the one of casestudy):

Generic SandboxSandboxieQEMUWineVirtualBoxVMWare

Do you wanna know more about the blue fish?

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 31 / 39

Page 51: One Flaw over the Cuckoo's Nest

Case Study: the pafish tool

Case Study: the pafish tool (I)

Tool that incorporates severaldetections for vms andsandboxing

Developed by Alberto Ortega

In v.0.2.5.1 (the one of casestudy):

Generic SandboxSandboxieQEMUWineVirtualBoxVMWare

Do you wanna know more about the blue fish?

→ attend Alberto’s session! (tomorrow afternoon)

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 31 / 39

Page 52: One Flaw over the Cuckoo's Nest

Case Study: the pafish tool

Case Study: the pafish tool (II)

It’s demo time!

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 32 / 39

Page 53: One Flaw over the Cuckoo's Nest

Related Work

Outline

1 Motivation

2 Previous ConceptsCuckoo SandboxDynamic Binary Instrumentation: The Pin Framework

3 On the Anti-VMs & Anti-Sandboxing TechniquesVM DetectionSandboxing detection

4 Mixing Cuckoo Sandbox and Pin DBISticking both ProgramsIntroducing PinVMShield

5 Case Study: the pafish tool

6 Related Work

7 Conclusions and Future Work

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 33 / 39

Page 54: One Flaw over the Cuckoo's Nest

Related Work

Related Work (I)

CWSandox

Sandbox environment

Three design criteria: automation, effectiveness and correctness

Performs a dynamic analysis

API hooking

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 34 / 39

Page 55: One Flaw over the Cuckoo's Nest

Related Work

Related Work (I)

CWSandox

Sandbox environment

Three design criteria: automation, effectiveness and correctness

Performs a dynamic analysis

API hooking

It is detected by sandbox detection techniques

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 34 / 39

Page 56: One Flaw over the Cuckoo's Nest

Related Work

Related Work (II)

Sandbox + DBI

Pin as DBI framework

Own-created sandbox environment

Two execution environments:

Testing: binary execution is traced. Traces are checked against somesecurity policiesReal: binary execution is monitored avoiding harmful behaviours

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 35 / 39

Page 57: One Flaw over the Cuckoo's Nest

Related Work

Related Work (II)

Sandbox + DBI

Pin as DBI framework

Own-created sandbox environment

Two execution environments:

Testing: binary execution is traced. Traces are checked against somesecurity policiesReal: binary execution is monitored avoiding harmful behaviours

Our solution also monitors the execution but. . .

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 35 / 39

Page 58: One Flaw over the Cuckoo's Nest

Related Work

Related Work (II)

Sandbox + DBI

Pin as DBI framework

Own-created sandbox environment

Two execution environments:

Testing: binary execution is traced. Traces are checked against somesecurity policiesReal: binary execution is monitored avoiding harmful behaviours

Our solution also monitors the execution but. . .besides avoids sandbox detection!

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 35 / 39

Page 59: One Flaw over the Cuckoo's Nest

Conclusions and Future Work

Outline

1 Motivation

2 Previous ConceptsCuckoo SandboxDynamic Binary Instrumentation: The Pin Framework

3 On the Anti-VMs & Anti-Sandboxing TechniquesVM DetectionSandboxing detection

4 Mixing Cuckoo Sandbox and Pin DBISticking both ProgramsIntroducing PinVMShield

5 Case Study: the pafish tool

6 Related Work

7 Conclusions and Future Work

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 36 / 39

Page 60: One Flaw over the Cuckoo's Nest

Conclusions and Future Work

Conclusions and Future Work (I)

PinVMShield

Integrated with Cuckoo Sandbox

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 37 / 39

Page 61: One Flaw over the Cuckoo's Nest

Conclusions and Future Work

Conclusions and Future Work (I)

PinVMShield

Integrated with Cuckoo Sandbox

X Avoids Cuckoo (and other) detections commonly realised by malware

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 37 / 39

Page 62: One Flaw over the Cuckoo's Nest

Conclusions and Future Work

Conclusions and Future Work (I)

PinVMShield

Integrated with Cuckoo Sandbox

X Avoids Cuckoo (and other) detections commonly realised by malware

X Not currently detected! ⌣

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 37 / 39

Page 63: One Flaw over the Cuckoo's Nest

Conclusions and Future Work

Conclusions and Future Work (I)

PinVMShield

Integrated with Cuckoo Sandbox

X Avoids Cuckoo (and other) detections commonly realised by malware

X Not currently detected! ⌣

X Main drawback: runtime

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 37 / 39

Page 64: One Flaw over the Cuckoo's Nest

Conclusions and Future Work

Conclusions and Future Work (I)

PinVMShield

Integrated with Cuckoo Sandbox

X Avoids Cuckoo (and other) detections commonly realised by malware

X Not currently detected! ⌣

X Main drawback: runtime

X Coding C++ is like a pain in the ass

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 37 / 39

Page 65: One Flaw over the Cuckoo's Nest

Conclusions and Future Work

Conclusions and Future Work (I)

PinVMShield

Integrated with Cuckoo Sandbox

X Avoids Cuckoo (and other) detections commonly realised by malware

X Not currently detected! ⌣

X Main drawback: runtime

X Coding C++ is like a pain in the ass

We do have more control on malware(binary) execution

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 37 / 39

Page 66: One Flaw over the Cuckoo's Nest

Conclusions and Future Work

Conclusions and Future Work (II)

Future Work

Find a logo

Stand-alone app

Improve anti-detection techniques (not only hooking. . . )

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 38 / 39

Page 67: One Flaw over the Cuckoo's Nest

Conclusions and Future Work

Conclusions and Future Work (II)

Future Work

Find a logo

Stand-alone app

Improve anti-detection techniques (not only hooking. . . )

Replace (totally) cuckoomon.dll

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 38 / 39

Page 68: One Flaw over the Cuckoo's Nest

Conclusions and Future Work

Conclusions and Future Work (II)

Future Work

Find a logo

Stand-alone app

Improve anti-detection techniques (not only hooking. . . )

Replace (totally) cuckoomon.dll

Add anti-DBI techniques

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 38 / 39

Page 69: One Flaw over the Cuckoo's Nest

Conclusions and Future Work

Conclusions and Future Work (II)

Future Work

Find a logo

Stand-alone app

Improve anti-detection techniques (not only hooking. . . )

Replace (totally) cuckoomon.dll

Add anti-DBI techniques

Test in real malware samples

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 38 / 39

Page 70: One Flaw over the Cuckoo's Nest

Conclusions and Future Work

Conclusions and Future Work (II)

Future Work

Find a logo

Stand-alone app

Improve anti-detection techniques (not only hooking. . . )

Replace (totally) cuckoomon.dll

Add anti-DBI techniques

Test in real malware samples

Acknowledgments

Alberto Ortega (pafish)

NcN staff

I. Rodrıguez-Gaston, R.J. Rodrıguez One FlAw over the Cuckoo’s Nest 1 Nov’13 38 / 39

Page 71: One Flaw over the Cuckoo's Nest

One FlAw over the Cuckoo’s Nest

Inaki Rodrıguez-Gaston†, Ricardo J. Rodrıguez‡

« All wrongs reversed

[email protected], [email protected]

@virtualminds es ※ @RicardoJRdez

†SensePost ‡Universidad Politecnica de MadridLondon, UK Madrid, Spain

1 de Noviembre, 2013

No cON Name 2013

Barcelona (Espana)