Top Banner
Malware Chengyu Song 1
41

Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Jun 26, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Malware

Chengyu Song

1

Page 2: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Lab1: reverse engineering• Goal: understand what the program does and how it works

• Approaches

• Static: disassembler (objdump, radare2, IDA)

• Dynamic: debugging (gdb)

• Why useful?

• QA: make sure the code is correct

• Bug fixing: figure out why

• Malware analysis

2

Page 3: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Malware• Malware = Malicious Software

• Virus

• Worm

• Botnet

• Spyware

• Rootkit

• Ransomeware

• etc

3

Page 4: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Computer virus• Virus = code that replicates

• Originates from a theoretical question

• Can a program reproduce itself like organism?

• "Theory of self-reproducing automata", John von Neumann, 1966

• Quine: a='a=%r;print(a%%a)';print(a%a)

• Like real virus, computer virus

• Infect other programs for replication

• Hijack the normal workflow for activation

4

Page 5: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Propagation of virus• General infection strategy: find some code lying around, alter it to include

the virus

• Executables, boot sectors, script (including embedded)

• Example one: attached USB thumb drive

• Alter executables it holds to include the virus or autorun script

• So once the drive is attached to another machine, boom

• Example two: email attachment

• Alters attachment to add a copy of itself

5

Page 6: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Activation of virus

6

Page 7: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Payload• Besides self-reproducing, what else can the virus do?

• Pretty much anything, payload is decoupled from propagation

• Only subject to permissions of the infected program

• Examples

• Brag or exhort (pop up a message)

• Trash files (just to be nasty) or encrypt them (ransomeware)

• Damage hardware (e.g., CIH)

• Keylogging

7

Page 8: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Computer worm• Worm = malware that self-propagates

• Propagation of virus requires certain type of user interaction

• Execute program, open file, insert USB disk, etc

• Worm propagate without user interaction

• How?

• By exploit vulnerabilities of the target system

• Requires interconnection

8

Page 9: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Notorious worms (1)• Morris (1988): the first worm

• Scanning the local subnet

• Exploiting a fingerd buffer overflow

• Exploiting sendmail's DEBUG mode (not a bug!)

• Infected approximately 6,000 machine

• 10% of computers connected to the Internet

• cost ~ $10 million in downtime and cleanup

9

Page 10: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Notorious worms (2)• ILOVEYOU (2000): email worm

• Propagation through email attachment

• Scans the contacts and sends an email to everyone

10

Page 11: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Notorious worms (3)• Code Red (2001): fast spreading

• Exploits buffer overflow vulnerability inside MS IIS

• Infected more than 359,000 computers in less than 14 hrs

Copyright UC Regents, Jeff Brown for CAIDA, UCSD.

11

Page 12: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Notorious worms (4)• Slammer (2003): fastest ever

• Exploits buffer overflow vulnerability inside MS SQLServer

• Infected more than 90 percent of vulnerable hosts within 10 mins

12

Page 13: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Notorious worms (5)• Stuxnet (2010): SCADA

• Multi-mode spreading

• Initially spreads via USB (virus-like)

• Once inside a network, quickly spreads internally using Windows

RPC

• Geographically clustered

• Iran: 59%; Indonesia: 18%; India: 8%

13

Page 14: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Notorious worms (6)• WannaCry (2017): ransomeware

• Leaked NSA EternalBlue exploit (Windows SMB)

14

Page 15: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Botnet• Botnet = malware that is remotely controlled by command and control (C&C)

server

• Collection of compromised hosts (infected in any ways)

• Platform for many attacks

• Spam forwarding (70% of all spam)

• Click fraud

• Distributed denial-of-service (DDoS)

15

Page 16: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Spyware• Spyware = malware that collects your activities

• Some people don't consider it as real malware (greyware)

• Google?

• But with advances in machine learning, such activities matters a lot

more!

16

Page 17: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Rootkit• Rootkit = malware that hides other malware

• Hide the evidence of infection

• Guarantees persistent

• Usually executes at very low level (kernel, bootloader, firmware, etc)

17

Page 18: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

How malware get into your system?• Virus: require human interaction

• Do not open suspicious files/attachments

• Do not insert unknown USB/Disk

• Do not insert your thumb drive into unknown computer

• Worm & drive-by: exploit vulnerabilities

• Patch your system as soon as possible

18

Page 19: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

How malware get into your system? (cont.)• Trojan horse: disguise as something legitimate

• Download software from trusted website

• Do not use pirate software

• Check integrity of the software

• Social engineering: motivate you to do something dangerous

• Think twice

19

Page 20: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

What if you really need/want to open?• Scan the file for known malware -> signature-based detection

• Static signature: look for bytes corresponding to the malware

• Where to get the samples?

• How to make sure each signature is unique/good?

• Why effective? replicating nature of malware

• Drove development of multi-billion $$ AV industry (AV = "antivirus")

• Limited but necessary

20

Page 21: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

An interesting story ...

21

Page 22: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

The arm race• If you are a virus writer, what would you do to make sure your effort does not

get "wasted" by a signature from the AV industry?

• If you are a AV company, how would you make sure your signature is hard to

evade and the database does not explode?

22

Page 23: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Polymorphic code• Idea: change the appearance of the code every time it propagates

• How? Encryption !

• Encodes the message so that the adversary cannot recover its original

content without knowing the secret

• Obfuscation (packing)

• Weak (but simple/fast) crypto algorithm works fine too

• Strong crypto algorithm: use random key / initial padding

23

Page 24: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Unpacking

24

Page 25: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Polymorphic propagation

25

Page 26: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Arm race: detecting polymorphic malware• How would you detect a polymorphic malware?

• Idea #1: detect the unpacker/decryptor

• False positives: less code to match, legitimate software also use

obfuscation to protect IP

• Idea #2: decrypt and detect

• Speculative runs the software for a while and scan memory

• But for how long?

• Virus-writer countermeasures?

26

Page 27: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Metamorphic code• Idea: change the syntax of the code every time it propagates

• How? Code rewriter

• Renumber registers

• Change order of conditional code

• Reorder operations not dependent on one another

• Replace one low-level algorithm with another

• Junk dead code

• etc

27

Page 28: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Metamorphic code in action

28

Page 29: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Arm race: detecting metamorphic malware• How would you detect a metamorphic malware?

• Idea: focus on semantics (behaviors) instead of appearance

• Create signatures for malicious behaviors (e.g., syscall-based)

• Monitor dynamic behaviors of a process and detect malicious ones

• Virus-writer countermeasures?

• Anti dynamic analysis

• VM/emulator/debugger detection, triggers, env binding, etc

• Metamorphic syscalls

29

Page 30: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Summary: host side detection• Deciding whether a software is malicious or not in general, is not decidable

• With theoretical proof

• In practice, signature/black-list based approach has one big limitation

• Only detects known malware

• VT as an oracle

• What about white list approach, like on iOS

• Much better but still limited

30

Page 31: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Network side detection: worm• Can we detect worm traffics and block them?

• Idea #1: generate signature based on payload (exploits)

• Issue? Polymorphic/metamorphic payload

• Idea #2: generate signature based on network behaviors

• Works well for aggressive worms (code red, slammer)

• Not so effective if malware tries to hide

31

Page 32: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Network side detection: botnet• Can we take down the command & control servers?

• Q: how to bot connects to the C&C servers?

• Hard coded IP addresses

• Domain names (e.g., bot.net)

• P2P

32

Page 33: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Taking down botnets: hosts

33

Page 34: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Arm race: host take down• Botmaster countermeasures?

• Idea #1: keep moving around the master server

• Use domain name instead of fixed IP addresses

• Rapidly alter address associated w/ name (fast flux)

• Idea #2: buy off the host/ISP

• Bullet-proof hosting

34

Page 35: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Taking down botnets: domain name• Block/seize/sinkhole the domain name used by C&C servers

• This is what’s currently often used, often to good effect

• May require court orders

• Botmaster countermeasures?

• Register a large list of domain names and switch to a new one after a

while (e.g., everyday)

• How? Domain Generation Algorithm (DGA)

• State-of-the-art

35

Page 36: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Arm race: peer-to-peer• P2P networks: resolve name inside the own network

• Distributed hash table (DHT)

• Kademlia (BT, eMule)

• P2P botnets: locate C&C server through P2P network

• Not really more resilient: rely on seeds to bootstrap

• Countermeasures

• Machine learning based protocol detection

36

Page 37: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Arm race: steganography• Use legitimate channel to send/receive commands

• Twitter, Facebook, Google, etc

• Can also be used to fetch domain name, bootstrap seed

37

Page 38: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Two types of malware• Two types of malware

• Targeted (a.k.a. advanced persistent threat, APT), state-driven, high tech,

highly stealthy

• Large-scale infection, monetization-driven, low tech

• For the second type of malware, the most effective way to stop them is the

economical way

• Cut their monetization channel

• But we need to understand how they monetize first!

38

Page 39: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Understanding the underground economy• What is their business model?

• Where does the money come from?

• How money flows?

• What is the criminal infrastructure?

• Hosts, DNS provider, payment processor

• Goal: find the weakest link

39

Page 40: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

Example: pay per install (PPI) ecosystem

40

Page 41: Malware - UCR Computer Science and Engineeringcsong/cs255/l/malware.pdfTwo types of malware • Two types of malware • Targeted (a .k.a. advanced persistent threat, APT ), state-driven,

The walled-garden model• Why there are only a few malware on iOS devices?

• How can you monetize on iOS?

• How can you achieve large infection/installation?

• A healthy ecosystem matters a lot!

41