GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot...

96
© Copyright Fortinet Inc. All rights reserved. GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE November 10-11, 2016 Raul Alvarez

Transcript of GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot...

Page 1: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

© Copyright Fortinet Inc. All rights reserved.

GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE November 10-11, 2016

Raul Alvarez

Page 2: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

2

About Me

Senior Security

Researcher @ Fortinet

22 published articles in

Virus Bulletin

Regular contributor in our

company blog

Confidential

Page 3: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

Malware Categories

Page 4: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

4

trojan

script/

macro

Malware Honeycomb

virus POS

bot

botnet

worm ransom

ware

Page 5: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

5

trojan

script/

macro

Virlock

virus POS

bot

botnet

worm ransom

ware

Page 6: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

Agenda

Page 7: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

7

Agenda

Confidential

Virlock as a common malware

• Reversing stages

• Metamorphic algorithm

Virlock as a file infector

• Detection

• Extracting the host file

Virlock as a polymorphic malware

• On-demand polymorphic algorithm

Virlock as a ransomware

• Visible signs

• Unlocking

Page 8: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

Virlock

Page 9: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

9

What Is A File Infector?

Confidential

Attaches the malware code into the host file.

Appending, prepending, and cavity type

Maintains persistency within the computer system

Infected file is hard to restore

Page 10: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

10

What Is A Ransomware?

Confidential

Holds your computer for ransom

Encrypts files

Uses cryptocurrency, such as bitcoins, for payment

Page 11: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

11

What Is Virlock?

Confidential

A ransomware

A file infector

Uses on-demand polymorphic algorithm

Uses metamorphic algorithm

Locks your screen

Page 12: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

12

Page 13: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

13

Page 14: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

14

Page 15: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

15

Page 16: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

16

Page 17: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

17

Page 18: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

18

Page 19: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

19 Confidential

Just kidding!

Page 20: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

20

Debugging Tools

Confidential

ollydbg

http://www.ollydbg.de/

immunity debugger

http://www.immunityinc.com/p

roducts/debugger/

x64dbg

http://x64dbg.com/

Page 21: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

Virlock As A Common Malware

Page 22: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

22

Common Reversing

Confidential

encrypted/

packed

decryptor

MZ header

Decrypting/Unpacking

malware using a

debugger

decrypted/

unpacked

decryptor

MZ header

1

Static/Dynamic

Analysis

2

Page 23: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

Reversing Stages

Page 24: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

24

Reversing Stages

Confidential

.text 0xbb000

.rsrc 0x01200

A

.text

.rsrc 0x01200

B

metamorphic

algorithm 0x06C77

MZ header MZ header

.text

.rsrc 0x01200

C

MZ header

decoded bytes 0x0250

.text

.rsrc 0x01200

MZ header

D

metamorphic

algorithm 0x06C77

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main functions

Virlock-infected file only

has 2 sections: .text and

.rscr

Page 25: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

25

Reversing Stages

Confidential

.text 0xbb000

.rsrc 0x01200

A

.text

.rsrc 0x01200

B

metamorphic

algorithm 0x06C77

MZ header MZ header

.text

.rsrc 0x01200

C

MZ header

decoded bytes 0x0250

.text

.rsrc 0x01200

MZ header

D

metamorphic

algorithm 0x06C77

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main functions

At the entry point, the

malware executes its

metamorphic algorithm.

Page 26: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

26

Reversing Stages

Confidential

.text 0xbb000

.rsrc 0x01200

A

.text

.rsrc 0x01200

B

metamorphic

algorithm 0x06C77

MZ header MZ header

.text

.rsrc 0x01200

C

MZ header

decoded bytes 0x0250

.text

.rsrc 0x01200

MZ header

D

metamorphic

algorithm 0x06C77

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main functions

The metamorphic

algorithm decodes

the initial decryptor.

Page 27: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

27

Reversing Stages

Confidential

.text 0xbb000

.rsrc 0x01200

A

.text

.rsrc 0x01200

B

metamorphic

algorithm 0x06C77

MZ header MZ header

.text

.rsrc 0x01200

C

MZ header

decoded bytes 0x0250

.text

.rsrc 0x01200

MZ header

D

metamorphic

algorithm 0x06C77

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main function

The initial decryptor

produces the main

function.

Page 28: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

28

Reversing Stages

Confidential

.text

.rsrc 0x01200

MZ header

E

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main function

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

F

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main functions

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

G

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main functions

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

H

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main functions

on-demand poly

on-demand poly

on-demand poly

on-demand poly

Host file

The main function calls

the malicious threads

and other sub-

functions. Each sub-

function is

decrypted/re-

encrypted by individual

on-demand

polymorphic algorithm.

Page 29: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

29

Reversing Stages

Confidential

.text

.rsrc 0x01200

MZ header

E

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main function

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

F

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main function

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

G

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main functions

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

H

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main functions

on-demand poly

on-demand poly

on-demand poly

on-demand poly

Host file

When an on-demand

polymorphic algorithm

runs, it decrypts the

malicious code and

executes them. Then

re-encrypts itself and

the malicious code

with a different key.

Page 30: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

30

Reversing Stages

Confidential

.text

.rsrc 0x01200

MZ header

E

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main function

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

F

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main function

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

G

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main function

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

H

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main functions

on-demand poly

on-demand poly

on-demand poly

on-demand poly

Host file

After executing the

rest of the

malicious code, the

malware in

memory looks

totally different

from its original

binary content.

Page 31: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

31

Reversing Stages

Confidential

.text

.rsrc 0x01200

MZ header

E

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main function

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

F

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main function

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

G

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main function

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

H

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main function

on-demand poly

on-demand poly

on-demand poly

on-demand poly

Host file

Finally, the host file

is decrypted,

dropped, and

executed.

Page 32: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

Metamorphic Algorithm

Page 33: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

33

Metamorphic Algorithm

Confidential

Basics:

Putting a value(0) in a register(EAX)

MOV EAX,0 EAX register gets 0 directly

XOR EAX,EAX XORing the same register by itself also

generates a zero value placed into a given

register

SUB EAX,EAX SUBtracting any register by itself also

generates the same result.

MOV EAX, 0x10

ADD EAX, 0x10

SUB EAX, 0x20

EAX also gets 0

Page 34: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

34

Metamorphic Algorithm

Confidential

Detection Limitation

• Hard to find similar bytes

• Unknown length of bytes

• Unpredictable code

Page 35: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

35

Reversing Stages

Confidential

.text 0xbb000

.rsrc 0x01200

A

.text

.rsrc 0x01200

B

metamorphic

algorithm 0x06C77

MZ header MZ header

.text

.rsrc 0x01200

C

MZ header

decoded bytes 0x0250

.text

.rsrc 0x01200

MZ header

D

metamorphic

algorithm 0x06C77

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main functions

At the entry point, the

malware executes its

metamorphic algorithm.

Page 36: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

36

Metamorphic Algorithm (sample 1)

Confidential

...

~ 28 kilobytes

Call to the decrypted

bytes at the start of the

.text section.

Entry Point

The size of the

metamorphic code varies

per infected file.

Approximately 28kb of

code constitutes the

metamorphic algorithm

that generates the rest of

the malicious code,

including the polymorphic

algorithm.

Page 37: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

37

Metamorphic Algorithm (sample 1)

Confidential

irrelevant bytes

decrypted bytes

first DWORD

second DWORD

third DWORD

Page 38: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

38

Metamorphic Algorithm (sample 2)

Confidential

irrelevant bytes

first DWORD

second DWORD

third DWORD

decrypted bytes

Page 39: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

39

Metamorphic Algorithm (sample 1)

Confidential

irrelevant bytes

decrypted bytes

first DWORD

second DWORD

third DWORD

Page 40: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

40

Metamorphic Algorithm (sample 2)

Confidential

irrelevant bytes

first DWORD

second DWORD

third DWORD

decrypted bytes

Page 41: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

41

Metamorphic Algorithm (comparison)

Confidential

Sample 1

Sample 2

first DWORD

MOV [EDI],ECX

MOV [EAX],ESI

Page 42: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

42

Metamorphic Algorithm (comparison)

Confidential

Sample 2

second DWORD

Sample 1

MOV [EAX],EBX

MOV [EDI],EBX

Page 43: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

43

Metamorphic Algorithm (comparison)

Confidential

Sample 2

third DWORD

Sample 1

MOV [EDX],ESI

MOV [EBX],ECX

Page 44: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

44

Metamorphic Algorithm (detection)

Confidential

Sample 2 Sample 1

MOV EAX, --------

NOP

JMP 0040108B

Page 45: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

Demo – Metamorphic Algorithm

Page 46: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

Virlock As A File Infector

Page 47: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

47

Cleaning: How To Clean An Infected File

Confidential

Basics:

• Determine the kind of virus

• Determine how to extract and restore the host

file

Page 48: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

48

Different Kinds Of File Infectors

Confidential

Basics:

• Appending

• Prepending

• Cavity

• Overwriting

• Companion

Page 49: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

49

Different Kinds Of File Infectors

Confidential

appending prepending cavity

overwriting companion

virlock

Page 50: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

50

Cleaning: Extracting The Host File From Virlock

Confidential

Details:

• Host file is encrypted and embedded within the

malware

• DecryptionKey can be found within the malware

• DecryptionKey is encrypted using a simple XOR

• Uses a simple decryption algorithm to extract the

host file

Page 51: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

51

Reversing Stages

Confidential

.text

.rsrc 0x01200

MZ header

E

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main function

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

F

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main function

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

G

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main function

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

H

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main function

on-demand poly

on-demand poly

on-demand poly

on-demand poly

Host file

Finally, the host file

is decrypted,

dropped, and

executed.

Page 52: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

52

Cleaning: Extracting The Host File From Virlock

Confidential

EBX = initial key

XORing EBX with dword in [ESI]

generates the DecryptionKey

ECX = EBX = DecryptionKey

EBX = the next DWORD

ESI = location of the encrypted DecryptionKey

Decrypts the

HOST file

Page 53: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

53

Cleaning: Extracting The Host File From Virlock

Confidential

Decrypts the

HOST file

DecryptionKey

Original Host

Filename Encrypted Host File

Decrypted Host File

Page 54: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

Virlock As A Polymorphic Malware

Page 55: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

55

Reversing Stages

Confidential

.text

.rsrc 0x01200

MZ header

E

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main function

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

F

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main function

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

G

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main functions

on-demand poly

on-demand poly

on-demand poly

on-demand poly

.text

.rsrc 0x01200

MZ header

H

metamorphic

algorithm 0x06C77

decoded bytes 0x0250

main functions

on-demand poly

on-demand poly

on-demand poly

on-demand poly

Host file

When an on-demand

polymorphic algorithm

runs, it decrypts the

malicious code and

executes them. Then

re-encrypts itself and

the malicious code

with a different key.

Page 56: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

Dynamic Routine Execution Map

Page 57: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

57

Dynamic Routine Execution Map

Confidential

Page 58: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

58

Dynamic Routine Execution Map

Confidential

Page 59: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

59

Dynamic Routine Execution Map

Confidential

Page 60: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

60

Dynamic Routine Execution Map

Confidential

Page 61: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

61

Dynamic Routine Execution Map

Confidential

Page 62: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

62

Dynamic Routine Execution Map

Confidential

Page 63: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

On-Demand Polymorphic Algorithm

Page 64: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

64

On-Demand Polymorphic Algorithm

Confidential

Implementation

• Uses Decryptor to decrypt a block of code using

an old key

• Executes the newly decrypted code

• Uses RDTSC (Read Time-Stamp Counter) to

generate a new dword value

• Uses NewKeyGenerator to generate new key

• Uses Encryptor to encrypt the same block of

code using the new key

newly decrypted

code

RDTSC

Page 65: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

65

Decryptor

Confidential

Features:

• Uses garbage code

• Keygen function for redundancy check

• Uses XOR to generate the key

• Uses XOR to decrypt a block of code

Page 66: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

66

Decryptor

Confidential

garbage code

# of bytes to

generate the key

actual key

generator;

EAX starts with

0xFFFFFFFF

starting location

of key-bytes

XOR decryptor keygen function

generates the

same EAX value

(key)

Page 67: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

67

On-Demand Polymorphic Algorithm

Confidential

Implementation

• Uses Decryptor to decrypt a block of code using

an old key

• Executes the newly decrypted code

• Uses RDTSC (Read Time-Stamp Counter) to

generate a new dword value

• Uses NewKeyGenerator to generate new key

• Uses Encryptor to encrypt the same block of

code using the new key

newly decrypted

code

RDTSC

Page 68: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

68

On-Demand Polymorphic Algorithm

Confidential

Implementation

• Uses Decryptor to decrypt a block of code using

an old key

• Executes the newly decrypted code

• Uses RDTSC (Read Time-Stamp Counter) to

generate a new dword value

• Uses NewKeyGenerator to generate new key

• Uses Encryptor to encrypt the same block of

code using the new key

newly decrypted

code

RDTSC

Page 69: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

69

On-Demand Polymorphic Algorithm

Confidential

Implementation

• Uses Decryptor to decrypt a block of code using

an old key

• Executes the newly decrypted code

• Uses RDTSC (Read Time-Stamp Counter) to

generate a new dword value

• Uses NewKeyGenerator to generate new key

• Uses Encryptor to encrypt the same block of

code using the new key

newly decrypted

code

RDTSC

Page 70: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

70

NewKeyGenerator

Confidential

Implementation:

• RDTSC generates a new dword value

• Saves it in different memory locations

• The memory locations are within the memory

range that contains key bytes

• Generates new key by XORing the key bytes

• Saves the new key to the original location of the

old key used in the Decryptor

Page 71: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

71

NewKeyGenerator

Confidential

location of the

bytes needed to

generate the

new key

starting location

is one byte

before the first

DWORD value

from RDTSC

EAX = DWORD value

NEW KEY

Page 72: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

72

NewKeyGenerator

Confidential

NEW KEY

old key

new key

location of the NEW KEY

Page 73: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

73

On-Demand Polymorphic Algorithm

Confidential

Implementation

• Uses Decryptor to decrypt a block of code using

an old key

• Executes the newly decrypted code

• Uses RDTSC (Read Time-Stamp Counter) to

generate a new dword value

• Uses NewKeyGenerator to generate new key

• Uses Encryptor to encrypt the same block of

code using the new key

newly decrypted

code

RDTSC

Page 74: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

74

On-Demand Polymorphic Algorithm

Confidential

Implementation

• Uses Decryptor to decrypt a block of code using

an old key

• Executes the newly decrypted code

• Uses RDTSC (Read Time-Stamp Counter) to

generate a new dword value

• Uses NewKeyGenerator to generate new key

• Uses Encryptor to encrypt the same block of

code using the new key

newly decrypted

code

RDTSC

Page 75: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

75

Encryptor

Confidential

Features:

• Uses the same algorithm as the Decryptor

• Uses the new key to encrypt the same block of

code

Page 76: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

76

Sample On-demand Polymorphic Values

Confidential

1C B0 19 99

F4 C7 7E 64

E2 40 7B 9A

F4 00 7B F1

E8 B0 62 02

00 C7 05 FF

16 40 00 01

00 00 00 6A

75 EB 89 E2

9D 9C EE 1F

8B 1B EB E1

9D 5B EB 8A

encrypted with OLD KEY

decrypted code

encrypted with NEW KEY

Page 77: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

77

Detection

Confidential

1C B0 19 99

F4 C7 7E 64

E2 40 7B 9A

F4 00 7B F1

E8 B0 62 02

00 C7 05 FF

16 40 00 01

00 00 00 6A

75 EB 89 E2

9D 9C EE 1F

8B 1B EB E1

9D 5B EB 8A

encrypted with OLD KEY

decrypted code

encrypted with NEW KEY

Page 78: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

78

Detection

Confidential

location of the

bytes needed to

generate the

new key

starting location

is one byte

before the first

DWORD value

from RDTSC

EAX = DWORD value

NEW KEY

Page 79: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

79

Detection

Confidential

location of the

bytes needed to

generate the

new key

starting location

is one byte

before the first

DWORD value

from RDTSC

EAX = DWORD value

NEW KEY

Page 80: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

80

Dynamic Routine Execution Map

Confidential

Page 81: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

Virlock As A Ransomware

Page 82: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

Visible Signs of Infection

Page 83: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

83

Page 84: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

84

Page 85: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

85

Page 86: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

86

Page 87: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

87

Page 88: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

88

Page 89: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

89

Page 90: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

Eradication

Page 91: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

91

Eradication

Confidential

• Manually create solution to clean the infected

files

• Download reliable standalone solution to remove

the malware from the system

• Always make sure that your antivirus and

security apps are updated

Page 92: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

92

What if your system is already locked?

Confidential

Steps:

• Reboot the system on safe mode

• Remove the malware entry on the startup

registry

• Then go back to eradication stage

Page 93: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

Demo – Unlocking Virlock

Page 94: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

94

Wrap Up

Confidential

• For reversing:

Set a breakpoint at the end of metamorphic

algorithm

Copy the decrypted code from memory

• For detection:

Get patterns from the decrypted code

• For cleaning:

Remove the entries from the registry keys

Extract the host file

Page 95: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom

Mulțumesc!

Page 96: GNISREVER A POLYMORPHIC FILE-INFECTING RANSOMWARE … 1... · Malware Honeycomb virus POS bot botnet worm ransom ware . 5 trojan script/ macro Virlock virus POS bot botnet worm ransom