T argeted attacks: from being a victim to counter attacking - - PowerPoint PPT Presentation

t argeted attacks from being a victim to counter attacking
SMART_READER_LITE
LIVE PREVIEW

T argeted attacks: from being a victim to counter attacking - - PowerPoint PPT Presentation

T argeted attacks: from being a victim to counter attacking Andrzej Dereszowski deresz <at> signal11.eu www.signal11.eu Motivation Are we able to counteratack ? Different possibilities: Traditional network scan and attack


slide-1
SLIDE 1

T argeted attacks: from being a victim to counter attacking

Andrzej Dereszowski deresz <at> signal11.eu www.signal11.eu

slide-2
SLIDE 2

Motivation

  • Are we able to counteratack ?
  • Different possibilities:
  • Traditional network scan and attack

known open ports

  • Running honeypot with infected

documents to steal

  • Discovering new vulnerability in the

backdoor program intruders use

slide-3
SLIDE 3

Outline

  • Intro
  • Scenario
  • Analysis of an infected document
  • RAT (Remote Administration T
  • ol)
  • Closer look at Poison Ivy RAT
  • Unobfuscating the code
  • The vulnerability
  • The exploit (demo)
  • The intellingence from the field
slide-4
SLIDE 4

Intro: targeted attacks

  • Highly focused on particular organisations (or
  • rganisation type)
  • Making less noize than the « non-targeted » malware
  • The most popular attack vector is an e-mail with an

infected document or link to a web page with an exploit

  • T
  • ols used to maintain the control and infiltrate the

target are more individual-oriented (designed for managing less machines, but you can do more with a single machine)

  • Main focus on stealing documents (amongst other

things ...)

slide-5
SLIDE 5

Intro: targeted attacks (2)

  • Different attackers from different

countries with different skills

  • Simplest attacks: only social

engineering « here is your unpaid bill: http://badness.com/bad.exe »

  • More advanced attacks: infected

DOC/PPT/PDF or link to a web page

  • The most advanced: 0-day vulnerability

exploited in MS/Adobe products

slide-6
SLIDE 6

Scenario

  • Our scenario starts here: an e-mail with the PDF

attached was sent to a pharmaceutical company

  • The PDF, when opened, makes the Adobe Reader

disappear for a second, and then reappers with an « analysis of the future of the drug market »

  • Closer analysis and Internet search reveals that the

article was copied from the news

  • The analysis of the PDF file reveals that it exploits a

vulnerability in Collab.collectEmailInfo in Adobe Reader up to 8.1.1 (CVE-2007-5659)

slide-7
SLIDE 7

Scenario (2)

  • Althought this was not 0-day at this time,

the system was not patched (quite common with Adobe products until recently)

  • The security products (the AntiVirus and

the IDS system) failed to block the threat becasue the JavaScript in the PDF was

  • bfuscated (see

http://www.signal11.eu/en/research/articles/m

  • n how easy is to fool the AV)
slide-8
SLIDE 8

Static analysis: Malicious JavaScript

  • Static analysis: the PDFTK (PDF toolkit) or

the pdf-parser.py

  • After uncompressing, the following code is

visible:

slide-9
SLIDE 9

Static analysis: shellcode analysis

Malicious JavaScript contains shellcode: We discontinue the static analysis because it's too time consuming – let's move on to dynamic analysis

slide-10
SLIDE 10

Dynamic analysis: Network footprint

Network footprint: 256 bytes sent right after a successful TCP handshake. These bytes appear random; they are different with each run:

slide-11
SLIDE 11

Dynamic analysis: Behavioral analysis

  • This is to give the overall picture what's going on in the

system: Process Monitor can be used, or some publicly available sandboxing services: Sunbelt CWSandbox, ThreatExpert, Anubis

  • Using these tools it is easy to see that the code injects

remote threads to other processes and creates new processes as well

  • T
  • get to the final code we need to follow all these hops
  • This will serve as a base for the third element of dynamic

analysis: code debugging

slide-12
SLIDE 12

Dynamic analysis: Debugging code

  • First, the code calls CreateRemoteThread()

in the explorer.exe process

  • We can attach a second copy of the

debugger to explorer.exe and break exactly where the new remote thread starts

slide-13
SLIDE 13

Dynamic analysis: Debugging code (2)

  • The hopping is not over; the injected explorer.exe

thread calls CreateProcess() on iexplore.exe in the suspended state,injects code and resumes the process

  • We can use the good old method; find the injeced

code in the injecting process, and modify its frist bytes to jump-to-itself. The thread in iexplore.exe process will wait for us in the infinite loop

slide-14
SLIDE 14

Dynamic analysis: Debugging code (3)

This seems to be a right payload:

  • Position independent code: CALL ESI + n, where ESI is a base

register

slide-15
SLIDE 15

Dynamic analysis: code walk-through

slide-16
SLIDE 16

Remote Administration T

  • ol:

Introducing the term RAT

  • Now we now something about the code, let’s check if it’s

not something that we can grab from the Internet

  • According to Wikipedia: A Remote Administration Tool (known

more commonly on the Internet as a RAT) is used to remotely connect and manage a single or multiple computers with a variety of tools, such as:

  • Screen/camera capture or control
  • File management (download/upload/execute/etc.)
  • Shell control (usually piped from command prompt)
  • Computer control (power off/on/log off)
  • Registry management (query/add/delete/modify)
  • Other product-specific function
  • Watch out for terminology: server is the remote part,

client is the GUI C&C part

slide-17
SLIDE 17

Remote Administration T

  • ol:

Four candidates

  • Searching on Remote Access T
  • ol gives some
  • results. After analysis, I chosed four that seem

most popular and can be publicly downloaded:

– Nuclear RAT – Gh0st RAT – Bifrost Remote Controller – Poison Ivy

  • Let’s analyse each of them to check if some of

them match to what we already know about

  • ur sample
slide-18
SLIDE 18

RAT: Remote Access T

  • ol

Nuclear RAT

  • Traffic characteristics does not match
  • ur case; data is sent in clear
slide-19
SLIDE 19

Remote Administration T

  • ol

Gh0st RAT

  • Infamous one, played main role in the

GhostNet report

  • The network footprint of this one does not

match either because, even if it’s encrypted, it starts the transmission with the string « Gh0st », which is not our case

slide-20
SLIDE 20

Remote Administration T

  • ol

Bifrost Remote Controller

  • This one seems close to what we are observing, at first

glance

  • Data is encrypted, but it is 9 bytes more than 256
  • If looked at closely, we can see that the first four bytes

desribe the length of the encrypted part

  • Not our case either
slide-21
SLIDE 21

Remote Administration T

  • ol

Poison Ivy RAT

  • The traffic characteristic is a 100% match; 256 random bytes
  • The code from the generated server matches as well
  • That means: WE’VE FOUND THE RIGHT ONE !
slide-22
SLIDE 22

Closer look at Poison Ivy: Introduction

  • Free for download at its home site:

www.poisonivy-rat.com

  • The license says you can order special, undetected

version

  • It also says that updating to new version is very easy

because the remote part does not need to be updated

slide-23
SLIDE 23

Closer look at Poison Ivy: The architecture

  • In the Poison Ivy naming convention

(other RAT s as well), the client is the GUI console and the server is the remote agent siting in the infected computer

slide-24
SLIDE 24

Closer look at Poison Ivy: The server

  • Generated from within the client with user

supplied options (IP to connect, password etc.)

  • Very small: around 6 kb of code (position

independent), all the rest sent on-demand from the client

  • Hides very well in the system: I’ve seen behavioral

tools failing to detect it because they couldn’t reconginze the API calls

  • Generate options include:

– Password when authenticating with the client – IP address to connect to – Is starting at boot or no – Where to drop the EXE – Whether to perform the code injection, etc, etc.

slide-25
SLIDE 25

Closer look at Poision Ivy: The client

slide-26
SLIDE 26

Closer look at Poison Ivy: The client

Its capabilities include:

  • File manager
  • File shredder
  • Registry manipulator
  • Process viewer and manipulator
  • Services and driver viewer
  • TCP/IP relay proxy
  • Active connection and port lister
  • Remote cmd.exe shell
  • Password dumper
  • Key logger
  • Screen and audio capture
  • Inernet camera capture
  • Has plugin architecture that allows writing more
slide-27
SLIDE 27

Closer look at Poison Ivy: The comms

  • Site says it uses Camelia Encryption
  • Challenge-response authentication: first 256

random bytes is a chalenge, the client sends the response and the server verifies if the client knows the password

  • The encryption is not well implemented; re-

seeding the crypto with each trasmission

slide-28
SLIDE 28

Closer look at Poison Ivy: The comms (2)

  • The encryption routines can be spotted by

seeing a lot of arithmetic operations

  • By tracing how these function work, we

can locate the password – very important

slide-29
SLIDE 29

Unobfuscating the code

  • Distributed obfuscated by ExeStealth v2.7x, as identified by

DiE.exe (Detect-It-Easy), PEiD failed to detect it

  • The code is written in Borland Delphi
  • The packer performs antidebugging tricks such as spaghetti

jumps, jumping to the middle of instruction, checking « BeingDebugged » flags, calculating the CRC over its own code

  • There is an easy trick to unpack this: after the first Access

Violation exception, place the breakpoint on the CODE section – the next break will be OEP

  • We need to hide the debugger; PhantOm for Olly is ok!
  • The final step is to use Import Reconstructor with the

appropiate plugin to rebuild the exe

slide-30
SLIDE 30

Unobfuscating the code (2)

slide-31
SLIDE 31

The vulnerability: Process stalking

  • After making sure the program works after

rebuilding it, we are ready to have closer look at it

  • It contains loads of code, so we probably

have to figure out which part we are interested in

  • Let’s employ Process Stalking technique

and use the PaiMei by Pedram Amini – an excellent debugging framework writen in Python

slide-32
SLIDE 32

The vulnerability: Process stalking (2)

  • No vulnerability can be spoted right away in

the code

  • Throwing random data at the client doesn’t

work either

  • We need to look deeper
slide-33
SLIDE 33

The vulnerability: Fuzzing PI by instrumenting the server

  • Idea: when the data is encrypted, we need to fuzz it

before the encryption takes place

  • Then we need to implement that encryption in the

fuzzer code … could be time consuming

  • Not really ! We can use PaiMei and instrument the PI

server; modify its function parameter while it is running, if we know what to modify

  • I knew the encryption functions, I figured it out

during the analysis !

  • It is what the PI fuzzer does; runs the server many

times while changing bytes just before the encryption function is called

slide-34
SLIDE 34

The vulnerability: Poison Ivy fuzzer code

slide-35
SLIDE 35

The vulnerability: We’ve found a candidate !

  • This way, our fuzzer was able to

produce a positive result:

slide-36
SLIDE 36

The vulnerability: What has happened ?

  • We have overwritten a fixed length

buffer of 0x8001 bytes on the stack

  • The overwrite was possible because

Poison Ivy client does not check for the length value (it correctly verifies the encrypted data length thought)

  • The length value is sent as a 32bit

DWORD and the payload follows; we could overwrite a lot on the stack …

  • The overwritten buffer is located one

step up in the function call chain

slide-37
SLIDE 37

The exploit

  • Can we transform this into working exploit ?
  • First try failed; I tried to use the famous SEH

technique but that is pretty well protected even under Windows XP SP2; cannot dispatch the execution to an arbitrary address

  • I then focused on the classic function RET pointer
  • verwrite but there are some problems to solve:

– How do we locate the code on the stack ? – We need to traverse two RET s as the function

  • wning the buffer is one step up in the call chain –

can we make it ? – Will the program be still working or will it crash after the payload has started or finished ? – Do we need to reverse or copy all the encryption and program logic to our exploit code ?

slide-38
SLIDE 38

The exploit: How do we locate code in the stack ?

  • We are lucky – seems that Borland Delphi compiler

doesn’t care about the stack unwinding when the function is the one that started the thread

  • The EBP register is preserved and points to where our

code is located

  • it is enough to find the CALL EBP instruction somewhere

– this is just two bytes: \xFF\xD5, great chance to find !

slide-39
SLIDE 39

The exploit: Are we able to traverse the two RET s ?

  • Yes we are. We need to do two things:

– We need to drive the execution flow the shortest path possible as the stack will be smashed – We need to provide some fake pointers to writable regions

  • f memory, so the program doesn’t crash on access

violations

  • The first thing can be achieved by deliberately sending

less data than declared in the length field that we

  • verflow; the program will assume the error

condition and go straight towards the first RET, and then the second RET

  • The second thing will be met by feeding the program

with addressable memory pointers on the stack where it accesses the variables

slide-40
SLIDE 40

The exploit: Will the exploit be stealthy ?

  • Poison Ivy client works internally by

assigning one thread to each connection; it is a multithreaded server

  • It should be easy then to just exit the

thread we are running, if we don’t damage any data

  • In Metasploit Framework, we can do it by

setting the EXITFUNC variable to « thread »

slide-41
SLIDE 41

The exploit: Do we need to reverse a lot ?

  • Not nececarilly; we can use PaiMei to

instrument the PI server, just like we used it during the fuzzing process

  • This way, we drive the execution of the PI

server, stop it in the appropiate place and modify the length value and the buffer (needs to be shorter than declared!)

  • Then we just continue the execution to make

the server encrypt everything for us, and send it towards the PI client !

slide-42
SLIDE 42

The exploit: The layout of the overflown buffer

slide-43
SLIDE 43

The exploit: DEMO

slide-44
SLIDE 44

The intelligence from the field: How cyberspies operate

  • Impressive number of victims with

different group IDs

slide-45
SLIDE 45

The intelligence from the field: The network infrastructure

  • T

wo-tier infrastructure; the IP where the server connects to is never a real C&C, it is always a proxy server

  • The proxy server often located in a

different country

slide-46
SLIDE 46

The intelligence from the field: Stealing documents

  • Browsing directory structure, looking

for documents

slide-47
SLIDE 47

The intelligence from the field: Listening to keystrokes

  • Looking at the keylogger data
slide-48
SLIDE 48

The intelligence from the field: Looking at mailboxes

  • Uploading mail browsing tools
slide-49
SLIDE 49

The intelligence from the field: Cracking passwords

  • Looking at stolen password hashes
slide-50
SLIDE 50

The intelligence from the field: Spreading further

  • Creating new PI server
slide-51
SLIDE 51

The intelligence from the field: The operating procedures

  • Defined operation hours (around 12h) – starting

around 3-4h in the morning, terminating 15-16h

  • Weekend is weekend – no work
  • Using VMware virtual machine, reverted to the base

snapshot at the beginning of each day of work

  • USB key is used as the working directory for Poison

Ivy; it is used at the end of the day to transfer newly stolen documents to somewhere else

  • The USB key contains massive amounts of stolen

documents sorted by organisation, keylogger data, password hashes, and hacking tools

slide-52
SLIDE 52

QUESTIONS ?