Exploiting NoSQL Like Never Before - PowerPoint PPT Presentation

1 / 78
About This Presentation
Title:

Exploiting NoSQL Like Never Before

Description:

About Me. Independent Security Researcher. Member _at_OpenSecurity. Currently Pursuing My Bachelors Degree . Spoken _at_ a couple of Conferences. Opensecurity a community ... – PowerPoint PPT presentation

Number of Views:158
Avg rating:3.0/5.0
Slides: 79
Provided by: isr46
Learn more at: http://is-ra.org
Category:

less

Transcript and Presenter's Notes

Title: Exploiting NoSQL Like Never Before


1
Exploiting NoSQL Like Never Before
  • c0c0n2014

2
About Me
  • Independent Security Researcher
  • Member _at_ OpenSecurity
  • Currently Pursuing My Bachelors Degree
  • Spoken _at_ a couple of Conferences

3
Agenda
  • More Emphasis Given on the Server-Client and
    Server Management Consoles
  • Pentesting Scenarios are given more importance.
  • We will not deal with Memory Related Bugs or
    issues.
  • Demos

4
INTRO TO NOSQL
5
Key Takeovers
6
Mainly 4 types
7
NoSQL Security
8
Why Developers Need to Worry ?
9
(No Transcript)
10
You Will Love this Part ?
11
ABUSING API CALLS
12
(No Transcript)
13
MongoDB
14
Mongo Trivia
15
Mongo Architecture
16
Mongo Client
Mongo Client
Mongo Client
Mongo Server
17
Attackers Perspective
Mongo Client
Mongo Client
Mongo Client
Sniffing,Enumeration,JS Injection,DOS
Mongo Server
18
JS Attack Surface
19
Issues
20
Some Useful Mongo Commands
21
Useful Commands for us
22
(No Transcript)
23
(No Transcript)
24
Saving JavaScript
25
Post Exploitation Phase
  • Allows the attacker to write JavaScript functions
    and save them
  • Can use for further attacks when needed.
  • db.system.js.save(
  • _id c0c0n2014ams" ,
  • value function (x, y) return x y
  • )
  • db.loadServerScripts()

26
Injecting JavaScript
27
Reference to DB in Mongo
  • Mongo Functions get to refer the db object and
    its main functions
  • An attacker who finds an Injection point could
    abuse this.
  • Found in Versions 2.2 or less
  • Mongo Patched for versions above.
  • Does JS Injection end here?

28
Timing Based Checks
  • Application can be tested for time based attacks
  • Mongo Shell Supports most of JavaScript functions
  • function() return sleep(500) would render the
    application response delayed by 5sec.
  • Module added to NoSQL framework while testing for
    JS Injection attacks

29
THIS Pointer Reference
  • Although mongo blocks reference to the db has
    ended
  • Attacker could use this pointer to return objects
    and dumping as always

30
What if THIS is Blocked? Version to Rescue
  • Version command by default binds to mongo
    instances defined functions
  • So if an admin blocks the this pointer
  • function()return this
  • Function()return version or function()return
    version())
  • Scenario useful when developer uses where to
    evaluate js code.

Blocked
31
Mongo With PHP
32
Vulnerable APP DEMO
33
Resource Exhaustion
34
CouchDB
35
CouchDB Architecture
36
(No Transcript)
37
Couch Architecture
Backend CouchDB
Couch FUTIL Interface
Administrator
38
CouchDBAttacker Perspective
Backend CouchDB
XSS,CSRF,Sniffing
Couch FUTIL Interface
Administrator
39
Key Features
40
Attack Surface
41
Vulnerabilities
42
Addressing Auth Cookie
43
PHP on Couch Driver
44
(No Transcript)
45
(No Transcript)
46
Vulnerable APP DEMO
47
Redis
48
Redis Architecture
49
(No Transcript)
50
Key Features
  • Key Value storage engine.
  • Contains Redis Server and Client
  • Driven By a Config File
  • Documentation is Laugh in a Park
  • Redis supports five data structures
  • strings, hashes, lists, sets and ordered sets.

51
Attacks Discussed
  • Bruteforce Redis Passwords
  • Denial of Service on the FLY.
  • Command Killing
  • Config Rewrite
  • Arbitrary File Rewrite
  • Blind File Enumeration (usefull in pentests)

52
Redis Version
  • Redis Version 2.6
  • No Support For Scripting.
  • Redis Introduced version 2.8
  • Added Ability for LUA Scripts

53
Did We Just Say Scripting ?
54
Welcome to Redis LUA Script Engine and Basics
  • Redis uses LUA to manage scripts
  • LUA engine is properly sandboxed and offers
    enough security
  • Global variables protection
  • Scripts are Executed using eval (Available from
    Redis 2.6)

55
  • Limited number of available of Available
    Libraries for Use
  • base lib.
  • table lib.
  • string lib.
  • math lib.
  • debug lib.
  • cjson lib.
  • cmsgpack lib.

56
Key Points
  • EVAL and EVALSHA are used to evaluate scripts
    using the Lua interpreter built into Redis.
  • SCRIPT KILL,LISTS,EXISTS
  • Important NB When a script is running no other
    functions can be accessed or any operations can
    be performed

57
Sample Lua One Line DOS
  • redis-cli eval "(cat test.lua)" 0
  • test.lua

58
Commands Disabled By an Attacker
  • rename-command API Call Used
  • Sample Command
  • rename-command CONFIG l33tshit
  • rename-command CONFIG "
  • Disables the command completely

59
Arbitrary File Rewrite
  • CONFIG GET
  • Gives the Current set of Configuration
  • CONFIG SET
  • Sets the configuration of the default command
  • CONFIG SET dir /var/www

60
File Name Enumeration
  • Restricted Environment
  • Allows to use dofile (open file in lua scripting)
  • Although file doesnt open gives the file or
    directory exists or not
  • eval "dofile('/var/www')" 0
  • Directory Exists but cant open file
  • eval "dofile('/var/wwws')" 0
  • No such directory exists

61
(No Transcript)
62
Cassandra
63
Key Takeaways
  • Written in Java
  • Main point Store huge datasets in "almost" SQL
  • Protocol CQL3 Thrift
  • CQL3 is very similar SQL, but with some
    limitations that come from the scalability (most
    notably no JOINs, no aggregate functions.)
  • Runs on Port 9160

64
Sad Facts ?
  • No OR
  • No UNION
  • No subrequests
  • Terms must be indexed
  • Primary key can only be queried for

65
Security Issues
  • Cassandra model Keyspace (database)
    ColumnFamily gt Data
  • CQL injection on Web Apps
  • Shell Commands can be useful to attacker(during
    privilege escalation).
  • SOURCE command
  • Reads the contents of the file
  • Database Enumeration and Dumping using NoSQL
    Exploitation Framework

66
(No Transcript)
67
NoSQL DBs Never End!! More Research Needed
  • Ne04j,Memcache,Riak are under scanners(Some
    Discussed Vulnerabilities applies to those also)
  • Support for Neo4j,Memcache and Riak soon to be
    added
  • Memory Leaks and Overflows on the Rise
  • An excellent address to Ne04j security issue was
    written recently
  • Linkhttp//blog.scrt.ch/2014/05/09/neo4j-enter-th
    e-graphdb/

68
Is Automation Needed?
  • Do We have a framework ?

69
NoSQL Exploitation Framework
70
Key Points
71
Key Features
  • Support for Mongo,Couch,Redis,H-Base and
    Cassandra
  • Support for
  • NoSQL Run Web Applications
  • Tests for JavaScript Attacks
  • Mongo DB Attacks
  • Couch PHP Driver Attack Vectors
  • Multithreaded Mass IP List Scanner

72
And the List Continues
  • Database Cloning Feature
  • Brute force Dictionary attacks
  • Post Exploitation Module Integrated
  • Shodan IP List Grabber
  • Sniffing DB credentials and cookies
  • Added More Payload List

73
Future Updates
  • Updated Cassandra and HBase attacks
  • Resource Exhaustion
  • Support for Riak,Memcache and Ne04j on its way.
  • More Stable (Bug Less ?)

74
(No Transcript)
75
Bugs or Contribute
  • Official Mailing List feedback_at_nosqlproject.com
  • Contribute By pulling from
  • github.com/torque59/Nosql-Exploitation-Framework.

76
References
  • http//kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-
    vs-redis

77
Thank You
  • Facebook francis.alexander.33
  • Twitter _at_torque59
  • Github torque59
  • LinkedInin.linkedin.com/in/francisalexander/

78
Questions
Write a Comment
User Comments (0)
About PowerShow.com