-11-
SQL Injection Isn't Dead: Smuggling Queries at the Protocol Level - @pspaul
SQL injection attacks exploit vulnerabilities in web applications that fail to properly sanitize user input, allowing attackers to inject malicious SQL code into database queries.
In the past, they were as prevalent as can be when it comes to web app vulnerabilities, but recent advances in web servers' default configurations and protection mechanisms have made them harder to exploit. This is evident by their ranking in the well-known OWASP Top 10 project.
However, in this talk, Paul shows an exciting new avenue for these vulnerabilities — attacking the underlying protocol!
When it comes to databases today like PostgreSQL, MySQL, Redis and MongoDB, servers communicate with them over the wire using a binary protocol. This binary protocol is TLV-based: first, the type of message, then its length, and finally, the value. So your SQL query is actually embedded within such a "packet".
While these binary protocols are commonplace in web servers' communication with peripherals, Paul focused on databases, and specifically how the length field of a message is handled by libraries when it receives a very large message, namely, more than the size that could fit in a 32-bit field.
He discovered that prominent open-source packages handling connecting and querying PostgreSQL and MongoDB, upon receiving a message longer than 232 bytes, calculate the length of the message correctly while truncating it to 32-bit before writing the length field.
This means that a message just over 232 bytes arrives at the database prepended with a length field which is very small, leaving the rest of the message to be accidentally parsed as packets! This gives a theoretical attack full control over queries.
While data exfiltration is almost not possible (the application usually returns the result of the first query), attackers can simply add a new user with high privileges to the database and use it to steal data.
On discovery, Paul wasn't satisfied with the vulnerability's exploitability — a potential attacker wouldn't know exactly the server's query and where the malicious payload is embedded, they have to send multiple 2GB queries, making the exploit very long and noisy. Through some nice tricks, borrowed from the world of shellcodes, he managed to reduce the attack process to at most 2 tries!
This research avenue still has a lot of possibilities open — Paul only scratched the surface. Binary protocols are used extensively for communication with many other applications like logging, storage, queues and caches. Even for databases — just a subset were inspected.
An enlightening talk, showing how produce it can be to take an approach and techniques used in one area of vulnerability research (in this case HTTP desync attacks by James Kettle) and applying it to a completely different domain.
#DEFCON #databases #sqli #vulnerability
https://www.youtube.com/watch?v=Tfg1B8u1yvE