Is it possible to SQL inject JS files?

186 views
Skip to first unread message

Jun Yin

unread,
Sep 15, 2021, 3:22:10 AM9/15/21
to OWASP ZAP Developer Group
High (Medium)高级SQL注入- MySQL > 5.0.11 stacked queries (SELECT - comment)
Description

A SQL injection may be possible using the attached payload



URL
https://www.xxxxx.xxx/view/global/user/mobile/js/plugins/swiper.min.js?1531331694=%3B%28SELECT+*+FROM+%28SELECT%28SLEEP%285%29%29%29dlRO%29%23
Method
GET
Parameter
1531331694
Attack
;(SELECT * FROM (SELECT(SLEEP(5)))dlRO)#
Instances
1
Solution

Do not trust client side input, even if there is client side validation in place.

In general, type check all data on the server side.

If the application uses JDBC, use PreparedStatement or CallableStatement, with parameters passed by '?'

If the application uses ASP, use ADO Command Objects with strong type checking and parameterized queries.

If database Stored Procedures can be used, use them.

Do *not* concatenate strings into queries in the stored procedure, or use 'exec', 'exec immediate', or equivalent functionality!

Do not create dynamic SQL queries using simple string concatenation.

Escape all data received from the client.

Apply a 'whitelist' of allowed characters, or a 'blacklist' of disallowed characters in user input.

Apply the privilege of least privilege by using the least privileged database user possible.

In particular, avoid using the 'sa' or 'db-owner' database users. This does not eliminate SQL injection, but minimizes its impact.

Grant the minimum database access that is necessary for the application.


Other information

查询时间是可控使用参数值[;(SELECT * FROM (SELECT(SLEEP(5)))dlRO)#],引起请求只需要[26,141] 毫秒,当原始的未修改查询值[] 平均要[1,642.311] 毫秒。


PS:

I understand that only the action of operating the database can cause problems related to SQL injection. If you are accessing purely static resources, such as JS, CSS, image, etc., there should be no possibility of SQL injection. I wonder if my understanding is correct? In the above scanning, the access to JS files prompts SQL injection. Is this judgment wrong?


thanks.





kingthorin+owaspzap

unread,
Sep 15, 2021, 11:24:19 AM9/15/21
to OWASP ZAP Developer Group
If you want to understand specifically what ZAP's doing you can review the code of the scan rules here: https://github.com/zaproxy/zap-extensions

In this particular case ZAP is alerting on a time based injection, so if the performance of the server was impacted by the scan or other testing/use at the time then it's likely a false positive. Unless you're actually serving js/css content from a DB.
Reply all
Reply to author
Forward
0 new messages