Suppose I do the following:
- I create a MySQL database, and populate it with some data.
- I create a MySQL user who has access only to that database, and who only has SELECT privileges.
- I create a web page through which a user (any user, no password required) can enter arbitrary SQL, and on submitting the form, a script attempts to run the SQL as the MySQL user I created; any result set generated is displayed to the user; any error message generated is displayed to the user.
- Assume that the database contains no stored procedures etc, just tables and views, and that I am happy for anybody to see any of the contents of that specific database.
We assume that the setup will be probed by a malicious user. What is the worst that could happen?
Some thoughts:
- MySQL provides various statements like SHOW etc. that a user even having only SELECT privileges could use to gather information about the database server or about my databases. Other information could be obtained from error messages. While probably not sufficient to gain improper access, this information could surely help in doing so.
- There might be flaws in the database software, or in my scripts, or in the scripting language itself, that could allow a visitor to do things they are not supposed to be able to do through this interface.
- Doing this might violate a terms of service agreement, particularly if I am using shared hosting.
Hmmm. Clever users may attack via syntax like:
And there’s a denial of service attack that could blow memory, like:
And frankly, it’s hard enough for experienced programmers to write queries that behave well… what chance does a poor user have even if they try to write a good query