Apache Solr Injection Michael Stepankin @artsploit DEF CON 27 - - PowerPoint PPT Presentation

apache solr injection
SMART_READER_LITE
LIVE PREVIEW

Apache Solr Injection Michael Stepankin @artsploit DEF CON 27 - - PowerPoint PPT Presentation

Apache Solr Injection Michael Stepankin @artsploit DEF CON 27 @whoami Michael Stepankin Security Researcher @ Veracode Web app breaker Works on making Dynamic and Static Code Analysis smarter Penetration tester in the


slide-1
SLIDE 1

Apache Solr Injection

Michael Stepankin @artsploit DEF CON 27

slide-2
SLIDE 2

@whoami – Michael Stepankin

  • Security Researcher @ Veracode
  • Web app breaker
  • Works on making Dynamic and Static Code Analysis smarter
  • Penetration tester in the past
  • Never reported SSL ciphers
slide-3
SLIDE 3

Ones upon a time on bug bounty…

slide-4
SLIDE 4

What is Solr?

  • Solr is the popular, blazing-fast, open source enterprise search

platform built on Apache Lucene

  • Written in Java, open source
  • REST API as a main connector
  • Used by many companies (AT&T, eBay, Netflix, Adobe etc…)

https://lucene.apache.org/solr/

slide-5
SLIDE 5

How does it look like?

slide-6
SLIDE 6

Solr Quick Start

$ ./bin/solr start -e dih //start solr //add some data //search data

slide-7
SLIDE 7

Solr 101: simple query

Requested content-type

slide-8
SLIDE 8

Solr 101: more complex query

Local parameter name (default field) Parser type Collection (‘database’) name Request Handler (select, update, config)

slide-9
SLIDE 9

Solr 101: more complex query

Requested Fields (columns) Subquery for column ‘similar’ Requested response type

slide-10
SLIDE 10

Common Solr Usage in Web App

:

slide-11
SLIDE 11

Solr Parameter Injection (HTTP Query Injection)

:

Browser Solr

/search?q=Apple%26xxx=yyy%23 /solr/db/select?q=Apple&xxx=yyy#&fl=id,name&rows=10

slide-12
SLIDE 12

Solr Parameter Injection: Magic Parameters

GET /solr/db/select?q=Apple&shards=http://127.0.0.1:8984/solr/db&qt=/ config%23&stream.body={"set-property":{"xxx":"yyy"}}&isShard=true

  • shards=http://127.0.0.1:8984/solr/db - allows to forward this request to

the specified url

  • qt=/config%23 – allows to rewrite query
  • stream.body={"set-property":{"xxx":"yyy"}} – treated by Solr as a POST

body

  • isShard=true - needed to prevent body parsing while proxying
slide-13
SLIDE 13

Solr Parameter Injection: Magic Parameters

GET /solr/db/select?q=Apple&shards=http://127.0.0.1:8984/solr/db&qt=/ config%23&stream.body={"set-property":{"xxx":"yyy"}}&isShard=true

slide-14
SLIDE 14

Solr Parameter Injection: collection name leak

slide-15
SLIDE 15

Solr Parameter Injection: update another collection

* The error is thrown after the update is done

slide-16
SLIDE 16

Solr Parameter Injection: query another collection

* We can rename columns in our query to match the original collection

slide-17
SLIDE 17

Solr Parameter Injection: JSON response rewriting

* json.wrf parameter acts like a JSONp callback, May work depending on the app’s JSON parser

slide-18
SLIDE 18

Solr Parameter Injection: XML response poisoning

* ValueAugmenterFactory adds a new field to every returned document

slide-19
SLIDE 19

Solr Parameter Injection: XSS via response poisoning

* Xml Transformer inserts a valid XML fragment in the document

slide-20
SLIDE 20

Solr Local Parameter Injection

:

Browser Solr

/search?q={!dismax+xxx=yyy}Apple /solr/db/select?q={!dismax+xxx=yyy}Apple&fl=id…

slide-21
SLIDE 21

Solr Local parameter injection

  • Known since 2013, but nobody knew how to exploit
  • We can specify only the parser name and local parameters
  • ‘shards’, ‘stream.body‘ are not ‘local’
  • XMLParser is the rescue!:
slide-22
SLIDE 22

Solr Local parameter injection: CVE-2017-12629

  • XMLParser is vulnerable to XXE, allowing to perform SSRF:
  • Therefore, all ‘shards’ magic also works if we can only control the ‘q’ param!
slide-23
SLIDE 23

Wait!

Are you mad telling us about HTTP injection, XXE and (even) XSS? Where is my CALCULATOR!!!???

slide-24
SLIDE 24

Ways to RCE

  • Documentation does not really help
  • But It’s java, so….
  • For sure it has XXEs
  • For sure it has Serialization
  • Indeed it has ScriptEngine()
  • Indeed it even has Runtime.exec()
slide-25
SLIDE 25

CVE-2017-12629 RunExecutableListener RCE

Target versions: 5.5x-5.5.4, 6x-6.6.3, 7x – 7.1 Requirements: None

slide-26
SLIDE 26

CVE-2017-12629 RunExecutableListener via shards

  • (step 1) Add a new query listener
  • (step 2) Perform any update operation

*Tnx Olga Barinova (@_lely___) for help with making it workJ

slide-27
SLIDE 27

CVE-2017-12629 RunExecutableListener via XXE

  • (step 1) Add a new query listener
  • (step 2) Perform any update operation
slide-28
SLIDE 28

CVE-2019-0192 RCE via jmx.serviceUrl

Target versions: 5x – 6x. In v7-8 JMX is ignored Requirements: OOB connection or direct access

slide-29
SLIDE 29

CVE-2019-0192 RCE via jmx.serviceUrl

What happen inside? Leads to un.rmi.transport.StreamRemoteCall#executeCall and then to ObjectInputStream.readObject()

slide-30
SLIDE 30

CVE-2019-0192 RCE via jmx.serviceUrl

1st way to exploit (via deserialization)

  • Start a malicious RMI server serving ROME2 object payload on port 1617
  • Trigger a Solr connection to the malicious RMI server by setting the

jmx.serviceUrl property

  • RMI server responds with a serialized object, triggering RCE on Solr

*Note: ROME gadget chain requires Solr extraction libraries in the classpath

slide-31
SLIDE 31

CVE-2019-0192 RCE via jmx.serviceUrl

slide-32
SLIDE 32

CVE-2019-0192 RCE via jmx.serviceUrl

2nd way to exploit (via JMX)

  • Create an innocent rmiregistry
  • Trigger a Solr connection to the rmiregistry by setting the jmx.serviceUrl
  • property. It will register Solr’s JMX port on our rmiregistry.
slide-33
SLIDE 33

CVE-2019-0192 RCE via jmx.serviceUrl

2nd way to exploit (via JMX)

  • Connect to the opened JMX port and create a malicious MBean
slide-34
SLIDE 34

CVE-2019-0193 DataImportHandler RCE

Target version: 1.3 – 8.2 Requirements: DataImportHandler enabled

slide-35
SLIDE 35

CVE-2019-0193 DataImportHandler RCE

slide-36
SLIDE 36

Example: search.maven.org

slide-37
SLIDE 37

Example: search.maven.org

slide-38
SLIDE 38

Example: search.maven.org

slide-39
SLIDE 39

Example: search.maven.org

slide-40
SLIDE 40

Example: search.maven.org

slide-41
SLIDE 41

Thank you!

F u ll wh ite p a p e r a t: h ttp s ://g ith u b .c o m/v e ra c o d e - re s e a rc h /s o lr-in jectio n