Malware Obfuscation Techniques: Packing November 18, 2014 Malware - - PowerPoint PPT Presentation

malware obfuscation techniques packing
SMART_READER_LITE
LIVE PREVIEW

Malware Obfuscation Techniques: Packing November 18, 2014 Malware - - PowerPoint PPT Presentation

Malware Obfuscation Techniques: Packing November 18, 2014 Malware and packing Not packed (20%) 80% of new malware are packed with various packers Malware Obfuscation Techniques: Packing 2 Malware and packing Not packed (20%) 80%


slide-1
SLIDE 1

Malware Obfuscation Techniques: Packing

November 18, 2014

slide-2
SLIDE 2

Malware and packing

Not packed (20%)

  • 80% of new malware are packed with various packers

Malware Obfuscation Techniques: Packing 2

slide-3
SLIDE 3

Malware and packing

Not packed (20%)

  • 80% of new malware are packed with various packers

50% of new malware samples are simply repacked versions of existing malware

Malware Obfuscation Techniques: Packing 2

slide-4
SLIDE 4

Code packing

◮ A technique to hide the real code of a program through one or

more layers of compression/encryption

◮ At run-time the unpacking routine restores the original code in

memory and then executes it

Malware Obfuscation Techniques: Packing 3

slide-5
SLIDE 5

Code packing

◮ A technique to hide the real code of a program through one or

more layers of compression/encryption

◮ At run-time the unpacking routine restores the original code in

memory and then executes it Malicious code

Malware Obfuscation Techniques: Packing 3

slide-6
SLIDE 6

Code packing

◮ A technique to hide the real code of a program through one or

more layers of compression/encryption

◮ At run-time the unpacking routine restores the original code in

memory and then executes it Malicious code Unpacking routine

Malware Obfuscation Techniques: Packing 3

slide-7
SLIDE 7

Code packing

◮ A technique to hide the real code of a program through one or

more layers of compression/encryption

◮ At run-time the unpacking routine restores the original code in

memory and then executes it Malicious code Unpacking routine Unpacking routine

Malware Obfuscation Techniques: Packing 3

slide-8
SLIDE 8

Code packing

◮ A technique to hide the real code of a program through one or

more layers of compression/encryption

◮ At run-time the unpacking routine restores the original code in

memory and then executes it Malicious code Unpacking routine Unpacking routine The effectiveness of malware detectors depends on the ability to recover the “real” malicious code, but recovery often fails!

Malware Obfuscation Techniques: Packing 3

slide-9
SLIDE 9

Traditional approaches to deal with packed code

Algorithmic unpacking

Use of specific unpacking routines to recover the original code (i.e.,

  • ne routine per packing algorithm)

Malware Obfuscation Techniques: Packing 4

slide-10
SLIDE 10

Traditional approaches to deal with packed code

Algorithmic unpacking

Use of specific unpacking routines to recover the original code (i.e.,

  • ne routine per packing algorithm)

Malicious program Malware detector

Malware Obfuscation Techniques: Packing 4

slide-11
SLIDE 11

Traditional approaches to deal with packed code

Algorithmic unpacking

Use of specific unpacking routines to recover the original code (i.e.,

  • ne routine per packing algorithm)

Malicious program ???? Malware detector

Malware Obfuscation Techniques: Packing 4

slide-12
SLIDE 12

Traditional approaches to deal with packed code

Algorithmic unpacking

Use of specific unpacking routines to recover the original code (i.e.,

  • ne routine per packing algorithm)

Malicious program ???? ???? Malware detector

Malware Obfuscation Techniques: Packing 4

slide-13
SLIDE 13

Traditional approaches to deal with packed code

Algorithmic unpacking

Use of specific unpacking routines to recover the original code (i.e.,

  • ne routine per packing algorithm)

Malicious program ???? ???? Malware detector Malicious

Malware Obfuscation Techniques: Packing 4

slide-14
SLIDE 14

Traditional approaches to deal with packed code

Algorithmic unpacking

Use of specific unpacking routines to recover the original code (i.e.,

  • ne routine per packing algorithm)

Malicious program ???? ???? Malware detector Malicious

Generic unpacking

Emulation/tracing of the execution until the unpacking routine terminates (e.g., PolyUnpack [ACSAC 06] and Renovo [WORM 07])

Malware Obfuscation Techniques: Packing 4

slide-15
SLIDE 15

Traditional approaches to deal with packed code

Algorithmic unpacking

Use of specific unpacking routines to recover the original code (i.e.,

  • ne routine per packing algorithm)

Malicious program ???? ???? Malware detector Malicious

Generic unpacking

Emulation/tracing of the execution until the unpacking routine terminates (e.g., PolyUnpack [ACSAC 06] and Renovo [WORM 07])

Packed code

Malware Obfuscation Techniques: Packing 4

slide-16
SLIDE 16

Traditional approaches to deal with packed code

Algorithmic unpacking

Use of specific unpacking routines to recover the original code (i.e.,

  • ne routine per packing algorithm)

Malicious program ???? ???? Malware detector Malicious

Generic unpacking

Emulation/tracing of the execution until the unpacking routine terminates (e.g., PolyUnpack [ACSAC 06] and Renovo [WORM 07])

Packed code

Malware Obfuscation Techniques: Packing 4

slide-17
SLIDE 17

Traditional approaches to deal with packed code

Algorithmic unpacking

Use of specific unpacking routines to recover the original code (i.e.,

  • ne routine per packing algorithm)

Malicious program ???? ???? Malware detector Malicious

Generic unpacking

Emulation/tracing of the execution until the unpacking routine terminates (e.g., PolyUnpack [ACSAC 06] and Renovo [WORM 07])

Packed code

Malware Obfuscation Techniques: Packing 4

slide-18
SLIDE 18

Traditional approaches to deal with packed code

Algorithmic unpacking

Use of specific unpacking routines to recover the original code (i.e.,

  • ne routine per packing algorithm)

Malicious program ???? ???? Malware detector Malicious

Generic unpacking

Emulation/tracing of the execution until the unpacking routine terminates (e.g., PolyUnpack [ACSAC 06] and Renovo [WORM 07])

Packed code Unpacked code

Malware Obfuscation Techniques: Packing 4

slide-19
SLIDE 19

A simple generic unpacker

◮ Track all memory writes and the program counter ◮ The execution of a previously written memory location denotes

the end of an unpacking stage

◮ All written-then-executed memory locations should then be

analyzed by a malware detector

Malware Obfuscation Techniques: Packing 5

slide-20
SLIDE 20

A simple generic unpacker

◮ Track all memory writes and the program counter ◮ The execution of a previously written memory location denotes

the end of an unpacking stage

◮ All written-then-executed memory locations should then be

analyzed by a malware detector Extend this idea to design an iterative unpacking algorithm that achieves low overhead yet does not compromise the security of the system

Malware Obfuscation Techniques: Packing 5

slide-21
SLIDE 21

Goals of Real-Time Unpackers

◮ Generic unpacking with low-overhead by using existing

hardware mechanisms

◮ Precise unpacking by running the program on the native OS ◮ A new malware detection strategy, independent of packing,

where the malware detector analyzes new pieces of code before they are executed.

Malware Obfuscation Techniques: Packing 6

slide-22
SLIDE 22

Efficient tracking of memory accesses

Coarse-grained memory access tracking (at page level), through the use of hardware mechanisms

Malware Obfuscation Techniques: Packing 7

slide-23
SLIDE 23

Efficient tracking of memory accesses

Coarse-grained memory access tracking (at page level), through the use of hardware mechanisms Memory

Executed page Written page Executed memory location Written memory location

Malware Obfuscation Techniques: Packing 7

slide-24
SLIDE 24

Efficient tracking of memory accesses

Coarse-grained memory access tracking (at page level), through the use of hardware mechanisms Memory

Executed page Written page Executed memory location Written memory location

Malware Obfuscation Techniques: Packing 7

slide-25
SLIDE 25

Efficient tracking of memory accesses

Coarse-grained memory access tracking (at page level), through the use of hardware mechanisms Memory

Executed page Written page Executed memory location Written memory location

Malware Obfuscation Techniques: Packing 7

slide-26
SLIDE 26

Efficient tracking of memory accesses

Coarse-grained memory access tracking (at page level), through the use of hardware mechanisms Malicious code Memory

Executed page Written page Executed memory location Written memory location

Malware Obfuscation Techniques: Packing 7

slide-27
SLIDE 27

Efficient tracking of memory accesses

Coarse-grained memory access tracking (at page level), through the use of hardware mechanisms Memory

Executed page Written page Executed memory location Written memory location

Unfortunately...

◮ Written-then-executed locations are indicative of unpacking but

not indicative of the end of unpacking

◮ Coarse-grained memory accesses tracking further increases the

chances to detect spurious unpacking stages (up to hundreds of thousands stages)

Malware Obfuscation Techniques: Packing 7

slide-28
SLIDE 28

Efficient tracking of memory accesses

Coarse-grained memory access tracking (at page level), through the use of hardware mechanisms Malicious code Memory

Executed page Written page Executed memory location Written memory location

Unfortunately...

◮ Written-then-executed locations are indicative of unpacking but

not indicative of the end of unpacking

◮ Coarse-grained memory accesses tracking further increases the

chances to detect spurious unpacking stages (up to hundreds of thousands stages)

Malware Obfuscation Techniques: Packing 7

slide-29
SLIDE 29

Efficient tracking of memory accesses

Coarse-grained memory access tracking (at page level), through the use of hardware mechanisms Malicious code Memory

Executed page Written page Executed memory location Written memory location

Unfortunately...

◮ Written-then-executed locations are indicative of unpacking but

not indicative of the end of unpacking

◮ Coarse-grained memory accesses tracking further increases the

chances to detect spurious unpacking stages (up to hundreds of thousands stages)

Malware Obfuscation Techniques: Packing 7

The overhead introduced by invoking the malware detector every time a written page is executed is prohibitive!

slide-30
SLIDE 30

Better approximating the end of an unpacking stage

Ideally:

Scan Start Halt

Malware Obfuscation Techniques: Packing 8

slide-31
SLIDE 31

Better approximating the end of an unpacking stage

Ideally:

Scan Start Halt

With coarse-grained memory access tracking:

Start Scan Scan Scan Halt

Malware Obfuscation Techniques: Packing 8

slide-32
SLIDE 32

Better approximating the end of an unpacking stage

Ideally:

Scan Start Halt

With coarse-grained memory access tracking:

Start Scan Scan Scan Halt

Mitigate the imprecision of the coarse-grained memory accesses tracking by considering an unpacking stage concluded when the execution of a previously written page is followed by a dangerous system call

Start Scan Halt

Malware Obfuscation Techniques: Packing 8

slide-33
SLIDE 33

Dangerous system calls

To achieve its malicious goals, the malware has to interact with the system (through system calls)

Malware Obfuscation Techniques: Packing 9

slide-34
SLIDE 34

Dangerous system calls

To achieve its malicious goals, the malware has to interact with the system (through system calls)

Only few system calls are dangerous

A system call is dangerous if its execution can leave the system in an unsafe state

Malware Obfuscation Techniques: Packing 9

slide-35
SLIDE 35

Dangerous system calls

To achieve its malicious goals, the malware has to interact with the system (through system calls)

Only few system calls are dangerous

A system call is dangerous if its execution can leave the system in an unsafe state

Start

  • Scan

Halt NtOpenFile NtOpenKey NtDeleteFile

Malware Obfuscation Techniques: Packing 9

slide-36
SLIDE 36

Unpacker algorithm

Input: an execution trace e0, e1, . . . where a trace event can be: w(p) write access to a memory page p x(p) instruction execution from a memory page p s invocation of the system call s

Malware Obfuscation Techniques: Packing 10

slide-37
SLIDE 37

Unpacker algorithm

Execution trace

x(0), w(2), s0, w(1), x(1), s1, x(2), s2, . . .

Memory pages status

Page Access # W WX 1 2 . . .

Malware Obfuscation Techniques: Packing 11

slide-38
SLIDE 38

Unpacker algorithm

Execution trace

x(0) , w(2), s0, w(1), x(1), s1, x(2), s2, . . .

Memory pages status

Page Access # W WX 1 2 . . . The memory page 0 is executed

Malware Obfuscation Techniques: Packing 11

slide-39
SLIDE 39

Unpacker algorithm

Execution trace

x(0), w(2) , s0, w(1), x(1), s1, x(2), s2, . . .

Memory pages status

Page Access # W WX 1 2

  • . . .

The memory page 2 is written The page is recorded in the set W of written pages

Malware Obfuscation Techniques: Packing 11

slide-40
SLIDE 40

Unpacker algorithm

Execution trace

x(0), w(2), s0 , w(1), x(1), s1, x(2), s2, . . . s0 is NtOpenFile

Memory pages status

Page Access # W WX 1 2

  • . . .

The system call s0 is executed (not dangerous and WX is empty)

Malware Obfuscation Techniques: Packing 11

slide-41
SLIDE 41

Unpacker algorithm

Execution trace

x(0), w(2), s0, w(1) , x(1), s1, x(2), s2, . . .

Memory pages status

Page Access # W WX 1

  • 2
  • . . .

The memory page 1 is written The page is recorded in the set W of written pages

Malware Obfuscation Techniques: Packing 11

slide-42
SLIDE 42

Unpacker algorithm

Execution trace

x(0), w(2), s0, w(1), x(1) , s1, x(2), s2, . . .

Memory pages status

Page Access # W WX 1

  • 2
  • . . .

The memory page 1 is executed The page is recorded in the set WX of written-then-executed pages

Malware Obfuscation Techniques: Packing 11

slide-43
SLIDE 43

Unpacker algorithm

Execution trace

x(0), w(2), s0, w(1), x(1), s1 , x(2), s2, . . . s1 is NtOpenKey

Memory pages status

Page Access # W WX 1

  • 2
  • . . .

The system call s1 is executed (not dangerous)

Malware Obfuscation Techniques: Packing 11

slide-44
SLIDE 44

Unpacker algorithm

Execution trace

x(0), w(2), s0, w(1), x(1), s1, x(2) , s2, . . .

Memory pages status

Page Access # W WX 1

  • 2
  • . . .

The memory page 2 is executed The page is recorded in the set WX of written-then-executed pages

Malware Obfuscation Techniques: Packing 11

slide-45
SLIDE 45

Unpacker algorithm

Execution trace

x(0), w(2), s0, w(1), x(1), s1, x(2), s2 , . . . s2 is NtDeleteFile

Memory pages status

Page Access # W WX 1

  • 2
  • . . .

The system call s2 is executed (dangerous) The malware detector is invoked to scan all the memory pages in W

Malware Obfuscation Techniques: Packing 11

slide-46
SLIDE 46

Unpacker algorithm

Execution trace

x(0), w(2), s0, w(1), x(1), s1, x(2), s2, . . .

Memory pages status

Page Access # W WX 1 2 . . . If the program is not malicious the sets W and WX are emptied and the execution is resumed

Malware Obfuscation Techniques: Packing 11

slide-47
SLIDE 47

OmniUnpack for Microsoft Windows XP

Kernel User Suspicious program ClamAV Malware detector OmniUnpack kernel driver Memory access monitor System-call monitor

Malware Obfuscation Techniques: Packing 12

slide-48
SLIDE 48

OmniUnpack for Microsoft Windows XP

Kernel User Suspicious program ClamAV Malware detector OmniUnpack kernel driver Memory access monitor System-call monitor

◮ The W ⊕ X policy is enforced on the memory pages of the

suspicious program

◮ Page-fault exceptions are trapped by OmniUnpack ◮ Non executable pages can be emulated via software

Malware Obfuscation Techniques: Packing 12

slide-49
SLIDE 49

OmniUnpack for Microsoft Windows XP

Kernel User Suspicious program ClamAV Malware detector OmniUnpack kernel driver Memory access monitor System-call monitor

◮ Any malware detection strategy can be used to scan the code

generated during the previous stage

Malware Obfuscation Techniques: Packing 12

slide-50
SLIDE 50

Food for Thoughts & Exercises

◮ Try to find out a method in order to evade Omninpack

system

◮ Following the parassite developed for the last homework

try to patch the got table on-the-fly and wrap some function and logs the parameters.

◮ Add a layer of protection to the parassite against the

static analysis the parassite should be able to unpack yourself during the execution of the binary.

Malware Obfuscation Techniques: Packing 13

slide-51
SLIDE 51

Q&A

Thank You! Q&A?

Malware Obfuscation Techniques: Packing 14