Okay, thank you everybody for coming or staying. So this talk is going to be about NoSQL, No Injections. My name is Wayne Huang. I am co-founder and CTO to Amorize Technologies. And my colleague, Kuang Ding, was a founding member. He was the first person to our Amorize Special Force team more than four years ago. This research was mostly done by Kuang. While I will be the presenter because I speak better English. Most of Amorize are based out of Taipei, and we're all from Taiwan. So this research started when we were crawling so much of the web to identify malware, and we had to ourselves implement a NoSQL solution and basically just retire. And together we come up with our own relational database solution. Amorize has two teams. The first on is a static analysis. So we write parsers and compilers, and we check for vulnerabilities inside codes. Actually this is more related to that team. But this research actually started from the other team crawling the web in search for malware. Because the data was getting much too big for traditional relational databases to handle. So that team, the Hackler team, started to do this research, but then this research would then actually benefit the CodeSecure team because as we see more and more NoSQL code, we need to know how to scan for vulnerabilities inside that code. And this is how the talk came about. So the slides are on SlideShare now, and if you go to my Twitter, you would get the link to the three of our talks this year at DEF CON. The next talk is going to be tomorrow. It's about how we automatically cluster the malware that we find using OBOX. So today we're going to be talking about what is NoSQL, types of NoSQL, who uses NoSQL, and so where the threats are. Note the NoSQL architecture. Security issues surrounding NoSQL and different families of NoSQL, and prevention and detection, and how NoSQL is affecting the current security technologies. So what is NoSQL? NoSQL technologies do not... Some common misconceptions. NoSQL technologies do not support SQL. The fact is, a lot of them do. NoSQL is a technology that is used to support SQL. NoSQL technologies are not vulnerable to threats such as SQL injection because there's NoSQL. One of the most commonly accepted definitions would be NoSQL is not only a SQL, and the storage itself is a non-relational DBMS, which can be semi-structured and schema-less, or sometimes, perhaps, even schema-less, or even schema-free, for example, in a key-value data store. So types of NoSQL, there are a lot of families to NoSQL. Key-value-based databases, column-based databases, document-based databases, graph-based databases, object-based databases, et cetera. So what's challenging for security users and security researchers today is NoSQL is resembled by its diversity. There are a lot of families, and then within the same family of NoSQL, implementations differ widely. And that presents a very big challenge as we see it. So why NoSQL? Why do people need to use the NoSQL technology? Well, mostly for two very important reasons. Performance and scalability. So who would use NoSQL, and so what's the impact? Cloud computing users or providers, or SaaS vendors, social network services providers, portal websites, and basically people that needs to process large amounts of data. And typically, they would use a mixture of databases which include both SQL databases and NoSQL databases. And that is, for example, what our current implementation is as well. So what's changed from the past, from SQL to NoSQL? So here's a typical NoSQL architecture. We have the web application and web services in the front. And in the center is the client library, which the web application and web services interact with. And then below is the NoSQL data storage. And the client library is gonna be the focus for security researchers as well as the attackers, because that's where the web application and web services are interfacing with the data storage. So the client library implementation, right now, has no standards such as ODBC, JDBC, ADO, PDO, et cetera. So these questions would strongly affect the security standing and aspects of these client libraries. How is it implemented? What interfaces does it support? Does it support a query interface? And here you see a CouchDB, oh, sorry, a CouchDB implementation of its SQL interface. Oh, I'm sorry, CouchQL. And as you can see, it looks very much like SQL. And in fact, it is a subset of SQL. While CouchDB itself is a NoSQL, it's also a NoSQL database. And so here, this, how this client library is implemented will affect what types of vulnerabilities would exist in this particular implementation. And so let's make room and let's look for, let's look at the old vectors versus the new vectors. So in the old days, there was only one horizontal vector. The SQL, right? And so, within that horizon, you would have, we would have ODBC, JDBC, ADO, PDO, what have you, for us and for, or for the attackers to do their SQL injections. Now, we have key value based databases and they may implement two versions, at least two versions of their client libraries, the Qo-like and the non-Qo-like. QO like. And these two different versions would have a lot of different implementations. And the same thing would be happening to column-based NoSQL databases. And the same thing happens to document-based NoSQL databases. So let's make room. Same thing happens to graph-based NoSQL databases. And the same thing happens to object-based NoSQL databases. So this is the landscape as we see it today. So as a vendor that developed static analysis tools to scan for security vulnerabilities, before we, for example, for database manipulation, for command injection, we had to scan for only a few categories. And SQL injection was among these categories. But now, if we want to support if we want to scan for NoSQL vulnerabilities, we end up with a landscape that looks like that down there. So perhaps it was a blessing that in the past, the notion of RDBMS matured, the notion of SQL matured, and SQL implementation standards matured as well, ODBC, JDBC, et cetera. And therefore, as new websites came out, as new frameworks came out, as new languages came out, everyone basically followed existing standards, ODBC, JDBC, ADO, PDO, et cetera, right? And so they weren't creating their own ways to access the database. Basically, even when new languages came out sometimes, they followed the SQL standard and implement some SQL-like interface or adopt ODBC or JDBC. But today, new implementations for yet another programming language's support to use yet another family of NoSQL is invented as needed. And that creates that picture there. And this is basically the threat that we see today. We see very, very few research on this topic. Apparently, the open source scanners, as well as the commercial scanners right now, they're not going to be able to do that. Now, haven't put a lot of effort into studying threats that exist here. However, more and more and more websites are starting to use NoSQL technologies. So we've covered the general topics. Now, let's look at the specific examples of vulnerabilities. So we'll be looking at some examples of NoSQL vulnerabilities. So we'll be looking at some examples of NoSQL vulnerabilities. And we'll be looking at some example of vulnerabilities, including connection pollution, JSON injection, view injection, key brute forcing, and key brute forcing. Sorry. Connection pollution using CouchDB as example. And CouchDB, the entire CouchDB interface is implemented in RESTful, which allows for cross-database or cross-pull access through restful and all of couch DB's global and database handlers are also implemented in restful so the this creates some attack vectors that are easier than before for example if we can manipulate the connector here if we can somehow manipulate the connector here then without further manipulation just by manipulating the connector itself we can restart a couch DB database and here is the list of all some of CouchDB's handlers that would allow us to execute a lot of commands if we're able to manipulate the connector. And, for example, the configuration itself is also in a RESTful interface. So, by manipulating the connector, we can also directly see the configuration of the database, which actually took a lot more steps in SQL injection. And here, and a lot of people, a lot of people, a lot of people thought that, okay, so you can still manipulate data flow, or you can still manipulate SQL commands. In a NoSQL implementation, however, real SQLs are very powerful. MySQL database is a very powerful set of SQL commands, which allowed you to execute system commands, for example. And then, so even if your NoSQL, even if my NoSQL implementation implements a SQL-like interface, well, most likely, there won't, you won't be able to execute database commands. You can, maybe you can, you can, you can, you can, you can, you know, manipulate, manipulate my database a bit, but you can't execute system commands. Well, that, that might not be true, because in this example that you see here, this is again CouchDB. If I am able to manipulate the configuration through the RESTful interface, then I can change the, the, the Javascript interpreter of CouchDB, and as you see here, we've changed it to JSF. as 2.exe which can be a file that we put on to the system or an arbitrary system command or system executable. So executing database, executing arbitrary commands through manipulation of the client interface is possible as well. And then what makes it harder, even when an injection vector exists, cross DB, cross databases is difficult. Cross databases was very easy with SQL injection because the SQL commands supported naming of databases so you can jump databases once you can manipulate SQL command. But it is absolutely not true in most SQL, in most NoSQL implementations. So traditionally what happens in a traditional SQL is you get connected, you do SQL injection and then you jump from one DB or one table to another. This is difficult to do in NoSQL implementation. So what you need to do is you need to find ways to inject variables, to inject something into the connection for you to do that. So basically once the connector is established, you're limited to that context in most NoSQL implementations. So document based issues, JSON injection as an example, also using CouchDB. And this is about data manipulation. So a lot of times it's really hard to do. And so I recommend that we do not implement our own JSON parser or handler, but sometimes you just have to. For example when you're handling very, very large JSON replies and existing ones are just too slow. But the key here is try, don't repeat yourself, leverage existing JSON implementation. Because if you really want to implement one, then there is risk because the trouble is with the stuff you're doing with JSON, you can't JavaMaker is a string type, and if we don't handle JSON well, there will be JSON injection. And when JSON injection happens in CouchDB, that is directly manipulating the data stored in the database. So the countermeasure is try to use collection types, such as hash and map, instead of manipulating the bare strings themselves. And when handling tented strings, at least we must remember to escape JSON and not escape JSON. Now view injection. I was using CouchDB. View injection allows for application manipulation. So CouchDB is scriptable, using SpiderMonkey as the scripting engine. So these JavaScripts are called views. In CouchDB, they're called views. In CouchDB, redefined views, and so there's redefined views and temporary views. And views are basically to do map reduce using JavaScript. And they allow for, and they're used to retrieve arbitrary data, modify return values to manipulate control flow. Oh, yeah. So if we can inject JavaScript. Into CouchDB as views, what we can do is we can then use that JavaScript data, use that JavaScript execution to retrieve arbitrary data, modify return values to manipulate control flow, and a lot of other things. So this is what we call view injection. It's basically when you inject JavaScript into CouchDB. And so as you can see, here is a typical example. So right here, as you can see, the view, the view is here, and the map is actually JavaScript, and it's executing it with SpiderMonkey. So if we can inject into this field, then we can just, we can basically do application manipulation. Okay. All right. So all these were injection issues in a NoSQL application, right? So NoSQL equals NoSQL injections, not necessarily, not necessarily. Key value-based problems. In a key value-based database, we can at least do key brute forcing. Key value-based databases are schema-free. So we don't have to get schema. So but then in a key value database, when we're doing key brute forcing, the key now is how to speed up the attacks. It really depends on the implementation of the client library and architecture. The challenge is can we make sense, context-sensitive attacks, meaning that we send a key and we do some static analysis. And according to the calculation, we can do some static analysis. The time in the calculation or the response differences, we can say, we can speed up this process and say, okay, this key, we can make quick judgment and say, this key doesn't exist in the key value data store. And that's how it usually looks like. And so we call this key brute forcing. Note that we're not manipulating the data flow at all. Okay. For example. For a video streaming website, for example, YouTube, there's typically a key associated with every video that gets eventually fed into the NoSQL database to retrieve that piece of video. So you don't need to manipulate anything for it to execute NoSQL dot get key, but you can very easily brute force the key. So prevention, it really depends on how data is modeled because there's no schema. So if, for example, we're storing all personal records in a single key data database, then once that is brute forced. Okay. They can get everything out, right? So it really depends on how your application logic is segmenting the data, how your application is modeling the data. Again, there's no schema. So data modeling is done by the application itself. And the key size, key space, and also unpredictable key generation algorithm. And also it can be challenge based. For example, asking for CAPTCHAs. Okay. And the impact on security technologies when these NoSQL implementations are adopted by websites. How NoSQL technologies would impact web application scanners. For traditional scanning, how to handle unknown error messages, meaning that for traditional black box scanners. Okay. Okay. Because most of them rely on knowing existing error messages of SQL databases and there aren't that many SQL databases, and so there aren't that many formats to database error messages. But here, as we saw, there's going to be a big wave of new formats to new error messages coming out. Okay. how would a web application scanner support all these new error messages? And then if we don't recognize the error messages, how to do blind injections? If a query language exists, how to perform logic-based blind injections? And then can we do time-based differential attacks based on static analysis as mentioned previously? And then finally, different types of attack payloads. Right now, well-known scanners, for example, commercial ones, Web Impact, Watchfire, Acunetix, Senzic, they all have a good database of attack payloads to execute against a website in order to find, for example, injection flaws. But how about for NoSQL implementations? So, first of all, the different languages, both in terms of data and programming. For example, for data manipulation, and by that we're referring to JSON injections, what is the language to be used? It's JSON. So, do we have a JSON-based pattern database for our injection purpose? And for programming languages, what is the language to be used? So, if we're doing language manipulation, for example, on CouchDB, then we're doing basically view injections. We're injecting JavaScript. Do we have that type of payload database for us to test out view injections inside a NoSQL web application? And then second one is the fact, the impact of a schema-less injection. Basically, because it's schema-less, the attack surface is redefined. Why? Because data is modeled not by SQL, but by the application itself. And therefore, the attack vectors are very, very sensitive to the entry points. Before it was not. Before it was, it doesn't matter which URL. It really didn't matter in which URL we're finding a SQL injection. When we find a SQL injection, that's a SQL injection, and we can jump tables, we can jump databases, we can execute system commands. But here, because everything, as we saw previously, is bound to the connector, the type of things that we can do, once we can manipulate the flow, the data, or the application itself, really depends on which URL. We're finding it in. And so, as the web developer, or the application developer, if they segment out and model out their NoSQL implementation well, their code would be a lot more secure. Because a lot of the entry points are not very useful, even if they're attacked. But then, how would a web application scanner test for this? And then, there are different attack concepts that can be played. For example, key brute forcing. Brute forcing the key, which is a very valid type of attack against, especially, just particularly NoSQL implementations. But are there any web application scanners implementing this type of checks? And then, so selecting the payload requires understanding of the data. Understanding of the underlying database. So, how to blindly identify URLs involving NoSQL. Right? So, now when you're a web scanner, when you're a pen tester, you go onto a website, you see a URL. How do you know what's behind this URL? Are there SQL databases, or are there NoSQL databases? And if there are NoSQL databases, what set of payload are you going to fire against that URL? Are you going to fire JSON manipulation? Or JavaScript injection? Or are you going to fire traditional SQL injection attack? Well, there are ways to find this out. Usually, NoSQL implementations of the SQL interface will be a subset of the SQL 9295. And, however, features that will impact parallelization typically will be removed. For example, UNION. So, when you start to see that you can manipulate the SQL command, but some of these commands are absent, especially, for example, commands like UNION, you know then it's probably an underlying, underneath is probably a NoSQL. NoSQL impacts on static analysis, or source code analysis. Source code analysis checks back. It's by data flow, so there's less of a problem. But diversity is a big problem, because you have to support so many, you have to recognize so many implementations of NoSQL databases. And so, right now, there are a lot of unsupported client libraries. But, in general, it's a lot easier than web application scanners. Sorry. NoSQL versus web application firewalls. Key brute forcing is not an injection attack. And it can be blocked by accessing thresholds. By access thresholds, for example. And so, web application firewalls has a good potential at blocking a lot of these attacks. A lot of these new attack vectors. Versus web application firewalls. So, web application scanners and static analysis tools, which are having a hard time finding these. Because web application firewalls are transparent, basically. To the back end. Or, web application WAFs can also help do URL integrity checks. For example, it can add some kind of HMAC to the key. HMAC to the key. Definition of attack payloads is going to be a challenge. So, what is a data or JSON injection? And what is a view or JavaScript injection? Right now, WAFs are very good at recognizing, okay, this is a SQL injection. So, I'm going to block it. This is probably a cross-site scripting. So, I'm going to block it. But, how will it develop patterns to detect attacks? Attacks against NoSQL databases. What are the patterns to these attacks? That's going to be the challenge. So, conclusion. Threat analysis must be conducted under a NoSQL mindset. Because a NoSQL implementation is so different from a SQL. The threat landscape is really, really different. Modeling of data is done by the application logic and not the SQL statement or database schema. And so, the threat is very sensitive to the entry point. So, where you're finding the vulnerability becomes critical. And not just, okay, I found a SQL injection. Great, I can do this and I can do that. Threat types are different. For example, new attack vectors would come out. And it impacts. And so, all of these would impact. Existing security technologies. And we'd love to hear your comments. Because we're considering implementing static and black box scanners as tools. Just for NoSQL technologies. But right now, because there's so many of them, we're also ourselves still in the research phase. So, if you'd like to join us. If you'd like to develop open source tools with us. We'd be very, very happy. So, please send us your comments. And we thank you for attending the talk. Thank you. Thank you.