nsc #2 - d1 02 - georgi geshev - your q is my q

59
Labs.mwrinfosecurity.com | © MWR Labs Your Q is my Q NoSuchCon 2014 Paris, France Message Queue Security G. Geshev

Upload: nosuchcon

Post on 12-Jul-2015

467 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 1

Labs.mwrinfosecurity.com | © MWR Labs

Your Q is my Q

NoSuchCon 2014

Paris, France

Message Queue Security

G. Geshev

Page 2: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 2

Introduction

Georgi Geshev

• Security Researcher at MWR Labs

• Research Interests

• Vulnerability Development

• IPv6 Network Reconnaissance

• Message Queues

Page 3: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 3

Agenda

• MQ Concepts

• Attack Surface

• Case Studies

• Attack Scenarios

• Common Issues

• MQ Hardening

Page 4: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 4

Disclaimer

• This is not a talk on new classes of bugs, i.e. none of the

vulnerabilities are MQ specific.

• This is a talk on problems found to be common across

some popular MQ implementations.

Page 5: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 5

MQ Concepts

• Message-oriented Middleware (MOM)

• Asynchronous Message Exchange

• Decoupling

– Space, Time and Synchronization Decoupling

• Publish & Subscribe

– Publishers Create Messages

– Subscribers Consume Messages

– Topic, Content and Type Based Subscriptions

Page 6: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 6

MQ Concepts

Producer Consumer

Broker

Page 7: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 7

MQ Concepts

Producer Consumer

Broker

Page 8: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 8

MQ Concepts

Producer Consumer

Broker

Page 9: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 9

MQ Concepts

Producer Consumer

Broker

Page 10: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 10

MQ Protocols

Page 11: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 11

MQ Protocols

• MQ Transport Protocols

• TCP, UDP, HTTP

Page 12: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 12

MQ Protocols

• MQ Transport Protocols

• TCP, UDP, HTTP

• MQ Application Protocols

Page 13: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 13

MQ Protocols

• MQ Transport Protocols

• TCP, UDP, HTTP

• MQ Application Protocols

• Binary Protocols:

– AMQP (Advanced Message Queuing Protocol)

– MQTT (MQ Telemetry Transport)

– OpenWire

Page 14: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 14

MQ Protocols

• MQ Transport Protocols

• TCP, UDP, HTTP

• MQ Application Protocols

• Binary Protocols:

– AMQP (Advanced Message Queuing Protocol)

– MQTT (MQ Telemetry Transport)

– OpenWire

• ASCII Protocols:

– STOMP (Streaming Text Oriented Messaging Protocol)

– XMPP

Page 15: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 15

MQ Security

• Transport over SSL/TLS

• Authentication and Authorisation Mechanisms:

• Certificates, Kerberos, LDAP, etc.

• Persistent Storage

• SQL Databases

• File Based Databases

• Redundant Brokers

• Clustering

• Broker Networks

Page 16: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 16

Misconfigurations

• Default Administrative Credentials

• Management Interfaces Exposed

• Java Management Extension (JMX)

• Java Remote Method Invocation (RMI)

• Java Debug Wire Protocol (JDWP)

• Default Queues

• Anonymous Access

– Publish

– Subscribe

Page 17: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 17

Demo

• ActiveMQ 5.6.0

• Debian 7.5.0

• Ubuntu 14.04.1

• Default Configuration

• Java Management Extension (JMX)

• Custom script to identify RMI service endpoint via JMX.

• RMI Registry endpoint is only locally exposed.*

• Port forwarding to access the RMI service.

• Deploying and executing a JAR payload.

Page 18: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 18

Case Studies

• Sending Serialised Objects

• Sending System Commands

• Rendering Untrusted Messages in Administrative or

Monitoring Consoles

• Cross-Site Scripting

• Inserting Unsanitised Messages in Databases

• SQL Injection

Page 19: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 19

Attack Scenarios

• Attacker’s Perspective

• Anonymous

• Client

• Broker

• Attacks

• Man-in-the-Middle

• Authentication Bypasses

• Implementation Specific

• DoS

Page 20: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 20

Attack Scenarios

• Attacker’s Perspective

• Anonymous

• Client

• Broker

• Attacks

• Man-in-the-Middle

• Authentication Bypasses

• Implementation Specific

• DoS

Anonymous vs. Client

Page 21: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 21

Attack Scenarios

• Attacker’s Perspective

• Anonymous

• Client

• Broker

• Attacks

• Man-in-the-Middle

• Authentication Bypasses

• Implementation Specific

• DoS

Anonymous vs. Client

Page 22: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 22

Attack Scenarios

• Attacker’s Perspective

• Anonymous

• Client

• Broker

• Attacks

• Man-in-the-Middle

• Authentication Bypasses

• Implementation Specific

• DoS

Anonymous vs. Client

Client vs. Client

Page 23: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 23

Attack Scenarios

• Attacker’s Perspective

• Anonymous

• Client

• Broker

• Attacks

• Man-in-the-Middle

• Authentication Bypasses

• Implementation Specific

• DoS

Anonymous vs. Client

Client vs. Client

Client vs. Broker

Page 24: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 24

Attack Scenarios

• Attacker’s Perspective

• Anonymous

• Client

• Broker

• Attacks

• Man-in-the-Middle

• Authentication Bypasses

• Implementation Specific

• DoS

Anonymous vs. Client

Client vs. Client

Client vs. Broker

Page 25: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 25

Attack Scenarios

• Attacker’s Perspective

• Anonymous

• Client

• Broker

• Attacks

• Man-in-the-Middle

• Authentication Bypasses

• Implementation Specific

• DoS

Anonymous vs. Client

Client vs. Client

Client vs. Broker

Broker vs. Client

Page 26: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 26

Attack Scenarios

• Attacker’s Perspective

• Anonymous

• Client

• Broker

• Attacks

• Man-in-the-Middle

• Authentication Bypasses

• Implementation Specific

• DoS

Anonymous vs. Client

Client vs. Client

Client vs. Broker

Broker vs. Client

Broker vs. Broker

Page 27: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 27

Bug Hunting

Page 28: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 28

Bug Hunting

• Source Code Audit

• Pattern Based

Page 29: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 29

Bug Hunting

• Source Code Audit

• Pattern Based

• Fuzzing

• Stateless

– Radamsa

• Stateful

– MITM Fuzzing

• Patching

• Traffic Generation

• Unit Tests

• Performance Harness Tools

• Code Samples

Page 30: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 30

Bug Hunting

• Source Code Audit

• Pattern Based

• Fuzzing

• Stateless

– Radamsa

• Stateful

– MITM Fuzzing

• Patching

• Outdated Libraries

• e.g. Vulnerable XStream in ActiveMQ < 5.10.0

• Traffic Generation

• Unit Tests

• Performance Harness Tools

• Code Samples

Page 31: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 31

AMQP State Machine

Page 32: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 32

LDAP Wildcard Interpretation

Attacker Broker

LDAP Server (Authenticator)

Credentials

tommy foobar

ronly ronly

client secret

Page 33: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 33

LDAP Wildcard Interpretation

Attacker Broker

LDAP Server (Authenticator)

Username: * Password: foobar Message Content

Credentials

tommy foobar

ronly ronly

client secret

Page 34: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 34

LDAP Wildcard Interpretation

Attacker Broker

LDAP Server (Authenticator)

B: Does ‘*’ user exist?

Credentials

tommy foobar

ronly ronly

client secret

Page 35: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 35

LDAP Wildcard Interpretation

Attacker Broker

LDAP Server (Authenticator)

A: Yes, user ‘tommy’ exists.

Credentials

tommy foobar

ronly ronly

client secret

Page 36: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 36

LDAP Wildcard Interpretation

Attacker Broker

LDAP Server (Authenticator)

B: Authenticate with ‘tommy:foobar’?

Credentials

tommy foobar

ronly ronly

client secret

Page 37: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 37

LDAP Wildcard Interpretation

Attacker Broker

LDAP Server (Authenticator)

A: Authenticated.

Credentials

tommy foobar

ronly ronly

client secret

Page 38: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 38

XML External Entities Processing

Attacker Broker

Page 39: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 39

XML External Entities Processing

Attacker Broker

Malicious

XML

Message

1. Adversary enqueues an XML message which contains XML external entities.

Page 40: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 40

XML External Entities Processing

Attacker Broker

1. Adversary enqueues an XML message which contains XML external entities.

Page 41: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 41

XML External Entities Processing

Attacker Broker

1. Adversary enqueues an XML message which contains XML external entities.

2. Then requests dequeuing an XML message which matches a criteria

expressed with XPath/XQuery based selector.

XPath /

XQuery

Selector

Page 42: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 42

XML External Entities Processing

Attacker Broker

1. Adversary enqueues an XML message which contains XML external entities.

2. Then requests dequeuing an XML message which matches a criteria

expressed with XPath/XQuery based selector.

Page 43: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 43

XML External Entities Processing

Attacker Broker

1. Adversary enqueues an XML message which contains XML external entities.

2. Then requests dequeuing an XML message which matches a criteria

expressed with XPath/XQuery based selector.

3. The broker will evaluate the XPath expression and attempt to match it

against the messages in the queue. This will cause the broker to resolve any

external entity references.

Page 44: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 44

Demo (1)

• Anonymous vs. Client / Broker

• Authentication Bypass*

Page 45: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 45

Demo (2)

• Client vs. Broker

• XML External Entity Processing

Page 46: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 46

Common Vulnerabilities

• XML External Entities Processing

• Brokers: 6

– Java, Python and C++

• Clients: 2*

• LDAP Wildcard Interpretation Bug

• Brokers: 3

– Java

• Unserialisation of Untrusted Data

• Brokers: 2*

– Java and Python

Page 47: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 47

Hardening

MQ

Applications

Page 48: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 48

Hardening

MQ

• Limit the number of transport

and application protocols.

• One application protocol over

one (SSL) transport.

Applications

Page 49: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 49

Hardening

MQ

• Limit the number of transport

and application protocols.

• One application protocol over

one (SSL) transport.

• Remove default accounts.

Applications

Page 50: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 50

Hardening

MQ

• Limit the number of transport

and application protocols.

• One application protocol over

one (SSL) transport.

• Remove default accounts.

• Disable JMX/RMI/JDWP/etc.*

Applications

Page 51: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 51

Hardening

MQ

• Limit the number of transport

and application protocols.

• One application protocol over

one (SSL) transport.

• Remove default accounts.

• Disable JMX/RMI/JDWP/etc.*

• Separate administration VLAN.

Applications

Page 52: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 52

Hardening

MQ

• Limit the number of transport

and application protocols.

• One application protocol over

one (SSL) transport.

• Remove default accounts.

• Disable JMX/RMI/JDWP/etc.*

• Separate administration VLAN.

• Disable anonymous client access.

Applications

Page 53: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 53

Hardening

MQ

• Limit the number of transport

and application protocols.

• One application protocol over

one (SSL) transport.

• Remove default accounts.

• Disable JMX/RMI/JDWP/etc.*

• Separate administration VLAN.

• Disable anonymous client access.

• Whitelist explicit P&S client IP

addresses.

Applications

Page 54: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 54

Hardening

MQ

• Limit the number of transport

and application protocols.

• One application protocol over

one (SSL) transport.

• Remove default accounts.

• Disable JMX/RMI/JDWP/etc.*

• Separate administration VLAN.

• Disable anonymous client access.

• Whitelist explicit P&S client IP

addresses.

Applications

• Perform validation on

received messages. Do not

assume trusted sources.

Page 55: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 55

Hardening

MQ

• Limit the number of transport

and application protocols.

• One application protocol over

one (SSL) transport.

• Remove default accounts.

• Disable JMX/RMI/JDWP/etc.*

• Separate administration VLAN.

• Disable anonymous client access.

• Whitelist explicit P&S client IP

addresses.

Applications

• Perform validation on

received messages. Do not

assume trusted sources.

• Enable integrity checking.

Ideally, authenticated

encryption.

Page 56: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 56

Hardening

MQ

• Limit the number of transport

and application protocols.

• One application protocol over

one (SSL) transport.

• Remove default accounts.

• Disable JMX/RMI/JDWP/etc.*

• Separate administration VLAN.

• Disable anonymous client access.

• Whitelist explicit P&S client IP

addresses.

Applications

• Perform validation on

received messages. Do not

assume trusted sources.

• Enable integrity checking.

Ideally, authenticated

encryption.

• Whitelist objects if

unserialising from

messages.

Page 57: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 57

Acknowledgments

• MWR Labs

• Red Hat and Apache’s Security Teams

• NoSuchCon Organisers

Page 58: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 58

References

• XML Out-of-Band Data Retrieval (BlackHat Europe 2013)

• Timur Yunusov (@a66at)

• Alexey Osipov (@Gi_sUngiven)

• XML External Entities Out-of-Band Exploitation

• Ivan Novikov (@d0znpp)

• Exploiting JMX RMI

• Braden Thomas

Page 59: NSC #2 - D1 02 - Georgi Geshev - Your Q is my Q

Labs.mwrinfosecurity.com | © MWR Labs 59

Questions

• Feedback

• @munmap

• georgi.geshev @ mwrinfosecurity . com