Creating the Bro RFB (VNC) parser Martin van Hensbergen, Fox-IT - - PowerPoint PPT Presentation

creating the bro rfb vnc parser
SMART_READER_LITE
LIVE PREVIEW

Creating the Bro RFB (VNC) parser Martin van Hensbergen, Fox-IT - - PowerPoint PPT Presentation

Creating the Bro RFB (VNC) parser Martin van Hensbergen, Fox-IT Agenda Introduction Context: How we use Bro The dangers of VNC VNC protocol Dev Deploy Future work Introduction Martin van Hensbergen - Fox-IT


slide-1
SLIDE 1

Creating the Bro RFB (VNC) parser

Martin van Hensbergen, Fox-IT

slide-2
SLIDE 2

Agenda

  • Introduction
  • Context: How we use Bro
  • The dangers of VNC
  • VNC protocol
  • Dev
  • Deploy
  • Future work
slide-3
SLIDE 3

Introduction

  • Martin van Hensbergen - Fox-IT
  • Studied Mathematics at University of Delft
  • Worked at Fox-IT 2001-2011 + 2016-?
  • Mostly as developer but also in few other areas
  • 2007-2011, worked on FoxReplay
  • Software for full-content reconstruction of network data
  • Lawful interception & forensics purposes
  • Required network protocol knowledge
slide-4
SLIDE 4

Bro at Fox-IT

slide-5
SLIDE 5

Bro at Fox-IT

  • We use Bro in three major services:
  • Passive Audits - 🤕
  • Compromise Assessments - 😩
  • Incident Response - 😶
slide-6
SLIDE 6

Bro at Fox-IT

  • We use Bro in three major services:
  • Passive Audits - network 🤕
  • Compromise Assessments - 😩
  • Incident Response - 😶
slide-7
SLIDE 7

Bro at Fox-IT

  • We use Bro in three major services:
  • Passive Audits - network 🤕
  • Compromise Assessments - network+hosts 😩
  • Incident Response - 😶
slide-8
SLIDE 8

Bro at Fox-IT

  • We use Bro in three major services:
  • Passive Audits - network 🤕
  • Compromise Assessments - network+hosts 😩
  • Incident Response - network+hosts 😶
slide-9
SLIDE 9

Bro at Fox-IT - Passive Audit

  • We take a ‘photograph’ of the network by

passively monitoring 4 weeks of network traffic

  • Combination of:
  • Bro
  • Suricata
  • Custom tooling
slide-10
SLIDE 10

Bro at Fox-IT - Passive Audit

  • Bro gives us a very detailed run-down on:
  • Protocols used in a network
  • Flow data
  • Suricata gives us alerting on known-bad
slide-11
SLIDE 11

Bro at Fox-IT - Passive Audit

Suricata Bro Wireshark

Use strengths of multiple products

slide-12
SLIDE 12

Bro at Fox-IT - Passive Audit

  • Mix: Automated and manual analysis
  • Deliver report on security of the network
slide-13
SLIDE 13

Bro at Fox-IT - Passive Audit

  • Some things we look for:
  • Weak protocols (security wise) / SSL configs / Plaintext

passwords

  • ‘Weird’ traffic / Context surrounding alerts
  • Network segmentation
  • Services exposed to e.g. outside world
  • Remote administration tools
  • RDP ... why not RFB/VNC?
slide-14
SLIDE 14

VNC basics

  • Versatile protocol to view and control GUI’s over

a network connection.

  • Original spec (v3.3) by Olivetti Research Lab in

1998, later maintained by RealVNC: v3.7 in 2003 and v3.8 in 2007.

  • Protocol published under RFC6143 by RealVNC

in 2011

slide-15
SLIDE 15

VNC basics

  • Server runs RFB server ( e.g. RealVNC server );

listens on (default) TCP port 5900

  • RFB client connects over network
  • Client can control server over network
slide-16
SLIDE 16

The dangers of VNC

slide-17
SLIDE 17

The dangers of VNC

  • My colleague Yonathan Klijnsma did some

research on publicly reachable VNC servers

  • It's 2016 .... VNC IS EVERYWHERE!
slide-18
SLIDE 18

The dangers of VNC

slide-19
SLIDE 19

The dangers of VNC

slide-20
SLIDE 20

Dangers of VNC

  • All good and fun until…
slide-21
SLIDE 21

The dangers of VNC - IoT

slide-22
SLIDE 22

Dangers of VNC

  • All good and fun untill:
slide-23
SLIDE 23

Dangers of VNC

  • VNC connections open to:
  • Medical devices
  • SCADA systems
  • Factories
  • Homes
slide-24
SLIDE 24

Dangers of VNC

  • VNC:
  • no- or weak authentications
  • unencrypted
slide-25
SLIDE 25

Bro Wishlist

  • What would we want to see from a security perspective:
  • are there RFB servers in the network?
  • from where and when are they accessed, for how long?
  • which software is used?
  • what kind of authentication is used, was it successful?
  • other useful information?
  • Bonus exercise: can we get a screenshot? 😈
slide-26
SLIDE 26

VNC protocol

slide-27
SLIDE 27

VNC protocol

ProtocolVersion Handshake Security Handshake SecurityResult Handshake Client/Server Init messages Frames!

slide-28
SLIDE 28

VNC protocol

ProtocolVersion Handshake Security Handshake SecurityResult Handshake Client/Server Init messages Frames!

slide-29
SLIDE 29

VNC protocol - Identification

Server Client Client Version

Server Version

slide-30
SLIDE 30

VNC protocol - Identification

Server Client Client Version

Server Version

12 byte string “RFB xxx.yyy\n” RFB 003.003 - RFB 003.007 - RFB 003.008

slide-31
SLIDE 31

RFB 002.000 RFB 003.002 RFB 003.003 RFB 003.004 RFB 003.005 RFB 003.006 RFB 003.007 RFB 003.008 RFB 003.010 RFB 003.016 RFB 003.033 RFB 003.039 RFB 003.043 RFB 003.130 RFB 003.236 RFB 003.889 RFB 004.000 RFB 004.001 RFB 005.000 RFB 009.123 RFB 009.221 RFB 009.963 RFB 103.006

Apple Remote Desktop RealVNC Personal RealVNC Enterprise

Source: Y. Klijnsma Identified RFB headers in the wild.

slide-32
SLIDE 32

VNC protocol - Identification

  • Certain version numbers can be attributed to

certain software

slide-33
SLIDE 33

VNC protocol

ProtocolVersion Handshake Security Handshake SecurityResult Handshake Client/Server Init messages Frames!

slide-34
SLIDE 34

VNC protocol security

  • Server sends a list of supported ‘security types’
  • These determine form of authentication

(examples):

  • 1 = No authentication
  • 2 = VNC authentication
  • 30 = Apple Remote Desktop authentication
slide-35
SLIDE 35

VNC protocol - VNC authentication

Server Client

16 byte challenge 16 byte response DES(challenge) with password derived key

slide-36
SLIDE 36

VNC protocol - VNC authentication

  • Custom authentication types possible
  • Found VNC server implementation that does

send username/password in cleartext over wire

  • 😴
slide-37
SLIDE 37

VNC protocol

ProtocolVersion Handshake Security Handshake SecurityResult Handshake Client/Server Init messages Frames!

slide-38
SLIDE 38

VNC protocol - Security result

  • Server always sends an explicit

acknowledgment if authentication succeeded.

  • If not successful: connection aborted
slide-39
SLIDE 39

VNC protocol

ProtocolVersion Handshake Security Handshake SecurityResult Handshake Client/Server Init messages Frames!

slide-40
SLIDE 40

VNC protocol - Init messages

  • Client sends ClientInit message with a

‘shared_flag’

  • Shared flag determines mode of operation:
  • 1 = Allow other connections to remain if

present

  • 0 = Disconnect other connections for

exclusive access

slide-41
SLIDE 41

VNC protocol - Init messages

  • Server sends ServerInitMsg, containing:
  • name of the server
  • width/height of shared screen in pixels
  • 16 bytes of pixel information encoding

information

slide-42
SLIDE 42

VNC protocol

ProtocolVersion Handshake Security Handshake SecurityResult Handshake Client/Server Init messages Frames!

slide-43
SLIDE 43

VNC protocol - frame messages

  • After the initial handshake, the server sends a

complete representation of the server’s screen to the client

  • One should be able to reconstruct a complete

screenshot from the screen using this first message!

slide-44
SLIDE 44

VNC protocol - frame messages

slide-45
SLIDE 45

VNC protocol - frame messages

120x120 1160x960 120x840

slide-46
SLIDE 46

VNC protocol - frame messages

120x120 1160x960 120x840 Compress & Encode

slide-47
SLIDE 47

VNC protocol - frame messages

Header

slide-48
SLIDE 48

VNC protocol - frame messages

  • Complete screen update first!
  • Then: Client and Server can send messages at

will:

  • containing keystrokes, mouse pointer

movements, screen updates.

  • For our purpose too much effort at this stage
slide-49
SLIDE 49

VNC protocol - Recap

ProtocolVersion Handshake Security Handshake SecurityResult Handshake Client/Server Init messages Frames!

slide-50
SLIDE 50

Bro Wishlist

  • What would we want to see from a security perspective:
  • are there RFB servers in the network?
  • from where and when are they accessed, for how long?
  • which software is used?
  • what kind of authentication is used, was it successful?
  • other useful information Server name, screen dimensions?
  • Bonus exercise: can we get a screenshot? 😈
slide-51
SLIDE 51

Dev/test/deploy

slide-52
SLIDE 52

Dev/test/deploy

  • Ingredients for creating a protocol parser:
  • wireshark and loads of sample PCAPs
  • knowledge of BinPac and Bro policy writing
  • knowledge of the protocol (obviously)
slide-53
SLIDE 53

Dev

BinPac (protocol parsing) Scripts Testing

  • Define events to emit
  • Define protocol messages
  • BinPac creates C++ parser

Define DPD to identify streams to process Connect events from parser to log output

Create tests based on pcaps Supply suspected output of your parser

slide-54
SLIDE 54

Dev - where to start

  • documentation on-line
  • learn from existing protocol parsers
  • https://github.com/grigorescu/binpac_quickstart
  • creates some boilerplate code for you to get your parser up

and running

  • bro-dev mailinglist
  • great supportive community!
slide-55
SLIDE 55

Dev - be prepared

  • #1 - No matter how simple the protocol, there's

always a catch

  • #2 - No matter how well your protocol parser is,

someone will always present you with a pcap that doesn't parse

slide-56
SLIDE 56

Dev - be prepared

  • #1 - No matter how simple the protocol, there's

always a catch

slide-57
SLIDE 57
  • Ideally, we would like to have something like this:

BinPac (protocol parsing)

Each message self-descriptive (SMB!)

slide-58
SLIDE 58

Dev

BinPac

slide-59
SLIDE 59

Dev

BinPac

slide-60
SLIDE 60

Dev

  • RFB messages do not contain e.g. a command

identifier, or total size of the message

  • How to interpret a set of bytes depends on the

messages before it

  • rfb-protocol-analyzer.pac implements state

machine

BinPac

slide-61
SLIDE 61

State machine

‘state’ - defines step in our protocol. After successfully parsing a message, ‘state’ gets updated accordingly.

BinPac

slide-62
SLIDE 62

State machine

BinPac Awaiting Server Banner Awaiting Client Banner Awaiting Server Auth Types 3.3 Awaiting Server Auth Types 3.7

3.7 3.3

Finish

... ...

slide-63
SLIDE 63

State machine

BinPac Awaiting Server Banner Awaiting Client Banner Awaiting Server Auth Types 3.3 Awaiting Server Auth Types 3.7

3.7 3.3

Finish

... ...

slide-64
SLIDE 64

Dev - be prepared

  • #2 - No matter how well your protocol parser is,

someone will always present you with a pcap that doesn't parse

slide-65
SLIDE 65

Reality...

BinPac

  • Many different dialects, custom features and

specific implementations hamper parsing

  • E.g. custom authentication protocols
slide-66
SLIDE 66

Dev - events

Logical breakdown

  • f events

Scripts

slide-67
SLIDE 67

Dev - DPD

Scripts

  • Supply DPD signature
slide-68
SLIDE 68

Dev - test

  • Test framework allows you to submit a sample

pcap with expected output for (regression) testing

Testing

slide-69
SLIDE 69

Dev - test

  • Simple test:

Testing

  • Execute:
slide-70
SLIDE 70

Dev

BinPac (protocol parsing) Scripts Testing

  • Deploy!
slide-71
SLIDE 71

Dev - deploy

slide-72
SLIDE 72

Dev - deploy

slide-73
SLIDE 73

Dev - deploy

  • What would we want to see from a security perspective:
  • are there RFB servers in the network?
  • from where and when are they accessed, for how long?
  • which software is used?
  • what kind of authentication is used, was it successful?
  • Server name, screen dimensions?
  • Bonus exercise: can we get a screenshot? 😈
slide-74
SLIDE 74

Dev - deploy

  • Are there RFB servers in the network?
  • bro-cut id.resp_h < rfb.log | sort | uniq
slide-75
SLIDE 75

Dev - deploy

  • From where and when are RFB servers

accessed, for how long?

  • bro-cut -d ts id.orig_h id.resp_h service duration

< conn.log | grep rfb

$ bro-cut -d ts id.orig_h id.resp_h service duration < conn.log | grep rfb 2016-03-27T17:45:51+0200 192.168.2.115 192.168.2.125 rfb 1.775081 2016-03-27T17:45:53+0200 192.168.2.115 192.168.2.125 rfb 2.778796 2016-03-27T17:45:48+0200 192.168.2.115 192.168.2.125 rfb 2.813754

slide-76
SLIDE 76

Dev - deploy

  • Which software is used?
  • bro-cut client_major_version client_minor_version <

rfb.log | sort | uniq -c | sort -nr

  • bro-cut server_major_version server_minor_version <

rfb.log | sort | uniq -c | sort -nr

  • Look for server/client versions: e.g. 3.889 = most likely

Apple Remote Desktop

slide-77
SLIDE 77

Dev - deploy

  • What kind of authentication is used, was it

successful?

  • bro-cut id.resp_h authentication_method auth <

rfb.log

$ bro-cut id.resp_h authentication_method auth < rfb.log 192.168.2.125 VNC T 192.168.2.125 VNC F 192.168.2.125 VNC -

slide-78
SLIDE 78

Dev - deploy

  • What kind of Server name, screen dimensions

are used, was the connection exclusive?

  • bro-cut id.resp_h desktop_name name width

height share_flag < rfb.log

$ bro-cut id.resp_h desktop_name name width height share_flag < rfb.log 192.168.2.125 root's X desktop (martin-VirtualBox:1) 1024 768 T 192.168.2.125 -

  • - -

192.168.2.125 -

  • - -
slide-79
SLIDE 79

Recap

  • We have seen why it is interesting to parse RFB
  • We have seen how RFB works and what

information we can get from parsing the protocol

  • We have seen what steps to take to build and

test a protocol parser

  • We have seen how we can answer our research

questions

slide-80
SLIDE 80

Recap

  • First version of RFB parser commit:
  • Will be in 2.5 release
slide-81
SLIDE 81

Future work

  • Handle different dialects/authentication types/

implementations (pcaps welcome!)

  • TLS over VNC support
  • Generating screenshot files from initial screen

update 😏

  • martin.vanhensbergen@fox-it.com
slide-82
SLIDE 82

Thanks

  • Thanks for listening!