70 points · by cottenio · 7y ago · 43 comments
Plus, realistically, SLEEP allows you to scan for thousands of different test cases in a quick period and measure the hang time to figure out which vector worked.
AND 1 IN (SELECT BENCHMARK(SOME_MULTIPLIER*15000000,MD5(CHAR(97))))--Because it's a good "canary" for SQL injection: it doesn't do any real damage, but it's noticeable enough to tell you that you have a possibly vulnerable condition.
I'm not sure about that. You can perform blind exfiltration of row data by using SLEEP. Handy in situations where you can run a query but can't get it reflected in the server's output.
Given the function has a valid use and there are other ways to do damage to the database system, I don't see it's something that stands out. There are numerous ways for doing database probe or even RCE, thus this is no more than one of them.
https://www.esecurityplanet.com/network-security/most-common...
https://www.ptsecurity.com/ww-en/analytics/web-application-a...
Though having worked as a penetration tester I can say that, while rare, it was certainly not unheard of for a client's web application to be vulnerable to SQL injection. And this is for clients who are willing to spend several $1000s on a penetration test for their website - imagine what its like for people who don't give a second thought to the security of their site.
This is not a sound assumption. SQL injection is still pretty common in practice. Even frameworks that try to sanitize input may have a "roll your own" approach that has flaws in it.
Afaict the only reason this idea ever became widespread was because PHP's native MySQL driver lacked support for it for ages (I guess till PHP5? Been years since I looked into this)
[1] Obviously I'm not talking about validation eg validating a phone number; anytime you're trying to embed strings within a program but have to be worry that your string doesn't get read as part of the program, something has gone horribly wrong
Here's a decent example of doing it right:
https://stackoverflow.com/questions/14767530/php-using-pdo-w...
Here's one showing noobs how to do it wrong:
http://pdo.w3clan.com/tutorial/176/like-clause-in-clause-and...
Look at that blind implode function. Argh. It's the danger of copy/paste echo-chambers.
https://www.postgresql.org/docs/current/functions-datetime.h...
SELECT pg_sleep(1.5);
SELECT pg_sleep_for('5 minutes');
SELECT pg_sleep_until('tomorrow 03:00');
Maybe useful for debugging? https://www.endpoint.com/blog/2012/11/05/how-to-make-postgre...Why not monitor for SLEEP execution instead?
Being able to enumerate vulnerable spots or exfiltrate data can arguably be more devastating than performing a DROP that's noticed immediately and the LKG table from backup is imported to fix it.
AND 1 IN (SELECT BENCHMARK(SOME_MULTIPLIER*15000000,MD5(CHAR(97))))--It’s the exposition of things that “act” on lax query permission sets that “appear” read-only (but in fact have interrupt style executions) that leads to trivialization of abuse.
If this is the case, removing sleep doesnt help you. Just run a slow query
https://dev.mysql.com/doc/refman/8.0/en/with.html#common-tab...
Though one can set a limit on query run time via max_execution_time.