Cache on Delivery

55
Cache on delivery mining memcached [email protected]

description

Presentation by Marco Slaviero at BlackHat USA in 2010. This presentation is about mining information from memchached. The presentation begins with a brief introduction to memcached. go-derper.rb, a tool developed by the presenter for hacking memchaced servers is introduced and a few memchached mining examples are given. The presentation ends with a brief discussion on serialized objects exposed in the chache.

Transcript of Cache on Delivery

Page 2: Cache on Delivery
Page 3: Cache on Delivery

• Large percentage of data remains relatively constant

• Wikipedia page contents

• Youtube video links

• FB Profile data

• Poorly designed solutions regenerate data on each request

• Don’t regenerate, rather regurgitate

The need for caching

Page 4: Cache on Delivery

• Large percentage of data remains relatively constant

• Wikipedia page contents

• Youtube video links

• FB Profile data

• Poorly designed solutions regenerate data on each request

• Don’t regenerate, rather regurgitate

The need for caching

Page 5: Cache on Delivery

Memcached

• memcached.org

• Written for LJ (2003) by Brad Fitzpatrick

• Non-persistent network-based KV store

• Why do we care? Mom&pop don’t need the cache.

Page 6: Cache on Delivery

Memcached

• memcached.org

• Written for LJ (2003) by Brad Fitzpatrick

• Non-persistent network-based KV store

• Why do we care? Mom&pop don’t need the cache.

Page 7: Cache on Delivery

Basic KV

• Slabs are fixed size

• Dst slab determined by value size

• Users don’t care about slabs

• Miners care about slabs

Page 8: Cache on Delivery

Trivial protocol

• set• get• stats

• ...• ????

Binary and UDP protocols also exist, these were not touched.

• ASCII-based• Long-lived• Tiny command set

Page 9: Cache on Delivery

Trivial protocol

• set• get• stats

• ...• ????

Binary and UDP protocols also exist, these were not touched.

• ASCII-based• Long-lived• Tiny command set

Page 10: Cache on Delivery

Trivial protocol

• set• get• stats

• ...• ????

Binary and UDP protocols also exist, these were not touched.

• ASCII-based• Long-lived• Tiny command set

Page 11: Cache on Delivery

Trivial protocol

• set• get• stats

• ...• ????

Binary and UDP protocols also exist, these were not touched.

• ASCII-based• Long-lived• Tiny command set

Page 12: Cache on Delivery

Trivial protocol

• set• get• stats

• ...• ????

Binary and UDP protocols also exist, these were not touched.

• ASCII-based• Long-lived• Tiny command set

Page 13: Cache on Delivery

1998

• Blank ‘sa’

• Anonymous ftp

• system/manager

Page 14: Cache on Delivery

Goals

• Connect to memcached

• Find all slabs

• Retrieve keynames from each slab

• Retrieve each key

Page 15: Cache on Delivery

Lies, damn lies, and stats

• stats cmd has subcmds

• items

• slabs

• ...

This gets us the slabs_ids

stats slabsSTAT 1:chunk_size 80<...>STAT 2:chunk_size 104<...>STAT 3:chunk_size 136<...>STAT 4:chunk_size 176<...>STAT 6:chunk_size 280<...>STAT 8:chunk_size 440<...>STAT 9:chunk_size 552<...>STAT 9:cas_badval 0STAT active_slabs 7

Page 16: Cache on Delivery

Retrieving key names

Rely on two {poorly|un}documented features

Page 17: Cache on Delivery

Retrieving key names

Feature #1:

Remote enabling of debug mode

Page 18: Cache on Delivery

Retrieving key names

Feature #2:

“stats cachedump”

Page 19: Cache on Delivery

Retrieving key names

Feature #2:

“stats cachedump”

Page 20: Cache on Delivery

Retrieving key names

Feature #2:

“stats cachedump”

Slabs IDSlabs ID

Page 21: Cache on Delivery

Retrieving key names

Feature #2:

“stats cachedump”

Key limitKey limit

Page 22: Cache on Delivery

Retrieving key names

Feature #2:

“stats cachedump”

Key listKey list

Page 23: Cache on Delivery

Retrieving key names

Feature #2:

“stats cachedump”

This gets us key names

Page 24: Cache on Delivery

And this gets us?• No need for complex hacks. Memcached serves up

all its data for us.

• What to do in an exposed cache?

• Mine

• SQLi is too hard for me

• Overwrite

• Client-side

• Server-side

Page 25: Cache on Delivery

Mining the cache

• go-derper.rb – memcached miner

• Retrieves up to k keys from each slab and their contents, store on disk

• Applies regexes and filters matches in a hits file

• Supports easy overwriting of cache entries

• [demo]

Page 26: Cache on Delivery

Two issues

Page 27: Cache on Delivery

Two issues

• Finding caches

• Again with the simple approach

• Pick a cloud network, scan for memcacheds on port 11211 with a mod’ed .nse

Page 28: Cache on Delivery

Two issues

http://www.rhythm.com/~keith/autoStereoGrams/vortexas.gif

• Linking apps to caches

• Who’s %$!#ing cache is this?

• Cached high scores suck. Where’s the good stuff?

• Is it live?

Page 29: Cache on Delivery

Results #1

IPs scanned 2^16# of caches found 229Retrieved Items 7.3GBAverage uptime ~50days

Total bandwidth used 9PBTotal entry count 288 millionTotal Bytes stored 136TB

Highest bandwidth 247TBHighest entry count 133 millionHighest Bytes Stored 19.3GB

Page 30: Cache on Delivery

Results #2

• HTML

• JavaScript

• Data

• Email

• Passwords (clear-text, crypt’ed, MD5)

• Objects found

• Serialized Java

• Pickled Python

• Ruby ActiveRecord

• .Net Object

• JSON

Page 31: Cache on Delivery

Globworld

Page 32: Cache on Delivery

Globworld

Page 33: Cache on Delivery

Globworld

Page 34: Cache on Delivery

Globworld

Page 35: Cache on Delivery

Gowalla

Page 36: Cache on Delivery

Gowalla

Page 37: Cache on Delivery

Gowalla

Page 38: Cache on Delivery

Gowalla

Page 39: Cache on Delivery

Gowalla

Page 40: Cache on Delivery

Gowalla

Page 41: Cache on Delivery

Bit.ly Pro

Page 42: Cache on Delivery

Bit.ly Pro

Page 43: Cache on Delivery

Bit.ly Pro

Page 44: Cache on Delivery

PBS

Page 45: Cache on Delivery

PBS

Page 46: Cache on Delivery

PBS

Page 47: Cache on Delivery

PBS

Page 48: Cache on Delivery

Sidebar: serialized objs

• Python’s pickle intentionally insecure

• But they’re exposed!

• Pickle shellcode

cossystem(S'echo hostname'tR.

• [demo]

Page 49: Cache on Delivery
Page 50: Cache on Delivery
Page 51: Cache on Delivery

Sidebar: serialized objs

• Python’s pickle intentionally insecure

• But they’re exposed!

• Pickle shellcode

cossystem(S'echo hostname'tR.

• [demo]

Page 52: Cache on Delivery

Fixes?• FW. FW. FW. FW. FW. FW. FW. FW. FW. FW. FW. FW.

FW. FW. FW. FW. FW. FW. FW. FW. FW. FW. FW. FW. FW. FW. FW. FW. FW. FW. FW. FW. FW. FW. FW. FW. (VPC)

• Hack code to disable stats facility (but doesn’t prevent key brute-force)

• Hack code to disable remote enabling of debug features

• Switch to SASL

• Requires binary protocol

• Not supported by a number of memcached libs

• Salt your passwords with a proper scheme (PHK’s MD5 or Bcrypt)

• Also, FW.

Page 53: Cache on Delivery

Random thoughts

• This can’t be new

• Inject tracker images / strings

• Trace Refers / hit Google

• Key guessing or prediction

• Your data ends up in places you never expected.

Page 54: Cache on Delivery

Places to keep looking

• Improve data detection/sifting/filtering

• Spread the search past a single provider

• Caching providers (?!?!)

• Other cache software

• Other infrastructure software