SlideShare une entreprise Scribd logo
1  sur  47
Attacking MongoDB



               Firstov Mihail
What is it?

 MongoDB — is an open source document-oriented database system.

                         Features :

 1. Ad hoc queries.

 2. Indexing

 3. Replication

 4. Load balancing

 5. File storage

 6. Aggregation

 7. Server-side JavaScript execution

 8. Capped collections
Inside mongo source code

./mongod — Server in C++


                                                    ./mongo – official client in
                                                    C++ and JS

                           There are a lot of drivers for different
                           program languages:
                                         C
                                         C++
                                         Java
                                         Javascript
                                         .NET (C# F#, PowerShell,
                                           etc)
                                         Node.js
                                         Perl
                                         PHP
                                         Python
                                         Ruby
                                         Scala
Who use mongoDB
      List of some big companies that use mongoDB:

 1.   SAP

 2.   SourceForge (hosting for open source projects)

 3.   The New York Times

 4.   GitHub (social coding project)

 5.   Foursquare

 6.   Yandex
WTF is RESTful?


       A RESTful web service (also called a RESTful web
       API) is a web service implemented using HTTP and
       the principles of REST. It is a collection of
       resources, with four defined aspects
How I can discover it?
Default port is «28017».

If server was started without “—rest”, you can see this:
How I can discover it?
What kind of vulns are there?

   Execution of arbitrary code server JS

   Stored XSS in mongoDB log

   Stored XSS in queries journal

   Cross Site Request Forgery




                          Our SSJS code
Attack

                1) Send “<script>” with our javascript code
                                                                 Site with
                                                                 mongoDB
                                                                 driver support
 Hacker




                                                                                  Admin’s browser




     Hacker’s
     Server
                                                              MongoDB

                                                              --REST
Attack

                1) Send “<script>” with our javascript code
                                                                                  Site with
                                                                                  mongoDB
                                                                                  driver support
 Hacker




                                                                                                   Admin’s browser




                                                              2) Inject our script in
                                                              REST interface




     Hacker’s
     Server
                                                                             MongoDB

                                                                             --REST
Attack

                1) Send “<script>” with our javascript code
                                                                                  Site with
                                                                                  mongoDB
                                                                                  driver support
 Hacker




                                                                                                      Admin’s browser




                                                              2) Inject our script in
                                                              REST interface




     Hacker’s
     Server                                                                                        3) Exec our js-code in
                                                                             MongoDB               admin’s browser
                                                                             --REST
Attack

                  1) Send “<script>” with our javascript code
                                                                                    Site with
                                                                                    mongoDB
                                                                                    driver support
  Hacker




4) Send SSJS
command to                                                                                              Admin’s browser
our script



                                                                2) Inject our script in
                                                                REST interface




       Hacker’s
       Server                                                                                        3) Exec our js-code in
                                                                               MongoDB               admin’s browser
                                                                               --REST
Attack

                  1) Send “<script>” with our javascript code
                                                                                      Site with
                                                                                      mongoDB
                                                                                      driver support
  Hacker




4) Send SSJS
command to                                                                                                Admin’s browser
our script



                                                                  2) Inject our script in
                                                                  REST interface


                            5) Wait until admin’s browser check
                            our server for the new commands
                            (via JSONP)


       Hacker’s
       Server                                                                                          3) Exec our js-code in
                                                                                 MongoDB               admin’s browser
                                                                                 --REST
Attack

                  1) Send “<script>” with our javascript code
                                                                                      Site with
                                                                                      mongoDB
                                                                                      driver support
  Hacker




4) Send SSJS
command to                                                                                                       Admin’s browser
our script



                                                                  2) Inject our script in
                                                                  REST interface            6) Our command gets executed

                            5) Wait until admin’s browser check
                            our server for the new commands
                            (via JSONP)


       Hacker’s
       Server                                                                                                 3) Exec our js-code in
                                                                                 MongoDB                      admin’s browser
                                                                                 --REST
Attack

                  1) Send “<script>” with our javascript code
                                                                                       Site with
                                                                                       mongoDB
                                                                                       driver support
  Hacker




4) Send SSJS
command to                                                                                                        Admin’s browser
our script                                                        7) Send answer to our sniffer



                                                                   2) Inject our script in
                                                                   REST interface            6) Our command gets executed

                            5) Wait until admin’s browser check
                            our server for the new commands
                            (via JSONP)


       Hacker’s
       Server                                                                                                  3) Exec our js-code in
                                                                                  MongoDB                      admin’s browser
                                                                                  --REST
Attack

                  1) Send “<script>” with our javascript code
                                                                                        Site with
                                                                                        mongoDB
                                                                                        driver support
  Hacker




4) Send SSJS
command to 8) Print result                                                                                         Admin’s browser
our script   of executed                                           7) Send answer to our sniffer
             command


                                                                    2) Inject our script in
                                                                    REST interface            6) Our command gets executed

                             5) Wait until admin’s browser check
                             our server for the new commands
                             (via JSONP)


       Hacker’s
       Server                                                                                                   3) Exec our js-code in
                                                                                   MongoDB                      admin’s browser
                                                                                   --REST
Video
Where we can find it?
Stable CRASH

There are a lot of concepts of DoS attacks:
Interesting features

    Ls, cat and other admin functions work only with mongoDb console client.

    NativeHelper function helps you with system commands:




    You can get data in text/plain by reading db-files of mongoDB with any text editor.
Network interaction

Adding user:

                      Decrypted salt:




Source Code:
Network interaction

Captured packets:




All your data are belong to us:
Network interaction

Algorithm for sniff and brute force password :
   Sniff some packets                       Read string
   with mongoDB data                        from
                                            dictionary
                                                           key2 = md5(nonce + user +
                                                           md5(user + ":mongo:" + passw)),
                                                           where “passw” is string from dict
                    Get key, nonce, login
                    from this packet




        Look for auth                                            key == key2                    print user:passwd
        packet


                                                   false
                                                                                         true
                               found

                                                                                                Exit
 Not found
Сетевое взаимодействие
Network interaction. MiTM attack


         1. Authorization
         query
                                     mongoDB


 admin




                            Hacker
Network interaction. MiTM attack


         1. Authorization
         query
                                                        mongoDB


 admin               2. Return special nonce
                     using which rainbow
                     tables were generated




                                               Hacker
Network interaction. MiTM attack


         1. Authorization
         query
                                                         mongoDB


 admin                2. Return special nonce
                      using which rainbow
                      tables were generated




                                                Hacker

         3. Client sends to us
         “key” and “login”
Network interaction. MiTM attack


                                                         4. Brute Force
         1. Authorization
                                                         password using
         query
                                                         pre-generated        mongoDB
                                                         rainbow tables for
                                                         this nonce
 admin                2. Return special nonce
                      using which rainbow
                      tables were generated




                                                Hacker

         3. Client sends to us
         “key” and “login”
Network interaction. MiTM attack


                                                         4. Brute Force
         1. Authorization
                                                         password using
         query
                                                         pre-generated               mongoDB
                                                         rainbow tables for
                                                         this nonce
 admin                2. Return special nonce
                      using which rainbow
                      tables were generated



                                                             5. Successfully login


                                                Hacker

         3. Client sends to us
         “key” and “login”
WTF is BSON?

What is it?                          Data types:

 BSON is a computer data                 string
 interchange format used mainly as       int
 a data storage and network              double
 transfer format in the MongoDB          DateTime
 database. The name "BSON" is            byte[]
 based on the term JSON and              bool
 stands for "Binary JSON".               null
                                         BsonObject
                                         BsonObject[]
   Example?
Overwriting variables

Some table with 2 documents:



Our query to database:


Injecting BSON document, and overwriting “isadmin” value:




Testing:
Reading memory
Exploit:
                 Length



In action:
Reading memory

In action:
Features of some programming languages




                      Ruby on Rails


                                nodejs


                                         PHP
Features of some programming languages




                Ruby on Rails
Features of some programming languages

Mass assignment in Ruby on Rails:
Features of some programming languages

Mass assignment in Ruby on Rails:
Features of some programming languages




                   NodeJS
Features of some programming languages

JSON injection в NodeJS + MongoDB:
                                            SEND
                                             SEND

        VULNERABLE SOURCE CODE:
         VULNERABLE SOURCE CODE:


                                     RESULT QUERY:
                                      RESULT QUERY:




                                                      Хакер 02/12 (157)
Features of some programming languages




                      PHP
Features of some programming languages

 Types of vulnerabilities:

    Bypass authorization via Array in php driver.

    Injecting SSJS code.

    Blind SSJS injecting, Time-based
Features of some programming languages

 As you know, php processes data from GPC as Array:


  password[$ne]=parol1




 There is find() function in the official driver for php:
Features of some programming languages


 And we got this query to mongoDB collection:




 With these techniques you can bypass authorization:
Features of some programming languages

 Injecting in SSJS.

 For example, we have this vulnerable code:
 $q = “function() { var loginn = ‘$login’; var passs = ‘$pass’; db.members.insert({id : 2,
 login : loginn, pass : passs}); }”;
 $db->execute($q);
 /

 We can see our login, id and pass in answer

 Trying to inject in SSJS query:




 As you can see, we rewrite “login” value by db.version() value
Features of some programming languages

 Sometimes we can’t see answer from our SSJS code.

 For this situations we can use Time-Based technique:




 A special script was written for this task.
NoSQL-injection Cheat Sheet


   db.getName() – Get current DB name

   db.members.count() – Get number of documents in the collection

   db.members.validate({ full : true}) – Get ALL information about this
    collection

   db.members.stats() – Get information about this collection

   db.members.remove() – remove all documents from current collection

   db.members.find().skip(0).limit(1) – Get documents from DB (Change only
    number in skip() function)

   db.getMongo().getDBNames().toString() – Get the list of all DBs

   db.members.find()[0][‘pass’] – Get “pass” value from current collection
Thanks!




        Firstov Mikhail
    mfirstov@ptsecurity.ru

Contenu connexe

Tendances

Webinar slides: MySQL & MariaDB load balancing with ProxySQL & ClusterControl...
Webinar slides: MySQL & MariaDB load balancing with ProxySQL & ClusterControl...Webinar slides: MySQL & MariaDB load balancing with ProxySQL & ClusterControl...
Webinar slides: MySQL & MariaDB load balancing with ProxySQL & ClusterControl...
Severalnines
 
Practicing Continuous Deployment
Practicing Continuous DeploymentPracticing Continuous Deployment
Practicing Continuous Deployment
zeeg
 
ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016
Derek Downey
 
События, шины и интеграция данных в непростом мире микросервисов / Валентин Г...
События, шины и интеграция данных в непростом мире микросервисов / Валентин Г...События, шины и интеграция данных в непростом мире микросервисов / Валентин Г...
События, шины и интеграция данных в непростом мире микросервисов / Валентин Г...
Ontico
 
Node.js, toy or power tool?
Node.js, toy or power tool?Node.js, toy or power tool?
Node.js, toy or power tool?
Ovidiu Dimulescu
 
Deploying Plack Web Applications: OSCON 2011
Deploying Plack Web Applications: OSCON 2011Deploying Plack Web Applications: OSCON 2011
Deploying Plack Web Applications: OSCON 2011
Tatsuhiko Miyagawa
 

Tendances (20)

Nginx Internals
Nginx InternalsNginx Internals
Nginx Internals
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
Nginx dhruba mandal
Nginx dhruba mandalNginx dhruba mandal
Nginx dhruba mandal
 
Webinar slides: MySQL & MariaDB load balancing with ProxySQL & ClusterControl...
Webinar slides: MySQL & MariaDB load balancing with ProxySQL & ClusterControl...Webinar slides: MySQL & MariaDB load balancing with ProxySQL & ClusterControl...
Webinar slides: MySQL & MariaDB load balancing with ProxySQL & ClusterControl...
 
Amazed by aws 1st session
Amazed by aws 1st sessionAmazed by aws 1st session
Amazed by aws 1st session
 
Building Client-Side Attacks with HTML5 Features
Building Client-Side Attacks with HTML5 FeaturesBuilding Client-Side Attacks with HTML5 Features
Building Client-Side Attacks with HTML5 Features
 
Practicing Continuous Deployment
Practicing Continuous DeploymentPracticing Continuous Deployment
Practicing Continuous Deployment
 
ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016
 
QEWD Update
QEWD UpdateQEWD Update
QEWD Update
 
Memcached Code Camp 2009
Memcached Code Camp 2009Memcached Code Camp 2009
Memcached Code Camp 2009
 
Apache httpd 2.4 Reverse Proxy
Apache httpd 2.4 Reverse ProxyApache httpd 2.4 Reverse Proxy
Apache httpd 2.4 Reverse Proxy
 
Codefest2015
Codefest2015Codefest2015
Codefest2015
 
OCCI Specification Walkthrough
OCCI Specification WalkthroughOCCI Specification Walkthrough
OCCI Specification Walkthrough
 
Proxysql ha plam_2016_2_keynote
Proxysql ha plam_2016_2_keynoteProxysql ha plam_2016_2_keynote
Proxysql ha plam_2016_2_keynote
 
Spring in the Cloud - using Spring with Cloud Foundry
Spring in the Cloud - using Spring with Cloud FoundrySpring in the Cloud - using Spring with Cloud Foundry
Spring in the Cloud - using Spring with Cloud Foundry
 
События, шины и интеграция данных в непростом мире микросервисов / Валентин Г...
События, шины и интеграция данных в непростом мире микросервисов / Валентин Г...События, шины и интеграция данных в непростом мире микросервисов / Валентин Г...
События, шины и интеграция данных в непростом мире микросервисов / Валентин Г...
 
Node.js, toy or power tool?
Node.js, toy or power tool?Node.js, toy or power tool?
Node.js, toy or power tool?
 
Proxysql use case scenarios plam 2016
Proxysql use case scenarios    plam 2016Proxysql use case scenarios    plam 2016
Proxysql use case scenarios plam 2016
 
Deploying Plack Web Applications: OSCON 2011
Deploying Plack Web Applications: OSCON 2011Deploying Plack Web Applications: OSCON 2011
Deploying Plack Web Applications: OSCON 2011
 
视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)
 

En vedette

Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"
Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"
Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"
Defcon Moscow
 

En vedette (20)

Hacking routers as Web Hacker
Hacking routers as Web HackerHacking routers as Web Hacker
Hacking routers as Web Hacker
 
Sql-Injection
Sql-InjectionSql-Injection
Sql-Injection
 
Client side
Client sideClient side
Client side
 
Attacking MongoDB
Attacking MongoDBAttacking MongoDB
Attacking MongoDB
 
Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"
Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"
Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"
 
Race condition
Race conditionRace condition
Race condition
 
Web Application Security 101 - 06 Authentication
Web Application Security 101 - 06 AuthenticationWeb Application Security 101 - 06 Authentication
Web Application Security 101 - 06 Authentication
 
LFI
LFILFI
LFI
 
StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection
StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injectionStHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection
StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection
 
How to Close the SecOps Gap
How to Close the SecOps GapHow to Close the SecOps Gap
How to Close the SecOps Gap
 
DevOps with Sec-ops
DevOps with Sec-opsDevOps with Sec-ops
DevOps with Sec-ops
 
AWS Security and SecOps
AWS Security and SecOpsAWS Security and SecOps
AWS Security and SecOps
 
Dev secops opsec, devsec, devops ?
Dev secops opsec, devsec, devops ?Dev secops opsec, devsec, devops ?
Dev secops opsec, devsec, devops ?
 
LCU14 500 ARM Trusted Firmware
LCU14 500 ARM Trusted FirmwareLCU14 500 ARM Trusted Firmware
LCU14 500 ARM Trusted Firmware
 
NoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDBNoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDB
 
Quality assurance in dev ops and secops world
Quality assurance in dev ops and secops worldQuality assurance in dev ops and secops world
Quality assurance in dev ops and secops world
 
Securing the LAN Best practices to secure the wired access network
Securing the LAN Best practices to secure the wired access networkSecuring the LAN Best practices to secure the wired access network
Securing the LAN Best practices to secure the wired access network
 
LCU13: An Introduction to ARM Trusted Firmware
LCU13: An Introduction to ARM Trusted FirmwareLCU13: An Introduction to ARM Trusted Firmware
LCU13: An Introduction to ARM Trusted Firmware
 
Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...
Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...
Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...
 
Secure Your REST API (The Right Way)
Secure Your REST API (The Right Way)Secure Your REST API (The Right Way)
Secure Your REST API (The Right Way)
 

Similaire à Mongo db eng

Shreeraj-Hacking_Web_2
Shreeraj-Hacking_Web_2Shreeraj-Hacking_Web_2
Shreeraj-Hacking_Web_2
guest66dc5f
 
Modern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScriptModern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScript
martinlippert
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
Rob Davarnia
 
Mad development
Mad developmentMad development
Mad development
Eric Lewis
 
JAX 2012: Moderne Architektur mit Spring und JavaScript
JAX 2012: Moderne Architektur mit Spring und JavaScriptJAX 2012: Moderne Architektur mit Spring und JavaScript
JAX 2012: Moderne Architektur mit Spring und JavaScript
martinlippert
 

Similaire à Mongo db eng (20)

Scalable XQuery Processing with Zorba on top of MongoDB
Scalable XQuery Processing with Zorba on top of MongoDBScalable XQuery Processing with Zorba on top of MongoDB
Scalable XQuery Processing with Zorba on top of MongoDB
 
Zedrick girish p_tryambakee 5102589493
Zedrick girish p_tryambakee 5102589493Zedrick girish p_tryambakee 5102589493
Zedrick girish p_tryambakee 5102589493
 
Monogo db in-action
Monogo db in-actionMonogo db in-action
Monogo db in-action
 
AFTAB AHMED.pptx
AFTAB AHMED.pptxAFTAB AHMED.pptx
AFTAB AHMED.pptx
 
Shreeraj-Hacking_Web_2
Shreeraj-Hacking_Web_2Shreeraj-Hacking_Web_2
Shreeraj-Hacking_Web_2
 
Modern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScriptModern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScript
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 
No More Mr. Nice Guy The MEAN Stack
No More Mr. Nice Guy   The MEAN StackNo More Mr. Nice Guy   The MEAN Stack
No More Mr. Nice Guy The MEAN Stack
 
Isomorphic JavaScript with Nashorn
Isomorphic JavaScript with NashornIsomorphic JavaScript with Nashorn
Isomorphic JavaScript with Nashorn
 
Nodejs
NodejsNodejs
Nodejs
 
Architecture of the Web browser
Architecture of the Web browserArchitecture of the Web browser
Architecture of the Web browser
 
Jcon 2017 How to use Swagger to develop REST applications
Jcon 2017 How to use Swagger to develop REST applicationsJcon 2017 How to use Swagger to develop REST applications
Jcon 2017 How to use Swagger to develop REST applications
 
20120306 dublin js
20120306 dublin js20120306 dublin js
20120306 dublin js
 
VIE - Using RDFa to make content editable
VIE - Using RDFa to make content editableVIE - Using RDFa to make content editable
VIE - Using RDFa to make content editable
 
Q con london2011-matthewwall-whyichosemongodbforguardiancouk
Q con london2011-matthewwall-whyichosemongodbforguardiancoukQ con london2011-matthewwall-whyichosemongodbforguardiancouk
Q con london2011-matthewwall-whyichosemongodbforguardiancouk
 
Node JS
Node JSNode JS
Node JS
 
Building single page applications
Building single page applicationsBuilding single page applications
Building single page applications
 
Mad development
Mad developmentMad development
Mad development
 
JAX 2012: Moderne Architektur mit Spring und JavaScript
JAX 2012: Moderne Architektur mit Spring und JavaScriptJAX 2012: Moderne Architektur mit Spring und JavaScript
JAX 2012: Moderne Architektur mit Spring und JavaScript
 
Introduction to meteor
Introduction to meteorIntroduction to meteor
Introduction to meteor
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Mongo db eng

  • 1. Attacking MongoDB Firstov Mihail
  • 2. What is it? MongoDB — is an open source document-oriented database system. Features : 1. Ad hoc queries. 2. Indexing 3. Replication 4. Load balancing 5. File storage 6. Aggregation 7. Server-side JavaScript execution 8. Capped collections
  • 3. Inside mongo source code ./mongod — Server in C++ ./mongo – official client in C++ and JS There are a lot of drivers for different program languages: C C++ Java Javascript .NET (C# F#, PowerShell, etc) Node.js Perl PHP Python Ruby Scala
  • 4. Who use mongoDB List of some big companies that use mongoDB: 1. SAP 2. SourceForge (hosting for open source projects) 3. The New York Times 4. GitHub (social coding project) 5. Foursquare 6. Yandex
  • 5. WTF is RESTful? A RESTful web service (also called a RESTful web API) is a web service implemented using HTTP and the principles of REST. It is a collection of resources, with four defined aspects
  • 6. How I can discover it? Default port is «28017». If server was started without “—rest”, you can see this:
  • 7. How I can discover it?
  • 8. What kind of vulns are there?  Execution of arbitrary code server JS  Stored XSS in mongoDB log  Stored XSS in queries journal  Cross Site Request Forgery Our SSJS code
  • 9. Attack 1) Send “<script>” with our javascript code Site with mongoDB driver support Hacker Admin’s browser Hacker’s Server MongoDB --REST
  • 10. Attack 1) Send “<script>” with our javascript code Site with mongoDB driver support Hacker Admin’s browser 2) Inject our script in REST interface Hacker’s Server MongoDB --REST
  • 11. Attack 1) Send “<script>” with our javascript code Site with mongoDB driver support Hacker Admin’s browser 2) Inject our script in REST interface Hacker’s Server 3) Exec our js-code in MongoDB admin’s browser --REST
  • 12. Attack 1) Send “<script>” with our javascript code Site with mongoDB driver support Hacker 4) Send SSJS command to Admin’s browser our script 2) Inject our script in REST interface Hacker’s Server 3) Exec our js-code in MongoDB admin’s browser --REST
  • 13. Attack 1) Send “<script>” with our javascript code Site with mongoDB driver support Hacker 4) Send SSJS command to Admin’s browser our script 2) Inject our script in REST interface 5) Wait until admin’s browser check our server for the new commands (via JSONP) Hacker’s Server 3) Exec our js-code in MongoDB admin’s browser --REST
  • 14. Attack 1) Send “<script>” with our javascript code Site with mongoDB driver support Hacker 4) Send SSJS command to Admin’s browser our script 2) Inject our script in REST interface 6) Our command gets executed 5) Wait until admin’s browser check our server for the new commands (via JSONP) Hacker’s Server 3) Exec our js-code in MongoDB admin’s browser --REST
  • 15. Attack 1) Send “<script>” with our javascript code Site with mongoDB driver support Hacker 4) Send SSJS command to Admin’s browser our script 7) Send answer to our sniffer 2) Inject our script in REST interface 6) Our command gets executed 5) Wait until admin’s browser check our server for the new commands (via JSONP) Hacker’s Server 3) Exec our js-code in MongoDB admin’s browser --REST
  • 16. Attack 1) Send “<script>” with our javascript code Site with mongoDB driver support Hacker 4) Send SSJS command to 8) Print result Admin’s browser our script of executed 7) Send answer to our sniffer command 2) Inject our script in REST interface 6) Our command gets executed 5) Wait until admin’s browser check our server for the new commands (via JSONP) Hacker’s Server 3) Exec our js-code in MongoDB admin’s browser --REST
  • 17. Video
  • 18. Where we can find it?
  • 19. Stable CRASH There are a lot of concepts of DoS attacks:
  • 20. Interesting features  Ls, cat and other admin functions work only with mongoDb console client.  NativeHelper function helps you with system commands:  You can get data in text/plain by reading db-files of mongoDB with any text editor.
  • 21. Network interaction Adding user: Decrypted salt: Source Code:
  • 22. Network interaction Captured packets: All your data are belong to us:
  • 23. Network interaction Algorithm for sniff and brute force password : Sniff some packets Read string with mongoDB data from dictionary key2 = md5(nonce + user + md5(user + ":mongo:" + passw)), where “passw” is string from dict Get key, nonce, login from this packet Look for auth key == key2 print user:passwd packet false true found Exit Not found
  • 25. Network interaction. MiTM attack 1. Authorization query mongoDB admin Hacker
  • 26. Network interaction. MiTM attack 1. Authorization query mongoDB admin 2. Return special nonce using which rainbow tables were generated Hacker
  • 27. Network interaction. MiTM attack 1. Authorization query mongoDB admin 2. Return special nonce using which rainbow tables were generated Hacker 3. Client sends to us “key” and “login”
  • 28. Network interaction. MiTM attack 4. Brute Force 1. Authorization password using query pre-generated mongoDB rainbow tables for this nonce admin 2. Return special nonce using which rainbow tables were generated Hacker 3. Client sends to us “key” and “login”
  • 29. Network interaction. MiTM attack 4. Brute Force 1. Authorization password using query pre-generated mongoDB rainbow tables for this nonce admin 2. Return special nonce using which rainbow tables were generated 5. Successfully login Hacker 3. Client sends to us “key” and “login”
  • 30. WTF is BSON? What is it? Data types: BSON is a computer data string interchange format used mainly as int a data storage and network double transfer format in the MongoDB DateTime database. The name "BSON" is byte[] based on the term JSON and bool stands for "Binary JSON". null BsonObject BsonObject[] Example?
  • 31. Overwriting variables Some table with 2 documents: Our query to database: Injecting BSON document, and overwriting “isadmin” value: Testing:
  • 32. Reading memory Exploit: Length In action:
  • 34. Features of some programming languages Ruby on Rails nodejs PHP
  • 35. Features of some programming languages Ruby on Rails
  • 36. Features of some programming languages Mass assignment in Ruby on Rails:
  • 37. Features of some programming languages Mass assignment in Ruby on Rails:
  • 38. Features of some programming languages NodeJS
  • 39. Features of some programming languages JSON injection в NodeJS + MongoDB: SEND SEND VULNERABLE SOURCE CODE: VULNERABLE SOURCE CODE: RESULT QUERY: RESULT QUERY: Хакер 02/12 (157)
  • 40. Features of some programming languages PHP
  • 41. Features of some programming languages Types of vulnerabilities: Bypass authorization via Array in php driver. Injecting SSJS code. Blind SSJS injecting, Time-based
  • 42. Features of some programming languages As you know, php processes data from GPC as Array: password[$ne]=parol1 There is find() function in the official driver for php:
  • 43. Features of some programming languages And we got this query to mongoDB collection: With these techniques you can bypass authorization:
  • 44. Features of some programming languages Injecting in SSJS. For example, we have this vulnerable code: $q = “function() { var loginn = ‘$login’; var passs = ‘$pass’; db.members.insert({id : 2, login : loginn, pass : passs}); }”; $db->execute($q); / We can see our login, id and pass in answer Trying to inject in SSJS query: As you can see, we rewrite “login” value by db.version() value
  • 45. Features of some programming languages Sometimes we can’t see answer from our SSJS code. For this situations we can use Time-Based technique: A special script was written for this task.
  • 46. NoSQL-injection Cheat Sheet  db.getName() – Get current DB name  db.members.count() – Get number of documents in the collection  db.members.validate({ full : true}) – Get ALL information about this collection  db.members.stats() – Get information about this collection  db.members.remove() – remove all documents from current collection  db.members.find().skip(0).limit(1) – Get documents from DB (Change only number in skip() function)  db.getMongo().getDBNames().toString() – Get the list of all DBs  db.members.find()[0][‘pass’] – Get “pass” value from current collection
  • 47. Thanks! Firstov Mikhail mfirstov@ptsecurity.ru